OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-CompactHash commits / ce33dfa

Fixing hash table initialization to be optional
ce33dfac340d55695f2a077230d827b6eca93596
by brobey <brobey@lanl.gov> · 2015-11-09T18:44:56.000Z

Changed files (3) +41 -34

neigh2d.c +6 -6
……@@ -1750,7 +1750,7 @@ struct neighbor2d *neighbors2d_hasholdlibcpu_opt_3( uint ncells, int mesh_size,
17501750 if(DETAILED_TIMING) cpu_timer_start(&tSection);
17511751
17521752 //Create Hash Table
1753 int *hash = compact_hash_init(smallestProthPrimeAbove(ncells / HASH_LOAD_FACTOR), imaxsize, jmaxsize, 1);
1753 int *hash = compact_hash_init(smallestProthPrimeAbove(ncells / HASH_LOAD_FACTOR), imaxsize, jmaxsize, 0, 1);
17541754
17551755 if(DETAILED_TIMING) createCPUTime = cpu_timer_stop(tSection);
17561756 if(DETAILED_TIMING) cpu_timer_start(&tSection);
……@@ -1886,7 +1886,7 @@ cl_mem neighbors2d_hashgpu( uint ncells, int mesh_size, int levmx, cl_mem i_buff
18861886 if(DETAILED_TIMING) GPUTime = 0;
18871887
18881888 //Create Hash Table
1889 hash_buffer = hash_init(hash_size, TILE_SIZE, context, queue, &GPUTime);
1889 hash_buffer = hash_init(hash_size, TILE_SIZE, 0, context, queue, &GPUTime);
18901890
18911891 if(DETAILED_TIMING) createGPUTime = (double)(GPUTime)*1.0e-9;
18921892 if(DETAILED_TIMING) cpu_timer_start(&tSection);
……@@ -2129,7 +2129,7 @@ cl_mem neighbors2d_hashgpu_opt_1( uint ncells, int mesh_size, int levmx, cl_mem
21292129 if(DETAILED_TIMING) GPUTime = 0;
21302130
21312131 //Create Hash Table
2132 hash_buffer = hash_init(hash_size, TILE_SIZE, context, queue, &GPUTime);
2132 hash_buffer = hash_init(hash_size, TILE_SIZE, 0, context, queue, &GPUTime);
21332133
21342134 if(DETAILED_TIMING) createGPUTime = (double)(GPUTime)*1.0e-9;
21352135 if(DETAILED_TIMING) cpu_timer_start(&tSection);
……@@ -2374,7 +2374,7 @@ cl_mem neighbors2d_hashgpu_opt_2( uint ncells, int mesh_size, int levmx, cl_mem
23742374 if(DETAILED_TIMING) GPUTime = 0;
23752375
23762376 //Create Hash Table
2377 hash_buffer = hash_init(hash_size, TILE_SIZE, context, queue, &GPUTime);
2377 hash_buffer = hash_init(hash_size, TILE_SIZE, 0, context, queue, &GPUTime);
23782378
23792379 if(DETAILED_TIMING) createGPUTime = (double)(GPUTime)*1.0e-9;
23802380 if(DETAILED_TIMING) cpu_timer_start(&tSection);
……@@ -2620,7 +2620,7 @@ cl_mem neighbors2d_hashgpu_opt_3( uint ncells, int mesh_size, int levmx, cl_mem
26202620 if(DETAILED_TIMING) GPUTime = 0;
26212621
26222622 //Create Hash Table
2623 hash_buffer = hash_init(hash_size, TILE_SIZE, context, queue, &GPUTime);
2623 hash_buffer = hash_init(hash_size, TILE_SIZE, 0, context, queue, &GPUTime);
26242624
26252625 if(DETAILED_TIMING) createGPUTime = (double)(GPUTime)*1.0e-9;
26262626 if(DETAILED_TIMING) cpu_timer_start(&tSection);
……@@ -2905,7 +2905,7 @@ cl_mem neighbors2d_hasholdlibgpu_opt_3( uint ncells, int mesh_size, int levmx, c
29052905 hash_size = gpu_perfect_hash_size;
29062906 }
29072907
2908 hash_buffer = hash_init(hash_size, TILE_SIZE, context, queue, &GPUTime);
2908 hash_buffer = hash_init(hash_size, TILE_SIZE, 1, context, queue, &GPUTime);
29092909
29102910 if(DETAILED_TIMING) createGPUTime = (double)(GPUTime)*1.0e-9;
29112911 if(DETAILED_TIMING) cpu_timer_start(&tSection);
simplehash/simplehash.c +31 -24
……@@ -81,7 +81,7 @@ long long get_hashtablesize(void) {
8181 return(hashtablesize);
8282}
8383
84int *compact_hash_init(int ncells, uint isize, uint jsize, uint report_level){
84int *compact_hash_init(int ncells, uint isize, uint jsize, int do_init, uint report_level){
8585 hash_ncells = 0;
8686 write_hash_collisions = 0;
8787 read_hash_collisions = 0;
……@@ -159,8 +159,10 @@ int *compact_hash_init(int ncells, uint isize, uint jsize, uint report_level){
159159 hashtablesize = perfect_hash_size;
160160
161161 hash = (int *)malloc(hashtablesize*sizeof(int));
162 for (uint ii = 0; ii<hashtablesize; ii++){
163 hash[ii] = -1;
162 if (do_init) {
163 for (uint ii = 0; ii<hashtablesize; ii++){
164 hash[ii] = -1;
165 }
164166 }
165167
166168 read_hash = read_hash_perfect;
……@@ -179,9 +181,9 @@ int *compact_hash_init(int ncells, uint isize, uint jsize, uint report_level){
179181#ifdef _OPENMP
180182
181183#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
182int *compact_hash_init_openmp(int ncells, uint isize, uint jsize, uint report_level){
184int *compact_hash_init_openmp(int ncells, uint isize, uint jsize, int do_init, uint report_level){
183185#else
184int *compact_hash_init_openmp(int ncells, uint isize, uint jsize, uint report_level, omp_lock_t **lock){
186int *compact_hash_init_openmp(int ncells, uint isize, uint jsize, int do_init, uint report_level, omp_lock_t **lock){
185187#endif
186188
187189 hash_ncells = 0;
……@@ -287,8 +289,10 @@ int *compact_hash_init_openmp(int ncells, uint isize, uint jsize, uint report_le
287289#ifdef _OPENMP
288290#pragma omp parallel for
289291#endif
290 for (uint ii = 0; ii<hashtablesize; ii++){
291 hash[ii] = -1;
292 if (do_init) {
293 for (uint ii = 0; ii<hashtablesize; ii++){
294 hash[ii] = -1;
295 }
292296 }
293297
294298 read_hash = read_hash_perfect;
……@@ -1366,7 +1370,7 @@ void hash_lib_init(cl_context context){
13661370 if (error != CL_SUCCESS) printf("Error is %d at line %d\n",error,__LINE__);
13671371}
13681372
1369cl_mem hash_init (int hash_size, int TILE_SIZE, cl_context context, cl_command_queue queue, long *gpu_time)
1373cl_mem hash_init (int hash_size, int TILE_SIZE, int do_init, cl_context context, cl_command_queue queue, long *gpu_time)
13701374{
13711375 cl_int error;
13721376
……@@ -1377,31 +1381,34 @@ cl_mem hash_init (int hash_size, int TILE_SIZE, cl_context context, cl_command_q
13771381
13781382 //init to -1
13791383
1380 error = clSetKernelArg(init_kernel, 0, sizeof(cl_uint), &hash_size);
1381 if (error != CL_SUCCESS) printf("Error is %d at line %d\n",error,__LINE__);
1382 error = clSetKernelArg(init_kernel, 1, sizeof(cl_mem), (void*)&hash_buffer);
1383 if (error != CL_SUCCESS) printf("Error is %d at line %d\n",error,__LINE__);
1384 if (do_init) {
13841385
1385 size_t global_work_size;
1386 size_t local_work_size;
1386 error = clSetKernelArg(init_kernel, 0, sizeof(cl_uint), &hash_size);
1387 if (error != CL_SUCCESS) printf("Error is %d at line %d\n",error,__LINE__);
1388 error = clSetKernelArg(init_kernel, 1, sizeof(cl_mem), (void*)&hash_buffer);
1389 if (error != CL_SUCCESS) printf("Error is %d at line %d\n",error,__LINE__);
13871390
1388 local_work_size = TILE_SIZE;
1389 global_work_size = ((hash_size+local_work_size-1)/local_work_size)*local_work_size;
1391 size_t global_work_size;
1392 size_t local_work_size;
13901393
1391 cl_event hash_init_event;
1394 local_work_size = TILE_SIZE;
1395 global_work_size = ((hash_size+local_work_size-1)/local_work_size)*local_work_size;
13921396
1393 error = clEnqueueNDRangeKernel(queue, init_kernel, 1, 0, &global_work_size, &local_work_size, 0, NULL, &hash_init_event);
1394 if (error != CL_SUCCESS) printf("Error is %d at line %d\n",error,__LINE__);
1397 cl_event hash_init_event;
13951398
1396 clWaitForEvents(1,&hash_init_event);
1399 error = clEnqueueNDRangeKernel(queue, init_kernel, 1, 0, &global_work_size, &local_work_size, 0, NULL, &hash_init_event);
1400 if (error != CL_SUCCESS) printf("Error is %d at line %d\n",error,__LINE__);
13971401
1398 clGetEventProfilingInfo(hash_init_event, CL_PROFILING_COMMAND_START, sizeof(gpu_time_start), &gpu_time_start, NULL);
1399 clGetEventProfilingInfo(hash_init_event, CL_PROFILING_COMMAND_END, sizeof(gpu_time_end), &gpu_time_end, NULL);
1402 clWaitForEvents(1,&hash_init_event);
14001403
1404 clGetEventProfilingInfo(hash_init_event, CL_PROFILING_COMMAND_START, sizeof(gpu_time_start), &gpu_time_start, NULL);
1405 clGetEventProfilingInfo(hash_init_event, CL_PROFILING_COMMAND_END, sizeof(gpu_time_end), &gpu_time_end, NULL);
14011406
1402 *gpu_time = gpu_time_end - gpu_time_start;
14031407
1404 clReleaseEvent(hash_init_event);
1408 *gpu_time = gpu_time_end - gpu_time_start;
1409
1410 clReleaseEvent(hash_init_event);
1411 }
14051412
14061413 //if (DETAILED_TIMING) printf("\n\tinit %.6lf,", (double)(gpu_time_end - gpu_time_start)*1.0e-9);
14071414
simplehash/simplehash.h +4 -4
……@@ -63,13 +63,13 @@ typedef unsigned int uint;
6363#endif
6464typedef unsigned long ulong;
6565
66int *compact_hash_init(int ncells, uint isize, uint jsize, uint report_level);
66int *compact_hash_init(int ncells, uint isize, uint jsize, int do_init, uint report_level);
6767
6868#ifdef _OPENMP
6969 #ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
70 int *compact_hash_init_openmp(int ncells, uint isize, uint jsize, uint report_level);
70 int *compact_hash_init_openmp(int ncells, uint isize, uint jsize, int do_init, uint report_level);
7171 #else
72 int *compact_hash_init_openmp(int ncells, uint isize, uint jsize, uint report_level, omp_lock_t **lock);
72 int *compact_hash_init_openmp(int ncells, uint isize, uint jsize, int do_init, uint report_level, omp_lock_t **lock);
7373 #endif
7474#endif
7575
……@@ -155,7 +155,7 @@ void final_hash_collision_report(void);
155155char *get_hash_kernel_source_string(void);
156156#ifdef HAVE_OPENCL
157157void hash_lib_init(cl_context context);
158cl_mem hash_init (int hash_size, int TILE_SIZE, cl_context context, cl_command_queue queue, long *gpu_time);
158cl_mem hash_init (int hash_size, int TILE_SIZE, int do_init, cl_context context, cl_command_queue queue, long *gpu_time);
159159#endif
160160void hash_lib_terminate(void);
161161