1010
1111#include < benchmark/benchmark.h>
1212
13+ #ifdef FPGA_USE_INTEL_HEXL
14+ #include " hexl/hexl.hpp"
15+ #else
1316#include " hexl-fpga.h"
17+ #endif
1418
1519static uint32_t get_iter () {
1620 char * env = getenv (" ITER" );
@@ -101,8 +105,6 @@ std::vector<std::string> keyswitch::glob(const char* pattern) {
101105
102106void keyswitch::setup_keyswitch (const std::vector<std::string>& files) {
103107 for (size_t i = 0 ; i < files.size (); i++) {
104- std::cout << " Constructing Test Vector " << i << " from File ... "
105- << files[i] << std::endl;
106108 test_vectors_.push_back (KeySwitchTestVector (files[i].c_str ()));
107109 }
108110
@@ -111,22 +113,35 @@ void keyswitch::setup_keyswitch(const std::vector<std::string>& files) {
111113}
112114
113115void keyswitch::bench_keyswitch () {
116+ #ifndef FPGA_USE_INTEL_HEXL
114117 intel::hexl::set_worksize_KeySwitch (test_vector_size_ * n_iter);
118+ #endif
119+
120+ #ifndef FPGA_USE_INTEL_HEXL
121+ // HEXL-FPGA version of keyswitch
122+ namespace ns = intel::hexl;
123+ #else
124+ // HEXL CPU version of keyswitch
125+ namespace ns = intel::hexl::internal;
126+ #endif
127+
115128 for (size_t n = 0 ; n < n_iter; n++) {
116129 for (size_t i = 0 ; i < test_vector_size_; i++) {
117- intel::hexl ::KeySwitch (test_vectors_[i].input .data (),
118- test_vectors_[i].t_target_iter_ptr .data (),
119- test_vectors_[0 ].coeff_count ,
120- test_vectors_[0 ].decomp_modulus_size ,
121- test_vectors_[0 ].key_modulus_size ,
122- test_vectors_[0 ].rns_modulus_size ,
123- test_vectors_[0 ].key_component_count ,
124- test_vectors_[0 ].moduli .data (),
125- test_vectors_[0 ].key_vectors .data (),
126- test_vectors_[0 ].modswitch_factors .data ());
130+ ns ::KeySwitch (test_vectors_[i].input .data (),
131+ test_vectors_[i].t_target_iter_ptr .data (),
132+ test_vectors_[0 ].coeff_count ,
133+ test_vectors_[0 ].decomp_modulus_size ,
134+ test_vectors_[0 ].key_modulus_size ,
135+ test_vectors_[0 ].rns_modulus_size ,
136+ test_vectors_[0 ].key_component_count ,
137+ test_vectors_[0 ].moduli .data (),
138+ test_vectors_[0 ].key_vectors .data (),
139+ test_vectors_[0 ].modswitch_factors .data ());
127140 }
128141 }
142+ #ifndef FPGA_USE_INTEL_HEXL
129143 intel::hexl::KeySwitchCompleted ();
144+ #endif
130145}
131146
132147BENCHMARK_F (keyswitch, 16384_6_7_7_2)
@@ -149,6 +164,9 @@ BENCHMARK_F(keyswitch, 16384_6_7_7_2)
149164
150165 setup_keyswitch (files);
151166
167+ // warm up the FPGA kernels specially the twiddle factor dispatching kernel
168+ bench_keyswitch ();
169+
152170 for (auto st : state) {
153171 bench_keyswitch ();
154172 }
0 commit comments