OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-CompactHash commits / d3c9999

Merging in simplehashlib into simplehash source
d3c99990925f2e833246cbf48488be5662fd3984
by brobey <brobey@lanl.gov> · 2015-10-21T22:48:05.000Z

Changed files (7) +149 -221

neigh2d.c +0 -1
……@@ -51,7 +51,6 @@
5151#include "gpu.h"
5252#include "HashFactory/HashFactory.h"
5353#include "simplehash/simplehash.h"
54#include "simplehash/simplehashlib.h"
5554#include "timer/timer.h"
5655
5756#ifdef HAVE_OPENCL
simplehash/Makefile.am +6 -6
……@@ -1,20 +1,20 @@
1default: simplehash.c simplehashlib.c libsimplehash.la
2all: simplehash.c simplehashlib.c libsimplehash.la
1default: simplehash.c libsimplehash.la
2all: simplehash.c libsimplehash.la
33
44AM_MAKEFLAGS = -j 4
55
66DEFAULT_INCLUDES=-I. -I..
77
88lib_LTLIBRARIES = libsimplehash.la
9include_HEADERS = simplehash.h simplehashlib.h
9include_HEADERS = simplehash.h
1010
11H_SRCS = simplehash.h simplehashlib.h
11H_SRCS = simplehash.h
1212
13C_SRCS = simplehash.c simplehashlib.c
13C_SRCS = simplehash.c
1414
1515libsimplehash_la_SOURCES = ${C_SRCS} ${H_SRCS}
1616
17simplehashlib.c: simplehashlib_kern.inc simplehash_kern.inc
17simplehash.c: simplehashlib_kern.inc simplehash_kern.inc
1818
1919simplehashlib_kern.inc:
2020 ./embed_source.pl simplehashlib_kern.cl > simplehashlib_kern.inc
simplehash/Makefile.in +7 -8
……@@ -122,7 +122,7 @@ am__uninstall_files_from_dir = { \
122122am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"
123123LTLIBRARIES = $(lib_LTLIBRARIES)
124124libsimplehash_la_LIBADD =
125am__objects_1 = simplehash.lo simplehashlib.lo
125am__objects_1 = simplehash.lo
126126am__objects_2 =
127127am_libsimplehash_la_OBJECTS = $(am__objects_1) $(am__objects_2)
128128libsimplehash_la_OBJECTS = $(am_libsimplehash_la_OBJECTS)
……@@ -318,9 +318,9 @@ top_srcdir = @top_srcdir@
318318AM_MAKEFLAGS = -j 4
319319DEFAULT_INCLUDES = -I. -I..
320320lib_LTLIBRARIES = libsimplehash.la
321include_HEADERS = simplehash.h simplehashlib.h
322H_SRCS = simplehash.h simplehashlib.h
323C_SRCS = simplehash.c simplehashlib.c
321include_HEADERS = simplehash.h
322H_SRCS = simplehash.h
323C_SRCS = simplehash.c
324324libsimplehash_la_SOURCES = ${C_SRCS} ${H_SRCS}
325325EXTRA_DIST = simplehash_kern.cl simplehashlib_kern.cl embed_source.pl
326326all: all-am
……@@ -403,7 +403,6 @@ distclean-compile:
403403 -rm -f *.tab.c
404404
405405@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/simplehash.Plo@am__quote@
406@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/simplehashlib.Plo@am__quote@
407406
408407.c.o:
409408@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
……@@ -661,10 +660,10 @@ uninstall-am: uninstall-includeHEADERS uninstall-libLTLIBRARIES
661660 tags tags-am uninstall uninstall-am uninstall-includeHEADERS \
662661 uninstall-libLTLIBRARIES
663662
664default: simplehash.c simplehashlib.c libsimplehash.la
665all: simplehash.c simplehashlib.c libsimplehash.la
663default: simplehash.c libsimplehash.la
664all: simplehash.c libsimplehash.la
666665
667simplehashlib.c: simplehashlib_kern.inc simplehash_kern.inc
666simplehash.c: simplehashlib_kern.inc simplehash_kern.inc
668667
669668simplehashlib_kern.inc:
670669 ./embed_source.pl simplehashlib_kern.cl > simplehashlib_kern.inc
simplehash/simplehash.c +122 -0
……@@ -34,6 +34,12 @@
3434#include <stdlib.h>
3535#include "simplehash.h"
3636
37#ifdef HAVE_OPENCL
38#include "simplehashlib_kern.inc"
39#include "simplehash_kern.inc"
40#endif
41
42
3743static ulong AA;
3844static ulong BB;
3945static ulong prime=4294967291;
……@@ -1287,6 +1293,122 @@ void final_hash_collision_report(void){
12871293 printf("Final hash collision report -- write/read collisions per cell %lf/%lf\n",write_hash_collisions_runsum/(double)write_hash_collisions_count,read_hash_collisions_runsum/(double)read_hash_collisions_count);
12881294 }
12891295}
1296
1297#ifdef HAVE_OPENCL
1298char *get_hash_kernel_source_string(void){
1299 return (char*) simplehash_kern_source;
1300}
1301
1302cl_kernel init_kernel;
1303void hash_lib_init(cl_context context){
1304
1305 cl_int error;
1306
1307 cl_program program = clCreateProgramWithSource(context, 1, (const char **)&simplehashlib_kern_source, NULL, &error);
1308 if (error != CL_SUCCESS){
1309 printf("clCreateProgramWithSource returned an error %d at line %d in file %s\n", error,__LINE__,__FILE__);
1310 }
1311
1312 size_t nReportSize;
1313 char* BuildReport;
1314 #ifdef HAVE_CL_DOUBLE
1315 error = clBuildProgram(program, 0, NULL, "-DHAVE_CL_DOUBLE", NULL, NULL);
1316 #else
1317 error = clBuildProgram(program, 0, NULL, "-DNO_CL_DOUBLE -cl-single-precision-constant", NULL, NULL);
1318 #endif
1319 if (error != CL_SUCCESS){
1320 printf("clBuildProgram returned an error %d at line %d in file %s\n", error,__LINE__,__FILE__);
1321
1322 cl_device_id device;
1323
1324 clGetContextInfo(context, CL_CONTEXT_DEVICES, 1, &device, NULL);
1325 if (context == NULL){
1326 printf("EZCL_DEVTYPE_INIT: Failed to find device and setup context in file %s at line %d\n", __FILE__, __LINE__);
1327 exit(-1); // No device is available, something is wrong
1328 }
1329
1330 error = clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, 0, NULL, &nReportSize);
1331 if (error != CL_SUCCESS) {
1332 switch (error){
1333 case CL_INVALID_DEVICE:
1334 printf("Invalid device in clProgramBuildInfo\n");
1335 break;
1336 case CL_INVALID_VALUE:
1337 printf("Invalid value in clProgramBuildInfo\n");
1338 break;
1339 case CL_INVALID_PROGRAM:
1340 printf("Invalid program in clProgramBuildInfo\n");
1341 break;
1342 }
1343 }
1344
1345 BuildReport = (char *)malloc(nReportSize);
1346
1347 error = clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, nReportSize, BuildReport, NULL);
1348 if (error != CL_SUCCESS) {
1349 switch (error){
1350 case CL_INVALID_DEVICE:
1351 printf("Invalid device in clProgramBuildInfo\n");
1352 break;
1353 case CL_INVALID_VALUE:
1354 printf("Invalid value in clProgramBuildInfo\n");
1355 break;
1356 case CL_INVALID_PROGRAM:
1357 printf("Invalid program in clProgramBuildInfo\n");
1358 break;
1359 }
1360 }
1361 printf("%s\n", BuildReport);
1362 }
1363
1364
1365 init_kernel = clCreateKernel(program, "init_kern", &error);
1366 if (error != CL_SUCCESS) printf("Error is %d at line %d\n",error,__LINE__);
1367}
1368
1369cl_mem hash_init (int hash_size, int TILE_SIZE, cl_context context, cl_command_queue queue, long *gpu_time)
1370{
1371 cl_int error;
1372
1373 long gpu_time_start, gpu_time_end;
1374
1375 cl_mem hash_buffer = clCreateBuffer(context, CL_MEM_READ_WRITE, hash_size*sizeof(int), NULL, &error);
1376 if (error != CL_SUCCESS) printf("Error is %d at line %d\n",error,__LINE__);
1377
1378 //init to -1
1379
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
1385 size_t global_work_size;
1386 size_t local_work_size;
1387
1388 local_work_size = TILE_SIZE;
1389 global_work_size = ((hash_size+local_work_size-1)/local_work_size)*local_work_size;
1390
1391 cl_event hash_init_event;
1392
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__);
1395
1396 clWaitForEvents(1,&hash_init_event);
1397
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);
1400
1401
1402 *gpu_time = gpu_time_end - gpu_time_start;
1403
1404 clReleaseEvent(hash_init_event);
1405
1406 //if (DETAILED_TIMING) printf("\n\tinit %.6lf,", (double)(gpu_time_end - gpu_time_start)*1.0e-9);
1407
1408 return(hash_buffer);
1409}
1410#endif
1411
12901412int read_dev_hash(int hash_method, ulong hashtablesize, ulong AA, ulong BB, ulong hashkey, int *hash){
12911413 //int hash_report_level = 3;
12921414 int max_collisions_allowed = 1000;
simplehash/simplehash.h +14 -0
……@@ -37,6 +37,13 @@
3737#include <omp.h>
3838#endif
3939
40#ifdef HAVE_OPENCL
41#ifdef __APPLE_CC__
42#include <OpenCL/OpenCL.h>
43#else
44#include <CL/cl.h>
45#endif
46#endif
4047
4148enum choose_hash_method
4249{ METHOD_UNSET = 0, // use 0 for no method set
……@@ -142,6 +149,13 @@ void compact_hash_delete(int *hash);
142149void read_hash_collision_report(void);
143150void final_hash_collision_report(void);
144151
152char *get_hash_kernel_source_string(void);
153#ifdef HAVE_OPENCL
154void hash_lib_init(cl_context context);
155cl_mem hash_init (int hash_size, int TILE_SIZE, cl_context context, cl_command_queue queue, long *gpu_time);
156#endif
157void hash_lib_terminate(void);
158
145159#ifdef __cplusplus
146160}
147161#endif
simplehash/simplehashlib.c +0 -156
……@@ -1,156 +0,0 @@
1/* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced
2 * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National
3 * Laboratory (LANL), which is operated by Los Alamos National Security, LLC
4 * for the U.S. Department of Energy. The U.S. Government has rights to use,
5 * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS
6 * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
7 * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified
8 * to produce derivative works, such modified software should be clearly marked,
9 * so as not to confuse it with the version available from LANL.
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
12 * use this file except in compliance with the License. You may obtain a copy
13 * of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software distributed
18 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
19 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
20 * specific language governing permissions and limitations under the License.
21 *
22 * Under this license, it is required to include a reference to this work. We
23 * request that each derivative work contain a reference to LANL Copyright
24 * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly
25 * measured. In addition, it is requested that a modifier is included as in
26 * the following example:
27 *
28 * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003
29 *
30 * This is LANL Copyright Disclosure C14043/LA-CC-14-003
31 */
32
33#include <stdlib.h>
34//#ifdef HAVE_CONFIG_H
35//#include "config.h"
36//#endif
37#include "simplehashlib.h"
38#include "simplehashlib_kern.inc"
39#include "simplehash_kern.inc"
40
41static int reportLevel = 0;
42
43char *get_hash_kernel_source_string(void){
44 return (char*) simplehash_kern_source;
45}
46
47#ifdef HAVE_OPENCL
48cl_kernel init_kernel;
49void hash_lib_init(cl_context context){
50
51 cl_int error;
52
53 cl_program program = clCreateProgramWithSource(context, 1, (const char **)&simplehashlib_kern_source, NULL, &error);
54 if (error != CL_SUCCESS){
55 printf("clCreateProgramWithSource returned an error %d at line %d in file %s\n", error,__LINE__,__FILE__);
56 }
57
58 size_t nReportSize;
59 char* BuildReport;
60 #ifdef HAVE_CL_DOUBLE
61 error = clBuildProgram(program, 0, NULL, "-DHAVE_CL_DOUBLE", NULL, NULL);
62 #else
63 error = clBuildProgram(program, 0, NULL, "-DNO_CL_DOUBLE -cl-single-precision-constant", NULL, NULL);
64 #endif
65 if (error != CL_SUCCESS){
66 printf("clBuildProgram returned an error %d at line %d in file %s\n", error,__LINE__,__FILE__);
67
68 cl_device_id device;
69
70 clGetContextInfo(context, CL_CONTEXT_DEVICES, 1, &device, NULL);
71 if (context == NULL){
72 printf("EZCL_DEVTYPE_INIT: Failed to find device and setup context in file %s at line %d\n", __FILE__, __LINE__);
73 exit(-1); // No device is available, something is wrong
74 }
75
76 error = clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, 0, NULL, &nReportSize);
77 if (error != CL_SUCCESS) {
78 switch (error){
79 case CL_INVALID_DEVICE:
80 printf("Invalid device in clProgramBuildInfo\n");
81 break;
82 case CL_INVALID_VALUE:
83 printf("Invalid value in clProgramBuildInfo\n");
84 break;
85 case CL_INVALID_PROGRAM:
86 printf("Invalid program in clProgramBuildInfo\n");
87 break;
88 }
89 }
90
91 BuildReport = (char *)malloc(nReportSize);
92
93 error = clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, nReportSize, BuildReport, NULL);
94 if (error != CL_SUCCESS) {
95 switch (error){
96 case CL_INVALID_DEVICE:
97 printf("Invalid device in clProgramBuildInfo\n");
98 break;
99 case CL_INVALID_VALUE:
100 printf("Invalid value in clProgramBuildInfo\n");
101 break;
102 case CL_INVALID_PROGRAM:
103 printf("Invalid program in clProgramBuildInfo\n");
104 break;
105 }
106 }
107 printf("%s\n", BuildReport);
108 }
109
110
111 init_kernel = clCreateKernel(program, "init_kern", &error);
112 if (error != CL_SUCCESS) printf("Error is %d at line %d\n",error,__LINE__);
113}
114
115cl_mem hash_init (int hash_size, int TILE_SIZE, cl_context context, cl_command_queue queue, long *gpu_time)
116{
117 cl_int error;
118
119 long gpu_time_start, gpu_time_end;
120
121 cl_mem hash_buffer = clCreateBuffer(context, CL_MEM_READ_WRITE, hash_size*sizeof(int), NULL, &error);
122 if (error != CL_SUCCESS) printf("Error is %d at line %d\n",error,__LINE__);
123
124 //init to -1
125
126 error = clSetKernelArg(init_kernel, 0, sizeof(cl_uint), &hash_size);
127 if (error != CL_SUCCESS) printf("Error is %d at line %d\n",error,__LINE__);
128 error = clSetKernelArg(init_kernel, 1, sizeof(cl_mem), (void*)&hash_buffer);
129 if (error != CL_SUCCESS) printf("Error is %d at line %d\n",error,__LINE__);
130
131 size_t global_work_size;
132 size_t local_work_size;
133
134 local_work_size = TILE_SIZE;
135 global_work_size = ((hash_size+local_work_size-1)/local_work_size)*local_work_size;
136
137 cl_event hash_init_event;
138
139 error = clEnqueueNDRangeKernel(queue, init_kernel, 1, 0, &global_work_size, &local_work_size, 0, NULL, &hash_init_event);
140 if (error != CL_SUCCESS) printf("Error is %d at line %d\n",error,__LINE__);
141
142 clWaitForEvents(1,&hash_init_event);
143
144 clGetEventProfilingInfo(hash_init_event, CL_PROFILING_COMMAND_START, sizeof(gpu_time_start), &gpu_time_start, NULL);
145 clGetEventProfilingInfo(hash_init_event, CL_PROFILING_COMMAND_END, sizeof(gpu_time_end), &gpu_time_end, NULL);
146
147
148 *gpu_time = gpu_time_end - gpu_time_start;
149
150 clReleaseEvent(hash_init_event);
151
152 //if (DETAILED_TIMING) printf("\n\tinit %.6lf,", (double)(gpu_time_end - gpu_time_start)*1.0e-9);
153
154 return(hash_buffer);
155}
156#endif
simplehash/simplehashlib.h +0 -50
……@@ -1,50 +0,0 @@
1/* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced
2 * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National
3 * Laboratory (LANL), which is operated by Los Alamos National Security, LLC
4 * for the U.S. Department of Energy. The U.S. Government has rights to use,
5 * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS
6 * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
7 * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified
8 * to produce derivative works, such modified software should be clearly marked,
9 * so as not to confuse it with the version available from LANL.
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
12 * use this file except in compliance with the License. You may obtain a copy
13 * of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software distributed
18 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
19 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
20 * specific language governing permissions and limitations under the License.
21 *
22 * Under this license, it is required to include a reference to this work. We
23 * request that each derivative work contain a reference to LANL Copyright
24 * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly
25 * measured. In addition, it is requested that a modifier is included as in
26 * the following example:
27 *
28 * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003
29 *
30 * This is LANL Copyright Disclosure C14043/LA-CC-14-003
31 */
32
33#include <stdio.h>
34//#ifdef HAVE_CONFIG_H
35//#include "config.h"
36//#endif
37
38#ifdef HAVE_OPENCL
39#ifdef __APPLE_CC__
40#include <OpenCL/OpenCL.h>
41#else
42#include <CL/cl.h>
43#endif
44#endif
45
46char *get_hash_kernel_source_string();
47#ifdef HAVE_OPENCL
48void hash_lib_init(cl_context context);
49cl_mem hash_init (int hash_size, int TILE_SIZE, cl_context context, cl_command_queue queue, long *gpu_time);
50#endif