Skip to content

Commit c481ba9

Browse files
committed
move hashtable generation outside timing
1 parent 483f2ef commit c481ba9

File tree

3 files changed

+51
-55
lines changed

3 files changed

+51
-55
lines changed

hashtable/CUDA/src/main.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,18 @@
1717
#include "vector"
1818
#include "chrono"
1919
#include <cstring>
20+
#include "linearprobing.h"
2021

22+
// #define DEBUG_TIME
2123
#define CPP_MODULE "MAIN"
22-
#include "linearprobing.h"
2324

2425
#define TIMER_START() time_start = std::chrono::steady_clock::now();
2526
#define TIMER_END() \
2627
time_end = std::chrono::steady_clock::now(); \
2728
time_total = std::chrono::duration<double, std::milli>(time_end - time_start).count();
2829
#define TIMER_PRINT(name) std::cout << name <<": " << time_total / 1e3 << " s\n";
2930

30-
// #ifndef DEBUG_TIME
31-
// #define DEBUG_TIME
32-
// #endif
33-
34-
#ifdef DEBUGTIME
31+
#ifdef DEBUG_TIME
3532
#define START_TIMER() start_time = std::chrono::steady_clock::now();
3633
#define STOP_TIMER() \
3734
stop_time = std::chrono::steady_clock::now(); \
@@ -132,8 +129,6 @@ int main(int argc, char* argv[])
132129
std::chrono::steady_clock::time_point time_end;
133130
double time_total = 0.0;
134131

135-
TIMER_START()
136-
137132
try {
138133

139134
// To recreate the same random numbers across runs of the program, set seed to a specific
@@ -148,25 +143,30 @@ int main(int argc, char* argv[])
148143
// for (uint32_t n = 0; n < NUM_LOOPS; ++n) {
149144
// printf("Initializing keyvalue pairs with random numbers...\n");
150145

151-
std::vector<KeyValue> insert_kvs = generate_random_keyvalues(rnd, kNumKeyValues);
152-
std::vector<KeyValue> lookup_kvs = shuffle_keyvalues(rnd, insert_kvs, kNumKeyValues / 2);
153-
std::vector<KeyValue> delete_kvs = shuffle_keyvalues(rnd, insert_kvs, kNumKeyValues / 2);
154-
155-
// Begin test
156-
// printf("Testing insertion/deletion of %d/%d elements into GPU hash table...\n",
157-
// (uint32_t)insert_kvs.size(), (uint32_t)delete_kvs.size());
158-
159146
#ifdef DEBUG_TIME
160147
std::chrono::steady_clock::time_point start_time;
161148
std::chrono::steady_clock::time_point stop_time;
162149
double duration = 0.0;
163150
double tot_time = 0.0;
164151

152+
START_TIMER();
153+
#endif
154+
std::vector<KeyValue> insert_kvs = generate_random_keyvalues(rnd, kNumKeyValues);
155+
std::vector<KeyValue> lookup_kvs = shuffle_keyvalues(rnd, insert_kvs, kNumKeyValues / 2);
156+
std::vector<KeyValue> delete_kvs = shuffle_keyvalues(rnd, insert_kvs, kNumKeyValues / 2);
157+
158+
#ifdef DEBUG_TIME
159+
STOP_TIMER();
160+
PRINT_TIMER("generate_hashtable ");
161+
#endif
162+
163+
TIMER_START()
164+
165+
#ifdef DEBUG_TIME
165166
START_TIMER();
166167
#endif
167168
checkCUDA(cudaSetDevice(0));
168169

169-
// Time timer = start_timer();
170170
#ifdef DEBUG_TIME
171171
STOP_TIMER();
172172
PRINT_TIMER("init ");

hashtable/HIP/src/main.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,18 @@
1717
#include "vector"
1818
#include "chrono"
1919
#include <cstring>
20+
#include "linearprobing.h"
2021

22+
// #define DEBUG_TIME
2123
#define CPP_MODULE "MAIN"
22-
#include "linearprobing.h"
2324

2425
#define TIMER_START() time_start = std::chrono::steady_clock::now();
2526
#define TIMER_END() \
2627
time_end = std::chrono::steady_clock::now(); \
2728
time_total = std::chrono::duration<double, std::milli>(time_end - time_start).count();
2829
#define TIMER_PRINT(name) std::cout << name <<": " << time_total / 1e3 << " s\n";
2930

30-
// #ifndef DEBUG_TIME
31-
// #define DEBUG_TIME
32-
// #endif
33-
34-
#ifdef DEBUGTIME
31+
#ifdef DEBUG_TIME
3532
#define START_TIMER() start_time = std::chrono::steady_clock::now();
3633
#define STOP_TIMER() \
3734
stop_time = std::chrono::steady_clock::now(); \
@@ -132,8 +129,6 @@ int main(int argc, char* argv[])
132129
std::chrono::steady_clock::time_point time_end;
133130
double time_total = 0.0;
134131

135-
TIMER_START()
136-
137132
try {
138133

139134
// To recreate the same random numbers across runs of the program, set seed to a specific
@@ -148,25 +143,30 @@ int main(int argc, char* argv[])
148143
// for (uint32_t n = 0; n < NUM_LOOPS; ++n) {
149144
// printf("Initializing keyvalue pairs with random numbers...\n");
150145

151-
std::vector<KeyValue> insert_kvs = generate_random_keyvalues(rnd, kNumKeyValues);
152-
std::vector<KeyValue> lookup_kvs = shuffle_keyvalues(rnd, insert_kvs, kNumKeyValues / 2);
153-
std::vector<KeyValue> delete_kvs = shuffle_keyvalues(rnd, insert_kvs, kNumKeyValues / 2);
154-
155-
// Begin test
156-
// printf("Testing insertion/deletion of %d/%d elements into GPU hash table...\n",
157-
// (uint32_t)insert_kvs.size(), (uint32_t)delete_kvs.size());
158-
159146
#ifdef DEBUG_TIME
160147
std::chrono::steady_clock::time_point start_time;
161148
std::chrono::steady_clock::time_point stop_time;
162149
double duration = 0.0;
163150
double tot_time = 0.0;
164151

152+
START_TIMER();
153+
#endif
154+
std::vector<KeyValue> insert_kvs = generate_random_keyvalues(rnd, kNumKeyValues);
155+
std::vector<KeyValue> lookup_kvs = shuffle_keyvalues(rnd, insert_kvs, kNumKeyValues / 2);
156+
std::vector<KeyValue> delete_kvs = shuffle_keyvalues(rnd, insert_kvs, kNumKeyValues / 2);
157+
158+
#ifdef DEBUG_TIME
159+
STOP_TIMER();
160+
PRINT_TIMER("generate_hashtable ");
161+
#endif
162+
163+
TIMER_START()
164+
165+
#ifdef DEBUG_TIME
165166
START_TIMER();
166167
#endif
167168
checkCUDA(hipSetDevice(0));
168169

169-
// Time timer = start_timer();
170170
#ifdef DEBUG_TIME
171171
STOP_TIMER();
172172
PRINT_TIMER("init ");

hashtable/SYCL/src/main.cpp

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,17 @@
1717
#include "vector"
1818
#include "chrono"
1919
#include <cstring>
20-
21-
#define CPP_MODULE "MAIN"
2220
#include "linearprobing.h"
2321

24-
#include <sycl/sycl.hpp>
22+
// #define DEBUG_TIME
23+
#define CPP_MODULE "MAIN"
2524

2625
#define TIMER_START() time_start = std::chrono::steady_clock::now();
2726
#define TIMER_END() \
2827
time_end = std::chrono::steady_clock::now(); \
2928
time_total = std::chrono::duration<double, std::milli>(time_end - time_start).count();
3029
#define TIMER_PRINT(name) std::cout << name <<": " << time_total / 1e3 << " s\n";
3130

32-
// #ifndef DEBUG_TIME
33-
// #define DEBUG_TIME
34-
// #endif
35-
3631
#ifdef DEBUG_TIME
3732
#define START_TIMER() start_time = std::chrono::steady_clock::now();
3833
#define STOP_TIMER() \
@@ -134,8 +129,6 @@ int main(int argc, char* argv[])
134129
std::chrono::steady_clock::time_point time_end;
135130
double time_total = 0.0;
136131

137-
TIMER_START()
138-
139132
try {
140133

141134
// To recreate the same random numbers across runs of the program, set seed to a specific
@@ -150,26 +143,29 @@ int main(int argc, char* argv[])
150143
// for (uint32_t n = 0; n < NUM_LOOPS; ++n) {
151144
// printf("Initializing keyvalue pairs with random numbers...\n");
152145

153-
std::vector<KeyValue> insert_kvs = generate_random_keyvalues(rnd, kNumKeyValues);
154-
std::vector<KeyValue> lookup_kvs = shuffle_keyvalues(rnd, insert_kvs, kNumKeyValues / 2);
155-
std::vector<KeyValue> delete_kvs = shuffle_keyvalues(rnd, insert_kvs, kNumKeyValues / 2);
156-
157-
// Begin test
158-
// printf("Testing insertion/deletion of %d/%d elements into GPU hash table...\n",
159-
// (uint32_t)insert_kvs.size(), (uint32_t)delete_kvs.size());
160-
161146
#ifdef DEBUG_TIME
162147
std::chrono::steady_clock::time_point start_time;
163148
std::chrono::steady_clock::time_point stop_time;
164149
double duration = 0.0;
165150
double tot_time = 0.0;
166151

167-
START_TIMER();
152+
START_TIMER();
153+
#endif
154+
std::vector<KeyValue> insert_kvs = generate_random_keyvalues(rnd, kNumKeyValues);
155+
std::vector<KeyValue> lookup_kvs = shuffle_keyvalues(rnd, insert_kvs, kNumKeyValues / 2);
156+
std::vector<KeyValue> delete_kvs = shuffle_keyvalues(rnd, insert_kvs, kNumKeyValues / 2);
157+
158+
#ifdef DEBUG_TIME
159+
STOP_TIMER();
160+
PRINT_TIMER("generate_hashtable ");
168161
#endif
169-
sycl::device dht = sycl::device(sycl::default_selector_v);
170162

171-
// Time timer = start_timer();
172-
sycl::queue qht(dht);
163+
TIMER_START()
164+
165+
#ifdef DEBUG_TIME
166+
START_TIMER();
167+
#endif
168+
sycl::queue qht;
173169
#ifdef DEBUG_TIME
174170
STOP_TIMER();
175171
PRINT_TIMER("init ");

0 commit comments

Comments
 (0)