| … | … | @@ -0,0 +1,465 @@ |
| 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 | /** | |
| 34 | * @file CLHash_Utilities.c | |
| 35 | * @author Ahrens/Robey -- rewritten for distribution | |
| 36 | * @date Sun Aug 4 2013 | |
| 37 | */ | |
| 38 | ||
| 39 | #include <execinfo.h> | |
| 40 | #include <stdio.h> | |
| 41 | #include <string.h> | |
| 42 | #include <stdlib.h> | |
| 43 | #include "CLHash_Utilities.h" | |
| 44 | ||
| 45 | //#ifdef HAVE_CONFIG_H | |
| 46 | //#include "config.h" | |
| 47 | //#endif | |
| 48 | ||
| 49 | #ifdef HAVE_OPENCL | |
| 50 | #ifdef __APPLE_CC__ | |
| 51 | #include <OpenCL/OpenCL.h> | |
| 52 | #else | |
| 53 | #include <CL/cl.h> | |
| 54 | #endif | |
| 55 | ||
| 56 | #else | |
| 57 | int clGetPlatformIDs(uint nentries, int *platforms, uint *nplatforms) { return 0; } | |
| 58 | int clGetDeviceIDs(int platform, int device_type, uint nentries, int *devices, uint *ndevices) { return 0; } | |
| 59 | int clGetPlatformInfo(int platform, int param_name, size_t size, void *value, size_t *size_ret) { return 0; } | |
| 60 | int clGetDeviceInfo(int device, int param_name, size_t size, void *value, size_t *size_ret) { return 0; } | |
| 61 | int clCreateContext(int *properties, uint ndevices, const int *devices, void *notify, void *user_data, int *errcode_ret) { return 0; } | |
| 62 | int clCreateCommandQueue(int context, int device, int properties, int *errcode_ret) { return 0; } | |
| 63 | int clCreateProgramWithSource(int context, uint count, const char **strings, const size_t *lengths, int *errcode_ret) { return 0; } | |
| 64 | int clBuildProgram(int program, uint ndevices, const int *device_list, const char *options, void *notify, void *user_data) { return 0; } | |
| 65 | int clGetProgramBuildInfo(int program, int devices, int param_name, size_t size, void *value, size_t *size_ret) { return 0; } | |
| 66 | ||
| 67 | #define CL_SUCCESS 0 | |
| 68 | #define CL_PROGRAM_LOG 0 | |
| 69 | #define CL_PROGRAM_BUILD_LOG 0 | |
| 70 | #define CL_DEVICE_TYPE_GPU 0 | |
| 71 | #define CL_DEVICE_TYPE_CPU 0 | |
| 72 | #define CL_DEVICE_TYPE_ACCELERATOR 0 | |
| 73 | #define CL_DEVICE_NAME 0 | |
| 74 | #define CL_DEVICE_VENDOR 0 | |
| 75 | #define CL_PLATFORM_NAME 0 | |
| 76 | #define CL_PLATFORM_VENDOR 0 | |
| 77 | #define CL_PLATFORM_VERSION 0 | |
| 78 | #define CL_QUEUE_PROFILING_ENABLE 0 | |
| 79 | ||
| 80 | #define CL_DEVICE_NOT_FOUND -1 | |
| 81 | #define CL_DEVICE_NOT_AVAILABLE -2 | |
| 82 | #define CL_COMPILER_NOT_AVAILABLE -3 | |
| 83 | #define CL_MEM_OBJECT_ALLOCATION_FAILURE -4 | |
| 84 | #define CL_OUT_OF_RESOURCES -5 | |
| 85 | #define CL_OUT_OF_HOST_MEMORY -6 | |
| 86 | #define CL_PROFILING_INFO_NOT_AVAILABLE -7 | |
| 87 | #define CL_MEM_COPY_OVERLAP -8 | |
| 88 | #define CL_IMAGE_FORMAT_MISMATCH -9 | |
| 89 | #define CL_IMAGE_FORMAT_NOT_SUPPORTED -10 | |
| 90 | #define CL_BUILD_PROGRAM_FAILURE -11 | |
| 91 | #define CL_MAP_FAILURE -12 | |
| 92 | #define CL_INVALID_VALUE -30 | |
| 93 | #define CL_INVALID_DEVICE_TYPE -31 | |
| 94 | #define CL_INVALID_PLATFORM -32 | |
| 95 | #define CL_INVALID_DEVICE -33 | |
| 96 | #define CL_INVALID_CONTEXT -34 | |
| 97 | #define CL_INVALID_QUEUE_PROPERTIES -35 | |
| 98 | #define CL_INVALID_COMMAND_QUEUE -36 | |
| 99 | #define CL_INVALID_HOST_PTR -37 | |
| 100 | #define CL_INVALID_MEM_OBJECT -38 | |
| 101 | #define CL_INVALID_IMAGE_FORMAT_DESCRIPTOR -39 | |
| 102 | #define CL_INVALID_IMAGE_SIZE -40 | |
| 103 | #define CL_INVALID_SAMPLER -41 | |
| 104 | #define CL_INVALID_BINARY -42 | |
| 105 | #define CL_INVALID_BUILD_OPTIONS -43 | |
| 106 | #define CL_INVALID_PROGRAM -44 | |
| 107 | #define CL_INVALID_PROGRAM_EXECUTABLE -45 | |
| 108 | #define CL_INVALID_KERNEL_NAME -46 | |
| 109 | #define CL_INVALID_KERNEL_DEFINITION -47 | |
| 110 | #define CL_INVALID_KERNEL -48 | |
| 111 | #define CL_INVALID_ARG_INDEX -49 | |
| 112 | #define CL_INVALID_ARG_VALUE -50 | |
| 113 | #define CL_INVALID_ARG_SIZE -51 | |
| 114 | #define CL_INVALID_KERNEL_ARGS -52 | |
| 115 | #define CL_INVALID_WORK_DIMENSION -53 | |
| 116 | #define CL_INVALID_WORK_GROUP_SIZE -54 | |
| 117 | #define CL_INVALID_WORK_ITEM_SIZE -55 | |
| 118 | #define CL_INVALID_GLOBAL_OFFSET -56 | |
| 119 | #define CL_INVALID_EVENT_WAIT_LIST -57 | |
| 120 | #define CL_INVALID_EVENT -58 | |
| 121 | #define CL_INVALID_OPERATION -59 | |
| 122 | #define CL_INVALID_GL_OBJECT -60 | |
| 123 | #define CL_INVALID_BUFFER_SIZE -61 | |
| 124 | #define CL_INVALID_MIP_LEVEL -62 | |
| 125 | #endif | |
| 126 | ||
| 127 | #ifndef DEBUG | |
| 128 | #define DEBUG 0 | |
| 129 | #endif | |
| 130 | ||
| 131 | typedef unsigned int uint; | |
| 132 | ||
| 133 | char *program_name = NULL; | |
| 134 | ||
| 135 | void CLHash_Init(const char *program_name_in) | |
| 136 | { | |
| 137 | program_name = strdup(program_name_in); | |
| 138 | } | |
| 139 | ||
| 140 | /* Find a GPU or CPU associated with the first available platform */ | |
| 141 | void CLHash_Utilities_CreateContext_p(cl_context *context, cl_command_queue *command_queue, const char *file , int line) { | |
| 142 | ||
| 143 | uint num_platforms; | |
| 144 | cl_platform_id *platforms; | |
| 145 | cl_device_id device; | |
| 146 | int err; | |
| 147 | ||
| 148 | /* Get all available platforms */ | |
| 149 | err = clGetPlatformIDs(0, NULL, &num_platforms); | |
| 150 | CLHash_Utilities_HandleError(err, "CLHash_Utilities_CreateContext", "clGetPlatformIDs"); | |
| 151 | platforms = (cl_platform_id *)malloc(num_platforms*sizeof(cl_platform_id)); | |
| 152 | /* Identify a platform */ | |
| 153 | err = clGetPlatformIDs(num_platforms, platforms, NULL); | |
| 154 | CLHash_Utilities_HandleError(err, "CLHash_Utilities_CreateContext", "clGetPlatformIDs"); | |
| 155 | ||
| 156 | if (DEBUG == 1) { | |
| 157 | char info[1024]; | |
| 158 | for (int iplatform=0; iplatform<num_platforms; iplatform++){ | |
| 159 | printf(" Platform %d:\n",iplatform+1); | |
| 160 | ||
| 161 | //clGetPlatformInfo(platforms[iplatform],CL_PLATFORM_PROFILE, 1024L,info,0); | |
| 162 | //printf(" CL_PLATFORM_PROFILE : %s\n",info); | |
| 163 | ||
| 164 | clGetPlatformInfo(platforms[iplatform],CL_PLATFORM_VERSION, 1024L,info,0); | |
| 165 | printf(" CL_PLATFORM_VERSION : %s\n",info); | |
| 166 | ||
| 167 | clGetPlatformInfo(platforms[iplatform],CL_PLATFORM_NAME, 1024L,info,0); | |
| 168 | printf(" CL_PLATFORM_NAME : %s\n",info); | |
| 169 | ||
| 170 | clGetPlatformInfo(platforms[iplatform],CL_PLATFORM_VENDOR, 1024L,info,0); | |
| 171 | printf(" CL_PLATFORM_VENDOR : %s\n",info); | |
| 172 | ||
| 173 | //clGetPlatformInfo(platforms[iplatform],CL_PLATFORM_EXTENSIONS,1024L,info,0); | |
| 174 | // printf(" CL_PLATFORM_EXTENSIONS : %s\n",info); | |
| 175 | } | |
| 176 | } | |
| 177 | ||
| 178 | /* Access a device */ | |
| 179 | for (int iplatform=0; iplatform<num_platforms; iplatform++){ | |
| 180 | err = clGetDeviceIDs(platforms[iplatform], CL_DEVICE_TYPE_GPU, 1, &device, NULL); | |
| 181 | if(err != CL_DEVICE_NOT_FOUND){ | |
| 182 | break; | |
| 183 | } | |
| 184 | } | |
| 185 | if(err == CL_DEVICE_NOT_FOUND){ | |
| 186 | for (int iplatform=0; iplatform<num_platforms; iplatform++){ | |
| 187 | err = clGetDeviceIDs(platforms[iplatform], CL_DEVICE_TYPE_ACCELERATOR, 1, &device, NULL); | |
| 188 | if(err != CL_DEVICE_NOT_FOUND){ | |
| 189 | break; | |
| 190 | } | |
| 191 | } | |
| 192 | if(err == CL_DEVICE_NOT_FOUND){ | |
| 193 | for (int iplatform=0; iplatform<num_platforms; iplatform++){ | |
| 194 | err = clGetDeviceIDs(platforms[iplatform], CL_DEVICE_TYPE_CPU, 1, &device, NULL); | |
| 195 | if(err != CL_DEVICE_NOT_FOUND){ | |
| 196 | break; | |
| 197 | } | |
| 198 | } | |
| 199 | } | |
| 200 | } | |
| 201 | CLHash_Utilities_HandleError(err, "CLHash_Utilities_CreateContext", "clGetDeviceIDs"); | |
| 202 | ||
| 203 | if (DEBUG == 1) { | |
| 204 | char info[1024]; | |
| 205 | ||
| 206 | printf("\n\n"); | |
| 207 | printf(" Device:\n"); | |
| 208 | clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(info), info, NULL); | |
| 209 | printf(" CL_DEVICE_NAME : %s\n",info); | |
| 210 | ||
| 211 | clGetDeviceInfo(device, CL_DEVICE_VENDOR, sizeof(info), info, NULL); | |
| 212 | printf(" CL_DEVICE_VENDOR : %s\n",info); | |
| 213 | } | |
| 214 | ||
| 215 | *context = clCreateContext(NULL, 1, &device, NULL, NULL, &err); | |
| 216 | if(err != CL_SUCCESS) CLHash_Utilities_PrintError_p(err, "CLHash_Utilities_CreateContext", "clCreateContext", file, line); | |
| 217 | ||
| 218 | *command_queue = clCreateCommandQueue(*context, device, CL_QUEUE_PROFILING_ENABLE, &err); | |
| 219 | if(err != CL_SUCCESS) CLHash_Utilities_PrintError_p(err, "CLHash_Utilities_CreateContext", "clCreateCommandQueue", file, line); | |
| 220 | ||
| 221 | free(platforms); | |
| 222 | } | |
| 223 | ||
| 224 | cl_program CLHash_Utilities_BuildProgramString_p(cl_context ctx, cl_device_id device, const char *programString, const char *file , int line){ | |
| 225 | /* Create program from string */ | |
| 226 | cl_int err; | |
| 227 | size_t program_size, nReportSize; | |
| 228 | program_size = strlen(programString); | |
| 229 | cl_program program = clCreateProgramWithSource(ctx, 1, (const char **)&programString, &program_size, &err); | |
| 230 | if(err != CL_SUCCESS) CLHash_Utilities_PrintError(err, "CLHash_Utilities_CreateDevice", "clCreateProgram"); | |
| 231 | ||
| 232 | /* Build program */ | |
| 233 | char *BuildReport; | |
| 234 | err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL); | |
| 235 | if(err != CL_SUCCESS) { | |
| 236 | /* Find size of log and print to std output */ | |
| 237 | clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, 0, NULL, &nReportSize); | |
| 238 | ||
| 239 | if (err != CL_SUCCESS) { | |
| 240 | switch (err){ | |
| 241 | case CL_INVALID_DEVICE: | |
| 242 | printf("Invalid device in clProgramBuildInfo\n"); | |
| 243 | break; | |
| 244 | case CL_INVALID_VALUE: | |
| 245 | printf("Invalid value in clProgramBuildInfo\n"); | |
| 246 | break; | |
| 247 | case CL_INVALID_PROGRAM: | |
| 248 | printf("Invalid program in clProgramBuildInfo\n"); | |
| 249 | break; | |
| 250 | } | |
| 251 | } | |
| 252 | ||
| 253 | BuildReport = (char*) malloc(nReportSize + 1); | |
| 254 | BuildReport[nReportSize] = '\0'; | |
| 255 | clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, nReportSize + 1, BuildReport, NULL); | |
| 256 | printf("%s\n", BuildReport); | |
| 257 | free(BuildReport); | |
| 258 | exit(1); | |
| 259 | } | |
| 260 | ||
| 261 | return program; | |
| 262 | } | |
| 263 | ||
| 264 | /* Create program from a file and compile it */ | |
| 265 | cl_program CLHash_Utilities_BuildProgramFile_p(cl_context ctx, cl_device_id device, const char* fileName, const char *file , int line) { | |
| 266 | ||
| 267 | cl_program program; | |
| 268 | FILE *program_handle; | |
| 269 | char *program_buffer; | |
| 270 | size_t program_size; | |
| 271 | int err; | |
| 272 | ||
| 273 | /* Read program file and place content into buffer */ | |
| 274 | program_handle = fopen(fileName, "r"); | |
| 275 | if(program_handle == NULL) { | |
| 276 | perror("Couldn't find the program file"); | |
| 277 | exit(1); | |
| 278 | } | |
| 279 | fseek(program_handle, 0, SEEK_END); | |
| 280 | program_size = ftell(program_handle); | |
| 281 | rewind(program_handle); | |
| 282 | program_buffer = (char*)malloc(program_size + 1); | |
| 283 | program_buffer[program_size] = '\0'; | |
| 284 | fread(program_buffer, sizeof(char), program_size, program_handle); | |
| 285 | fclose(program_handle); | |
| 286 | program = CLHash_Utilities_BuildProgramString(ctx, device, program_buffer); | |
| 287 | free(program_buffer); | |
| 288 | return program; | |
| 289 | } | |
| 290 | ||
| 291 | void CLHash_Utilities_PrintError_p(cl_int err, const char *routine, const char *cl_routine, const char *file, int line){ | |
| 292 | switch(err){ | |
| 293 | case CL_DEVICE_NOT_FOUND: //#define CL_DEVICE_NOT_FOUND -1 | |
| 294 | printf("\nERROR: %s -- Device not found in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 295 | break; | |
| 296 | case CL_DEVICE_NOT_AVAILABLE: //#define CL_DEVICE_NOT_AVAILABLE -2 | |
| 297 | printf("\nERROR: %s -- Device not available in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 298 | break; | |
| 299 | case CL_COMPILER_NOT_AVAILABLE: //#define CL_COMPILER_NOT_AVAILABLE -3 | |
| 300 | printf("\nERROR: %s -- CL compiler not available failure in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 301 | break; | |
| 302 | case CL_MEM_OBJECT_ALLOCATION_FAILURE: //#define CL_MEM_OBJECT_ALLOCATION_FAILURE -4 | |
| 303 | printf("\nERROR: %s -- Mem object allocation failure in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 304 | break; | |
| 305 | case CL_OUT_OF_RESOURCES: //#define CL_OUT_OF_RESOURCES -5 | |
| 306 | printf("\nERROR: %s -- Out of resources in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 307 | break; | |
| 308 | case CL_OUT_OF_HOST_MEMORY: //#define CL_OUT_OF_HOST_MEMORY -6 | |
| 309 | printf("\nERROR: %s -- Out of host memory in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 310 | break; | |
| 311 | case CL_PROFILING_INFO_NOT_AVAILABLE: //#define CL_PROFILING_INFO_NOT_AVAILABLE -7 | |
| 312 | printf("\nERROR: %s -- Profiling info not available in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 313 | break; | |
| 314 | case CL_MEM_COPY_OVERLAP: //#define CL_MEM_COPY_OVERLAP -8 | |
| 315 | printf("\nERROR: %s -- Mem copy overlap in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 316 | break; | |
| 317 | case CL_IMAGE_FORMAT_MISMATCH: //#define CL_IMAGE_FORMAT_MISMATCH -9 | |
| 318 | printf("\nERROR: %s -- Image format mismatch in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 319 | break; | |
| 320 | case CL_IMAGE_FORMAT_NOT_SUPPORTED: //#define CL_IMAGE_FORMAT_NOT_SUPPORTED -10 | |
| 321 | printf("\nERROR: %s -- Image format not supported in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 322 | break; | |
| 323 | case CL_BUILD_PROGRAM_FAILURE: //#define CL_BUILD_PROGRAM_FAILURE -11 | |
| 324 | printf("\nERROR: %s -- Build program failure in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 325 | break; | |
| 326 | case CL_MAP_FAILURE: //#define CL_MAP_FAILURE -12 | |
| 327 | printf("\nERROR: %s -- Map failure in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 328 | break; | |
| 329 | case CL_INVALID_VALUE: //#define CL_INVALID_VALUE -30 | |
| 330 | printf("\nERROR: %s -- Invalid value in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 331 | break; | |
| 332 | case CL_INVALID_DEVICE_TYPE: //#define CL_INVALID_DEVICE_TYPE -31 | |
| 333 | printf("\nERROR: %s -- Invalid device type in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 334 | break; | |
| 335 | case CL_INVALID_PLATFORM: //#define CL_INVALID_PLATFORM -32 | |
| 336 | printf("\nERROR: %s -- Invalid platform in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 337 | break; | |
| 338 | case CL_INVALID_DEVICE: //#define CL_INVALID_DEVICE -33 | |
| 339 | printf("\nERROR: %s -- Invalid device in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 340 | break; | |
| 341 | case CL_INVALID_CONTEXT: //#define CL_INVALID_CONTEXT -34 | |
| 342 | printf("\nERROR: %s -- Invalid context in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 343 | break; | |
| 344 | case CL_INVALID_QUEUE_PROPERTIES: //#define CL_INVALID_QUEUE_PROPERTIES -35 | |
| 345 | printf("\nERROR: %s -- Invalid queue properties in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 346 | break; | |
| 347 | case CL_INVALID_COMMAND_QUEUE: //#define CL_INVALID_COMMAND_QUEUE -36 | |
| 348 | printf("\nERROR: %s -- Invalid command queue in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 349 | break; | |
| 350 | case CL_INVALID_HOST_PTR: //#define CL_INVALID_HOST_PTR -37 | |
| 351 | printf("\nERROR: %s -- Invalid host pointer in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 352 | break; | |
| 353 | case CL_INVALID_MEM_OBJECT: //#define CL_INVALID_MEM_OBJECT -38 | |
| 354 | printf("\nERROR: %s -- Invalid memory object in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 355 | break; | |
| 356 | case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: //#define CL_INVALID_IMAGE_FORMAT_DESCRIPTOR -39 | |
| 357 | printf("\nERROR: %s -- Invalid image format descriptor in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 358 | break; | |
| 359 | case CL_INVALID_IMAGE_SIZE: //#define CL_INVALID_IMAGE_SIZE -40 | |
| 360 | printf("\nERROR: %s -- Invalid image size in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 361 | break; | |
| 362 | case CL_INVALID_SAMPLER: //#define CL_INVALID_SAMPLER -41 | |
| 363 | printf("\nERROR: %s -- Invalid sampler in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 364 | break; | |
| 365 | case CL_INVALID_BINARY: //#define CL_INVALID_BINARY -42 | |
| 366 | printf("\nERROR: %s -- Invalid binary in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 367 | break; | |
| 368 | case CL_INVALID_BUILD_OPTIONS: //#define CL_INVALID_BUILD_OPTIONS -43 | |
| 369 | printf("\nERROR: %s -- Invalid build options in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 370 | break; | |
| 371 | case CL_INVALID_PROGRAM: //#define CL_INVALID_PROGRAM -44 | |
| 372 | printf("\nERROR: %s -- Invalid program in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 373 | break; | |
| 374 | case CL_INVALID_PROGRAM_EXECUTABLE: //#define CL_INVALID_PROGRAM_EXECUTABLE -45 | |
| 375 | printf("\nERROR: %s -- Invalid program executable in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 376 | break; | |
| 377 | case CL_INVALID_KERNEL_NAME: //#define CL_INVALID_KERNEL_NAME -46 | |
| 378 | printf("\nERROR: %s -- Invalid kernel name in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 379 | break; | |
| 380 | case CL_INVALID_KERNEL_DEFINITION: //#define CL_INVALID_KERNEL_DEFINITION -47 | |
| 381 | printf("\nERROR: %s -- Invalid kernel definition in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 382 | break; | |
| 383 | case CL_INVALID_KERNEL: //#define CL_INVALID_KERNEL -48 | |
| 384 | printf("\nERROR: %s -- Invalid kernel in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 385 | break; | |
| 386 | case CL_INVALID_ARG_INDEX: //#define CL_INVALID_ARG_INDEX -49 | |
| 387 | printf("\nERROR: %s -- Invalid arg index in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 388 | break; | |
| 389 | case CL_INVALID_ARG_VALUE: //#define CL_INVALID_ARG_VALUE -50 | |
| 390 | printf("\nERROR: %s -- Invalid arg value in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 391 | break; | |
| 392 | case CL_INVALID_ARG_SIZE: //#define CL_INVALID_ARG_SIZE -51 | |
| 393 | printf("\nERROR: %s -- Invalid arg size in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 394 | break; | |
| 395 | case CL_INVALID_KERNEL_ARGS: //#define CL_INVALID_KERNEL_ARGS -52 | |
| 396 | printf("\nERROR: %s -- Invalid kernel args in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 397 | break; | |
| 398 | case CL_INVALID_WORK_DIMENSION: //#define CL_INVALID_WORK_DIMENSION -53 | |
| 399 | printf("\nERROR: %s -- Invalid work dimension in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 400 | break; | |
| 401 | case CL_INVALID_WORK_GROUP_SIZE: //#define CL_INVALID_WORK_GROUP_SIZE -54 | |
| 402 | printf("\nERROR: %s -- Invalid work group size in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 403 | break; | |
| 404 | case CL_INVALID_WORK_ITEM_SIZE: //#define CL_INVALID_WORK_ITEM_SIZE -55 | |
| 405 | printf("\nERROR: %s -- Invalid work item size in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 406 | break; | |
| 407 | case CL_INVALID_GLOBAL_OFFSET: //#define CL_INVALID_GLOBAL_OFFSET -56 | |
| 408 | printf("\nERROR: %s -- Invalid global offset in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 409 | break; | |
| 410 | case CL_INVALID_EVENT_WAIT_LIST: //#define CL_INVALID_EVENT_WAIT_LIST -57 | |
| 411 | printf("\nERROR: %s -- Invalid event wait list in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 412 | break; | |
| 413 | case CL_INVALID_EVENT: //#define CL_INVALID_EVENT -58 | |
| 414 | printf("\nERROR: %s -- Invalid event in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 415 | break; | |
| 416 | case CL_INVALID_OPERATION: //#define CL_INVALID_OPERATION -59 | |
| 417 | printf("\nERROR: %s -- Invalid operation in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 418 | break; | |
| 419 | case CL_INVALID_GL_OBJECT: //#define CL_INVALID_GL_OBJECT -60 | |
| 420 | printf("\nERROR: %s -- Invalid GL object in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 421 | break; | |
| 422 | case CL_INVALID_BUFFER_SIZE: //#define CL_INVALID_BUFFER_SIZE -61 | |
| 423 | printf("\nERROR: %s -- Invalid buffer size in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 424 | break; | |
| 425 | case CL_INVALID_MIP_LEVEL: //#define CL_INVALID_MIP_LEVEL -62 | |
| 426 | break; | |
| 427 | ||
| 428 | default: | |
| 429 | printf("\nERROR: %s -- %d in %s at line %d in file %s\n", routine, err, cl_routine, line, file); | |
| 430 | break; | |
| 431 | } | |
| 432 | void* callstack[128]; | |
| 433 | int frames = backtrace(callstack, 128); | |
| 434 | if (frames > 2) { | |
| 435 | #ifdef HAVE_ADDR2LINE | |
| 436 | char hex_address[21]; | |
| 437 | char command_string[80]; | |
| 438 | #endif | |
| 439 | char** strs = backtrace_symbols(callstack, frames); | |
| 440 | fprintf(stderr,"\n =============== Backtrace ===============\n"); | |
| 441 | for (int i = 1; i < frames-1; ++i) { | |
| 442 | fprintf(stderr," %s \t", strs[i]); | |
| 443 | #ifdef HAVE_ADDR2LINE | |
| 444 | if (program_name != NULL) { | |
| 445 | sscanf(strs[i],"%*s [%[^]]s]",hex_address); | |
| 446 | //printf("DEBUG addr2line -e clamr -f -s -i -p %s\n",hex_address); | |
| 447 | //sprintf(command_string,"addr2line -e %s -f -s -i %s | sed -e \'1,1s\?\\n\?\?' \n",program_name,hex_address); | |
| 448 | sprintf(command_string,"addr2line -e %s -f -s -i %s",program_name,hex_address); | |
| 449 | //printf("%s",command_string); | |
| 450 | system(command_string); | |
| 451 | } | |
| 452 | // on mac, need to install binutils using macports "port install binutils" | |
| 453 | #endif | |
| 454 | fprintf(stderr,"\n"); | |
| 455 | } | |
| 456 | fprintf(stderr," =============== Backtrace ===============\n\n"); | |
| 457 | free(strs); | |
| 458 | } | |
| 459 | exit(-1); | |
| 460 | } | |
| 461 | ||
| 462 | const char* CLHash_Utilities_HandleError_p(cl_int err, const char *routine, const char *cl_routine, const char *file, int line){ | |
| 463 | if(err != CL_SUCCESS) CLHash_Utilities_PrintError_p(err, routine, cl_routine, file, line); | |
| 464 | return(NULL); | |
| 465 | } |
| … | … | @@ -0,0 +1,92 @@ |
| 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 | /** | |
| 34 | * @file CLHash_Utilities.h | |
| 35 | * @author Ahrens/Robey -- rewritten for distribution | |
| 36 | * @date Sun Aug 4 2013 | |
| 37 | */ | |
| 38 | #ifndef CLHASH_UTILITIES_H | |
| 39 | #define CLHASH_UTILITIES_H | |
| 40 | ||
| 41 | #ifdef HAVE_OPENCL | |
| 42 | #ifdef __APPLE_CC__ | |
| 43 | #include <OpenCL/OpenCL.h> | |
| 44 | #else | |
| 45 | #include <CL/cl.h> | |
| 46 | #endif | |
| 47 | #else | |
| 48 | typedef int cl_int; | |
| 49 | typedef int cl_context; | |
| 50 | typedef int cl_program; | |
| 51 | typedef int cl_command_queue; | |
| 52 | typedef int cl_device_id; | |
| 53 | typedef int cl_platform_id; | |
| 54 | ||
| 55 | int clGetPlatformIDs(uint nentries, int *platforms, uint *nplatforms); | |
| 56 | int clGetDeviceIDs(int platform, int device_type, uint nentries, int *devices, uint *ndevices); | |
| 57 | int clGetPlatformInfo(int platform, int param_name, size_t size, void *value, size_t *size_ret); | |
| 58 | int clGetDeviceInfo(int device, int param_name, size_t size, void *value, size_t *size_ret); | |
| 59 | int clCreateContext(int *properties, uint ndevices, const int *devices, void *notify, void *user_data, int *errcode_ret); | |
| 60 | int clCreateCommandQueue(int context, int device, int properties, int *errcode_ret); | |
| 61 | int clCreateProgramWithSource(int context, uint count, const char **strings, const size_t *lengths, int *errcode_ret); | |
| 62 | int clBuildProgram(int program, uint ndevices, const int *device_list, const char *options, void *notify, void *user_data); | |
| 63 | int clGetProgramBuildInfo(int program, int devices, int param_name, size_t size, void *value, size_t *size_ret); | |
| 64 | #endif | |
| 65 | ||
| 66 | #define CLHash_Utilities_CreateContext( context, command_queue) \ | |
| 67 | ( CLHash_Utilities_CreateContext_p( context, command_queue, __FILE__, __LINE__) ) | |
| 68 | #define CLHash_Utilities_BuildProgramString( context, device, programString) \ | |
| 69 | ( CLHash_Utilities_BuildProgramString_p( context, device, programString, __FILE__, __LINE__) ) | |
| 70 | #define CLHash_Utilities_BuildProgramFile( context, device, fileName) \ | |
| 71 | ( CLHash_Utilities_BuildProgramFile_p( context, device, fileName, __FILE__, __LINE__) ) | |
| 72 | ||
| 73 | #define CLHash_Utilities_HandleError( ierr, routine, cl_routine) \ | |
| 74 | ( CLHash_Utilities_HandleError_p( ierr, routine, cl_routine, __FILE__, __LINE__) ) | |
| 75 | #define CLHash_Utilities_PrintError( ierr, routine, cl_routine) \ | |
| 76 | ( CLHash_Utilities_PrintError_p( ierr, routine, cl_routine, __FILE__, __LINE__) ) | |
| 77 | ||
| 78 | /* Initialize Hash lib with program name for error reporting */ | |
| 79 | void CLHash_Init(const char *program_name_in); | |
| 80 | ||
| 81 | /* Hardware detection */ | |
| 82 | void CLHash_Utilities_CreateContext_p(cl_context *context, cl_command_queue *command_queue, const char *file, int line); | |
| 83 | ||
| 84 | /* Build Programs */ | |
| 85 | cl_program CLHash_Utilities_BuildProgramString_p(cl_context contex, cl_device_id device, const char *programString, const char *file, int line); | |
| 86 | cl_program CLHash_Utilities_BuildProgramFile_p(cl_context contex, cl_device_id device, const char* fileName, const char *file, int line); | |
| 87 | ||
| 88 | /* Error Handling */ | |
| 89 | const char* CLHash_Utilities_HandleError_p(cl_int err, const char *routine, const char *cl_routine, const char *file, int line); | |
| 90 | void CLHash_Utilities_PrintError_p(cl_int err, const char *routine, const char *cl_routine, const char *file, int line); | |
| 91 | ||
| 92 | #endif |
| … | … | @@ -0,0 +1,6495 @@ |
| 1 | ||
| 2 | /* Copyright (C) 1991-2012 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public | |
| 7 | License as published by the Free Software Foundation; either | |
| 8 | version 2.1 of the License, or (at your option) any later version. | |
| 9 | ||
| 10 | The GNU C Library is distributed in the hope that it will be useful, | |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | Lesser General Public License for more details. | |
| 14 | ||
| 15 | You should have received a copy of the GNU Lesser General Public | |
| 16 | License along with the GNU C Library; if not, see | |
| 17 | <http://www.gnu.org/licenses/>. */ | |
| 18 | /* This header is separate from features.h so that the compiler can | |
| 19 | include it implicitly at the start of every compilation. It must | |
| 20 | not itself include <features.h> or any other header that includes | |
| 21 | <features.h> because the implicit include comes before any feature | |
| 22 | test macros that may be defined in a source file before it first | |
| 23 | explicitly includes a system header. GCC knows the name of this | |
| 24 | header in order to preinclude it. */ | |
| 25 | /* We do support the IEC 559 math functionality, real and complex. */ | |
| 26 | /* wchar_t uses ISO/IEC 10646 (2nd ed., published 2011-03-15) / | |
| 27 | Unicode 6.0. */ | |
| 28 | /* We do not support C11 <threads.h>. */ | |
| 29 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 30 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 31 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 32 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 33 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 34 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 35 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 36 | * to produce derivative works, such modified software should be clearly marked, | |
| 37 | * so as not to confuse it with the version available from LANL. | |
| 38 | * | |
| 39 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 40 | * use this file except in compliance with the License. You may obtain a copy | |
| 41 | * of the License at | |
| 42 | * | |
| 43 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 44 | * | |
| 45 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 46 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 47 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 48 | * specific language governing permissions and limitations under the License. | |
| 49 | * | |
| 50 | * Under this license, it is required to include a reference to this work. We | |
| 51 | * request that each derivative work contain a reference to LANL Copyright | |
| 52 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 53 | * measured. In addition, it is requested that a modifier is included as in | |
| 54 | * the following example: | |
| 55 | * | |
| 56 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 57 | * | |
| 58 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 59 | */ | |
| 60 | /** | |
| 61 | * @file hash.c | |
| 62 | * @author Peter Ahrens | |
| 63 | * @date Thu Jun 6 2013 | |
| 64 | */ | |
| 65 | // | |
| 66 | #include "HashFactory.h" | |
| 67 | #ifdef HAVE_OPENCL | |
| 68 | #ifdef __APPLE_CC__ | |
| 69 | #include <OpenCL/OpenCL.h> | |
| 70 | #else | |
| 71 | #include <CL/cl.h> | |
| 72 | #endif | |
| 73 | #else | |
| 74 | typedef int cl_kernel; | |
| 75 | #define CL_CONTEXT_DEVICES 0 | |
| 76 | #define CL_MEM_READ_WRITE 0 | |
| 77 | #define CL_TRUE 1 | |
| 78 | #define CL_MEM_READ_ONLY 0 | |
| 79 | #define CL_MEM_COPY_HOST_PTR 0 | |
| 80 | #define CL_MEM_WRITE_ONLY 0 | |
| 81 | #define CL_KERNEL_WORK_GROUP_SIZE 128 | |
| 82 | int clRetainContext(int context) { | |
| 83 | return context; | |
| 84 | } | |
| 85 | int clRetainCommandQueue(int command_queue) { | |
| 86 | return command_queue; | |
| 87 | } | |
| 88 | int clGetContextInfo(int context, int param, size_t size, void *value, | |
| 89 | size_t * size_ret) { | |
| 90 | return 0; | |
| 91 | } | |
| 92 | int clReleaseContext(int context) { | |
| 93 | return context; | |
| 94 | } | |
| 95 | int clReleaseCommandQueue(int command_queue) { | |
| 96 | return command_queue; | |
| 97 | } | |
| 98 | int clReleaseProgram(int program) { | |
| 99 | return program; | |
| 100 | } | |
| 101 | int clRetainKernel(int kernel) { | |
| 102 | return kernel; | |
| 103 | } | |
| 104 | int clRetainProgram(int program) { | |
| 105 | return program; | |
| 106 | } | |
| 107 | cl_mem clCreateBuffer(int context, int flags, size_t size, void *value, | |
| 108 | int *size_ret) { | |
| 109 | return 0; | |
| 110 | } | |
| 111 | int clEnqueueWriteBuffer(int command_queue, void *buffer, int blocking_write, | |
| 112 | size_t offset, size_t cb, const void *ptr, | |
| 113 | uint nevents, const int *wait_list, int *event) { | |
| 114 | return 0; | |
| 115 | } | |
| 116 | int clEnqueueReadBuffer(int command_queue, void *buffer, int blocking_write, | |
| 117 | size_t offset, size_t cb, const void *ptr, uint nevents, | |
| 118 | const int *wait_list, int *event) { | |
| 119 | return 0; | |
| 120 | } | |
| 121 | int clCreateKernel(int program, const char *kernel_name, int *errcode_ret) { | |
| 122 | return 0; | |
| 123 | } | |
| 124 | int clReleaseKernel(int kernel) { | |
| 125 | return kernel; | |
| 126 | } | |
| 127 | int clReleaseMemObject(void *memobj) { | |
| 128 | return 0; | |
| 129 | } | |
| 130 | int clSetKernelArg(int kernel, uint arg_index, size_t arg_size, | |
| 131 | const void *arg_value) { | |
| 132 | return 0; | |
| 133 | } | |
| 134 | int clGetKernelWorkGroupInfo(int kernel, int device, int param_name, | |
| 135 | size_t size, void *value, size_t * size_ret) { | |
| 136 | return 0; | |
| 137 | } | |
| 138 | int clEnqueueNDRangeKernel(int command_queue, int kernel, uint work_dim, | |
| 139 | const size_t * offset, const size_t * size, | |
| 140 | const size_t * local_size, uint nevents, | |
| 141 | const int *wait_list, int *event) { | |
| 142 | return 0; | |
| 143 | } | |
| 144 | int clFinish(int command_queue) { | |
| 145 | return 0; | |
| 146 | } | |
| 147 | #endif | |
| 148 | #define PRIME_NUM_CHECKS 20 | |
| 149 | typedef unsigned int uint; | |
| 150 | #include <math.h> | |
| 151 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 152 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 153 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 154 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 155 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 156 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 157 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 158 | * to produce derivative works, such modified software should be clearly marked, | |
| 159 | * so as not to confuse it with the version available from LANL. | |
| 160 | * | |
| 161 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 162 | * use this file except in compliance with the License. You may obtain a copy | |
| 163 | * of the License at | |
| 164 | * | |
| 165 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 166 | * | |
| 167 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 168 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 169 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 170 | * specific language governing permissions and limitations under the License. | |
| 171 | * | |
| 172 | * Under this license, it is required to include a reference to this work. We | |
| 173 | * request that each derivative work contain a reference to LANL Copyright | |
| 174 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 175 | * measured. In addition, it is requested that a modifier is included as in | |
| 176 | * the following example: | |
| 177 | * | |
| 178 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 179 | * | |
| 180 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 181 | */ | |
| 182 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 183 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 184 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 185 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 186 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 187 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 188 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 189 | * to produce derivative works, such modified software should be clearly marked, | |
| 190 | * so as not to confuse it with the version available from LANL. | |
| 191 | * | |
| 192 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 193 | * use this file except in compliance with the License. You may obtain a copy | |
| 194 | * of the License at | |
| 195 | * | |
| 196 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 197 | * | |
| 198 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 199 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 200 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 201 | * specific language governing permissions and limitations under the License. | |
| 202 | * | |
| 203 | * Under this license, it is required to include a reference to this work. We | |
| 204 | * request that each derivative work contain a reference to LANL Copyright | |
| 205 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 206 | * measured. In addition, it is requested that a modifier is included as in | |
| 207 | * the following example: | |
| 208 | * | |
| 209 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 210 | * | |
| 211 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 212 | */ | |
| 213 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 214 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 215 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 216 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 217 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 218 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 219 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 220 | * to produce derivative works, such modified software should be clearly marked, | |
| 221 | * so as not to confuse it with the version available from LANL. | |
| 222 | * | |
| 223 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 224 | * use this file except in compliance with the License. You may obtain a copy | |
| 225 | * of the License at | |
| 226 | * | |
| 227 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 228 | * | |
| 229 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 230 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 231 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 232 | * specific language governing permissions and limitations under the License. | |
| 233 | * | |
| 234 | * Under this license, it is required to include a reference to this work. We | |
| 235 | * request that each derivative work contain a reference to LANL Copyright | |
| 236 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 237 | * measured. In addition, it is requested that a modifier is included as in | |
| 238 | * the following example: | |
| 239 | * | |
| 240 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 241 | * | |
| 242 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 243 | */ | |
| 244 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 245 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 246 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 247 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 248 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 249 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 250 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 251 | * to produce derivative works, such modified software should be clearly marked, | |
| 252 | * so as not to confuse it with the version available from LANL. | |
| 253 | * | |
| 254 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 255 | * use this file except in compliance with the License. You may obtain a copy | |
| 256 | * of the License at | |
| 257 | * | |
| 258 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 259 | * | |
| 260 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 261 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 262 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 263 | * specific language governing permissions and limitations under the License. | |
| 264 | * | |
| 265 | * Under this license, it is required to include a reference to this work. We | |
| 266 | * request that each derivative work contain a reference to LANL Copyright | |
| 267 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 268 | * measured. In addition, it is requested that a modifier is included as in | |
| 269 | * the following example: | |
| 270 | * | |
| 271 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 272 | * | |
| 273 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 274 | */ | |
| 275 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 276 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 277 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 278 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 279 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 280 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 281 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 282 | * to produce derivative works, such modified software should be clearly marked, | |
| 283 | * so as not to confuse it with the version available from LANL. | |
| 284 | * | |
| 285 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 286 | * use this file except in compliance with the License. You may obtain a copy | |
| 287 | * of the License at | |
| 288 | * | |
| 289 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 290 | * | |
| 291 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 292 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 293 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 294 | * specific language governing permissions and limitations under the License. | |
| 295 | * | |
| 296 | * Under this license, it is required to include a reference to this work. We | |
| 297 | * request that each derivative work contain a reference to LANL Copyright | |
| 298 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 299 | * measured. In addition, it is requested that a modifier is included as in | |
| 300 | * the following example: | |
| 301 | * | |
| 302 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 303 | * | |
| 304 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 305 | */ | |
| 306 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 307 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 308 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 309 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 310 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 311 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 312 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 313 | * to produce derivative works, such modified software should be clearly marked, | |
| 314 | * so as not to confuse it with the version available from LANL. | |
| 315 | * | |
| 316 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 317 | * use this file except in compliance with the License. You may obtain a copy | |
| 318 | * of the License at | |
| 319 | * | |
| 320 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 321 | * | |
| 322 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 323 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 324 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 325 | * specific language governing permissions and limitations under the License. | |
| 326 | * | |
| 327 | * Under this license, it is required to include a reference to this work. We | |
| 328 | * request that each derivative work contain a reference to LANL Copyright | |
| 329 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 330 | * measured. In addition, it is requested that a modifier is included as in | |
| 331 | * the following example: | |
| 332 | * | |
| 333 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 334 | * | |
| 335 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 336 | */ | |
| 337 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 338 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 339 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 340 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 341 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 342 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 343 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 344 | * to produce derivative works, such modified software should be clearly marked, | |
| 345 | * so as not to confuse it with the version available from LANL. | |
| 346 | * | |
| 347 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 348 | * use this file except in compliance with the License. You may obtain a copy | |
| 349 | * of the License at | |
| 350 | * | |
| 351 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 352 | * | |
| 353 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 354 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 355 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 356 | * specific language governing permissions and limitations under the License. | |
| 357 | * | |
| 358 | * Under this license, it is required to include a reference to this work. We | |
| 359 | * request that each derivative work contain a reference to LANL Copyright | |
| 360 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 361 | * measured. In addition, it is requested that a modifier is included as in | |
| 362 | * the following example: | |
| 363 | * | |
| 364 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 365 | * | |
| 366 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 367 | */ | |
| 368 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 369 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 370 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 371 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 372 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 373 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 374 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 375 | * to produce derivative works, such modified software should be clearly marked, | |
| 376 | * so as not to confuse it with the version available from LANL. | |
| 377 | * | |
| 378 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 379 | * use this file except in compliance with the License. You may obtain a copy | |
| 380 | * of the License at | |
| 381 | * | |
| 382 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 383 | * | |
| 384 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 385 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 386 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 387 | * specific language governing permissions and limitations under the License. | |
| 388 | * | |
| 389 | * Under this license, it is required to include a reference to this work. We | |
| 390 | * request that each derivative work contain a reference to LANL Copyright | |
| 391 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 392 | * measured. In addition, it is requested that a modifier is included as in | |
| 393 | * the following example: | |
| 394 | * | |
| 395 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 396 | * | |
| 397 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 398 | */ | |
| 399 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 400 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 401 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 402 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 403 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 404 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 405 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 406 | * to produce derivative works, such modified software should be clearly marked, | |
| 407 | * so as not to confuse it with the version available from LANL. | |
| 408 | * | |
| 409 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 410 | * use this file except in compliance with the License. You may obtain a copy | |
| 411 | * of the License at | |
| 412 | * | |
| 413 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 414 | * | |
| 415 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 416 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 417 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 418 | * specific language governing permissions and limitations under the License. | |
| 419 | * | |
| 420 | * Under this license, it is required to include a reference to this work. We | |
| 421 | * request that each derivative work contain a reference to LANL Copyright | |
| 422 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 423 | * measured. In addition, it is requested that a modifier is included as in | |
| 424 | * the following example: | |
| 425 | * | |
| 426 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 427 | * | |
| 428 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 429 | */ | |
| 430 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 431 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 432 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 433 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 434 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 435 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 436 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 437 | * to produce derivative works, such modified software should be clearly marked, | |
| 438 | * so as not to confuse it with the version available from LANL. | |
| 439 | * | |
| 440 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 441 | * use this file except in compliance with the License. You may obtain a copy | |
| 442 | * of the License at | |
| 443 | * | |
| 444 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 445 | * | |
| 446 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 447 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 448 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 449 | * specific language governing permissions and limitations under the License. | |
| 450 | * | |
| 451 | * Under this license, it is required to include a reference to this work. We | |
| 452 | * request that each derivative work contain a reference to LANL Copyright | |
| 453 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 454 | * measured. In addition, it is requested that a modifier is included as in | |
| 455 | * the following example: | |
| 456 | * | |
| 457 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 458 | * | |
| 459 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 460 | */ | |
| 461 | static int reportLevel = 0; | |
| 462 | const char *HashFactory_source; | |
| 463 | const char *Hash_GetKernelSourceString() { | |
| 464 | return HashFactory_source; | |
| 465 | } | |
| 466 | size_t roundUpToNearest(size_t x, size_t r) { | |
| 467 | return (((x - 1) / r) + 1) * r; | |
| 468 | } | |
| 469 | int modularPow(int base, int exponent, int modulus) { | |
| 470 | int result = 1; | |
| 471 | while (exponent) { | |
| 472 | if (exponent & 1) | |
| 473 | result = ((long long int)result * base) % modulus; | |
| 474 | exponent >>= 1; | |
| 475 | base = ((long long int)base * base) % modulus; | |
| 476 | } | |
| 477 | return result; | |
| 478 | } | |
| 479 | int largestProthPrimeUnder(int N) { | |
| 480 | if (N < 4) { | |
| 481 | return N; | |
| 482 | } | |
| 483 | //determine the nearest proth number | |
| 484 | int n; | |
| 485 | int m; | |
| 486 | frexp((double)N, &n); | |
| 487 | n /= 2; | |
| 488 | int s = 1 << n; | |
| 489 | int p = s * ((N - 1) / s) + 1; | |
| 490 | int i; | |
| 491 | int a; | |
| 492 | srand(p); | |
| 493 | while (p > 3) { | |
| 494 | //check if a proth number is prime | |
| 495 | for (i = 0; i < PRIME_NUM_CHECKS; i++) { | |
| 496 | a = rand(); | |
| 497 | if (modularPow(a, (p - 1) / 2, p) == p - 1) { | |
| 498 | return p; | |
| 499 | } | |
| 500 | } | |
| 501 | //determine the next proth number | |
| 502 | if (p - 1 == s * s / 4) { | |
| 503 | s /= 2; | |
| 504 | } | |
| 505 | p -= s; | |
| 506 | } | |
| 507 | return 3; | |
| 508 | } | |
| 509 | int smallestProthPrimeAbove(int N) { | |
| 510 | if (N < 4) { | |
| 511 | return N; | |
| 512 | } | |
| 513 | //determine the nearest proth number | |
| 514 | int n; | |
| 515 | int m; | |
| 516 | frexp((double)N, &n); | |
| 517 | n /= 2; | |
| 518 | int s = 1 << n; | |
| 519 | int p = s * ((N - 1) / s) + 1; | |
| 520 | int i; | |
| 521 | int a; | |
| 522 | srand(p); | |
| 523 | while (1) { | |
| 524 | //determine the next proth number | |
| 525 | if (p - 1 == s * s) { | |
| 526 | s *= 2; | |
| 527 | } | |
| 528 | p += s; | |
| 529 | //check if a proth number is prime | |
| 530 | for (i = 0; i < PRIME_NUM_CHECKS; i++) { | |
| 531 | a = rand(); | |
| 532 | if (modularPow(a, (p - 1) / 2, p) == p - 1) { | |
| 533 | return p; | |
| 534 | } | |
| 535 | } | |
| 536 | } | |
| 537 | return 3; | |
| 538 | } | |
| 539 | int intLog2(int n) { | |
| 540 | int result = 0; | |
| 541 | while (n >>= 1) { | |
| 542 | result++; | |
| 543 | } | |
| 544 | return result; | |
| 545 | } | |
| 546 | void Hash_SetReportLevel(int level) { | |
| 547 | reportLevel = level; | |
| 548 | } | |
| 549 | int Hash_GetReportLevel() { | |
| 550 | return reportLevel; | |
| 551 | } | |
| 552 | char *Hash_ExitCodeString(int exitCode) { | |
| 553 | switch (exitCode) { | |
| 554 | case HASH_EXIT_CODE_NORMAL: | |
| 555 | return "Normal"; | |
| 556 | case HASH_EXIT_CODE_ERROR: | |
| 557 | return "Error"; | |
| 558 | case HASH_EXIT_CODE_OVERWRITE: | |
| 559 | return "Overwrite"; | |
| 560 | case HASH_EXIT_CODE_KEY_DNE: | |
| 561 | return "Key Does Not Exist"; | |
| 562 | case HASH_EXIT_CODE_CYCLE: | |
| 563 | return "Cycle"; | |
| 564 | case HASH_EXIT_CODE_MAX_ENTRIES_EXCEEDED: | |
| 565 | return "Maximum Number Of Entries Exceeded"; | |
| 566 | default: | |
| 567 | return "Unknown"; | |
| 568 | } | |
| 569 | } | |
| 570 | void Hash_ExitCodeDebug(int exitCode) { | |
| 571 | if (exitCode != HASH_EXIT_CODE_NORMAL) { | |
| 572 | printf("HashExitCode: %s\n", Hash_ExitCodeString(exitCode)); | |
| 573 | } | |
| 574 | } | |
| 575 | ||
| 576 | struct intintHash_Table_ { | |
| 577 | char *tableData; | |
| 578 | cl_mem tableDataBuffer; | |
| 579 | int (*destroyFunc) (intintHash_Table *); | |
| 580 | int (*emptyFunc) (intintHash_Table *); | |
| 581 | int (*queryFunc) (intintHash_Table *, size_t, int *, int *); | |
| 582 | int (*querySingleFunc) (intintHash_Table *, int, int *); | |
| 583 | int (*insertFunc) (intintHash_Table *, size_t, int *, int *); | |
| 584 | int (*insertSingleFunc) (intintHash_Table *, int, int); | |
| 585 | int (*insertNoOverwriteFunc) (intintHash_Table *, size_t, int *, int *); | |
| 586 | int (*insertSingleNoOverwriteFunc) (intintHash_Table *, int, int); | |
| 587 | int (*bufferQueryFunc) (intintHash_Table *, size_t, cl_mem, cl_mem); | |
| 588 | int (*bufferInsertFunc) (intintHash_Table *, size_t, cl_mem, cl_mem); | |
| 589 | int (*bufferInsertNoOverwriteFunc) (intintHash_Table *, size_t, cl_mem, | |
| 590 | cl_mem); | |
| 591 | cl_context context; | |
| 592 | cl_command_queue queue; | |
| 593 | cl_program utilProgram; | |
| 594 | cl_kernel emptyKernel; | |
| 595 | size_t emptyKernelLocalWorkSize; | |
| 596 | cl_program program; | |
| 597 | cl_kernel querySingleKernel; | |
| 598 | cl_kernel insertSingleKernel; | |
| 599 | cl_kernel insertSingleNoOverwriteKernel; | |
| 600 | size_t localWorkSize; | |
| 601 | }; | |
| 602 | struct intintHash_Factory_ { | |
| 603 | cl_context context; | |
| 604 | cl_program program; | |
| 605 | cl_command_queue queue; | |
| 606 | int hashTypesAvailable; | |
| 607 | cl_program utilProgram[HASH_NUM_CL_HASHES]; | |
| 608 | cl_kernel emptyKernel[HASH_NUM_CL_HASHES]; | |
| 609 | size_t emptyKernelLocalWorkSize[HASH_NUM_CL_HASHES]; | |
| 610 | cl_kernel querySingleKernel[HASH_NUM_CL_HASHES]; | |
| 611 | cl_kernel insertSingleKernel[HASH_NUM_CL_HASHES]; | |
| 612 | cl_kernel insertSingleNoOverwriteKernel[HASH_NUM_CL_HASHES]; | |
| 613 | int emptyValue; | |
| 614 | size_t localWorkSize; | |
| 615 | intintHash_Table *(*createFunc[HASH_NUM_HASHES]) (intintHash_Factory *, | |
| 616 | int hashIndex, | |
| 617 | size_t keyRange, | |
| 618 | size_t numEntries, | |
| 619 | float loadFactor); | |
| 620 | int (*destroyFunc[HASH_NUM_HASHES]) (intintHash_Factory *, | |
| 621 | int hashIndex); | |
| 622 | }; | |
| 623 | intintHash_Factory *intintHash_CreateFactory(int hashTypes, int *emptyValue, | |
| 624 | size_t localWorkSize, | |
| 625 | cl_context * context, | |
| 626 | cl_command_queue * queue) { | |
| 627 | if (hashTypes == 0) { | |
| 628 | hashTypes = HASH_ALL_C_HASHES; | |
| 629 | } | |
| 630 | if (!(hashTypes & HASH_ALL_HASHES)) { | |
| 631 | printf("Please specify a valid hash type to create.\n"); | |
| 632 | exit(1); | |
| 633 | } | |
| 634 | hashTypes &= HASH_ALL_HASHES; | |
| 635 | if ((hashTypes & HASH_SENTINEL_PERFECT_HASHES) == hashTypes | |
| 636 | && emptyValue == NULL) { | |
| 637 | printf | |
| 638 | ("emptyValue must be valid if a sentinel perfect hash is the only option available.\n"); | |
| 639 | exit(1); | |
| 640 | } | |
| 641 | intintHash_Factory *factory = | |
| 642 | (intintHash_Factory *) malloc(sizeof(intintHash_Factory)); | |
| 643 | if (emptyValue == NULL) { | |
| 644 | hashTypes &= !HASH_SENTINEL_PERFECT_HASHES; | |
| 645 | } else { | |
| 646 | factory->emptyValue = *emptyValue; | |
| 647 | } | |
| 648 | factory->hashTypesAvailable = hashTypes; | |
| 649 | if (hashTypes & HASH_ALL_CL_HASHES) { | |
| 650 | if (localWorkSize == 0) { | |
| 651 | factory->localWorkSize = HASH_DEFAULT_LOCAL_WORK_SIZE; | |
| 652 | } else { | |
| 653 | factory->localWorkSize = 1 << intLog2(localWorkSize); | |
| 654 | } | |
| 655 | if (context == NULL) { | |
| 656 | CLHash_Utilities_CreateContext(&factory->context, | |
| 657 | &factory->queue); | |
| 658 | } else { | |
| 659 | factory->context = *context; | |
| 660 | clRetainContext(*context); | |
| 661 | if (queue == NULL) { | |
| 662 | printf | |
| 663 | ("Please specify a command queue for your context.\n"); | |
| 664 | exit(-1); | |
| 665 | } | |
| 666 | factory->queue = *queue; | |
| 667 | clRetainCommandQueue(*queue); | |
| 668 | } | |
| 669 | cl_int error; | |
| 670 | cl_device_id device; | |
| 671 | error = | |
| 672 | clGetContextInfo(factory->context, CL_CONTEXT_DEVICES, | |
| 673 | sizeof(device), &device, NULL); | |
| 674 | CLHash_Utilities_HandleError(error, "intintHash_CreateFactory", | |
| 675 | "clGetContextInfo"); | |
| 676 | factory->program = | |
| 677 | CLHash_Utilities_BuildProgramString(factory->context, | |
| 678 | device, | |
| 679 | Hash_GetKernelSourceString | |
| 680 | ()); | |
| 681 | } | |
| 682 | int hashType = 1; | |
| 683 | for (int hashIndex = 0; hashIndex < HASH_NUM_HASHES; hashIndex++) { | |
| 684 | hashType = 1 << hashIndex; | |
| 685 | switch (hashType & hashTypes) { | |
| 686 | case IDENTITY_PERFECT_HASH_ID: | |
| 687 | intintIdentityPerfectHash_CreateFactory(factory, | |
| 688 | hashIndex); | |
| 689 | break; | |
| 690 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 691 | intintIdentityPerfectCLHash_CreateFactory(factory, | |
| 692 | hashIndex); | |
| 693 | break; | |
| 694 | case IDENTITY_SENTINEL_PERFECT_HASH_ID: | |
| 695 | intintIdentitySentinelPerfectHash_CreateFactory(factory, | |
| 696 | hashIndex); | |
| 697 | break; | |
| 698 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 699 | intintIdentitySentinelPerfectCLHash_CreateFactory | |
| 700 | (factory, hashIndex); | |
| 701 | break; | |
| 702 | case LCG_LINEAR_OPEN_COMPACT_HASH_ID: | |
| 703 | intintLCGLinearOpenCompactHash_CreateFactory(factory, | |
| 704 | hashIndex); | |
| 705 | break; | |
| 706 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 707 | intintLCGLinearOpenCompactCLHash_CreateFactory(factory, | |
| 708 | hashIndex); | |
| 709 | break; | |
| 710 | case LCG_QUADRATIC_OPEN_COMPACT_HASH_ID: | |
| 711 | intintLCGQuadraticOpenCompactHash_CreateFactory(factory, | |
| 712 | hashIndex); | |
| 713 | break; | |
| 714 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 715 | intintLCGQuadraticOpenCompactCLHash_CreateFactory | |
| 716 | (factory, hashIndex); | |
| 717 | break; | |
| 718 | } | |
| 719 | } | |
| 720 | return factory; | |
| 721 | } | |
| 722 | int intintHash_DestroyFactory(intintHash_Factory * factory) { | |
| 723 | int hashType; | |
| 724 | for (int hashIndex = 0; hashIndex < HASH_NUM_HASHES; | |
| 725 | hashType = 1 << hashIndex) { | |
| 726 | switch (hashType & factory->hashTypesAvailable) { | |
| 727 | case IDENTITY_PERFECT_HASH_ID: | |
| 728 | intintIdentityPerfectHash_DestroyFactory(factory, | |
| 729 | hashIndex); | |
| 730 | break; | |
| 731 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 732 | intintIdentityPerfectCLHash_DestroyFactory(factory, | |
| 733 | hashIndex); | |
| 734 | break; | |
| 735 | case IDENTITY_SENTINEL_PERFECT_HASH_ID: | |
| 736 | intintIdentitySentinelPerfectHash_DestroyFactory | |
| 737 | (factory, hashIndex); | |
| 738 | break; | |
| 739 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 740 | intintIdentitySentinelPerfectCLHash_DestroyFactory | |
| 741 | (factory, hashIndex); | |
| 742 | break; | |
| 743 | case LCG_LINEAR_OPEN_COMPACT_HASH_ID: | |
| 744 | intintLCGLinearOpenCompactHash_DestroyFactory(factory, | |
| 745 | hashIndex); | |
| 746 | break; | |
| 747 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 748 | intintLCGLinearOpenCompactCLHash_DestroyFactory(factory, | |
| 749 | hashIndex); | |
| 750 | break; | |
| 751 | case LCG_QUADRATIC_OPEN_COMPACT_HASH_ID: | |
| 752 | intintLCGQuadraticOpenCompactHash_DestroyFactory | |
| 753 | (factory, hashIndex); | |
| 754 | break; | |
| 755 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 756 | intintLCGQuadraticOpenCompactCLHash_DestroyFactory | |
| 757 | (factory, hashIndex); | |
| 758 | break; | |
| 759 | } | |
| 760 | hashIndex++; | |
| 761 | } | |
| 762 | if (factory->hashTypesAvailable & HASH_ALL_CL_HASHES) { | |
| 763 | clReleaseContext(factory->context); | |
| 764 | clReleaseCommandQueue(factory->queue); | |
| 765 | clReleaseProgram(factory->program); | |
| 766 | } | |
| 767 | free(factory); | |
| 768 | return (0); | |
| 769 | } | |
| 770 | intintHash_Table *intintHash_CreateTable(intintHash_Factory * factory, | |
| 771 | int hashTypes, size_t keyRange, | |
| 772 | size_t numEntries, float loadFactor) { | |
| 773 | if (loadFactor > 1.0 || loadFactor < HASH_MIN_LOAD_FACTOR) { | |
| 774 | loadFactor = HASH_DEFAULT_LOAD_FACTOR; | |
| 775 | } | |
| 776 | if (hashTypes == 0) { | |
| 777 | hashTypes = factory->hashTypesAvailable; | |
| 778 | if ((hashTypes & HASH_ALL_CL_HASHES) | |
| 779 | && (hashTypes & HASH_ALL_C_HASHES)) { | |
| 780 | hashTypes &= HASH_ALL_C_HASHES; | |
| 781 | } | |
| 782 | } | |
| 783 | if (!(hashTypes & factory->hashTypesAvailable)) { | |
| 784 | printf | |
| 785 | ("None of the selected hash types are supported by this factory.\n"); | |
| 786 | exit(1); | |
| 787 | } | |
| 788 | hashTypes &= factory->hashTypesAvailable; | |
| 789 | if ((hashTypes & HASH_ALL_CL_HASHES) && (hashTypes & HASH_ALL_C_HASHES)) { | |
| 790 | printf("Please decide between OpenCL or C hash.\n"); | |
| 791 | exit(1); | |
| 792 | } | |
| 793 | if ((hashTypes & HASH_PERFECT_HASHES) == hashTypes && keyRange == 0) { | |
| 794 | printf | |
| 795 | ("keyRange must be set if a perfect hash is the only option available.\n"); | |
| 796 | exit(1); | |
| 797 | } | |
| 798 | if ((hashTypes & HASH_COMPACT_HASHES) == hashTypes && numEntries == 0) { | |
| 799 | printf | |
| 800 | ("numEntries must be set if a compact hash is the only option available.\n"); | |
| 801 | exit(1); | |
| 802 | } | |
| 803 | if (numEntries == 0 && keyRange == 0) { | |
| 804 | printf("either numEntries or keyRange must be set.\n"); | |
| 805 | exit(1); | |
| 806 | } | |
| 807 | size_t perfectNumBuckets = keyRange; | |
| 808 | size_t compactNumBuckets = (size_t) (numEntries / loadFactor); | |
| 809 | int hashIndex; | |
| 810 | if ((hashTypes & HASH_SENTINEL_PERFECT_HASHES) | |
| 811 | && ((hashTypes == (hashTypes & HASH_SENTINEL_PERFECT_HASHES)) | |
| 812 | || (compactNumBuckets == 0 | |
| 813 | || (perfectNumBuckets / compactNumBuckets < | |
| 814 | HASH_PERFECT_COMPACT_SWITCH_FACTOR)))) { | |
| 815 | hashIndex = intLog2(hashTypes & HASH_SENTINEL_PERFECT_HASHES); | |
| 816 | } else if ((hashTypes & HASH_NOSENTINEL_PERFECT_HASHES) | |
| 817 | && ((hashTypes == (hashTypes & HASH_PERFECT_HASHES)) | |
| 818 | || (compactNumBuckets == 0 | |
| 819 | || (perfectNumBuckets / compactNumBuckets < | |
| 820 | HASH_PERFECT_COMPACT_SWITCH_FACTOR)))) { | |
| 821 | hashIndex = intLog2(hashTypes & HASH_NOSENTINEL_PERFECT_HASHES); | |
| 822 | } else if ((hashTypes & HASH_LINEAR_COMPACT_HASHES) | |
| 823 | && | |
| 824 | ((hashTypes == | |
| 825 | (hashTypes & | |
| 826 | (HASH_PERFECT_HASHES | HASH_LINEAR_COMPACT_HASHES))) | |
| 827 | || | |
| 828 | ((hashTypes & HASH_COMPACT_HASHES & | |
| 829 | HASH_LINEAR_COMPACT_HASHES) == | |
| 830 | (hashTypes & HASH_COMPACT_HASHES) || loadFactor > 0.5))) { | |
| 831 | hashIndex = intLog2(hashTypes & HASH_LINEAR_COMPACT_HASHES); | |
| 832 | } else { | |
| 833 | hashIndex = intLog2(hashTypes & HASH_QUADRATIC_COMPACT_HASHES); | |
| 834 | } | |
| 835 | intintHash_Table *table = | |
| 836 | factory->createFunc[hashIndex] (factory, hashIndex, keyRange, | |
| 837 | numEntries, loadFactor); | |
| 838 | return table; | |
| 839 | } | |
| 840 | int intintHash_EmptyTable(intintHash_Table * table) { | |
| 841 | table->emptyFunc(table); | |
| 842 | return (0); | |
| 843 | } | |
| 844 | int intintHash_DestroyTable(intintHash_Table * table) { | |
| 845 | table->destroyFunc(table); | |
| 846 | return (0); | |
| 847 | } | |
| 848 | cl_mem intintHash_GetTableDataBuffer(intintHash_Table * table) { | |
| 849 | return table->tableDataBuffer; | |
| 850 | } | |
| 851 | cl_mem *intintHash_GetTableDataBufferPtr(intintHash_Table * table) { | |
| 852 | return &table->tableDataBuffer; | |
| 853 | } | |
| 854 | int intintHash_GetTableType(intintHash_Table * table) { | |
| 855 | return ((int *)table->tableData)[0]; | |
| 856 | } int intintHash_Query(intintHash_Table * table, size_t numKeys, int *keys, | |
| 857 | int *valuesOutput) { | |
| 858 | table->queryFunc(table, numKeys, keys, valuesOutput); | |
| 859 | return (0); | |
| 860 | } | |
| 861 | int intintHash_QuerySingle(intintHash_Table * table, int key, int *valueOutput) { | |
| 862 | table->querySingleFunc(table, key, valueOutput); | |
| 863 | return (0); | |
| 864 | } | |
| 865 | int intintHash_Insert(intintHash_Table * table, size_t numEntries, int *keys, | |
| 866 | int *values) { | |
| 867 | table->insertFunc(table, numEntries, keys, values); | |
| 868 | return (0); | |
| 869 | } | |
| 870 | int intintHash_InsertSingle(intintHash_Table * table, int key, int value) { | |
| 871 | table->insertSingleFunc(table, key, value); | |
| 872 | return (0); | |
| 873 | } | |
| 874 | int intintHash_InsertNoOverwrite(intintHash_Table * table, size_t numEntries, | |
| 875 | int *keys, int *values) { | |
| 876 | table->insertNoOverwriteFunc(table, numEntries, keys, values); | |
| 877 | return (0); | |
| 878 | } | |
| 879 | int intintHash_InsertSingleNoOverwrite(intintHash_Table * table, int key, | |
| 880 | int value) { | |
| 881 | table->insertSingleNoOverwriteFunc(table, key, value); | |
| 882 | return (0); | |
| 883 | } | |
| 884 | int intintHash_BufferQuery(intintHash_Table * table, size_t numKeys, | |
| 885 | cl_mem keys, cl_mem valuesOutput) { | |
| 886 | table->bufferQueryFunc(table, numKeys, keys, valuesOutput); | |
| 887 | return (0); | |
| 888 | } | |
| 889 | int intintHash_BufferInsert(intintHash_Table * table, size_t numEntries, | |
| 890 | cl_mem keys, cl_mem values) { | |
| 891 | table->bufferInsertFunc(table, numEntries, keys, values); | |
| 892 | return (0); | |
| 893 | } | |
| 894 | int intintHash_BufferInsertNoOverwrite(intintHash_Table * table, | |
| 895 | size_t numEntries, cl_mem keys, | |
| 896 | cl_mem values) { | |
| 897 | table->bufferInsertNoOverwriteFunc(table, numEntries, keys, values); | |
| 898 | return (0); | |
| 899 | } | |
| 900 | ||
| 901 | typedef struct intintIdentityPerfectHash_TableData { | |
| 902 | int hashID; | |
| 903 | unsigned int numBuckets; | |
| 904 | char compressFuncData; | |
| 905 | } intintIdentityPerfectHash_TableData; | |
| 906 | typedef struct intintIdentityPerfectHash_Bucket { | |
| 907 | int key; | |
| 908 | int value; | |
| 909 | } intintIdentityPerfectHash_Bucket; | |
| 910 | intintHash_Table *intintIdentityPerfectHash_CreateTable(intintHash_Factory * | |
| 911 | factory, int hashIndex, | |
| 912 | size_t keyRange, | |
| 913 | size_t numEntries, | |
| 914 | float loadFactor) { | |
| 915 | intintHash_Table *table = | |
| 916 | (intintHash_Table *) malloc(sizeof(intintHash_Table)); | |
| 917 | table->destroyFunc = &intintIdentityPerfectHash_DestroyTable; | |
| 918 | table->emptyFunc = &intintIdentityPerfectHash_EmptyTable; | |
| 919 | table->queryFunc = &intintIdentityPerfectHash_Query; | |
| 920 | table->querySingleFunc = &intintIdentityPerfectHash_QuerySingle; | |
| 921 | table->insertFunc = &intintIdentityPerfectHash_Insert; | |
| 922 | table->insertSingleFunc = &intintIdentityPerfectHash_InsertSingle; | |
| 923 | table->insertNoOverwriteFunc = | |
| 924 | &intintIdentityPerfectHash_InsertNoOverwrite; | |
| 925 | table->insertSingleNoOverwriteFunc = | |
| 926 | &intintIdentityPerfectHash_InsertSingleNoOverwrite; | |
| 927 | table->tableData = | |
| 928 | (char *)malloc(sizeof(intintIdentityPerfectHash_TableData)); | |
| 929 | ((intintIdentityPerfectHash_TableData *) table->tableData)->hashID = | |
| 930 | IDENTITY_PERFECT_HASH_ID; | |
| 931 | ((intintIdentityPerfectHash_TableData *) table->tableData)->numBuckets = | |
| 932 | keyRange + 1; | |
| 933 | char *tempHashData = | |
| 934 | (char *)malloc(sizeof(intintIdentityPerfectHash_TableData) + | |
| 935 | ((intintIdentityPerfectHash_TableData *) table-> | |
| 936 | tableData)->numBuckets * | |
| 937 | sizeof(intintIdentityPerfectHash_Bucket)); | |
| 938 | memcpy(tempHashData, table->tableData, | |
| 939 | sizeof(intintIdentityPerfectHash_TableData)); | |
| 940 | free(table->tableData); | |
| 941 | table->tableData = tempHashData; | |
| 942 | return table; | |
| 943 | } | |
| 944 | int intintIdentityPerfectHash_CreateFactory(intintHash_Factory * factory, | |
| 945 | int hashIndex) { | |
| 946 | factory->createFunc[hashIndex] = &intintIdentityPerfectHash_CreateTable; | |
| 947 | factory->destroyFunc[hashIndex] = | |
| 948 | &intintIdentityPerfectHash_DestroyFactory;; | |
| 949 | return HASH_EXIT_CODE_NORMAL; | |
| 950 | } | |
| 951 | int intintIdentityPerfectHash_DestroyFactory(intintHash_Factory * factory, | |
| 952 | int hashIndex) {; | |
| 953 | return HASH_EXIT_CODE_NORMAL; | |
| 954 | } | |
| 955 | int intintIdentityPerfectHash_DestroyTable(intintHash_Table * table) { | |
| 956 | int exitCode = 0; | |
| 957 | free(table->tableData); | |
| 958 | free(table); | |
| 959 | return exitCode; | |
| 960 | } | |
| 961 | int intintIdentityPerfectHash_EmptyTable(intintHash_Table * table) { | |
| 962 | int exitCode = 0; | |
| 963 | intintIdentityPerfectHash_Bucket *buckets = | |
| 964 | (intintIdentityPerfectHash_Bucket *) & table-> | |
| 965 | tableData[sizeof(intintIdentityPerfectHash_TableData)]; | |
| 966 | int index; | |
| 967 | for (index = 0; | |
| 968 | index < | |
| 969 | ((intintIdentityPerfectHash_TableData *) table->tableData)-> | |
| 970 | numBuckets; index++) { | |
| 971 | buckets[index].key = HASH_BUCKET_STATUS_EMPTY; | |
| 972 | } | |
| 973 | exitCode = HASH_EXIT_CODE_NORMAL; | |
| 974 | return exitCode; | |
| 975 | } | |
| 976 | int intintIdentityPerfectHash_InnerQuerySingle(char *tableData, int key, | |
| 977 | int *valueOutput) { | |
| 978 | intintIdentityPerfectHash_Bucket *buckets = | |
| 979 | (intintIdentityPerfectHash_Bucket *) & | |
| 980 | tableData[sizeof(intintIdentityPerfectHash_TableData)]; | |
| 981 | int index; | |
| 982 | int exitCode; | |
| 983 | index = | |
| 984 | intintHash_CompressIdentity(((intintIdentityPerfectHash_TableData *) | |
| 985 | tableData)->compressFuncData, key); | |
| 986 | if ((buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 987 | if (key == buckets[index].key) { | |
| 988 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 989 | } else { | |
| 990 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 991 | } | |
| 992 | } else { | |
| 993 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 994 | } | |
| 995 | switch (exitCode) { | |
| 996 | case HASH_SEARCH_CODE_MATCH: | |
| 997 | *valueOutput = buckets[index].value; | |
| 998 | return HASH_EXIT_CODE_NORMAL; | |
| 999 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1000 | case HASH_SEARCH_CODE_EMPTY: | |
| 1001 | return HASH_EXIT_CODE_KEY_DNE; | |
| 1002 | default: | |
| 1003 | return exitCode; | |
| 1004 | } | |
| 1005 | } | |
| 1006 | int intintIdentityPerfectHash_InnerQuery(char *tableData, unsigned int numKeys, | |
| 1007 | int *keys, int *valuesOutput) { | |
| 1008 | intintIdentityPerfectHash_Bucket *buckets = | |
| 1009 | (intintIdentityPerfectHash_Bucket *) & | |
| 1010 | tableData[sizeof(intintIdentityPerfectHash_TableData)]; | |
| 1011 | int key; | |
| 1012 | int *valueOutput; | |
| 1013 | int index; | |
| 1014 | int exitCode; | |
| 1015 | uint i; | |
| 1016 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1017 | for (i = 0; i < numKeys; i++) { | |
| 1018 | key = keys[i]; | |
| 1019 | valueOutput = &valuesOutput[i]; | |
| 1020 | index = | |
| 1021 | intintHash_CompressIdentity(((intintIdentityPerfectHash_TableData *) tableData)->compressFuncData, key); | |
| 1022 | if ((buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 1023 | if (key == buckets[index].key) { | |
| 1024 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1025 | } else { | |
| 1026 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 1027 | } | |
| 1028 | } else { | |
| 1029 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1030 | } | |
| 1031 | switch (exitCode) { | |
| 1032 | case HASH_SEARCH_CODE_MATCH: | |
| 1033 | *valueOutput = buckets[index].value; | |
| 1034 | break; | |
| 1035 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1036 | case HASH_SEARCH_CODE_EMPTY: | |
| 1037 | resultExitCode = HASH_EXIT_CODE_KEY_DNE; | |
| 1038 | break; | |
| 1039 | default: | |
| 1040 | return exitCode; | |
| 1041 | } | |
| 1042 | } | |
| 1043 | return resultExitCode; | |
| 1044 | } | |
| 1045 | int intintIdentityPerfectHash_InnerInsertSingle(char *tableData, int key, | |
| 1046 | int value) { | |
| 1047 | intintIdentityPerfectHash_Bucket *buckets = | |
| 1048 | (intintIdentityPerfectHash_Bucket *) & | |
| 1049 | tableData[sizeof(intintIdentityPerfectHash_TableData)]; | |
| 1050 | int index; | |
| 1051 | int exitCode; | |
| 1052 | index = | |
| 1053 | intintHash_CompressIdentity(((intintIdentityPerfectHash_TableData *) | |
| 1054 | tableData)->compressFuncData, key); | |
| 1055 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 1056 | buckets[index]. | |
| 1057 | key = key; | |
| 1058 | HASH_BUCKET_STATUS_EMPTY;} | |
| 1059 | ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 1060 | if (key == buckets[index].key) { | |
| 1061 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1062 | } else { | |
| 1063 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 1064 | } | |
| 1065 | } else { | |
| 1066 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1067 | } | |
| 1068 | switch (exitCode) { | |
| 1069 | case HASH_SEARCH_CODE_MATCH: | |
| 1070 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1071 | buckets[index].value = value; | |
| 1072 | return HASH_EXIT_CODE_OVERWRITE; | |
| 1073 | case HASH_SEARCH_CODE_EMPTY: | |
| 1074 | buckets[index].value = value; | |
| 1075 | return HASH_EXIT_CODE_NORMAL; | |
| 1076 | default: | |
| 1077 | return exitCode; | |
| 1078 | } | |
| 1079 | } | |
| 1080 | int intintIdentityPerfectHash_InnerInsert(char *tableData, | |
| 1081 | unsigned int numEntries, int *keys, | |
| 1082 | int *values) { | |
| 1083 | intintIdentityPerfectHash_Bucket *buckets = | |
| 1084 | (intintIdentityPerfectHash_Bucket *) & | |
| 1085 | tableData[sizeof(intintIdentityPerfectHash_TableData)]; | |
| 1086 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1087 | int key; | |
| 1088 | int value; | |
| 1089 | int index; | |
| 1090 | int exitCode; | |
| 1091 | uint i; | |
| 1092 | for (i = 0; i < numEntries; i++) { | |
| 1093 | key = keys[i]; | |
| 1094 | index = | |
| 1095 | intintHash_CompressIdentity(((intintIdentityPerfectHash_TableData *) tableData)->compressFuncData, key); | |
| 1096 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 1097 | buckets | |
| 1098 | [index]. | |
| 1099 | key = | |
| 1100 | key; | |
| 1101 | HASH_BUCKET_STATUS_EMPTY;} | |
| 1102 | ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 1103 | if (key == buckets[index].key) { | |
| 1104 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1105 | } else { | |
| 1106 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 1107 | } | |
| 1108 | } else { | |
| 1109 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1110 | } | |
| 1111 | switch (exitCode) { | |
| 1112 | case HASH_SEARCH_CODE_MATCH: | |
| 1113 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1114 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 1115 | case HASH_SEARCH_CODE_EMPTY: | |
| 1116 | buckets[index].value = values[i]; | |
| 1117 | break; | |
| 1118 | default: | |
| 1119 | return exitCode; | |
| 1120 | } | |
| 1121 | } | |
| 1122 | return resultExitCode; | |
| 1123 | } | |
| 1124 | int intintIdentityPerfectHash_InnerInsertSingleNoOverwrite(char *tableData, | |
| 1125 | int key, int value) { | |
| 1126 | intintIdentityPerfectHash_Bucket *buckets = | |
| 1127 | (intintIdentityPerfectHash_Bucket *) & | |
| 1128 | tableData[sizeof(intintIdentityPerfectHash_TableData)]; | |
| 1129 | int index; | |
| 1130 | int exitCode; | |
| 1131 | index = | |
| 1132 | intintHash_CompressIdentity(((intintIdentityPerfectHash_TableData *) | |
| 1133 | tableData)->compressFuncData, key); | |
| 1134 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 1135 | buckets[index]. | |
| 1136 | key = key; | |
| 1137 | HASH_BUCKET_STATUS_EMPTY;} | |
| 1138 | ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 1139 | if (key == buckets[index].key) { | |
| 1140 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1141 | } else { | |
| 1142 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 1143 | } | |
| 1144 | } else { | |
| 1145 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1146 | } | |
| 1147 | switch (exitCode) { | |
| 1148 | case HASH_SEARCH_CODE_MATCH: | |
| 1149 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1150 | return HASH_EXIT_CODE_OVERWRITE; | |
| 1151 | case HASH_SEARCH_CODE_EMPTY: | |
| 1152 | buckets[index].value = value; | |
| 1153 | return HASH_EXIT_CODE_NORMAL; | |
| 1154 | default: | |
| 1155 | return exitCode; | |
| 1156 | } | |
| 1157 | } | |
| 1158 | int intintIdentityPerfectHash_InnerInsertNoOverwrite(char *tableData, | |
| 1159 | unsigned int numEntries, | |
| 1160 | int *keys, int *values) { | |
| 1161 | intintIdentityPerfectHash_Bucket *buckets = | |
| 1162 | (intintIdentityPerfectHash_Bucket *) & | |
| 1163 | tableData[sizeof(intintIdentityPerfectHash_TableData)]; | |
| 1164 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1165 | int key; | |
| 1166 | int value; | |
| 1167 | int index; | |
| 1168 | int exitCode; | |
| 1169 | uint i; | |
| 1170 | for (i = 0; i < numEntries; i++) { | |
| 1171 | key = keys[i]; | |
| 1172 | index = | |
| 1173 | intintHash_CompressIdentity(((intintIdentityPerfectHash_TableData *) tableData)->compressFuncData, key); | |
| 1174 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 1175 | buckets | |
| 1176 | [index]. | |
| 1177 | key = | |
| 1178 | key; | |
| 1179 | HASH_BUCKET_STATUS_EMPTY;} | |
| 1180 | ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 1181 | if (key == buckets[index].key) { | |
| 1182 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1183 | } else { | |
| 1184 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 1185 | } | |
| 1186 | } else { | |
| 1187 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1188 | } | |
| 1189 | switch (exitCode) { | |
| 1190 | case HASH_SEARCH_CODE_MATCH: | |
| 1191 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1192 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 1193 | break; | |
| 1194 | case HASH_SEARCH_CODE_EMPTY: | |
| 1195 | buckets[index].value = values[i]; | |
| 1196 | break; | |
| 1197 | default: | |
| 1198 | return exitCode; | |
| 1199 | } | |
| 1200 | } | |
| 1201 | return resultExitCode; | |
| 1202 | } | |
| 1203 | int intintIdentityPerfectHash_QuerySingle(intintHash_Table * table, int key, | |
| 1204 | int *valueOutput) { | |
| 1205 | return intintIdentityPerfectHash_InnerQuerySingle(table->tableData, key, | |
| 1206 | valueOutput); | |
| 1207 | } | |
| 1208 | int intintIdentityPerfectHash_Query(intintHash_Table * table, size_t numKeys, | |
| 1209 | int *keys, int *valuesOutput) { | |
| 1210 | return intintIdentityPerfectHash_InnerQuery(table->tableData, numKeys, | |
| 1211 | keys, valuesOutput); | |
| 1212 | } | |
| 1213 | int intintIdentityPerfectHash_InsertSingle(intintHash_Table * table, int key, | |
| 1214 | int value) { | |
| 1215 | return intintIdentityPerfectHash_InnerInsertSingle(table->tableData, | |
| 1216 | key, value); | |
| 1217 | } | |
| 1218 | int intintIdentityPerfectHash_Insert(intintHash_Table * table, | |
| 1219 | size_t numEntries, int *keys, | |
| 1220 | int *values) { | |
| 1221 | return intintIdentityPerfectHash_InnerInsert(table->tableData, | |
| 1222 | numEntries, keys, values); | |
| 1223 | } | |
| 1224 | int intintIdentityPerfectHash_InsertSingleNoOverwrite(intintHash_Table * table, | |
| 1225 | int key, int value) { | |
| 1226 | return intintIdentityPerfectHash_InnerInsertSingleNoOverwrite(table-> | |
| 1227 | tableData, | |
| 1228 | key, | |
| 1229 | value); | |
| 1230 | } | |
| 1231 | int intintIdentityPerfectHash_InsertNoOverwrite(intintHash_Table * table, | |
| 1232 | size_t numEntries, int *keys, | |
| 1233 | int *values) { | |
| 1234 | return intintIdentityPerfectHash_InnerInsertNoOverwrite(table-> | |
| 1235 | tableData, | |
| 1236 | numEntries, | |
| 1237 | keys, values); | |
| 1238 | } | |
| 1239 | ||
| 1240 | typedef struct intintIdentityPerfectCLHash_TableData { | |
| 1241 | int hashID; | |
| 1242 | unsigned int numBuckets; | |
| 1243 | char compressFuncData; | |
| 1244 | } intintIdentityPerfectCLHash_TableData; | |
| 1245 | typedef struct intintIdentityPerfectCLHash_Bucket { | |
| 1246 | int key; | |
| 1247 | int value; | |
| 1248 | } intintIdentityPerfectCLHash_Bucket; | |
| 1249 | intintHash_Table *intintIdentityPerfectCLHash_CreateTable(intintHash_Factory * | |
| 1250 | factory, | |
| 1251 | int hashIndex, | |
| 1252 | size_t keyRange, | |
| 1253 | size_t numEntries, | |
| 1254 | float loadFactor) { | |
| 1255 | intintHash_Table *table = | |
| 1256 | (intintHash_Table *) malloc(sizeof(intintHash_Table)); | |
| 1257 | table->destroyFunc = &intintIdentityPerfectCLHash_DestroyTable; | |
| 1258 | table->emptyFunc = &intintIdentityPerfectCLHash_EmptyTable; | |
| 1259 | table->queryFunc = &intintIdentityPerfectCLHash_Query; | |
| 1260 | table->querySingleFunc = &intintIdentityPerfectCLHash_QuerySingle; | |
| 1261 | table->insertFunc = &intintIdentityPerfectCLHash_Insert; | |
| 1262 | table->insertSingleFunc = &intintIdentityPerfectCLHash_InsertSingle; | |
| 1263 | table->insertNoOverwriteFunc = | |
| 1264 | &intintIdentityPerfectCLHash_InsertNoOverwrite; | |
| 1265 | table->insertSingleNoOverwriteFunc = | |
| 1266 | &intintIdentityPerfectCLHash_InsertSingleNoOverwrite; | |
| 1267 | table->tableData = | |
| 1268 | (char *)malloc(sizeof(intintIdentityPerfectCLHash_TableData)); | |
| 1269 | ((intintIdentityPerfectCLHash_TableData *) table->tableData)->hashID = | |
| 1270 | IDENTITY_PERFECT_CL_HASH_ID; | |
| 1271 | table->context = factory->context; | |
| 1272 | table->queue = factory->queue; | |
| 1273 | table->program = factory->program; | |
| 1274 | table->localWorkSize = factory->localWorkSize; | |
| 1275 | table->utilProgram = factory->utilProgram[hashIndex]; | |
| 1276 | table->emptyKernel = factory->emptyKernel[hashIndex]; | |
| 1277 | table->emptyKernelLocalWorkSize = | |
| 1278 | factory->emptyKernelLocalWorkSize[hashIndex]; | |
| 1279 | table->querySingleKernel = factory->querySingleKernel[hashIndex]; | |
| 1280 | table->insertSingleKernel = factory->insertSingleKernel[hashIndex]; | |
| 1281 | table->insertSingleNoOverwriteKernel = | |
| 1282 | factory->insertSingleNoOverwriteKernel[hashIndex]; | |
| 1283 | clRetainContext(table->context); | |
| 1284 | clRetainCommandQueue(table->queue); | |
| 1285 | clRetainProgram(table->program); | |
| 1286 | clRetainProgram(table->utilProgram); | |
| 1287 | clRetainKernel(table->emptyKernel); | |
| 1288 | clRetainKernel(table->querySingleKernel); | |
| 1289 | clRetainKernel(table->insertSingleKernel); | |
| 1290 | clRetainKernel(table->insertSingleNoOverwriteKernel);; | |
| 1291 | ((intintIdentityPerfectCLHash_TableData *) table->tableData)-> | |
| 1292 | numBuckets = keyRange + 1; | |
| 1293 | char *tempHashData = | |
| 1294 | (char *)malloc(sizeof(intintIdentityPerfectCLHash_TableData) + | |
| 1295 | ((intintIdentityPerfectCLHash_TableData *) table-> | |
| 1296 | tableData)->numBuckets * | |
| 1297 | sizeof(intintIdentityPerfectCLHash_Bucket)); | |
| 1298 | memcpy(tempHashData, table->tableData, | |
| 1299 | sizeof(intintIdentityPerfectCLHash_TableData)); | |
| 1300 | free(table->tableData); | |
| 1301 | table->tableData = tempHashData; | |
| 1302 | cl_int err; | |
| 1303 | table->tableDataBuffer = | |
| 1304 | clCreateBuffer(table->context, CL_MEM_READ_WRITE, | |
| 1305 | sizeof(intintIdentityPerfectHash_TableData) + | |
| 1306 | ((intintIdentityPerfectHash_TableData *) table-> | |
| 1307 | tableData)->numBuckets * | |
| 1308 | sizeof(intintIdentityPerfectHash_Bucket), NULL, | |
| 1309 | &err); | |
| 1310 | CLHash_Utilities_HandleError(err, | |
| 1311 | "intintIdentityPerfectCLHash_InitTable", | |
| 1312 | "clCreateBuffer"); | |
| 1313 | err = | |
| 1314 | clEnqueueWriteBuffer(table->queue, table->tableDataBuffer, CL_TRUE, | |
| 1315 | 0, sizeof(intintIdentityPerfectHash_TableData), | |
| 1316 | table->tableData, 0, NULL, NULL); | |
| 1317 | CLHash_Utilities_HandleError(err, | |
| 1318 | "intintIdentityPerfectCLHash_InitTable", | |
| 1319 | "clEnqueueWriteBuffer"); | |
| 1320 | return table; | |
| 1321 | } | |
| 1322 | int intintIdentityPerfectCLHash_CreateFactory(intintHash_Factory * factory, | |
| 1323 | int hashIndex) { | |
| 1324 | factory->createFunc[hashIndex] = | |
| 1325 | &intintIdentityPerfectCLHash_CreateTable; | |
| 1326 | factory->destroyFunc[hashIndex] = | |
| 1327 | &intintIdentityPerfectCLHash_DestroyFactory; | |
| 1328 | cl_int error; | |
| 1329 | cl_device_id device; | |
| 1330 | error = | |
| 1331 | clGetContextInfo(factory->context, CL_CONTEXT_DEVICES, | |
| 1332 | sizeof(device), &device, NULL); | |
| 1333 | CLHash_Utilities_HandleError(error, "intintHash_CreateFactory", | |
| 1334 | "clGetContextInfo"); | |
| 1335 | factory->querySingleKernel[hashIndex] = | |
| 1336 | clCreateKernel(factory->program, | |
| 1337 | "intintIdentityPerfectCLHash_RangeQuerySingle", | |
| 1338 | &error); | |
| 1339 | CLHash_Utilities_HandleError(error, | |
| 1340 | "intintIdentityPerfectCLHash_CreateFactory", | |
| 1341 | "clCreateKernel"); | |
| 1342 | factory->insertSingleKernel[hashIndex] = | |
| 1343 | clCreateKernel(factory->program, | |
| 1344 | "intintIdentityPerfectCLHash_RangeInsertSingle", | |
| 1345 | &error); | |
| 1346 | CLHash_Utilities_HandleError(error, | |
| 1347 | "intintIdentityPerfectCLHash_CreateFactory", | |
| 1348 | "clCreateKernel"); | |
| 1349 | factory->insertSingleNoOverwriteKernel[hashIndex] = | |
| 1350 | clCreateKernel(factory->program, | |
| 1351 | "intintIdentityPerfectCLHash_RangeInsertSingleNoOverwrite", | |
| 1352 | &error); | |
| 1353 | CLHash_Utilities_HandleError(error, | |
| 1354 | "intintIdentityPerfectCLHash_CreateFactory", | |
| 1355 | "clCreateKernel"); | |
| 1356 | factory->utilProgram[hashIndex] = | |
| 1357 | CLHash_Utilities_BuildProgramString(factory->context, device, | |
| 1358 | "static inline unsigned int intintHash_CompressIdentity(char data, int hashCode){ return hashCode; } typedef struct intintHash_CompressLCGData{ long unsigned int a; long unsigned int c; unsigned int m; unsigned int n; }intintHash_CompressLCGData; static inline unsigned int intintHash_CompressLCG(intintHash_CompressLCGData compressLCGData, int hashCode){ return ((compressLCGData.a * hashCode + compressLCGData.c) % compressLCGData.m) % compressLCGData.n; } typedef struct intintIdentityPerfectCLHash_TableData{ int hashID; unsigned int numBuckets; char compressFuncData; }intintIdentityPerfectCLHash_TableData; typedef struct intintIdentityPerfectCLHash_Bucket{ int key; int value; }intintIdentityPerfectCLHash_Bucket; __kernel void intintIdentityPerfectCLHash_Empty(__global char *tableData){ int index = get_global_id(0); if(index >= ((__global intintIdentityPerfectCLHash_TableData*)tableData)->numBuckets){ return; } __global intintIdentityPerfectCLHash_Bucket *buckets = (__global intintIdentityPerfectCLHash_Bucket*)&tableData[sizeof(intintIdentityPerfectCLHash_TableData)]; buckets[index].key = -1;/*HASH_BUCKET_STATUS_EMPTY*/ }"); | |
| 1359 | factory->emptyKernel[hashIndex] = | |
| 1360 | clCreateKernel(factory->utilProgram[hashIndex], | |
| 1361 | "intintIdentityPerfectCLHash_Empty", &error); | |
| 1362 | CLHash_Utilities_HandleError(error, | |
| 1363 | "intintIdentityPerfectCLHash_CreateFactory", | |
| 1364 | "clCreateKernel"); | |
| 1365 | error = | |
| 1366 | clGetKernelWorkGroupInfo(factory->emptyKernel[hashIndex], device, | |
| 1367 | CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), | |
| 1368 | &factory-> | |
| 1369 | emptyKernelLocalWorkSize[hashIndex], NULL); | |
| 1370 | CLHash_Utilities_HandleError(error, | |
| 1371 | "intintIdentityPerfectCLHash_CreateFactory", | |
| 1372 | "clGetKernelWorkGroupInfo");;; | |
| 1373 | return HASH_EXIT_CODE_NORMAL; | |
| 1374 | } | |
| 1375 | int intintIdentityPerfectCLHash_DestroyFactory(intintHash_Factory * factory, | |
| 1376 | int hashIndex) {; | |
| 1377 | clReleaseKernel(factory->emptyKernel[hashIndex]); | |
| 1378 | clReleaseProgram(factory->utilProgram[hashIndex]); | |
| 1379 | clReleaseKernel(factory->querySingleKernel[hashIndex]); | |
| 1380 | clReleaseKernel(factory->insertSingleKernel[hashIndex]); | |
| 1381 | clReleaseKernel(factory->insertSingleNoOverwriteKernel[hashIndex]);; | |
| 1382 | return HASH_EXIT_CODE_NORMAL; | |
| 1383 | } | |
| 1384 | int intintIdentityPerfectCLHash_DestroyTable(intintHash_Table * table) { | |
| 1385 | int exitCode = 0; | |
| 1386 | clReleaseMemObject(table->tableDataBuffer); | |
| 1387 | clReleaseContext(table->context); | |
| 1388 | clReleaseCommandQueue(table->queue); | |
| 1389 | clReleaseProgram(table->utilProgram); | |
| 1390 | clReleaseKernel(table->emptyKernel); | |
| 1391 | clReleaseProgram(table->program); | |
| 1392 | clReleaseKernel(table->querySingleKernel); | |
| 1393 | clReleaseKernel(table->insertSingleKernel); | |
| 1394 | clReleaseKernel(table->insertSingleNoOverwriteKernel); | |
| 1395 | free(table->tableData); | |
| 1396 | free(table); | |
| 1397 | return exitCode; | |
| 1398 | } | |
| 1399 | int intintIdentityPerfectCLHash_EmptyTable(intintHash_Table * table) { | |
| 1400 | int exitCode = 0; | |
| 1401 | cl_int err; | |
| 1402 | err = | |
| 1403 | clSetKernelArg(table->emptyKernel, 0, sizeof(cl_mem), | |
| 1404 | &table->tableDataBuffer); | |
| 1405 | CLHash_Utilities_HandleError(err, | |
| 1406 | "intintIdentityPerfectCLHash_EmptyTable", | |
| 1407 | "clSetKernelArg"); | |
| 1408 | const size_t groupWorkSize = | |
| 1409 | roundUpToNearest(((intintIdentityPerfectHash_TableData *) table-> | |
| 1410 | tableData)->numBuckets, | |
| 1411 | table->emptyKernelLocalWorkSize); | |
| 1412 | err = | |
| 1413 | clEnqueueNDRangeKernel(table->queue, table->emptyKernel, 1, 0, | |
| 1414 | &groupWorkSize, | |
| 1415 | (const size_t *)&table-> | |
| 1416 | emptyKernelLocalWorkSize, 0, NULL, NULL); | |
| 1417 | CLHash_Utilities_HandleError(err, | |
| 1418 | "intintIdentityPerfectCLHash_EmptyTable", | |
| 1419 | "clEnqueueNDRangeKernel"); | |
| 1420 | exitCode = HASH_EXIT_CODE_NORMAL;; | |
| 1421 | return exitCode; | |
| 1422 | } | |
| 1423 | int intintIdentityPerfectCLHash_QuerySingle(intintHash_Table * table, int key, | |
| 1424 | int *valueOutput) { | |
| 1425 | return intintIdentityPerfectCLHash_Query(table, 1, &key, valueOutput); | |
| 1426 | } | |
| 1427 | int intintIdentityPerfectCLHash_Query(intintHash_Table * table, size_t numKeys, | |
| 1428 | int *keys, int *valuesOutput) { | |
| 1429 | cl_int err; | |
| 1430 | cl_mem keysBuffer = | |
| 1431 | clCreateBuffer(table->context, | |
| 1432 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 1433 | sizeof(int) * numKeys, keys, &err); | |
| 1434 | CLHash_Utilities_HandleError(err, "intintIdentityPerfectCLHash_Query", | |
| 1435 | "clCreateBuffer"); | |
| 1436 | cl_mem valuesOutputBuffer = | |
| 1437 | clCreateBuffer(table->context, CL_MEM_WRITE_ONLY, | |
| 1438 | sizeof(int) * numKeys, NULL, &err); | |
| 1439 | CLHash_Utilities_HandleError(err, "intintIdentityPerfectCLHash_Query", | |
| 1440 | "clCreateBuffer"); | |
| 1441 | intintIdentityPerfectCLHash_BufferQuery(table, numKeys, keysBuffer, | |
| 1442 | valuesOutputBuffer); | |
| 1443 | err = | |
| 1444 | clEnqueueReadBuffer(table->queue, valuesOutputBuffer, CL_TRUE, 0, | |
| 1445 | sizeof(int) * numKeys, valuesOutput, 0, NULL, | |
| 1446 | NULL); | |
| 1447 | CLHash_Utilities_HandleError(err, "intintIdentityPerfectCLHash_Query", | |
| 1448 | "clEnqueueReadBuffer"); | |
| 1449 | clReleaseMemObject(keysBuffer); | |
| 1450 | clReleaseMemObject(valuesOutputBuffer); | |
| 1451 | return HASH_EXIT_CODE_NORMAL; | |
| 1452 | } | |
| 1453 | int intintIdentityPerfectCLHash_BufferQuery(intintHash_Table * table, | |
| 1454 | size_t numKeys, cl_mem keysBuffer, | |
| 1455 | cl_mem valuesOutputBuffer) { | |
| 1456 | cl_int err; | |
| 1457 | err = | |
| 1458 | clSetKernelArg(table->querySingleKernel, 0, sizeof(cl_mem), | |
| 1459 | &table->tableDataBuffer); | |
| 1460 | CLHash_Utilities_HandleError(err, | |
| 1461 | "intintIdentityPerfectCLHash_BufferQuery", | |
| 1462 | "clSetKernelArg"); | |
| 1463 | err = | |
| 1464 | clSetKernelArg(table->querySingleKernel, 1, sizeof(unsigned int), | |
| 1465 | &numKeys); | |
| 1466 | CLHash_Utilities_HandleError(err, | |
| 1467 | "intintIdentityPerfectCLHash_BufferQuery", | |
| 1468 | "clSetKernelArg"); | |
| 1469 | err = | |
| 1470 | clSetKernelArg(table->querySingleKernel, 2, sizeof(cl_mem), | |
| 1471 | &keysBuffer); | |
| 1472 | CLHash_Utilities_HandleError(err, | |
| 1473 | "intintIdentityPerfectCLHash_BufferQuery", | |
| 1474 | "clSetKernelArg"); | |
| 1475 | err = | |
| 1476 | clSetKernelArg(table->querySingleKernel, 3, sizeof(cl_mem), | |
| 1477 | &valuesOutputBuffer); | |
| 1478 | CLHash_Utilities_HandleError(err, | |
| 1479 | "intintIdentityPerfectCLHash_BufferQuery", | |
| 1480 | "clSetKernelArg"); | |
| 1481 | const size_t groupWorkSize = | |
| 1482 | roundUpToNearest(numKeys, table->localWorkSize); | |
| 1483 | err = | |
| 1484 | clEnqueueNDRangeKernel(table->queue, table->querySingleKernel, 1, 0, | |
| 1485 | &groupWorkSize, | |
| 1486 | (const size_t *)&table->localWorkSize, 0, | |
| 1487 | NULL, NULL); | |
| 1488 | CLHash_Utilities_HandleError(err, | |
| 1489 | "intintIdentityPerfectCLHash_BufferQuery", | |
| 1490 | "clEnqueueNDRangeKernel"); | |
| 1491 | clFinish(table->queue); | |
| 1492 | return HASH_EXIT_CODE_NORMAL; | |
| 1493 | } | |
| 1494 | int intintIdentityPerfectCLHash_InsertSingle(intintHash_Table * table, int key, | |
| 1495 | int value) { | |
| 1496 | return intintIdentityPerfectCLHash_Insert(table, 1, &key, &value); | |
| 1497 | } | |
| 1498 | int intintIdentityPerfectCLHash_Insert(intintHash_Table * table, | |
| 1499 | size_t numEntries, int *keys, | |
| 1500 | int *values) { | |
| 1501 | cl_int err; | |
| 1502 | cl_mem keysBuffer = | |
| 1503 | clCreateBuffer(table->context, | |
| 1504 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 1505 | sizeof(int) * numEntries, keys, &err); | |
| 1506 | CLHash_Utilities_HandleError(err, "intintIdentityPerfectCLHash_Insert", | |
| 1507 | "clCreateBuffer"); | |
| 1508 | cl_mem valuesBuffer = | |
| 1509 | clCreateBuffer(table->context, | |
| 1510 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 1511 | sizeof(int) * numEntries, values, &err); | |
| 1512 | CLHash_Utilities_HandleError(err, "intintIdentityPerfectCLHash_Insert", | |
| 1513 | "clCreateBuffer"); | |
| 1514 | intintIdentityPerfectCLHash_BufferInsert(table, numEntries, keysBuffer, | |
| 1515 | valuesBuffer); | |
| 1516 | clReleaseMemObject(keysBuffer); | |
| 1517 | clReleaseMemObject(valuesBuffer); | |
| 1518 | return HASH_EXIT_CODE_NORMAL; | |
| 1519 | } | |
| 1520 | int intintIdentityPerfectCLHash_BufferInsert(intintHash_Table * table, | |
| 1521 | size_t numEntries, | |
| 1522 | cl_mem keysBuffer, | |
| 1523 | cl_mem valuesBuffer) { | |
| 1524 | cl_int err; | |
| 1525 | err = | |
| 1526 | clSetKernelArg(table->insertSingleKernel, 0, sizeof(cl_mem), | |
| 1527 | &table->tableDataBuffer); | |
| 1528 | CLHash_Utilities_HandleError(err, | |
| 1529 | "intintIdentityPerfectCLHash_BufferInsert", | |
| 1530 | "clSetKernelArg"); | |
| 1531 | err = | |
| 1532 | clSetKernelArg(table->insertSingleKernel, 1, sizeof(unsigned int), | |
| 1533 | &numEntries); | |
| 1534 | CLHash_Utilities_HandleError(err, | |
| 1535 | "intintIdentityPerfectCLHash_BufferInsert", | |
| 1536 | "clSetKernelArg"); | |
| 1537 | err = | |
| 1538 | clSetKernelArg(table->insertSingleKernel, 2, sizeof(cl_mem), | |
| 1539 | &keysBuffer); | |
| 1540 | CLHash_Utilities_HandleError(err, | |
| 1541 | "intintIdentityPerfectCLHash_BufferInsert", | |
| 1542 | "clSetKernelArg"); | |
| 1543 | err = | |
| 1544 | clSetKernelArg(table->insertSingleKernel, 3, sizeof(cl_mem), | |
| 1545 | &valuesBuffer); | |
| 1546 | CLHash_Utilities_HandleError(err, | |
| 1547 | "intintIdentityPerfectCLHash_BufferInsert", | |
| 1548 | "clSetKernelArg"); | |
| 1549 | const size_t groupWorkSize = | |
| 1550 | roundUpToNearest(numEntries, table->localWorkSize); | |
| 1551 | err = | |
| 1552 | clEnqueueNDRangeKernel(table->queue, table->insertSingleKernel, 1, | |
| 1553 | 0, &groupWorkSize, | |
| 1554 | (const size_t *)&table->localWorkSize, 0, | |
| 1555 | NULL, NULL); | |
| 1556 | CLHash_Utilities_HandleError(err, NULL, "clEnqueueNDRangeKernel"); | |
| 1557 | return (0); | |
| 1558 | } | |
| 1559 | int intintIdentityPerfectCLHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 1560 | table, int key, | |
| 1561 | int value) { | |
| 1562 | return intintIdentityPerfectCLHash_InsertNoOverwrite(table, 1, &key, | |
| 1563 | &value); | |
| 1564 | } | |
| 1565 | int intintIdentityPerfectCLHash_InsertNoOverwrite(intintHash_Table * table, | |
| 1566 | size_t numEntries, int *keys, | |
| 1567 | int *values) { | |
| 1568 | cl_int err; | |
| 1569 | cl_mem keysBuffer = | |
| 1570 | clCreateBuffer(table->context, | |
| 1571 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 1572 | sizeof(int) * numEntries, keys, &err); | |
| 1573 | CLHash_Utilities_HandleError(err, | |
| 1574 | "intintIdentityPerfectCLHash_InsertNoOverwrite", | |
| 1575 | "clCreateBuffer"); | |
| 1576 | cl_mem valuesBuffer = | |
| 1577 | clCreateBuffer(table->context, | |
| 1578 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 1579 | sizeof(int) * numEntries, values, &err); | |
| 1580 | CLHash_Utilities_HandleError(err, | |
| 1581 | "intintIdentityPerfectCLHash_InsertNoOverwrite", | |
| 1582 | "clCreateBuffer"); | |
| 1583 | intintIdentityPerfectCLHash_BufferInsertNoOverwrite(table, numEntries, | |
| 1584 | keysBuffer, | |
| 1585 | valuesBuffer); | |
| 1586 | clReleaseMemObject(keysBuffer); | |
| 1587 | clReleaseMemObject(valuesBuffer); | |
| 1588 | return HASH_EXIT_CODE_NORMAL; | |
| 1589 | } | |
| 1590 | int intintIdentityPerfectCLHash_BufferInsertNoOverwrite(intintHash_Table * | |
| 1591 | table, | |
| 1592 | size_t numEntries, | |
| 1593 | cl_mem keysBuffer, | |
| 1594 | cl_mem valuesBuffer) { | |
| 1595 | cl_int err; | |
| 1596 | err = | |
| 1597 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 0, | |
| 1598 | sizeof(cl_mem), &table->tableDataBuffer); | |
| 1599 | CLHash_Utilities_HandleError(err, | |
| 1600 | "intintIdentityPerfectCLHash_BufferInsertNoOverwrite", | |
| 1601 | "clSetKernelArg"); | |
| 1602 | err = | |
| 1603 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 1, | |
| 1604 | sizeof(unsigned int), &numEntries); | |
| 1605 | CLHash_Utilities_HandleError(err, | |
| 1606 | "intintIdentityPerfectCLHash_BufferInsertNoOverwrite", | |
| 1607 | "ClSetKernelArg"); | |
| 1608 | err = | |
| 1609 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 2, | |
| 1610 | sizeof(cl_mem), &keysBuffer); | |
| 1611 | CLHash_Utilities_HandleError(err, | |
| 1612 | "intintIdentityPerfectCLHash_BufferInsertNoOverwrite", | |
| 1613 | "clSetKernelArg"); | |
| 1614 | err = | |
| 1615 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 3, | |
| 1616 | sizeof(cl_mem), &valuesBuffer); | |
| 1617 | CLHash_Utilities_HandleError(err, | |
| 1618 | "intintIdentityPerfectCLHash_BufferInsertNoOverwrite", | |
| 1619 | "clSetKernelArg"); | |
| 1620 | const size_t groupWorkSize = | |
| 1621 | roundUpToNearest(numEntries, table->localWorkSize); | |
| 1622 | err = | |
| 1623 | clEnqueueNDRangeKernel(table->queue, | |
| 1624 | table->insertSingleNoOverwriteKernel, 1, 0, | |
| 1625 | &groupWorkSize, | |
| 1626 | (const size_t *)&table->localWorkSize, 0, | |
| 1627 | NULL, NULL); | |
| 1628 | CLHash_Utilities_HandleError(err, | |
| 1629 | "intintIdentityPerfectCLHash_BufferInsertNoOverwrite", | |
| 1630 | "clEnqueueNDRangeKernel"); | |
| 1631 | return (0); | |
| 1632 | } | |
| 1633 | ||
| 1634 | typedef struct intintIdentitySentinelPerfectHash_TableData { | |
| 1635 | int hashID; | |
| 1636 | unsigned int numBuckets; | |
| 1637 | char compressFuncData; | |
| 1638 | int emptyValue; | |
| 1639 | } intintIdentitySentinelPerfectHash_TableData; | |
| 1640 | typedef struct intintIdentitySentinelPerfectHash_Bucket { | |
| 1641 | int value; | |
| 1642 | } intintIdentitySentinelPerfectHash_Bucket; | |
| 1643 | intintHash_Table | |
| 1644 | *intintIdentitySentinelPerfectHash_CreateTable(intintHash_Factory * factory, | |
| 1645 | int hashIndex, | |
| 1646 | size_t keyRange, | |
| 1647 | size_t numEntries, | |
| 1648 | float loadFactor) { | |
| 1649 | intintHash_Table *table = | |
| 1650 | (intintHash_Table *) malloc(sizeof(intintHash_Table)); | |
| 1651 | table->destroyFunc = &intintIdentitySentinelPerfectHash_DestroyTable; | |
| 1652 | table->emptyFunc = &intintIdentitySentinelPerfectHash_EmptyTable; | |
| 1653 | table->queryFunc = &intintIdentitySentinelPerfectHash_Query; | |
| 1654 | table->querySingleFunc = &intintIdentitySentinelPerfectHash_QuerySingle; | |
| 1655 | table->insertFunc = &intintIdentitySentinelPerfectHash_Insert; | |
| 1656 | table->insertSingleFunc = | |
| 1657 | &intintIdentitySentinelPerfectHash_InsertSingle; | |
| 1658 | table->insertNoOverwriteFunc = | |
| 1659 | &intintIdentitySentinelPerfectHash_InsertNoOverwrite; | |
| 1660 | table->insertSingleNoOverwriteFunc = | |
| 1661 | &intintIdentitySentinelPerfectHash_InsertSingleNoOverwrite; | |
| 1662 | table->tableData = | |
| 1663 | (char *)malloc(sizeof(intintIdentitySentinelPerfectHash_TableData)); | |
| 1664 | ((intintIdentitySentinelPerfectHash_TableData *) table->tableData)-> | |
| 1665 | hashID = IDENTITY_SENTINEL_PERFECT_HASH_ID; | |
| 1666 | ((intintIdentitySentinelPerfectHash_TableData *) table->tableData)-> | |
| 1667 | emptyValue = factory->emptyValue; | |
| 1668 | ((intintIdentitySentinelPerfectHash_TableData *) table->tableData)-> | |
| 1669 | numBuckets = keyRange + 1; | |
| 1670 | char *tempHashData = | |
| 1671 | (char *)malloc(sizeof(intintIdentitySentinelPerfectHash_TableData) + | |
| 1672 | ((intintIdentitySentinelPerfectHash_TableData *) | |
| 1673 | table->tableData)->numBuckets * | |
| 1674 | sizeof(intintIdentitySentinelPerfectHash_Bucket)); | |
| 1675 | memcpy(tempHashData, table->tableData, | |
| 1676 | sizeof(intintIdentitySentinelPerfectHash_TableData)); | |
| 1677 | free(table->tableData); | |
| 1678 | table->tableData = tempHashData; | |
| 1679 | return table; | |
| 1680 | } | |
| 1681 | int intintIdentitySentinelPerfectHash_CreateFactory(intintHash_Factory * | |
| 1682 | factory, int hashIndex) { | |
| 1683 | factory->createFunc[hashIndex] = | |
| 1684 | &intintIdentitySentinelPerfectHash_CreateTable; | |
| 1685 | factory->destroyFunc[hashIndex] = | |
| 1686 | &intintIdentitySentinelPerfectHash_DestroyFactory;; | |
| 1687 | return HASH_EXIT_CODE_NORMAL; | |
| 1688 | } | |
| 1689 | int intintIdentitySentinelPerfectHash_DestroyFactory(intintHash_Factory * | |
| 1690 | factory, int hashIndex) {; | |
| 1691 | return HASH_EXIT_CODE_NORMAL; | |
| 1692 | } | |
| 1693 | int intintIdentitySentinelPerfectHash_DestroyTable(intintHash_Table * table) { | |
| 1694 | int exitCode = 0; | |
| 1695 | free(table->tableData); | |
| 1696 | free(table); | |
| 1697 | return exitCode; | |
| 1698 | } | |
| 1699 | int intintIdentitySentinelPerfectHash_EmptyTable(intintHash_Table * table) { | |
| 1700 | int exitCode = 0; | |
| 1701 | intintIdentitySentinelPerfectHash_Bucket *buckets = | |
| 1702 | (intintIdentitySentinelPerfectHash_Bucket *) & table-> | |
| 1703 | tableData[sizeof(intintIdentitySentinelPerfectHash_TableData)]; | |
| 1704 | int index; | |
| 1705 | for (index = 0; | |
| 1706 | index < | |
| 1707 | ((intintIdentitySentinelPerfectHash_TableData *) table-> | |
| 1708 | tableData)->numBuckets; index++) { | |
| 1709 | buckets[index].value = | |
| 1710 | ((intintIdentitySentinelPerfectHash_TableData *) table-> | |
| 1711 | tableData)->emptyValue; | |
| 1712 | } | |
| 1713 | exitCode = HASH_EXIT_CODE_NORMAL; | |
| 1714 | return exitCode; | |
| 1715 | } | |
| 1716 | int intintIdentitySentinelPerfectHash_InnerQuerySingle(char *tableData, int key, | |
| 1717 | int *valueOutput) { | |
| 1718 | intintIdentitySentinelPerfectHash_Bucket *buckets = | |
| 1719 | (intintIdentitySentinelPerfectHash_Bucket *) & | |
| 1720 | tableData[sizeof(intintIdentitySentinelPerfectHash_TableData)]; | |
| 1721 | int index; | |
| 1722 | int exitCode; | |
| 1723 | index = | |
| 1724 | intintHash_CompressIdentity(((intintIdentitySentinelPerfectHash_TableData *) tableData)->compressFuncData, key); | |
| 1725 | if (buckets[index].value != | |
| 1726 | ((intintIdentitySentinelPerfectHash_TableData *) tableData)-> | |
| 1727 | emptyValue) { | |
| 1728 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1729 | } else { | |
| 1730 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1731 | } | |
| 1732 | switch (exitCode) { | |
| 1733 | case HASH_SEARCH_CODE_MATCH: | |
| 1734 | *valueOutput = buckets[index].value; | |
| 1735 | return HASH_EXIT_CODE_NORMAL; | |
| 1736 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1737 | case HASH_SEARCH_CODE_EMPTY: | |
| 1738 | return HASH_EXIT_CODE_KEY_DNE; | |
| 1739 | default: | |
| 1740 | return exitCode; | |
| 1741 | } | |
| 1742 | } | |
| 1743 | int intintIdentitySentinelPerfectHash_InnerQuery(char *tableData, | |
| 1744 | unsigned int numKeys, | |
| 1745 | int *keys, int *valuesOutput) { | |
| 1746 | intintIdentitySentinelPerfectHash_Bucket *buckets = | |
| 1747 | (intintIdentitySentinelPerfectHash_Bucket *) & | |
| 1748 | tableData[sizeof(intintIdentitySentinelPerfectHash_TableData)]; | |
| 1749 | int key; | |
| 1750 | int *valueOutput; | |
| 1751 | int index; | |
| 1752 | int exitCode; | |
| 1753 | uint i; | |
| 1754 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1755 | for (i = 0; i < numKeys; i++) { | |
| 1756 | key = keys[i]; | |
| 1757 | valueOutput = &valuesOutput[i]; | |
| 1758 | index = | |
| 1759 | intintHash_CompressIdentity(((intintIdentitySentinelPerfectHash_TableData *) tableData)->compressFuncData, key); | |
| 1760 | if (buckets[index].value != | |
| 1761 | ((intintIdentitySentinelPerfectHash_TableData *) | |
| 1762 | tableData)->emptyValue) { | |
| 1763 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1764 | } else { | |
| 1765 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1766 | } | |
| 1767 | switch (exitCode) { | |
| 1768 | case HASH_SEARCH_CODE_MATCH: | |
| 1769 | *valueOutput = buckets[index].value; | |
| 1770 | break; | |
| 1771 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1772 | case HASH_SEARCH_CODE_EMPTY: | |
| 1773 | resultExitCode = HASH_EXIT_CODE_KEY_DNE; | |
| 1774 | break; | |
| 1775 | default: | |
| 1776 | return exitCode; | |
| 1777 | } | |
| 1778 | } | |
| 1779 | return resultExitCode; | |
| 1780 | } | |
| 1781 | int intintIdentitySentinelPerfectHash_InnerInsertSingle(char *tableData, | |
| 1782 | int key, int value) { | |
| 1783 | intintIdentitySentinelPerfectHash_Bucket *buckets = | |
| 1784 | (intintIdentitySentinelPerfectHash_Bucket *) & | |
| 1785 | tableData[sizeof(intintIdentitySentinelPerfectHash_TableData)]; | |
| 1786 | int index; | |
| 1787 | int exitCode; | |
| 1788 | index = | |
| 1789 | intintHash_CompressIdentity(((intintIdentitySentinelPerfectHash_TableData *) tableData)->compressFuncData, key); | |
| 1790 | if (buckets[index].value != | |
| 1791 | ((intintIdentitySentinelPerfectHash_TableData *) tableData)-> | |
| 1792 | emptyValue) { | |
| 1793 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1794 | } else { | |
| 1795 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1796 | } | |
| 1797 | switch (exitCode) { | |
| 1798 | case HASH_SEARCH_CODE_MATCH: | |
| 1799 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1800 | buckets[index].value = value; | |
| 1801 | return HASH_EXIT_CODE_OVERWRITE; | |
| 1802 | case HASH_SEARCH_CODE_EMPTY: | |
| 1803 | buckets[index].value = value; | |
| 1804 | return HASH_EXIT_CODE_NORMAL; | |
| 1805 | default: | |
| 1806 | return exitCode; | |
| 1807 | } | |
| 1808 | } | |
| 1809 | int intintIdentitySentinelPerfectHash_InnerInsert(char *tableData, | |
| 1810 | unsigned int numEntries, | |
| 1811 | int *keys, int *values) { | |
| 1812 | intintIdentitySentinelPerfectHash_Bucket *buckets = | |
| 1813 | (intintIdentitySentinelPerfectHash_Bucket *) & | |
| 1814 | tableData[sizeof(intintIdentitySentinelPerfectHash_TableData)]; | |
| 1815 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1816 | int key; | |
| 1817 | int value; | |
| 1818 | int index; | |
| 1819 | int exitCode; | |
| 1820 | uint i; | |
| 1821 | for (i = 0; i < numEntries; i++) { | |
| 1822 | key = keys[i]; | |
| 1823 | index = | |
| 1824 | intintHash_CompressIdentity(((intintIdentitySentinelPerfectHash_TableData *) tableData)->compressFuncData, key); | |
| 1825 | if (buckets[index].value != | |
| 1826 | ((intintIdentitySentinelPerfectHash_TableData *) | |
| 1827 | tableData)->emptyValue) { | |
| 1828 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1829 | } else { | |
| 1830 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1831 | } | |
| 1832 | switch (exitCode) { | |
| 1833 | case HASH_SEARCH_CODE_MATCH: | |
| 1834 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1835 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 1836 | case HASH_SEARCH_CODE_EMPTY: | |
| 1837 | buckets[index].value = values[i]; | |
| 1838 | break; | |
| 1839 | default: | |
| 1840 | return exitCode; | |
| 1841 | } | |
| 1842 | } | |
| 1843 | return resultExitCode; | |
| 1844 | } | |
| 1845 | int intintIdentitySentinelPerfectHash_InnerInsertSingleNoOverwrite(char | |
| 1846 | *tableData, | |
| 1847 | int key, | |
| 1848 | int value) { | |
| 1849 | intintIdentitySentinelPerfectHash_Bucket *buckets = | |
| 1850 | (intintIdentitySentinelPerfectHash_Bucket *) & | |
| 1851 | tableData[sizeof(intintIdentitySentinelPerfectHash_TableData)]; | |
| 1852 | int index; | |
| 1853 | int exitCode; | |
| 1854 | index = | |
| 1855 | intintHash_CompressIdentity(((intintIdentitySentinelPerfectHash_TableData *) tableData)->compressFuncData, key); | |
| 1856 | if (buckets[index].value != | |
| 1857 | ((intintIdentitySentinelPerfectHash_TableData *) tableData)-> | |
| 1858 | emptyValue) { | |
| 1859 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1860 | } else { | |
| 1861 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1862 | } | |
| 1863 | switch (exitCode) { | |
| 1864 | case HASH_SEARCH_CODE_MATCH: | |
| 1865 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1866 | return HASH_EXIT_CODE_OVERWRITE; | |
| 1867 | case HASH_SEARCH_CODE_EMPTY: | |
| 1868 | buckets[index].value = value; | |
| 1869 | return HASH_EXIT_CODE_NORMAL; | |
| 1870 | default: | |
| 1871 | return exitCode; | |
| 1872 | } | |
| 1873 | } | |
| 1874 | int intintIdentitySentinelPerfectHash_InnerInsertNoOverwrite(char *tableData, | |
| 1875 | unsigned int | |
| 1876 | numEntries, | |
| 1877 | int *keys, | |
| 1878 | int *values) { | |
| 1879 | intintIdentitySentinelPerfectHash_Bucket *buckets = | |
| 1880 | (intintIdentitySentinelPerfectHash_Bucket *) & | |
| 1881 | tableData[sizeof(intintIdentitySentinelPerfectHash_TableData)]; | |
| 1882 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1883 | int key; | |
| 1884 | int value; | |
| 1885 | int index; | |
| 1886 | int exitCode; | |
| 1887 | uint i; | |
| 1888 | for (i = 0; i < numEntries; i++) { | |
| 1889 | key = keys[i]; | |
| 1890 | index = | |
| 1891 | intintHash_CompressIdentity(((intintIdentitySentinelPerfectHash_TableData *) tableData)->compressFuncData, key); | |
| 1892 | if (buckets[index].value != | |
| 1893 | ((intintIdentitySentinelPerfectHash_TableData *) | |
| 1894 | tableData)->emptyValue) { | |
| 1895 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1896 | } else { | |
| 1897 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1898 | } | |
| 1899 | switch (exitCode) { | |
| 1900 | case HASH_SEARCH_CODE_MATCH: | |
| 1901 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1902 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 1903 | break; | |
| 1904 | case HASH_SEARCH_CODE_EMPTY: | |
| 1905 | buckets[index].value = values[i]; | |
| 1906 | break; | |
| 1907 | default: | |
| 1908 | return exitCode; | |
| 1909 | } | |
| 1910 | } | |
| 1911 | return resultExitCode; | |
| 1912 | } | |
| 1913 | int intintIdentitySentinelPerfectHash_QuerySingle(intintHash_Table * table, | |
| 1914 | int key, int *valueOutput) { | |
| 1915 | return intintIdentitySentinelPerfectHash_InnerQuerySingle(table-> | |
| 1916 | tableData, | |
| 1917 | key, | |
| 1918 | valueOutput); | |
| 1919 | } | |
| 1920 | int intintIdentitySentinelPerfectHash_Query(intintHash_Table * table, | |
| 1921 | size_t numKeys, int *keys, | |
| 1922 | int *valuesOutput) { | |
| 1923 | return intintIdentitySentinelPerfectHash_InnerQuery(table->tableData, | |
| 1924 | numKeys, keys, | |
| 1925 | valuesOutput); | |
| 1926 | } | |
| 1927 | int intintIdentitySentinelPerfectHash_InsertSingle(intintHash_Table * table, | |
| 1928 | int key, int value) { | |
| 1929 | return intintIdentitySentinelPerfectHash_InnerInsertSingle(table-> | |
| 1930 | tableData, | |
| 1931 | key, value); | |
| 1932 | } | |
| 1933 | int intintIdentitySentinelPerfectHash_Insert(intintHash_Table * table, | |
| 1934 | size_t numEntries, int *keys, | |
| 1935 | int *values) { | |
| 1936 | return intintIdentitySentinelPerfectHash_InnerInsert(table->tableData, | |
| 1937 | numEntries, keys, | |
| 1938 | values); | |
| 1939 | } | |
| 1940 | int intintIdentitySentinelPerfectHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 1941 | table, int key, | |
| 1942 | int value) { | |
| 1943 | return | |
| 1944 | intintIdentitySentinelPerfectHash_InnerInsertSingleNoOverwrite | |
| 1945 | (table->tableData, key, value); | |
| 1946 | } | |
| 1947 | int intintIdentitySentinelPerfectHash_InsertNoOverwrite(intintHash_Table * | |
| 1948 | table, | |
| 1949 | size_t numEntries, | |
| 1950 | int *keys, | |
| 1951 | int *values) { | |
| 1952 | return intintIdentitySentinelPerfectHash_InnerInsertNoOverwrite(table-> | |
| 1953 | tableData, | |
| 1954 | numEntries, | |
| 1955 | keys, | |
| 1956 | values); | |
| 1957 | } | |
| 1958 | ||
| 1959 | typedef struct intintIdentitySentinelPerfectCLHash_TableData { | |
| 1960 | int hashID; | |
| 1961 | unsigned int numBuckets; | |
| 1962 | char compressFuncData; | |
| 1963 | int emptyValue; | |
| 1964 | } intintIdentitySentinelPerfectCLHash_TableData; | |
| 1965 | typedef struct intintIdentitySentinelPerfectCLHash_Bucket { | |
| 1966 | int value; | |
| 1967 | } intintIdentitySentinelPerfectCLHash_Bucket; | |
| 1968 | intintHash_Table | |
| 1969 | *intintIdentitySentinelPerfectCLHash_CreateTable(intintHash_Factory * | |
| 1970 | factory, int hashIndex, | |
| 1971 | size_t keyRange, | |
| 1972 | size_t numEntries, | |
| 1973 | float loadFactor) { | |
| 1974 | intintHash_Table *table = | |
| 1975 | (intintHash_Table *) malloc(sizeof(intintHash_Table)); | |
| 1976 | table->destroyFunc = &intintIdentitySentinelPerfectCLHash_DestroyTable; | |
| 1977 | table->emptyFunc = &intintIdentitySentinelPerfectCLHash_EmptyTable; | |
| 1978 | table->queryFunc = &intintIdentitySentinelPerfectCLHash_Query; | |
| 1979 | table->querySingleFunc = | |
| 1980 | &intintIdentitySentinelPerfectCLHash_QuerySingle; | |
| 1981 | table->insertFunc = &intintIdentitySentinelPerfectCLHash_Insert; | |
| 1982 | table->insertSingleFunc = | |
| 1983 | &intintIdentitySentinelPerfectCLHash_InsertSingle; | |
| 1984 | table->insertNoOverwriteFunc = | |
| 1985 | &intintIdentitySentinelPerfectCLHash_InsertNoOverwrite; | |
| 1986 | table->insertSingleNoOverwriteFunc = | |
| 1987 | &intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite; | |
| 1988 | table->tableData = | |
| 1989 | (char *) | |
| 1990 | malloc(sizeof(intintIdentitySentinelPerfectCLHash_TableData)); | |
| 1991 | ((intintIdentitySentinelPerfectCLHash_TableData *) table->tableData)-> | |
| 1992 | hashID = IDENTITY_SENTINEL_PERFECT_CL_HASH_ID; | |
| 1993 | table->context = factory->context; | |
| 1994 | table->queue = factory->queue; | |
| 1995 | table->program = factory->program; | |
| 1996 | table->localWorkSize = factory->localWorkSize; | |
| 1997 | table->utilProgram = factory->utilProgram[hashIndex]; | |
| 1998 | table->emptyKernel = factory->emptyKernel[hashIndex]; | |
| 1999 | table->emptyKernelLocalWorkSize = | |
| 2000 | factory->emptyKernelLocalWorkSize[hashIndex]; | |
| 2001 | table->querySingleKernel = factory->querySingleKernel[hashIndex]; | |
| 2002 | table->insertSingleKernel = factory->insertSingleKernel[hashIndex]; | |
| 2003 | table->insertSingleNoOverwriteKernel = | |
| 2004 | factory->insertSingleNoOverwriteKernel[hashIndex]; | |
| 2005 | clRetainContext(table->context); | |
| 2006 | clRetainCommandQueue(table->queue); | |
| 2007 | clRetainProgram(table->program); | |
| 2008 | clRetainProgram(table->utilProgram); | |
| 2009 | clRetainKernel(table->emptyKernel); | |
| 2010 | clRetainKernel(table->querySingleKernel); | |
| 2011 | clRetainKernel(table->insertSingleKernel); | |
| 2012 | clRetainKernel(table->insertSingleNoOverwriteKernel);; | |
| 2013 | ((intintIdentitySentinelPerfectCLHash_TableData *) table->tableData)-> | |
| 2014 | emptyValue = factory->emptyValue; | |
| 2015 | ((intintIdentitySentinelPerfectCLHash_TableData *) table->tableData)-> | |
| 2016 | numBuckets = keyRange + 1; | |
| 2017 | char *tempHashData = | |
| 2018 | (char *)malloc(sizeof(intintIdentitySentinelPerfectCLHash_TableData) | |
| 2019 | + | |
| 2020 | ((intintIdentitySentinelPerfectCLHash_TableData *) | |
| 2021 | table->tableData)->numBuckets * | |
| 2022 | sizeof(intintIdentitySentinelPerfectCLHash_Bucket)); | |
| 2023 | memcpy(tempHashData, table->tableData, | |
| 2024 | sizeof(intintIdentitySentinelPerfectCLHash_TableData)); | |
| 2025 | free(table->tableData); | |
| 2026 | table->tableData = tempHashData; | |
| 2027 | cl_int err; | |
| 2028 | table->tableDataBuffer = | |
| 2029 | clCreateBuffer(table->context, CL_MEM_READ_WRITE, | |
| 2030 | sizeof(intintIdentitySentinelPerfectHash_TableData) + | |
| 2031 | ((intintIdentitySentinelPerfectHash_TableData *) | |
| 2032 | table->tableData)->numBuckets * | |
| 2033 | sizeof(intintIdentitySentinelPerfectHash_Bucket), | |
| 2034 | NULL, &err); | |
| 2035 | CLHash_Utilities_HandleError(err, | |
| 2036 | "intintIdentitySentinelPerfectCLHash_InitTable", | |
| 2037 | "clCreateBuffer"); | |
| 2038 | err = | |
| 2039 | clEnqueueWriteBuffer(table->queue, table->tableDataBuffer, CL_TRUE, | |
| 2040 | 0, | |
| 2041 | sizeof | |
| 2042 | (intintIdentitySentinelPerfectHash_TableData), | |
| 2043 | table->tableData, 0, NULL, NULL); | |
| 2044 | CLHash_Utilities_HandleError(err, | |
| 2045 | "intintIdentitySentinelPerfectCLHash_InitTable", | |
| 2046 | "clEnqueueWriteBuffer"); | |
| 2047 | return table; | |
| 2048 | } | |
| 2049 | int intintIdentitySentinelPerfectCLHash_CreateFactory(intintHash_Factory * | |
| 2050 | factory, int hashIndex) { | |
| 2051 | factory->createFunc[hashIndex] = | |
| 2052 | &intintIdentitySentinelPerfectCLHash_CreateTable; | |
| 2053 | factory->destroyFunc[hashIndex] = | |
| 2054 | &intintIdentitySentinelPerfectCLHash_DestroyFactory; | |
| 2055 | cl_int error; | |
| 2056 | cl_device_id device; | |
| 2057 | error = | |
| 2058 | clGetContextInfo(factory->context, CL_CONTEXT_DEVICES, | |
| 2059 | sizeof(device), &device, NULL); | |
| 2060 | CLHash_Utilities_HandleError(error, "intintHash_CreateFactory", | |
| 2061 | "clGetContextInfo"); | |
| 2062 | factory->querySingleKernel[hashIndex] = | |
| 2063 | clCreateKernel(factory->program, | |
| 2064 | "intintIdentitySentinelPerfectCLHash_RangeQuerySingle", | |
| 2065 | &error); | |
| 2066 | CLHash_Utilities_HandleError(error, | |
| 2067 | "intintIdentitySentinelPerfectCLHash_CreateFactory", | |
| 2068 | "clCreateKernel"); | |
| 2069 | factory->insertSingleKernel[hashIndex] = | |
| 2070 | clCreateKernel(factory->program, | |
| 2071 | "intintIdentitySentinelPerfectCLHash_RangeInsertSingle", | |
| 2072 | &error); | |
| 2073 | CLHash_Utilities_HandleError(error, | |
| 2074 | "intintIdentitySentinelPerfectCLHash_CreateFactory", | |
| 2075 | "clCreateKernel"); | |
| 2076 | factory->insertSingleNoOverwriteKernel[hashIndex] = | |
| 2077 | clCreateKernel(factory->program, | |
| 2078 | "intintIdentitySentinelPerfectCLHash_RangeInsertSingleNoOverwrite", | |
| 2079 | &error); | |
| 2080 | CLHash_Utilities_HandleError(error, | |
| 2081 | "intintIdentitySentinelPerfectCLHash_CreateFactory", | |
| 2082 | "clCreateKernel"); | |
| 2083 | factory->utilProgram[hashIndex] = | |
| 2084 | CLHash_Utilities_BuildProgramString(factory->context, device, | |
| 2085 | "static inline unsigned int intintHash_CompressIdentity(char data, int hashCode){ return hashCode; } typedef struct intintHash_CompressLCGData{ long unsigned int a; long unsigned int c; unsigned int m; unsigned int n; }intintHash_CompressLCGData; static inline unsigned int intintHash_CompressLCG(intintHash_CompressLCGData compressLCGData, int hashCode){ return ((compressLCGData.a * hashCode + compressLCGData.c) % compressLCGData.m) % compressLCGData.n; } typedef struct intintIdentitySentinelPerfectCLHash_TableData{ int hashID; unsigned int numBuckets; char compressFuncData; int emptyValue; }intintIdentitySentinelPerfectCLHash_TableData; typedef struct intintIdentitySentinelPerfectCLHash_Bucket{ int value; }intintIdentitySentinelPerfectCLHash_Bucket; __kernel void intintIdentitySentinelPerfectCLHash_Empty(__global char *tableData){ int index = get_global_id(0); if(index >= ((__global intintIdentitySentinelPerfectCLHash_TableData*)tableData)->numBuckets){ return; } __global intintIdentitySentinelPerfectCLHash_Bucket *buckets = (__global intintIdentitySentinelPerfectCLHash_Bucket*)&tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)]; buckets[index].value = ((__global intintIdentitySentinelPerfectCLHash_TableData*)tableData)->emptyValue; }"); | |
| 2086 | factory->emptyKernel[hashIndex] = | |
| 2087 | clCreateKernel(factory->utilProgram[hashIndex], | |
| 2088 | "intintIdentitySentinelPerfectCLHash_Empty", &error); | |
| 2089 | CLHash_Utilities_HandleError(error, | |
| 2090 | "intintIdentitySentinelPerfectCLHash_CreateFactory", | |
| 2091 | "clCreateKernel"); | |
| 2092 | error = | |
| 2093 | clGetKernelWorkGroupInfo(factory->emptyKernel[hashIndex], device, | |
| 2094 | CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), | |
| 2095 | &factory-> | |
| 2096 | emptyKernelLocalWorkSize[hashIndex], NULL); | |
| 2097 | CLHash_Utilities_HandleError(error, | |
| 2098 | "intintIdentitySentinelPerfectCLHash_CreateFactory", | |
| 2099 | "clGetKernelWorkGroupInfo");;; | |
| 2100 | return HASH_EXIT_CODE_NORMAL; | |
| 2101 | } | |
| 2102 | int intintIdentitySentinelPerfectCLHash_DestroyFactory(intintHash_Factory * | |
| 2103 | factory, | |
| 2104 | int hashIndex) {; | |
| 2105 | clReleaseKernel(factory->emptyKernel[hashIndex]); | |
| 2106 | clReleaseProgram(factory->utilProgram[hashIndex]); | |
| 2107 | clReleaseKernel(factory->querySingleKernel[hashIndex]); | |
| 2108 | clReleaseKernel(factory->insertSingleKernel[hashIndex]); | |
| 2109 | clReleaseKernel(factory->insertSingleNoOverwriteKernel[hashIndex]);; | |
| 2110 | return HASH_EXIT_CODE_NORMAL; | |
| 2111 | } | |
| 2112 | int intintIdentitySentinelPerfectCLHash_DestroyTable(intintHash_Table * table) { | |
| 2113 | int exitCode = 0; | |
| 2114 | clReleaseMemObject(table->tableDataBuffer); | |
| 2115 | clReleaseContext(table->context); | |
| 2116 | clReleaseCommandQueue(table->queue); | |
| 2117 | clReleaseProgram(table->utilProgram); | |
| 2118 | clReleaseKernel(table->emptyKernel); | |
| 2119 | clReleaseProgram(table->program); | |
| 2120 | clReleaseKernel(table->querySingleKernel); | |
| 2121 | clReleaseKernel(table->insertSingleKernel); | |
| 2122 | clReleaseKernel(table->insertSingleNoOverwriteKernel); | |
| 2123 | free(table->tableData); | |
| 2124 | free(table); | |
| 2125 | return exitCode; | |
| 2126 | } | |
| 2127 | int intintIdentitySentinelPerfectCLHash_EmptyTable(intintHash_Table * table) { | |
| 2128 | int exitCode = 0; | |
| 2129 | cl_int err; | |
| 2130 | err = | |
| 2131 | clSetKernelArg(table->emptyKernel, 0, sizeof(cl_mem), | |
| 2132 | &table->tableDataBuffer); | |
| 2133 | CLHash_Utilities_HandleError(err, | |
| 2134 | "intintIdentitySentinelPerfectCLHash_EmptyTable", | |
| 2135 | "clSetKernelArg"); | |
| 2136 | const size_t groupWorkSize = | |
| 2137 | roundUpToNearest(((intintIdentitySentinelPerfectHash_TableData *) | |
| 2138 | table->tableData)->numBuckets, | |
| 2139 | table->emptyKernelLocalWorkSize); | |
| 2140 | err = | |
| 2141 | clEnqueueNDRangeKernel(table->queue, table->emptyKernel, 1, 0, | |
| 2142 | &groupWorkSize, | |
| 2143 | (const size_t *)&table-> | |
| 2144 | emptyKernelLocalWorkSize, 0, NULL, NULL); | |
| 2145 | CLHash_Utilities_HandleError(err, | |
| 2146 | "intintIdentitySentinelPerfectCLHash_EmptyTable", | |
| 2147 | "clEnqueueNDRangeKernel"); | |
| 2148 | exitCode = HASH_EXIT_CODE_NORMAL;; | |
| 2149 | return exitCode; | |
| 2150 | } | |
| 2151 | int intintIdentitySentinelPerfectCLHash_QuerySingle(intintHash_Table * table, | |
| 2152 | int key, int *valueOutput) { | |
| 2153 | return intintIdentitySentinelPerfectCLHash_Query(table, 1, &key, | |
| 2154 | valueOutput); | |
| 2155 | } | |
| 2156 | int intintIdentitySentinelPerfectCLHash_Query(intintHash_Table * table, | |
| 2157 | size_t numKeys, int *keys, | |
| 2158 | int *valuesOutput) { | |
| 2159 | cl_int err; | |
| 2160 | cl_mem keysBuffer = | |
| 2161 | clCreateBuffer(table->context, | |
| 2162 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 2163 | sizeof(int) * numKeys, keys, &err); | |
| 2164 | CLHash_Utilities_HandleError(err, | |
| 2165 | "intintIdentitySentinelPerfectCLHash_Query", | |
| 2166 | "clCreateBuffer"); | |
| 2167 | cl_mem valuesOutputBuffer = | |
| 2168 | clCreateBuffer(table->context, CL_MEM_WRITE_ONLY, | |
| 2169 | sizeof(int) * numKeys, NULL, &err); | |
| 2170 | CLHash_Utilities_HandleError(err, | |
| 2171 | "intintIdentitySentinelPerfectCLHash_Query", | |
| 2172 | "clCreateBuffer"); | |
| 2173 | intintIdentitySentinelPerfectCLHash_BufferQuery(table, numKeys, | |
| 2174 | keysBuffer, | |
| 2175 | valuesOutputBuffer); | |
| 2176 | err = | |
| 2177 | clEnqueueReadBuffer(table->queue, valuesOutputBuffer, CL_TRUE, 0, | |
| 2178 | sizeof(int) * numKeys, valuesOutput, 0, NULL, | |
| 2179 | NULL); | |
| 2180 | CLHash_Utilities_HandleError(err, | |
| 2181 | "intintIdentitySentinelPerfectCLHash_Query", | |
| 2182 | "clEnqueueReadBuffer"); | |
| 2183 | clReleaseMemObject(keysBuffer); | |
| 2184 | clReleaseMemObject(valuesOutputBuffer); | |
| 2185 | return HASH_EXIT_CODE_NORMAL; | |
| 2186 | } | |
| 2187 | int intintIdentitySentinelPerfectCLHash_BufferQuery(intintHash_Table * table, | |
| 2188 | size_t numKeys, | |
| 2189 | cl_mem keysBuffer, | |
| 2190 | cl_mem valuesOutputBuffer) { | |
| 2191 | cl_int err; | |
| 2192 | err = | |
| 2193 | clSetKernelArg(table->querySingleKernel, 0, sizeof(cl_mem), | |
| 2194 | &table->tableDataBuffer); | |
| 2195 | CLHash_Utilities_HandleError(err, | |
| 2196 | "intintIdentitySentinelPerfectCLHash_BufferQuery", | |
| 2197 | "clSetKernelArg"); | |
| 2198 | err = | |
| 2199 | clSetKernelArg(table->querySingleKernel, 1, sizeof(unsigned int), | |
| 2200 | &numKeys); | |
| 2201 | CLHash_Utilities_HandleError(err, | |
| 2202 | "intintIdentitySentinelPerfectCLHash_BufferQuery", | |
| 2203 | "clSetKernelArg"); | |
| 2204 | err = | |
| 2205 | clSetKernelArg(table->querySingleKernel, 2, sizeof(cl_mem), | |
| 2206 | &keysBuffer); | |
| 2207 | CLHash_Utilities_HandleError(err, | |
| 2208 | "intintIdentitySentinelPerfectCLHash_BufferQuery", | |
| 2209 | "clSetKernelArg"); | |
| 2210 | err = | |
| 2211 | clSetKernelArg(table->querySingleKernel, 3, sizeof(cl_mem), | |
| 2212 | &valuesOutputBuffer); | |
| 2213 | CLHash_Utilities_HandleError(err, | |
| 2214 | "intintIdentitySentinelPerfectCLHash_BufferQuery", | |
| 2215 | "clSetKernelArg"); | |
| 2216 | const size_t groupWorkSize = | |
| 2217 | roundUpToNearest(numKeys, table->localWorkSize); | |
| 2218 | err = | |
| 2219 | clEnqueueNDRangeKernel(table->queue, table->querySingleKernel, 1, 0, | |
| 2220 | &groupWorkSize, | |
| 2221 | (const size_t *)&table->localWorkSize, 0, | |
| 2222 | NULL, NULL); | |
| 2223 | CLHash_Utilities_HandleError(err, | |
| 2224 | "intintIdentitySentinelPerfectCLHash_BufferQuery", | |
| 2225 | "clEnqueueNDRangeKernel"); | |
| 2226 | clFinish(table->queue); | |
| 2227 | return HASH_EXIT_CODE_NORMAL; | |
| 2228 | } | |
| 2229 | int intintIdentitySentinelPerfectCLHash_InsertSingle(intintHash_Table * table, | |
| 2230 | int key, int value) { | |
| 2231 | return intintIdentitySentinelPerfectCLHash_Insert(table, 1, &key, | |
| 2232 | &value); | |
| 2233 | } | |
| 2234 | int intintIdentitySentinelPerfectCLHash_Insert(intintHash_Table * table, | |
| 2235 | size_t numEntries, int *keys, | |
| 2236 | int *values) { | |
| 2237 | cl_int err; | |
| 2238 | cl_mem keysBuffer = | |
| 2239 | clCreateBuffer(table->context, | |
| 2240 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 2241 | sizeof(int) * numEntries, keys, &err); | |
| 2242 | CLHash_Utilities_HandleError(err, | |
| 2243 | "intintIdentitySentinelPerfectCLHash_Insert", | |
| 2244 | "clCreateBuffer"); | |
| 2245 | cl_mem valuesBuffer = | |
| 2246 | clCreateBuffer(table->context, | |
| 2247 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 2248 | sizeof(int) * numEntries, values, &err); | |
| 2249 | CLHash_Utilities_HandleError(err, | |
| 2250 | "intintIdentitySentinelPerfectCLHash_Insert", | |
| 2251 | "clCreateBuffer"); | |
| 2252 | intintIdentitySentinelPerfectCLHash_BufferInsert(table, numEntries, | |
| 2253 | keysBuffer, | |
| 2254 | valuesBuffer); | |
| 2255 | clReleaseMemObject(keysBuffer); | |
| 2256 | clReleaseMemObject(valuesBuffer); | |
| 2257 | return HASH_EXIT_CODE_NORMAL; | |
| 2258 | } | |
| 2259 | int intintIdentitySentinelPerfectCLHash_BufferInsert(intintHash_Table * table, | |
| 2260 | size_t numEntries, | |
| 2261 | cl_mem keysBuffer, | |
| 2262 | cl_mem valuesBuffer) { | |
| 2263 | cl_int err; | |
| 2264 | err = | |
| 2265 | clSetKernelArg(table->insertSingleKernel, 0, sizeof(cl_mem), | |
| 2266 | &table->tableDataBuffer); | |
| 2267 | CLHash_Utilities_HandleError(err, | |
| 2268 | "intintIdentitySentinelPerfectCLHash_BufferInsert", | |
| 2269 | "clSetKernelArg"); | |
| 2270 | err = | |
| 2271 | clSetKernelArg(table->insertSingleKernel, 1, sizeof(unsigned int), | |
| 2272 | &numEntries); | |
| 2273 | CLHash_Utilities_HandleError(err, | |
| 2274 | "intintIdentitySentinelPerfectCLHash_BufferInsert", | |
| 2275 | "clSetKernelArg"); | |
| 2276 | err = | |
| 2277 | clSetKernelArg(table->insertSingleKernel, 2, sizeof(cl_mem), | |
| 2278 | &keysBuffer); | |
| 2279 | CLHash_Utilities_HandleError(err, | |
| 2280 | "intintIdentitySentinelPerfectCLHash_BufferInsert", | |
| 2281 | "clSetKernelArg"); | |
| 2282 | err = | |
| 2283 | clSetKernelArg(table->insertSingleKernel, 3, sizeof(cl_mem), | |
| 2284 | &valuesBuffer); | |
| 2285 | CLHash_Utilities_HandleError(err, | |
| 2286 | "intintIdentitySentinelPerfectCLHash_BufferInsert", | |
| 2287 | "clSetKernelArg"); | |
| 2288 | const size_t groupWorkSize = | |
| 2289 | roundUpToNearest(numEntries, table->localWorkSize); | |
| 2290 | err = | |
| 2291 | clEnqueueNDRangeKernel(table->queue, table->insertSingleKernel, 1, | |
| 2292 | 0, &groupWorkSize, | |
| 2293 | (const size_t *)&table->localWorkSize, 0, | |
| 2294 | NULL, NULL); | |
| 2295 | CLHash_Utilities_HandleError(err, NULL, "clEnqueueNDRangeKernel"); | |
| 2296 | return (0); | |
| 2297 | } | |
| 2298 | int intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite(intintHash_Table | |
| 2299 | * table, | |
| 2300 | int key, | |
| 2301 | int value) { | |
| 2302 | return intintIdentitySentinelPerfectCLHash_InsertNoOverwrite(table, 1, | |
| 2303 | &key, | |
| 2304 | &value); | |
| 2305 | } | |
| 2306 | int intintIdentitySentinelPerfectCLHash_InsertNoOverwrite(intintHash_Table * | |
| 2307 | table, | |
| 2308 | size_t numEntries, | |
| 2309 | int *keys, | |
| 2310 | int *values) { | |
| 2311 | cl_int err; | |
| 2312 | cl_mem keysBuffer = | |
| 2313 | clCreateBuffer(table->context, | |
| 2314 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 2315 | sizeof(int) * numEntries, keys, &err); | |
| 2316 | CLHash_Utilities_HandleError(err, | |
| 2317 | "intintIdentitySentinelPerfectCLHash_InsertNoOverwrite", | |
| 2318 | "clCreateBuffer"); | |
| 2319 | cl_mem valuesBuffer = | |
| 2320 | clCreateBuffer(table->context, | |
| 2321 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 2322 | sizeof(int) * numEntries, values, &err); | |
| 2323 | CLHash_Utilities_HandleError(err, | |
| 2324 | "intintIdentitySentinelPerfectCLHash_InsertNoOverwrite", | |
| 2325 | "clCreateBuffer"); | |
| 2326 | intintIdentitySentinelPerfectCLHash_BufferInsertNoOverwrite(table, | |
| 2327 | numEntries, | |
| 2328 | keysBuffer, | |
| 2329 | valuesBuffer); | |
| 2330 | clReleaseMemObject(keysBuffer); | |
| 2331 | clReleaseMemObject(valuesBuffer); | |
| 2332 | return HASH_EXIT_CODE_NORMAL; | |
| 2333 | } | |
| 2334 | int intintIdentitySentinelPerfectCLHash_BufferInsertNoOverwrite(intintHash_Table | |
| 2335 | * table, | |
| 2336 | size_t | |
| 2337 | numEntries, | |
| 2338 | cl_mem | |
| 2339 | keysBuffer, | |
| 2340 | cl_mem | |
| 2341 | valuesBuffer) { | |
| 2342 | cl_int err; | |
| 2343 | err = | |
| 2344 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 0, | |
| 2345 | sizeof(cl_mem), &table->tableDataBuffer); | |
| 2346 | CLHash_Utilities_HandleError(err, | |
| 2347 | "intintIdentitySentinelPerfectCLHash_BufferInsertNoOverwrite", | |
| 2348 | "clSetKernelArg"); | |
| 2349 | err = | |
| 2350 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 1, | |
| 2351 | sizeof(unsigned int), &numEntries); | |
| 2352 | CLHash_Utilities_HandleError(err, | |
| 2353 | "intintIdentitySentinelPerfectCLHash_BufferInsertNoOverwrite", | |
| 2354 | "ClSetKernelArg"); | |
| 2355 | err = | |
| 2356 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 2, | |
| 2357 | sizeof(cl_mem), &keysBuffer); | |
| 2358 | CLHash_Utilities_HandleError(err, | |
| 2359 | "intintIdentitySentinelPerfectCLHash_BufferInsertNoOverwrite", | |
| 2360 | "clSetKernelArg"); | |
| 2361 | err = | |
| 2362 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 3, | |
| 2363 | sizeof(cl_mem), &valuesBuffer); | |
| 2364 | CLHash_Utilities_HandleError(err, | |
| 2365 | "intintIdentitySentinelPerfectCLHash_BufferInsertNoOverwrite", | |
| 2366 | "clSetKernelArg"); | |
| 2367 | const size_t groupWorkSize = | |
| 2368 | roundUpToNearest(numEntries, table->localWorkSize); | |
| 2369 | err = | |
| 2370 | clEnqueueNDRangeKernel(table->queue, | |
| 2371 | table->insertSingleNoOverwriteKernel, 1, 0, | |
| 2372 | &groupWorkSize, | |
| 2373 | (const size_t *)&table->localWorkSize, 0, | |
| 2374 | NULL, NULL); | |
| 2375 | CLHash_Utilities_HandleError(err, | |
| 2376 | "intintIdentitySentinelPerfectCLHash_BufferInsertNoOverwrite", | |
| 2377 | "clEnqueueNDRangeKernel"); | |
| 2378 | return (0); | |
| 2379 | } | |
| 2380 | ||
| 2381 | typedef struct intintLCGLinearOpenCompactHash_TableData { | |
| 2382 | int hashID; | |
| 2383 | unsigned int numBuckets; | |
| 2384 | intintHash_CompressLCGData compressFuncData; | |
| 2385 | } intintLCGLinearOpenCompactHash_TableData; | |
| 2386 | typedef struct intintLCGLinearOpenCompactHash_Bucket { | |
| 2387 | int key; | |
| 2388 | int value; | |
| 2389 | } intintLCGLinearOpenCompactHash_Bucket; | |
| 2390 | intintHash_Table *intintLCGLinearOpenCompactHash_CreateTable(intintHash_Factory | |
| 2391 | * factory, | |
| 2392 | int hashIndex, | |
| 2393 | size_t keyRange, | |
| 2394 | size_t numEntries, | |
| 2395 | float loadFactor) { | |
| 2396 | intintHash_Table *table = | |
| 2397 | (intintHash_Table *) malloc(sizeof(intintHash_Table)); | |
| 2398 | table->destroyFunc = &intintLCGLinearOpenCompactHash_DestroyTable; | |
| 2399 | table->emptyFunc = &intintLCGLinearOpenCompactHash_EmptyTable; | |
| 2400 | table->queryFunc = &intintLCGLinearOpenCompactHash_Query; | |
| 2401 | table->querySingleFunc = &intintLCGLinearOpenCompactHash_QuerySingle; | |
| 2402 | table->insertFunc = &intintLCGLinearOpenCompactHash_Insert; | |
| 2403 | table->insertSingleFunc = &intintLCGLinearOpenCompactHash_InsertSingle; | |
| 2404 | table->insertNoOverwriteFunc = | |
| 2405 | &intintLCGLinearOpenCompactHash_InsertNoOverwrite; | |
| 2406 | table->insertSingleNoOverwriteFunc = | |
| 2407 | &intintLCGLinearOpenCompactHash_InsertSingleNoOverwrite; | |
| 2408 | table->tableData = | |
| 2409 | (char *)malloc(sizeof(intintLCGLinearOpenCompactHash_TableData)); | |
| 2410 | ((intintLCGLinearOpenCompactHash_TableData *) table->tableData)-> | |
| 2411 | hashID = LCG_LINEAR_OPEN_COMPACT_HASH_ID; | |
| 2412 | ((intintLCGLinearOpenCompactHash_TableData *) table->tableData)-> | |
| 2413 | numBuckets = (unsigned int)((double)numEntries / loadFactor); | |
| 2414 | ((intintLCGLinearOpenCompactHash_TableData *) table->tableData)-> | |
| 2415 | compressFuncData.a = HASH_LCG_A; | |
| 2416 | ((intintLCGLinearOpenCompactHash_TableData *) table->tableData)-> | |
| 2417 | compressFuncData.c = HASH_LCG_C; | |
| 2418 | ((intintLCGLinearOpenCompactHash_TableData *) table->tableData)-> | |
| 2419 | compressFuncData.m = HASH_LCG_M; | |
| 2420 | ((intintLCGLinearOpenCompactHash_TableData *) table->tableData)-> | |
| 2421 | compressFuncData.n = | |
| 2422 | ((intintLCGLinearOpenCompactHash_TableData *) table->tableData)-> | |
| 2423 | numBuckets; | |
| 2424 | char *tempHashData = | |
| 2425 | (char *)malloc(sizeof(intintLCGLinearOpenCompactHash_TableData) + | |
| 2426 | ((intintLCGLinearOpenCompactHash_TableData *) table-> | |
| 2427 | tableData)->numBuckets * | |
| 2428 | sizeof(intintLCGLinearOpenCompactHash_Bucket)); | |
| 2429 | memcpy(tempHashData, table->tableData, | |
| 2430 | sizeof(intintLCGLinearOpenCompactHash_TableData)); | |
| 2431 | free(table->tableData); | |
| 2432 | table->tableData = tempHashData; | |
| 2433 | return table; | |
| 2434 | } | |
| 2435 | int intintLCGLinearOpenCompactHash_CreateFactory(intintHash_Factory * factory, | |
| 2436 | int hashIndex) { | |
| 2437 | factory->createFunc[hashIndex] = | |
| 2438 | &intintLCGLinearOpenCompactHash_CreateTable; | |
| 2439 | factory->destroyFunc[hashIndex] = | |
| 2440 | &intintLCGLinearOpenCompactHash_DestroyFactory;; | |
| 2441 | return HASH_EXIT_CODE_NORMAL; | |
| 2442 | } | |
| 2443 | int intintLCGLinearOpenCompactHash_DestroyFactory(intintHash_Factory * factory, | |
| 2444 | int hashIndex) {; | |
| 2445 | return HASH_EXIT_CODE_NORMAL; | |
| 2446 | } | |
| 2447 | int intintLCGLinearOpenCompactHash_DestroyTable(intintHash_Table * table) { | |
| 2448 | int exitCode = 0; | |
| 2449 | free(table->tableData); | |
| 2450 | free(table); | |
| 2451 | return exitCode; | |
| 2452 | } | |
| 2453 | int intintLCGLinearOpenCompactHash_EmptyTable(intintHash_Table * table) { | |
| 2454 | int exitCode = 0; | |
| 2455 | intintLCGLinearOpenCompactHash_Bucket *buckets = | |
| 2456 | (intintLCGLinearOpenCompactHash_Bucket *) & table-> | |
| 2457 | tableData[sizeof(intintLCGLinearOpenCompactHash_TableData)]; | |
| 2458 | int index; | |
| 2459 | for (index = 0; | |
| 2460 | index < | |
| 2461 | ((intintLCGLinearOpenCompactHash_TableData *) table->tableData)-> | |
| 2462 | numBuckets; index++) { | |
| 2463 | buckets[index].key = HASH_BUCKET_STATUS_EMPTY; | |
| 2464 | } | |
| 2465 | exitCode = HASH_EXIT_CODE_NORMAL; | |
| 2466 | return exitCode; | |
| 2467 | } | |
| 2468 | int intintLCGLinearOpenCompactHash_InnerQuerySingle(char *tableData, int key, | |
| 2469 | int *valueOutput) { | |
| 2470 | intintLCGLinearOpenCompactHash_Bucket *buckets = | |
| 2471 | (intintLCGLinearOpenCompactHash_Bucket *) & | |
| 2472 | tableData[sizeof(intintLCGLinearOpenCompactHash_TableData)]; | |
| 2473 | int index; | |
| 2474 | int exitCode; | |
| 2475 | intintLCGLinearOpenCompactHash_TableData *mytableData = | |
| 2476 | (intintLCGLinearOpenCompactHash_TableData *) tableData; | |
| 2477 | intintHash_CompressLCGData compressFuncData = | |
| 2478 | mytableData->compressFuncData; | |
| 2479 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 2480 | unsigned long int iteration = 0; | |
| 2481 | for (;;) { | |
| 2482 | index = | |
| 2483 | ((1 * iteration + | |
| 2484 | c) % | |
| 2485 | ((intintLCGLinearOpenCompactHash_TableData *) tableData)-> | |
| 2486 | numBuckets); | |
| 2487 | if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 2488 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 2489 | break; | |
| 2490 | } else if (key == buckets[index].key) { | |
| 2491 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 2492 | break; | |
| 2493 | } else if ((index == c && iteration > 0)) { | |
| 2494 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 2495 | break; | |
| 2496 | } | |
| 2497 | iteration++; | |
| 2498 | } | |
| 2499 | switch (exitCode) { | |
| 2500 | case HASH_SEARCH_CODE_MATCH: | |
| 2501 | *valueOutput = buckets[index].value; | |
| 2502 | return HASH_EXIT_CODE_NORMAL; | |
| 2503 | case HASH_SEARCH_CODE_MISMATCH: | |
| 2504 | case HASH_SEARCH_CODE_EMPTY: | |
| 2505 | return HASH_EXIT_CODE_KEY_DNE; | |
| 2506 | default: | |
| 2507 | return exitCode; | |
| 2508 | } | |
| 2509 | } | |
| 2510 | int intintLCGLinearOpenCompactHash_InnerQuery(char *tableData, | |
| 2511 | unsigned int numKeys, int *keys, | |
| 2512 | int *valuesOutput) { | |
| 2513 | intintLCGLinearOpenCompactHash_Bucket *buckets = | |
| 2514 | (intintLCGLinearOpenCompactHash_Bucket *) & | |
| 2515 | tableData[sizeof(intintLCGLinearOpenCompactHash_TableData)]; | |
| 2516 | int key; | |
| 2517 | int *valueOutput; | |
| 2518 | int index; | |
| 2519 | int exitCode; | |
| 2520 | uint i; | |
| 2521 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 2522 | for (i = 0; i < numKeys; i++) { | |
| 2523 | key = keys[i]; | |
| 2524 | valueOutput = &valuesOutput[i]; | |
| 2525 | intintLCGLinearOpenCompactHash_TableData *mytableData = | |
| 2526 | (intintLCGLinearOpenCompactHash_TableData *) tableData; | |
| 2527 | intintHash_CompressLCGData compressFuncData = | |
| 2528 | mytableData->compressFuncData; | |
| 2529 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 2530 | unsigned long int iteration = 0; | |
| 2531 | for (;;) { | |
| 2532 | index = | |
| 2533 | ((1 * iteration + | |
| 2534 | c) % | |
| 2535 | ((intintLCGLinearOpenCompactHash_TableData *) | |
| 2536 | tableData)->numBuckets); | |
| 2537 | if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 2538 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 2539 | break; | |
| 2540 | } else if (key == buckets[index].key) { | |
| 2541 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 2542 | break; | |
| 2543 | } else if ((index == c && iteration > 0)) { | |
| 2544 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 2545 | break; | |
| 2546 | } | |
| 2547 | iteration++; | |
| 2548 | } | |
| 2549 | switch (exitCode) { | |
| 2550 | case HASH_SEARCH_CODE_MATCH: | |
| 2551 | *valueOutput = buckets[index].value; | |
| 2552 | break; | |
| 2553 | case HASH_SEARCH_CODE_MISMATCH: | |
| 2554 | case HASH_SEARCH_CODE_EMPTY: | |
| 2555 | resultExitCode = HASH_EXIT_CODE_KEY_DNE; | |
| 2556 | break; | |
| 2557 | default: | |
| 2558 | return exitCode; | |
| 2559 | } | |
| 2560 | } | |
| 2561 | return resultExitCode; | |
| 2562 | } | |
| 2563 | int intintLCGLinearOpenCompactHash_InnerInsertSingle(char *tableData, int key, | |
| 2564 | int value) { | |
| 2565 | intintLCGLinearOpenCompactHash_Bucket *buckets = | |
| 2566 | (intintLCGLinearOpenCompactHash_Bucket *) & | |
| 2567 | tableData[sizeof(intintLCGLinearOpenCompactHash_TableData)]; | |
| 2568 | int index; | |
| 2569 | int exitCode; | |
| 2570 | intintLCGLinearOpenCompactHash_TableData *mytableData = | |
| 2571 | (intintLCGLinearOpenCompactHash_TableData *) tableData; | |
| 2572 | intintHash_CompressLCGData compressFuncData = | |
| 2573 | mytableData->compressFuncData; | |
| 2574 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 2575 | unsigned long int iteration = 0; | |
| 2576 | for (;;) { | |
| 2577 | index = | |
| 2578 | ((1 * iteration + | |
| 2579 | c) % | |
| 2580 | ((intintLCGLinearOpenCompactHash_TableData *) tableData)-> | |
| 2581 | numBuckets); | |
| 2582 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 2583 | buckets | |
| 2584 | [index]. | |
| 2585 | key = | |
| 2586 | key; | |
| 2587 | HASH_BUCKET_STATUS_EMPTY;} | |
| 2588 | ): buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 2589 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 2590 | break; | |
| 2591 | } else if (key == buckets[index].key) { | |
| 2592 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 2593 | break; | |
| 2594 | } else if ((index == c && iteration > 0)) { | |
| 2595 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 2596 | break; | |
| 2597 | } | |
| 2598 | iteration++; | |
| 2599 | } | |
| 2600 | switch (exitCode) { | |
| 2601 | case HASH_SEARCH_CODE_MATCH: | |
| 2602 | case HASH_SEARCH_CODE_MISMATCH: | |
| 2603 | buckets[index].value = value; | |
| 2604 | return HASH_EXIT_CODE_OVERWRITE; | |
| 2605 | case HASH_SEARCH_CODE_EMPTY: | |
| 2606 | buckets[index].value = value; | |
| 2607 | return HASH_EXIT_CODE_NORMAL; | |
| 2608 | default: | |
| 2609 | return exitCode; | |
| 2610 | } | |
| 2611 | } | |
| 2612 | int intintLCGLinearOpenCompactHash_InnerInsert(char *tableData, | |
| 2613 | unsigned int numEntries, | |
| 2614 | int *keys, int *values) { | |
| 2615 | intintLCGLinearOpenCompactHash_Bucket *buckets = | |
| 2616 | (intintLCGLinearOpenCompactHash_Bucket *) & | |
| 2617 | tableData[sizeof(intintLCGLinearOpenCompactHash_TableData)]; | |
| 2618 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 2619 | int key; | |
| 2620 | int value; | |
| 2621 | int index; | |
| 2622 | int exitCode; | |
| 2623 | uint i; | |
| 2624 | for (i = 0; i < numEntries; i++) { | |
| 2625 | key = keys[i]; | |
| 2626 | intintLCGLinearOpenCompactHash_TableData *mytableData = | |
| 2627 | (intintLCGLinearOpenCompactHash_TableData *) tableData; | |
| 2628 | intintHash_CompressLCGData compressFuncData = | |
| 2629 | mytableData->compressFuncData; | |
| 2630 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 2631 | unsigned long int iteration = 0; | |
| 2632 | for (;;) { | |
| 2633 | index = | |
| 2634 | ((1 * iteration + | |
| 2635 | c) % | |
| 2636 | ((intintLCGLinearOpenCompactHash_TableData *) | |
| 2637 | tableData)->numBuckets); | |
| 2638 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 2639 | buckets | |
| 2640 | [index]. | |
| 2641 | key | |
| 2642 | = | |
| 2643 | key; | |
| 2644 | HASH_BUCKET_STATUS_EMPTY;} | |
| 2645 | ): buckets[index].key) == | |
| 2646 | HASH_BUCKET_STATUS_EMPTY) { | |
| 2647 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 2648 | break; | |
| 2649 | } else if (key == buckets[index].key) { | |
| 2650 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 2651 | break; | |
| 2652 | } else if ((index == c && iteration > 0)) { | |
| 2653 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 2654 | break; | |
| 2655 | } | |
| 2656 | iteration++; | |
| 2657 | } | |
| 2658 | switch (exitCode) { | |
| 2659 | case HASH_SEARCH_CODE_MATCH: | |
| 2660 | case HASH_SEARCH_CODE_MISMATCH: | |
| 2661 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 2662 | case HASH_SEARCH_CODE_EMPTY: | |
| 2663 | buckets[index].value = values[i]; | |
| 2664 | break; | |
| 2665 | default: | |
| 2666 | return exitCode; | |
| 2667 | } | |
| 2668 | } | |
| 2669 | return resultExitCode; | |
| 2670 | } | |
| 2671 | int intintLCGLinearOpenCompactHash_InnerInsertSingleNoOverwrite(char *tableData, | |
| 2672 | int key, | |
| 2673 | int value) { | |
| 2674 | intintLCGLinearOpenCompactHash_Bucket *buckets = | |
| 2675 | (intintLCGLinearOpenCompactHash_Bucket *) & | |
| 2676 | tableData[sizeof(intintLCGLinearOpenCompactHash_TableData)]; | |
| 2677 | int index; | |
| 2678 | int exitCode; | |
| 2679 | intintLCGLinearOpenCompactHash_TableData *mytableData = | |
| 2680 | (intintLCGLinearOpenCompactHash_TableData *) tableData; | |
| 2681 | intintHash_CompressLCGData compressFuncData = | |
| 2682 | mytableData->compressFuncData; | |
| 2683 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 2684 | unsigned long int iteration = 0; | |
| 2685 | for (;;) { | |
| 2686 | index = | |
| 2687 | ((1 * iteration + | |
| 2688 | c) % | |
| 2689 | ((intintLCGLinearOpenCompactHash_TableData *) tableData)-> | |
| 2690 | numBuckets); | |
| 2691 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 2692 | buckets | |
| 2693 | [index]. | |
| 2694 | key = | |
| 2695 | key; | |
| 2696 | HASH_BUCKET_STATUS_EMPTY;} | |
| 2697 | ): buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 2698 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 2699 | break; | |
| 2700 | } else if (key == buckets[index].key) { | |
| 2701 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 2702 | break; | |
| 2703 | } else if ((index == c && iteration > 0)) { | |
| 2704 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 2705 | break; | |
| 2706 | } | |
| 2707 | iteration++; | |
| 2708 | } | |
| 2709 | switch (exitCode) { | |
| 2710 | case HASH_SEARCH_CODE_MATCH: | |
| 2711 | case HASH_SEARCH_CODE_MISMATCH: | |
| 2712 | return HASH_EXIT_CODE_OVERWRITE; | |
| 2713 | case HASH_SEARCH_CODE_EMPTY: | |
| 2714 | buckets[index].value = value; | |
| 2715 | return HASH_EXIT_CODE_NORMAL; | |
| 2716 | default: | |
| 2717 | return exitCode; | |
| 2718 | } | |
| 2719 | } | |
| 2720 | int intintLCGLinearOpenCompactHash_InnerInsertNoOverwrite(char *tableData, | |
| 2721 | unsigned int | |
| 2722 | numEntries, int *keys, | |
| 2723 | int *values) { | |
| 2724 | intintLCGLinearOpenCompactHash_Bucket *buckets = | |
| 2725 | (intintLCGLinearOpenCompactHash_Bucket *) & | |
| 2726 | tableData[sizeof(intintLCGLinearOpenCompactHash_TableData)]; | |
| 2727 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 2728 | int key; | |
| 2729 | int value; | |
| 2730 | int index; | |
| 2731 | int exitCode; | |
| 2732 | uint i; | |
| 2733 | for (i = 0; i < numEntries; i++) { | |
| 2734 | key = keys[i]; | |
| 2735 | intintLCGLinearOpenCompactHash_TableData *mytableData = | |
| 2736 | (intintLCGLinearOpenCompactHash_TableData *) tableData; | |
| 2737 | intintHash_CompressLCGData compressFuncData = | |
| 2738 | mytableData->compressFuncData; | |
| 2739 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 2740 | unsigned long int iteration = 0; | |
| 2741 | for (;;) { | |
| 2742 | index = | |
| 2743 | ((1 * iteration + | |
| 2744 | c) % | |
| 2745 | ((intintLCGLinearOpenCompactHash_TableData *) | |
| 2746 | tableData)->numBuckets); | |
| 2747 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 2748 | buckets | |
| 2749 | [index]. | |
| 2750 | key | |
| 2751 | = | |
| 2752 | key; | |
| 2753 | HASH_BUCKET_STATUS_EMPTY;} | |
| 2754 | ): buckets[index].key) == | |
| 2755 | HASH_BUCKET_STATUS_EMPTY) { | |
| 2756 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 2757 | break; | |
| 2758 | } else if (key == buckets[index].key) { | |
| 2759 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 2760 | break; | |
| 2761 | } else if ((index == c && iteration > 0)) { | |
| 2762 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 2763 | break; | |
| 2764 | } | |
| 2765 | iteration++; | |
| 2766 | } | |
| 2767 | switch (exitCode) { | |
| 2768 | case HASH_SEARCH_CODE_MATCH: | |
| 2769 | case HASH_SEARCH_CODE_MISMATCH: | |
| 2770 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 2771 | break; | |
| 2772 | case HASH_SEARCH_CODE_EMPTY: | |
| 2773 | buckets[index].value = values[i]; | |
| 2774 | break; | |
| 2775 | default: | |
| 2776 | return exitCode; | |
| 2777 | } | |
| 2778 | } | |
| 2779 | return resultExitCode; | |
| 2780 | } | |
| 2781 | int intintLCGLinearOpenCompactHash_QuerySingle(intintHash_Table * table, | |
| 2782 | int key, int *valueOutput) { | |
| 2783 | return intintLCGLinearOpenCompactHash_InnerQuerySingle(table->tableData, | |
| 2784 | key, | |
| 2785 | valueOutput); | |
| 2786 | } | |
| 2787 | int intintLCGLinearOpenCompactHash_Query(intintHash_Table * table, | |
| 2788 | size_t numKeys, int *keys, | |
| 2789 | int *valuesOutput) { | |
| 2790 | return intintLCGLinearOpenCompactHash_InnerQuery(table->tableData, | |
| 2791 | numKeys, keys, | |
| 2792 | valuesOutput); | |
| 2793 | } | |
| 2794 | int intintLCGLinearOpenCompactHash_InsertSingle(intintHash_Table * table, | |
| 2795 | int key, int value) { | |
| 2796 | return intintLCGLinearOpenCompactHash_InnerInsertSingle(table-> | |
| 2797 | tableData, key, | |
| 2798 | value); | |
| 2799 | } | |
| 2800 | int intintLCGLinearOpenCompactHash_Insert(intintHash_Table * table, | |
| 2801 | size_t numEntries, int *keys, | |
| 2802 | int *values) { | |
| 2803 | return intintLCGLinearOpenCompactHash_InnerInsert(table->tableData, | |
| 2804 | numEntries, keys, | |
| 2805 | values); | |
| 2806 | } | |
| 2807 | int intintLCGLinearOpenCompactHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 2808 | table, int key, | |
| 2809 | int value) { | |
| 2810 | return | |
| 2811 | intintLCGLinearOpenCompactHash_InnerInsertSingleNoOverwrite(table-> | |
| 2812 | tableData, | |
| 2813 | key, | |
| 2814 | value); | |
| 2815 | } | |
| 2816 | int intintLCGLinearOpenCompactHash_InsertNoOverwrite(intintHash_Table * table, | |
| 2817 | size_t numEntries, | |
| 2818 | int *keys, int *values) { | |
| 2819 | return intintLCGLinearOpenCompactHash_InnerInsertNoOverwrite(table-> | |
| 2820 | tableData, | |
| 2821 | numEntries, | |
| 2822 | keys, | |
| 2823 | values); | |
| 2824 | } | |
| 2825 | ||
| 2826 | typedef struct intintLCGLinearOpenCompactCLHash_TableData { | |
| 2827 | int hashID; | |
| 2828 | unsigned int numBuckets; | |
| 2829 | intintHash_CompressLCGData compressFuncData; | |
| 2830 | } intintLCGLinearOpenCompactCLHash_TableData; | |
| 2831 | typedef struct intintLCGLinearOpenCompactCLHash_Bucket { | |
| 2832 | int key; | |
| 2833 | int value; | |
| 2834 | } intintLCGLinearOpenCompactCLHash_Bucket; | |
| 2835 | intintHash_Table | |
| 2836 | *intintLCGLinearOpenCompactCLHash_CreateTable(intintHash_Factory * factory, | |
| 2837 | int hashIndex, | |
| 2838 | size_t keyRange, | |
| 2839 | size_t numEntries, | |
| 2840 | float loadFactor) { | |
| 2841 | intintHash_Table *table = | |
| 2842 | (intintHash_Table *) malloc(sizeof(intintHash_Table)); | |
| 2843 | table->destroyFunc = &intintLCGLinearOpenCompactCLHash_DestroyTable; | |
| 2844 | table->emptyFunc = &intintLCGLinearOpenCompactCLHash_EmptyTable; | |
| 2845 | table->queryFunc = &intintLCGLinearOpenCompactCLHash_Query; | |
| 2846 | table->querySingleFunc = &intintLCGLinearOpenCompactCLHash_QuerySingle; | |
| 2847 | table->insertFunc = &intintLCGLinearOpenCompactCLHash_Insert; | |
| 2848 | table->insertSingleFunc = | |
| 2849 | &intintLCGLinearOpenCompactCLHash_InsertSingle; | |
| 2850 | table->insertNoOverwriteFunc = | |
| 2851 | &intintLCGLinearOpenCompactCLHash_InsertNoOverwrite; | |
| 2852 | table->insertSingleNoOverwriteFunc = | |
| 2853 | &intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite; | |
| 2854 | table->tableData = | |
| 2855 | (char *)malloc(sizeof(intintLCGLinearOpenCompactCLHash_TableData)); | |
| 2856 | ((intintLCGLinearOpenCompactCLHash_TableData *) table->tableData)-> | |
| 2857 | hashID = LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID; | |
| 2858 | table->context = factory->context; | |
| 2859 | table->queue = factory->queue; | |
| 2860 | table->program = factory->program; | |
| 2861 | table->localWorkSize = factory->localWorkSize; | |
| 2862 | table->utilProgram = factory->utilProgram[hashIndex]; | |
| 2863 | table->emptyKernel = factory->emptyKernel[hashIndex]; | |
| 2864 | table->emptyKernelLocalWorkSize = | |
| 2865 | factory->emptyKernelLocalWorkSize[hashIndex]; | |
| 2866 | table->querySingleKernel = factory->querySingleKernel[hashIndex]; | |
| 2867 | table->insertSingleKernel = factory->insertSingleKernel[hashIndex]; | |
| 2868 | table->insertSingleNoOverwriteKernel = | |
| 2869 | factory->insertSingleNoOverwriteKernel[hashIndex]; | |
| 2870 | clRetainContext(table->context); | |
| 2871 | clRetainCommandQueue(table->queue); | |
| 2872 | clRetainProgram(table->program); | |
| 2873 | clRetainProgram(table->utilProgram); | |
| 2874 | clRetainKernel(table->emptyKernel); | |
| 2875 | clRetainKernel(table->querySingleKernel); | |
| 2876 | clRetainKernel(table->insertSingleKernel); | |
| 2877 | clRetainKernel(table->insertSingleNoOverwriteKernel);; | |
| 2878 | ((intintLCGLinearOpenCompactCLHash_TableData *) table->tableData)-> | |
| 2879 | numBuckets = (unsigned int)((double)numEntries / loadFactor); | |
| 2880 | ((intintLCGLinearOpenCompactCLHash_TableData *) table->tableData)-> | |
| 2881 | compressFuncData.a = HASH_LCG_A; | |
| 2882 | ((intintLCGLinearOpenCompactCLHash_TableData *) table->tableData)-> | |
| 2883 | compressFuncData.c = HASH_LCG_C; | |
| 2884 | ((intintLCGLinearOpenCompactCLHash_TableData *) table->tableData)-> | |
| 2885 | compressFuncData.m = HASH_LCG_M; | |
| 2886 | ((intintLCGLinearOpenCompactCLHash_TableData *) table->tableData)-> | |
| 2887 | compressFuncData.n = | |
| 2888 | ((intintLCGLinearOpenCompactCLHash_TableData *) table->tableData)-> | |
| 2889 | numBuckets; | |
| 2890 | char *tempHashData = | |
| 2891 | (char *)malloc(sizeof(intintLCGLinearOpenCompactCLHash_TableData) + | |
| 2892 | ((intintLCGLinearOpenCompactCLHash_TableData *) | |
| 2893 | table->tableData)->numBuckets * | |
| 2894 | sizeof(intintLCGLinearOpenCompactCLHash_Bucket)); | |
| 2895 | memcpy(tempHashData, table->tableData, | |
| 2896 | sizeof(intintLCGLinearOpenCompactCLHash_TableData)); | |
| 2897 | free(table->tableData); | |
| 2898 | table->tableData = tempHashData; | |
| 2899 | cl_int err; | |
| 2900 | table->tableDataBuffer = | |
| 2901 | clCreateBuffer(table->context, CL_MEM_READ_WRITE, | |
| 2902 | sizeof(intintLCGLinearOpenCompactHash_TableData) + | |
| 2903 | ((intintLCGLinearOpenCompactHash_TableData *) table-> | |
| 2904 | tableData)->numBuckets * | |
| 2905 | sizeof(intintLCGLinearOpenCompactHash_Bucket), NULL, | |
| 2906 | &err); | |
| 2907 | CLHash_Utilities_HandleError(err, | |
| 2908 | "intintLCGLinearOpenCompactCLHash_InitTable", | |
| 2909 | "clCreateBuffer"); | |
| 2910 | err = | |
| 2911 | clEnqueueWriteBuffer(table->queue, table->tableDataBuffer, CL_TRUE, | |
| 2912 | 0, | |
| 2913 | sizeof | |
| 2914 | (intintLCGLinearOpenCompactHash_TableData), | |
| 2915 | table->tableData, 0, NULL, NULL); | |
| 2916 | CLHash_Utilities_HandleError(err, | |
| 2917 | "intintLCGLinearOpenCompactCLHash_InitTable", | |
| 2918 | "clEnqueueWriteBuffer"); | |
| 2919 | return table; | |
| 2920 | } | |
| 2921 | int intintLCGLinearOpenCompactCLHash_CreateFactory(intintHash_Factory * factory, | |
| 2922 | int hashIndex) { | |
| 2923 | factory->createFunc[hashIndex] = | |
| 2924 | &intintLCGLinearOpenCompactCLHash_CreateTable; | |
| 2925 | factory->destroyFunc[hashIndex] = | |
| 2926 | &intintLCGLinearOpenCompactCLHash_DestroyFactory; | |
| 2927 | cl_int error; | |
| 2928 | cl_device_id device; | |
| 2929 | error = | |
| 2930 | clGetContextInfo(factory->context, CL_CONTEXT_DEVICES, | |
| 2931 | sizeof(device), &device, NULL); | |
| 2932 | CLHash_Utilities_HandleError(error, "intintHash_CreateFactory", | |
| 2933 | "clGetContextInfo"); | |
| 2934 | factory->querySingleKernel[hashIndex] = | |
| 2935 | clCreateKernel(factory->program, | |
| 2936 | "intintLCGLinearOpenCompactCLHash_RangeQuerySingle", | |
| 2937 | &error); | |
| 2938 | CLHash_Utilities_HandleError(error, | |
| 2939 | "intintLCGLinearOpenCompactCLHash_CreateFactory", | |
| 2940 | "clCreateKernel"); | |
| 2941 | factory->insertSingleKernel[hashIndex] = | |
| 2942 | clCreateKernel(factory->program, | |
| 2943 | "intintLCGLinearOpenCompactCLHash_RangeInsertSingle", | |
| 2944 | &error); | |
| 2945 | CLHash_Utilities_HandleError(error, | |
| 2946 | "intintLCGLinearOpenCompactCLHash_CreateFactory", | |
| 2947 | "clCreateKernel"); | |
| 2948 | factory->insertSingleNoOverwriteKernel[hashIndex] = | |
| 2949 | clCreateKernel(factory->program, | |
| 2950 | "intintLCGLinearOpenCompactCLHash_RangeInsertSingleNoOverwrite", | |
| 2951 | &error); | |
| 2952 | CLHash_Utilities_HandleError(error, | |
| 2953 | "intintLCGLinearOpenCompactCLHash_CreateFactory", | |
| 2954 | "clCreateKernel"); | |
| 2955 | factory->utilProgram[hashIndex] = | |
| 2956 | CLHash_Utilities_BuildProgramString(factory->context, device, | |
| 2957 | "static inline unsigned int intintHash_CompressIdentity(char data, int hashCode){ return hashCode; } typedef struct intintHash_CompressLCGData{ long unsigned int a; long unsigned int c; unsigned int m; unsigned int n; }intintHash_CompressLCGData; static inline unsigned int intintHash_CompressLCG(intintHash_CompressLCGData compressLCGData, int hashCode){ return ((compressLCGData.a * hashCode + compressLCGData.c) % compressLCGData.m) % compressLCGData.n; } typedef struct intintLCGLinearOpenCompactCLHash_TableData{ int hashID; unsigned int numBuckets; intintHash_CompressLCGData compressFuncData; }intintLCGLinearOpenCompactCLHash_TableData; typedef struct intintLCGLinearOpenCompactCLHash_Bucket{ int key; int value; }intintLCGLinearOpenCompactCLHash_Bucket; __kernel void intintLCGLinearOpenCompactCLHash_Empty(__global char *tableData){ int index = get_global_id(0); if(index >= ((__global intintLCGLinearOpenCompactCLHash_TableData*)tableData)->numBuckets){ return; } __global intintLCGLinearOpenCompactCLHash_Bucket *buckets = (__global intintLCGLinearOpenCompactCLHash_Bucket*)&tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)]; buckets[index].key = -1;/*HASH_BUCKET_STATUS_EMPTY*/ }"); | |
| 2958 | factory->emptyKernel[hashIndex] = | |
| 2959 | clCreateKernel(factory->utilProgram[hashIndex], | |
| 2960 | "intintLCGLinearOpenCompactCLHash_Empty", &error); | |
| 2961 | CLHash_Utilities_HandleError(error, | |
| 2962 | "intintLCGLinearOpenCompactCLHash_CreateFactory", | |
| 2963 | "clCreateKernel"); | |
| 2964 | error = | |
| 2965 | clGetKernelWorkGroupInfo(factory->emptyKernel[hashIndex], device, | |
| 2966 | CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), | |
| 2967 | &factory-> | |
| 2968 | emptyKernelLocalWorkSize[hashIndex], NULL); | |
| 2969 | CLHash_Utilities_HandleError(error, | |
| 2970 | "intintLCGLinearOpenCompactCLHash_CreateFactory", | |
| 2971 | "clGetKernelWorkGroupInfo");;; | |
| 2972 | return HASH_EXIT_CODE_NORMAL; | |
| 2973 | } | |
| 2974 | int intintLCGLinearOpenCompactCLHash_DestroyFactory(intintHash_Factory * | |
| 2975 | factory, int hashIndex) {; | |
| 2976 | clReleaseKernel(factory->emptyKernel[hashIndex]); | |
| 2977 | clReleaseProgram(factory->utilProgram[hashIndex]); | |
| 2978 | clReleaseKernel(factory->querySingleKernel[hashIndex]); | |
| 2979 | clReleaseKernel(factory->insertSingleKernel[hashIndex]); | |
| 2980 | clReleaseKernel(factory->insertSingleNoOverwriteKernel[hashIndex]);; | |
| 2981 | return HASH_EXIT_CODE_NORMAL; | |
| 2982 | } | |
| 2983 | int intintLCGLinearOpenCompactCLHash_DestroyTable(intintHash_Table * table) { | |
| 2984 | int exitCode = 0; | |
| 2985 | clReleaseMemObject(table->tableDataBuffer); | |
| 2986 | clReleaseContext(table->context); | |
| 2987 | clReleaseCommandQueue(table->queue); | |
| 2988 | clReleaseProgram(table->utilProgram); | |
| 2989 | clReleaseKernel(table->emptyKernel); | |
| 2990 | clReleaseProgram(table->program); | |
| 2991 | clReleaseKernel(table->querySingleKernel); | |
| 2992 | clReleaseKernel(table->insertSingleKernel); | |
| 2993 | clReleaseKernel(table->insertSingleNoOverwriteKernel); | |
| 2994 | free(table->tableData); | |
| 2995 | free(table); | |
| 2996 | return exitCode; | |
| 2997 | } | |
| 2998 | int intintLCGLinearOpenCompactCLHash_EmptyTable(intintHash_Table * table) { | |
| 2999 | int exitCode = 0; | |
| 3000 | cl_int err; | |
| 3001 | err = | |
| 3002 | clSetKernelArg(table->emptyKernel, 0, sizeof(cl_mem), | |
| 3003 | &table->tableDataBuffer); | |
| 3004 | CLHash_Utilities_HandleError(err, | |
| 3005 | "intintLCGLinearOpenCompactCLHash_EmptyTable", | |
| 3006 | "clSetKernelArg"); | |
| 3007 | const size_t groupWorkSize = | |
| 3008 | roundUpToNearest(((intintLCGLinearOpenCompactHash_TableData *) | |
| 3009 | table->tableData)->numBuckets, | |
| 3010 | table->emptyKernelLocalWorkSize); | |
| 3011 | err = | |
| 3012 | clEnqueueNDRangeKernel(table->queue, table->emptyKernel, 1, 0, | |
| 3013 | &groupWorkSize, | |
| 3014 | (const size_t *)&table-> | |
| 3015 | emptyKernelLocalWorkSize, 0, NULL, NULL); | |
| 3016 | CLHash_Utilities_HandleError(err, | |
| 3017 | "intintLCGLinearOpenCompactCLHash_EmptyTable", | |
| 3018 | "clEnqueueNDRangeKernel"); | |
| 3019 | exitCode = HASH_EXIT_CODE_NORMAL;; | |
| 3020 | return exitCode; | |
| 3021 | } | |
| 3022 | int intintLCGLinearOpenCompactCLHash_QuerySingle(intintHash_Table * table, | |
| 3023 | int key, int *valueOutput) { | |
| 3024 | return intintLCGLinearOpenCompactCLHash_Query(table, 1, &key, | |
| 3025 | valueOutput); | |
| 3026 | } | |
| 3027 | int intintLCGLinearOpenCompactCLHash_Query(intintHash_Table * table, | |
| 3028 | size_t numKeys, int *keys, | |
| 3029 | int *valuesOutput) { | |
| 3030 | cl_int err; | |
| 3031 | cl_mem keysBuffer = | |
| 3032 | clCreateBuffer(table->context, | |
| 3033 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 3034 | sizeof(int) * numKeys, keys, &err); | |
| 3035 | CLHash_Utilities_HandleError(err, | |
| 3036 | "intintLCGLinearOpenCompactCLHash_Query", | |
| 3037 | "clCreateBuffer"); | |
| 3038 | cl_mem valuesOutputBuffer = | |
| 3039 | clCreateBuffer(table->context, CL_MEM_WRITE_ONLY, | |
| 3040 | sizeof(int) * numKeys, NULL, &err); | |
| 3041 | CLHash_Utilities_HandleError(err, | |
| 3042 | "intintLCGLinearOpenCompactCLHash_Query", | |
| 3043 | "clCreateBuffer"); | |
| 3044 | intintLCGLinearOpenCompactCLHash_BufferQuery(table, numKeys, keysBuffer, | |
| 3045 | valuesOutputBuffer); | |
| 3046 | err = | |
| 3047 | clEnqueueReadBuffer(table->queue, valuesOutputBuffer, CL_TRUE, 0, | |
| 3048 | sizeof(int) * numKeys, valuesOutput, 0, NULL, | |
| 3049 | NULL); | |
| 3050 | CLHash_Utilities_HandleError(err, | |
| 3051 | "intintLCGLinearOpenCompactCLHash_Query", | |
| 3052 | "clEnqueueReadBuffer"); | |
| 3053 | clReleaseMemObject(keysBuffer); | |
| 3054 | clReleaseMemObject(valuesOutputBuffer); | |
| 3055 | return HASH_EXIT_CODE_NORMAL; | |
| 3056 | } | |
| 3057 | int intintLCGLinearOpenCompactCLHash_BufferQuery(intintHash_Table * table, | |
| 3058 | size_t numKeys, | |
| 3059 | cl_mem keysBuffer, | |
| 3060 | cl_mem valuesOutputBuffer) { | |
| 3061 | cl_int err; | |
| 3062 | err = | |
| 3063 | clSetKernelArg(table->querySingleKernel, 0, sizeof(cl_mem), | |
| 3064 | &table->tableDataBuffer); | |
| 3065 | CLHash_Utilities_HandleError(err, | |
| 3066 | "intintLCGLinearOpenCompactCLHash_BufferQuery", | |
| 3067 | "clSetKernelArg"); | |
| 3068 | err = | |
| 3069 | clSetKernelArg(table->querySingleKernel, 1, sizeof(unsigned int), | |
| 3070 | &numKeys); | |
| 3071 | CLHash_Utilities_HandleError(err, | |
| 3072 | "intintLCGLinearOpenCompactCLHash_BufferQuery", | |
| 3073 | "clSetKernelArg"); | |
| 3074 | err = | |
| 3075 | clSetKernelArg(table->querySingleKernel, 2, sizeof(cl_mem), | |
| 3076 | &keysBuffer); | |
| 3077 | CLHash_Utilities_HandleError(err, | |
| 3078 | "intintLCGLinearOpenCompactCLHash_BufferQuery", | |
| 3079 | "clSetKernelArg"); | |
| 3080 | err = | |
| 3081 | clSetKernelArg(table->querySingleKernel, 3, sizeof(cl_mem), | |
| 3082 | &valuesOutputBuffer); | |
| 3083 | CLHash_Utilities_HandleError(err, | |
| 3084 | "intintLCGLinearOpenCompactCLHash_BufferQuery", | |
| 3085 | "clSetKernelArg"); | |
| 3086 | const size_t groupWorkSize = | |
| 3087 | roundUpToNearest(numKeys, table->localWorkSize); | |
| 3088 | err = | |
| 3089 | clEnqueueNDRangeKernel(table->queue, table->querySingleKernel, 1, 0, | |
| 3090 | &groupWorkSize, | |
| 3091 | (const size_t *)&table->localWorkSize, 0, | |
| 3092 | NULL, NULL); | |
| 3093 | CLHash_Utilities_HandleError(err, | |
| 3094 | "intintLCGLinearOpenCompactCLHash_BufferQuery", | |
| 3095 | "clEnqueueNDRangeKernel"); | |
| 3096 | clFinish(table->queue); | |
| 3097 | return HASH_EXIT_CODE_NORMAL; | |
| 3098 | } | |
| 3099 | int intintLCGLinearOpenCompactCLHash_InsertSingle(intintHash_Table * table, | |
| 3100 | int key, int value) { | |
| 3101 | return intintLCGLinearOpenCompactCLHash_Insert(table, 1, &key, &value); | |
| 3102 | } | |
| 3103 | int intintLCGLinearOpenCompactCLHash_Insert(intintHash_Table * table, | |
| 3104 | size_t numEntries, int *keys, | |
| 3105 | int *values) { | |
| 3106 | cl_int err; | |
| 3107 | cl_mem keysBuffer = | |
| 3108 | clCreateBuffer(table->context, | |
| 3109 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 3110 | sizeof(int) * numEntries, keys, &err); | |
| 3111 | CLHash_Utilities_HandleError(err, | |
| 3112 | "intintLCGLinearOpenCompactCLHash_Insert", | |
| 3113 | "clCreateBuffer"); | |
| 3114 | cl_mem valuesBuffer = | |
| 3115 | clCreateBuffer(table->context, | |
| 3116 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 3117 | sizeof(int) * numEntries, values, &err); | |
| 3118 | CLHash_Utilities_HandleError(err, | |
| 3119 | "intintLCGLinearOpenCompactCLHash_Insert", | |
| 3120 | "clCreateBuffer"); | |
| 3121 | intintLCGLinearOpenCompactCLHash_BufferInsert(table, numEntries, | |
| 3122 | keysBuffer, valuesBuffer); | |
| 3123 | clReleaseMemObject(keysBuffer); | |
| 3124 | clReleaseMemObject(valuesBuffer); | |
| 3125 | return HASH_EXIT_CODE_NORMAL; | |
| 3126 | } | |
| 3127 | int intintLCGLinearOpenCompactCLHash_BufferInsert(intintHash_Table * table, | |
| 3128 | size_t numEntries, | |
| 3129 | cl_mem keysBuffer, | |
| 3130 | cl_mem valuesBuffer) { | |
| 3131 | cl_int err; | |
| 3132 | err = | |
| 3133 | clSetKernelArg(table->insertSingleKernel, 0, sizeof(cl_mem), | |
| 3134 | &table->tableDataBuffer); | |
| 3135 | CLHash_Utilities_HandleError(err, | |
| 3136 | "intintLCGLinearOpenCompactCLHash_BufferInsert", | |
| 3137 | "clSetKernelArg"); | |
| 3138 | err = | |
| 3139 | clSetKernelArg(table->insertSingleKernel, 1, sizeof(unsigned int), | |
| 3140 | &numEntries); | |
| 3141 | CLHash_Utilities_HandleError(err, | |
| 3142 | "intintLCGLinearOpenCompactCLHash_BufferInsert", | |
| 3143 | "clSetKernelArg"); | |
| 3144 | err = | |
| 3145 | clSetKernelArg(table->insertSingleKernel, 2, sizeof(cl_mem), | |
| 3146 | &keysBuffer); | |
| 3147 | CLHash_Utilities_HandleError(err, | |
| 3148 | "intintLCGLinearOpenCompactCLHash_BufferInsert", | |
| 3149 | "clSetKernelArg"); | |
| 3150 | err = | |
| 3151 | clSetKernelArg(table->insertSingleKernel, 3, sizeof(cl_mem), | |
| 3152 | &valuesBuffer); | |
| 3153 | CLHash_Utilities_HandleError(err, | |
| 3154 | "intintLCGLinearOpenCompactCLHash_BufferInsert", | |
| 3155 | "clSetKernelArg"); | |
| 3156 | const size_t groupWorkSize = | |
| 3157 | roundUpToNearest(numEntries, table->localWorkSize); | |
| 3158 | err = | |
| 3159 | clEnqueueNDRangeKernel(table->queue, table->insertSingleKernel, 1, | |
| 3160 | 0, &groupWorkSize, | |
| 3161 | (const size_t *)&table->localWorkSize, 0, | |
| 3162 | NULL, NULL); | |
| 3163 | CLHash_Utilities_HandleError(err, NULL, "clEnqueueNDRangeKernel"); | |
| 3164 | return (0); | |
| 3165 | } | |
| 3166 | int intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 3167 | table, int key, | |
| 3168 | int value) { | |
| 3169 | return intintLCGLinearOpenCompactCLHash_InsertNoOverwrite(table, 1, | |
| 3170 | &key, &value); | |
| 3171 | } | |
| 3172 | int intintLCGLinearOpenCompactCLHash_InsertNoOverwrite(intintHash_Table * table, | |
| 3173 | size_t numEntries, | |
| 3174 | int *keys, int *values) { | |
| 3175 | cl_int err; | |
| 3176 | cl_mem keysBuffer = | |
| 3177 | clCreateBuffer(table->context, | |
| 3178 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 3179 | sizeof(int) * numEntries, keys, &err); | |
| 3180 | CLHash_Utilities_HandleError(err, | |
| 3181 | "intintLCGLinearOpenCompactCLHash_InsertNoOverwrite", | |
| 3182 | "clCreateBuffer"); | |
| 3183 | cl_mem valuesBuffer = | |
| 3184 | clCreateBuffer(table->context, | |
| 3185 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 3186 | sizeof(int) * numEntries, values, &err); | |
| 3187 | CLHash_Utilities_HandleError(err, | |
| 3188 | "intintLCGLinearOpenCompactCLHash_InsertNoOverwrite", | |
| 3189 | "clCreateBuffer"); | |
| 3190 | intintLCGLinearOpenCompactCLHash_BufferInsertNoOverwrite(table, | |
| 3191 | numEntries, | |
| 3192 | keysBuffer, | |
| 3193 | valuesBuffer); | |
| 3194 | clReleaseMemObject(keysBuffer); | |
| 3195 | clReleaseMemObject(valuesBuffer); | |
| 3196 | return HASH_EXIT_CODE_NORMAL; | |
| 3197 | } | |
| 3198 | int intintLCGLinearOpenCompactCLHash_BufferInsertNoOverwrite(intintHash_Table * | |
| 3199 | table, | |
| 3200 | size_t numEntries, | |
| 3201 | cl_mem keysBuffer, | |
| 3202 | cl_mem | |
| 3203 | valuesBuffer) { | |
| 3204 | cl_int err; | |
| 3205 | err = | |
| 3206 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 0, | |
| 3207 | sizeof(cl_mem), &table->tableDataBuffer); | |
| 3208 | CLHash_Utilities_HandleError(err, | |
| 3209 | "intintLCGLinearOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 3210 | "clSetKernelArg"); | |
| 3211 | err = | |
| 3212 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 1, | |
| 3213 | sizeof(unsigned int), &numEntries); | |
| 3214 | CLHash_Utilities_HandleError(err, | |
| 3215 | "intintLCGLinearOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 3216 | "ClSetKernelArg"); | |
| 3217 | err = | |
| 3218 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 2, | |
| 3219 | sizeof(cl_mem), &keysBuffer); | |
| 3220 | CLHash_Utilities_HandleError(err, | |
| 3221 | "intintLCGLinearOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 3222 | "clSetKernelArg"); | |
| 3223 | err = | |
| 3224 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 3, | |
| 3225 | sizeof(cl_mem), &valuesBuffer); | |
| 3226 | CLHash_Utilities_HandleError(err, | |
| 3227 | "intintLCGLinearOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 3228 | "clSetKernelArg"); | |
| 3229 | const size_t groupWorkSize = | |
| 3230 | roundUpToNearest(numEntries, table->localWorkSize); | |
| 3231 | err = | |
| 3232 | clEnqueueNDRangeKernel(table->queue, | |
| 3233 | table->insertSingleNoOverwriteKernel, 1, 0, | |
| 3234 | &groupWorkSize, | |
| 3235 | (const size_t *)&table->localWorkSize, 0, | |
| 3236 | NULL, NULL); | |
| 3237 | CLHash_Utilities_HandleError(err, | |
| 3238 | "intintLCGLinearOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 3239 | "clEnqueueNDRangeKernel"); | |
| 3240 | return (0); | |
| 3241 | } | |
| 3242 | ||
| 3243 | typedef struct intintLCGQuadraticOpenCompactHash_TableData { | |
| 3244 | int hashID; | |
| 3245 | unsigned int numBuckets; | |
| 3246 | intintHash_CompressLCGData compressFuncData; | |
| 3247 | } intintLCGQuadraticOpenCompactHash_TableData; | |
| 3248 | typedef struct intintLCGQuadraticOpenCompactHash_Bucket { | |
| 3249 | int key; | |
| 3250 | int value; | |
| 3251 | } intintLCGQuadraticOpenCompactHash_Bucket; | |
| 3252 | intintHash_Table | |
| 3253 | *intintLCGQuadraticOpenCompactHash_CreateTable(intintHash_Factory * factory, | |
| 3254 | int hashIndex, | |
| 3255 | size_t keyRange, | |
| 3256 | size_t numEntries, | |
| 3257 | float loadFactor) { | |
| 3258 | intintHash_Table *table = | |
| 3259 | (intintHash_Table *) malloc(sizeof(intintHash_Table)); | |
| 3260 | table->destroyFunc = &intintLCGQuadraticOpenCompactHash_DestroyTable; | |
| 3261 | table->emptyFunc = &intintLCGQuadraticOpenCompactHash_EmptyTable; | |
| 3262 | table->queryFunc = &intintLCGQuadraticOpenCompactHash_Query; | |
| 3263 | table->querySingleFunc = &intintLCGQuadraticOpenCompactHash_QuerySingle; | |
| 3264 | table->insertFunc = &intintLCGQuadraticOpenCompactHash_Insert; | |
| 3265 | table->insertSingleFunc = | |
| 3266 | &intintLCGQuadraticOpenCompactHash_InsertSingle; | |
| 3267 | table->insertNoOverwriteFunc = | |
| 3268 | &intintLCGQuadraticOpenCompactHash_InsertNoOverwrite; | |
| 3269 | table->insertSingleNoOverwriteFunc = | |
| 3270 | &intintLCGQuadraticOpenCompactHash_InsertSingleNoOverwrite; | |
| 3271 | table->tableData = | |
| 3272 | (char *)malloc(sizeof(intintLCGQuadraticOpenCompactHash_TableData)); | |
| 3273 | ((intintLCGQuadraticOpenCompactHash_TableData *) table->tableData)-> | |
| 3274 | hashID = LCG_QUADRATIC_OPEN_COMPACT_HASH_ID; | |
| 3275 | ((intintLCGQuadraticOpenCompactHash_TableData *) table->tableData)-> | |
| 3276 | numBuckets = (unsigned int)((double)numEntries / loadFactor); | |
| 3277 | ((intintLCGQuadraticOpenCompactHash_TableData *) table->tableData)-> | |
| 3278 | compressFuncData.a = HASH_LCG_A; | |
| 3279 | ((intintLCGQuadraticOpenCompactHash_TableData *) table->tableData)-> | |
| 3280 | compressFuncData.c = HASH_LCG_C; | |
| 3281 | ((intintLCGQuadraticOpenCompactHash_TableData *) table->tableData)-> | |
| 3282 | compressFuncData.m = HASH_LCG_M; | |
| 3283 | ((intintLCGQuadraticOpenCompactHash_TableData *) table->tableData)-> | |
| 3284 | compressFuncData.n = | |
| 3285 | ((intintLCGQuadraticOpenCompactHash_TableData *) table->tableData)-> | |
| 3286 | numBuckets; | |
| 3287 | ((intintLCGQuadraticOpenCompactHash_TableData *) table->tableData)-> | |
| 3288 | numBuckets = | |
| 3289 | largestProthPrimeUnder(((intintLCGQuadraticOpenCompactHash_TableData | |
| 3290 | *) table->tableData)->numBuckets); | |
| 3291 | char *tempHashData = | |
| 3292 | (char *)malloc(sizeof(intintLCGQuadraticOpenCompactHash_TableData) + | |
| 3293 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3294 | table->tableData)->numBuckets * | |
| 3295 | sizeof(intintLCGQuadraticOpenCompactHash_Bucket)); | |
| 3296 | memcpy(tempHashData, table->tableData, | |
| 3297 | sizeof(intintLCGQuadraticOpenCompactHash_TableData)); | |
| 3298 | free(table->tableData); | |
| 3299 | table->tableData = tempHashData; | |
| 3300 | return table; | |
| 3301 | } | |
| 3302 | int intintLCGQuadraticOpenCompactHash_CreateFactory(intintHash_Factory * | |
| 3303 | factory, int hashIndex) { | |
| 3304 | factory->createFunc[hashIndex] = | |
| 3305 | &intintLCGQuadraticOpenCompactHash_CreateTable; | |
| 3306 | factory->destroyFunc[hashIndex] = | |
| 3307 | &intintLCGQuadraticOpenCompactHash_DestroyFactory;; | |
| 3308 | return HASH_EXIT_CODE_NORMAL; | |
| 3309 | } | |
| 3310 | int intintLCGQuadraticOpenCompactHash_DestroyFactory(intintHash_Factory * | |
| 3311 | factory, int hashIndex) {; | |
| 3312 | return HASH_EXIT_CODE_NORMAL; | |
| 3313 | } | |
| 3314 | int intintLCGQuadraticOpenCompactHash_DestroyTable(intintHash_Table * table) { | |
| 3315 | int exitCode = 0; | |
| 3316 | free(table->tableData); | |
| 3317 | free(table); | |
| 3318 | return exitCode; | |
| 3319 | } | |
| 3320 | int intintLCGQuadraticOpenCompactHash_EmptyTable(intintHash_Table * table) { | |
| 3321 | int exitCode = 0; | |
| 3322 | intintLCGQuadraticOpenCompactHash_Bucket *buckets = | |
| 3323 | (intintLCGQuadraticOpenCompactHash_Bucket *) & table-> | |
| 3324 | tableData[sizeof(intintLCGQuadraticOpenCompactHash_TableData)]; | |
| 3325 | int index; | |
| 3326 | for (index = 0; | |
| 3327 | index < | |
| 3328 | ((intintLCGQuadraticOpenCompactHash_TableData *) table-> | |
| 3329 | tableData)->numBuckets; index++) { | |
| 3330 | buckets[index].key = HASH_BUCKET_STATUS_EMPTY; | |
| 3331 | } | |
| 3332 | exitCode = HASH_EXIT_CODE_NORMAL; | |
| 3333 | return exitCode; | |
| 3334 | } | |
| 3335 | int intintLCGQuadraticOpenCompactHash_InnerQuerySingle(char *tableData, int key, | |
| 3336 | int *valueOutput) { | |
| 3337 | intintLCGQuadraticOpenCompactHash_Bucket *buckets = | |
| 3338 | (intintLCGQuadraticOpenCompactHash_Bucket *) & | |
| 3339 | tableData[sizeof(intintLCGQuadraticOpenCompactHash_TableData)]; | |
| 3340 | int index; | |
| 3341 | int exitCode; | |
| 3342 | intintLCGQuadraticOpenCompactHash_TableData *mytableData = | |
| 3343 | (intintLCGQuadraticOpenCompactHash_TableData *) tableData; | |
| 3344 | intintHash_CompressLCGData compressFuncData = | |
| 3345 | mytableData->compressFuncData; | |
| 3346 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 3347 | unsigned long int iteration = 0; | |
| 3348 | for (;;) { | |
| 3349 | index = | |
| 3350 | ((1 * iteration * iteration + 0 * iteration + | |
| 3351 | c) % | |
| 3352 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3353 | tableData)->numBuckets); | |
| 3354 | if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 3355 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 3356 | break; | |
| 3357 | } else if (key == buckets[index].key) { | |
| 3358 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 3359 | break; | |
| 3360 | } else | |
| 3361 | if ((iteration > | |
| 3362 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3363 | tableData)->numBuckets)) { | |
| 3364 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 3365 | break; | |
| 3366 | } | |
| 3367 | iteration++; | |
| 3368 | } | |
| 3369 | switch (exitCode) { | |
| 3370 | case HASH_SEARCH_CODE_MATCH: | |
| 3371 | *valueOutput = buckets[index].value; | |
| 3372 | return HASH_EXIT_CODE_NORMAL; | |
| 3373 | case HASH_SEARCH_CODE_MISMATCH: | |
| 3374 | case HASH_SEARCH_CODE_EMPTY: | |
| 3375 | return HASH_EXIT_CODE_KEY_DNE; | |
| 3376 | default: | |
| 3377 | return exitCode; | |
| 3378 | } | |
| 3379 | } | |
| 3380 | int intintLCGQuadraticOpenCompactHash_InnerQuery(char *tableData, | |
| 3381 | unsigned int numKeys, | |
| 3382 | int *keys, int *valuesOutput) { | |
| 3383 | intintLCGQuadraticOpenCompactHash_Bucket *buckets = | |
| 3384 | (intintLCGQuadraticOpenCompactHash_Bucket *) & | |
| 3385 | tableData[sizeof(intintLCGQuadraticOpenCompactHash_TableData)]; | |
| 3386 | int key; | |
| 3387 | int *valueOutput; | |
| 3388 | int index; | |
| 3389 | int exitCode; | |
| 3390 | uint i; | |
| 3391 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 3392 | for (i = 0; i < numKeys; i++) { | |
| 3393 | key = keys[i]; | |
| 3394 | valueOutput = &valuesOutput[i]; | |
| 3395 | intintLCGQuadraticOpenCompactHash_TableData *mytableData = | |
| 3396 | (intintLCGQuadraticOpenCompactHash_TableData *) tableData; | |
| 3397 | intintHash_CompressLCGData compressFuncData = | |
| 3398 | mytableData->compressFuncData; | |
| 3399 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 3400 | unsigned long int iteration = 0; | |
| 3401 | for (;;) { | |
| 3402 | index = | |
| 3403 | ((1 * iteration * iteration + 0 * iteration + | |
| 3404 | c) % | |
| 3405 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3406 | tableData)->numBuckets); | |
| 3407 | if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 3408 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 3409 | break; | |
| 3410 | } else if (key == buckets[index].key) { | |
| 3411 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 3412 | break; | |
| 3413 | } else | |
| 3414 | if ((iteration > | |
| 3415 | ((intintLCGQuadraticOpenCompactHash_TableData | |
| 3416 | *) tableData)->numBuckets)) { | |
| 3417 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 3418 | break; | |
| 3419 | } | |
| 3420 | iteration++; | |
| 3421 | } | |
| 3422 | switch (exitCode) { | |
| 3423 | case HASH_SEARCH_CODE_MATCH: | |
| 3424 | *valueOutput = buckets[index].value; | |
| 3425 | break; | |
| 3426 | case HASH_SEARCH_CODE_MISMATCH: | |
| 3427 | case HASH_SEARCH_CODE_EMPTY: | |
| 3428 | resultExitCode = HASH_EXIT_CODE_KEY_DNE; | |
| 3429 | break; | |
| 3430 | default: | |
| 3431 | return exitCode; | |
| 3432 | } | |
| 3433 | } | |
| 3434 | return resultExitCode; | |
| 3435 | } | |
| 3436 | int intintLCGQuadraticOpenCompactHash_InnerInsertSingle(char *tableData, | |
| 3437 | int key, int value) { | |
| 3438 | intintLCGQuadraticOpenCompactHash_Bucket *buckets = | |
| 3439 | (intintLCGQuadraticOpenCompactHash_Bucket *) & | |
| 3440 | tableData[sizeof(intintLCGQuadraticOpenCompactHash_TableData)]; | |
| 3441 | int index; | |
| 3442 | int exitCode; | |
| 3443 | intintLCGQuadraticOpenCompactHash_TableData *mytableData = | |
| 3444 | (intintLCGQuadraticOpenCompactHash_TableData *) tableData; | |
| 3445 | intintHash_CompressLCGData compressFuncData = | |
| 3446 | mytableData->compressFuncData; | |
| 3447 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 3448 | unsigned long int iteration = 0; | |
| 3449 | for (;;) { | |
| 3450 | index = | |
| 3451 | ((1 * iteration * iteration + 0 * iteration + | |
| 3452 | c) % | |
| 3453 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3454 | tableData)->numBuckets); | |
| 3455 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 3456 | buckets | |
| 3457 | [index]. | |
| 3458 | key = | |
| 3459 | key; | |
| 3460 | HASH_BUCKET_STATUS_EMPTY;} | |
| 3461 | ): buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 3462 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 3463 | break; | |
| 3464 | } else if (key == buckets[index].key) { | |
| 3465 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 3466 | break; | |
| 3467 | } else | |
| 3468 | if ((iteration > | |
| 3469 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3470 | tableData)->numBuckets)) { | |
| 3471 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 3472 | break; | |
| 3473 | } | |
| 3474 | iteration++; | |
| 3475 | } | |
| 3476 | switch (exitCode) { | |
| 3477 | case HASH_SEARCH_CODE_MATCH: | |
| 3478 | case HASH_SEARCH_CODE_MISMATCH: | |
| 3479 | buckets[index].value = value; | |
| 3480 | return HASH_EXIT_CODE_OVERWRITE; | |
| 3481 | case HASH_SEARCH_CODE_EMPTY: | |
| 3482 | buckets[index].value = value; | |
| 3483 | return HASH_EXIT_CODE_NORMAL; | |
| 3484 | default: | |
| 3485 | return exitCode; | |
| 3486 | } | |
| 3487 | } | |
| 3488 | int intintLCGQuadraticOpenCompactHash_InnerInsert(char *tableData, | |
| 3489 | unsigned int numEntries, | |
| 3490 | int *keys, int *values) { | |
| 3491 | intintLCGQuadraticOpenCompactHash_Bucket *buckets = | |
| 3492 | (intintLCGQuadraticOpenCompactHash_Bucket *) & | |
| 3493 | tableData[sizeof(intintLCGQuadraticOpenCompactHash_TableData)]; | |
| 3494 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 3495 | int key; | |
| 3496 | int value; | |
| 3497 | int index; | |
| 3498 | int exitCode; | |
| 3499 | uint i; | |
| 3500 | for (i = 0; i < numEntries; i++) { | |
| 3501 | key = keys[i]; | |
| 3502 | intintLCGQuadraticOpenCompactHash_TableData *mytableData = | |
| 3503 | (intintLCGQuadraticOpenCompactHash_TableData *) tableData; | |
| 3504 | intintHash_CompressLCGData compressFuncData = | |
| 3505 | mytableData->compressFuncData; | |
| 3506 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 3507 | unsigned long int iteration = 0; | |
| 3508 | for (;;) { | |
| 3509 | index = | |
| 3510 | ((1 * iteration * iteration + 0 * iteration + | |
| 3511 | c) % | |
| 3512 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3513 | tableData)->numBuckets); | |
| 3514 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 3515 | buckets | |
| 3516 | [index]. | |
| 3517 | key | |
| 3518 | = | |
| 3519 | key; | |
| 3520 | HASH_BUCKET_STATUS_EMPTY;} | |
| 3521 | ): buckets[index].key) == | |
| 3522 | HASH_BUCKET_STATUS_EMPTY) { | |
| 3523 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 3524 | break; | |
| 3525 | } else if (key == buckets[index].key) { | |
| 3526 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 3527 | break; | |
| 3528 | } else | |
| 3529 | if ((iteration > | |
| 3530 | ((intintLCGQuadraticOpenCompactHash_TableData | |
| 3531 | *) tableData)->numBuckets)) { | |
| 3532 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 3533 | break; | |
| 3534 | } | |
| 3535 | iteration++; | |
| 3536 | } | |
| 3537 | switch (exitCode) { | |
| 3538 | case HASH_SEARCH_CODE_MATCH: | |
| 3539 | case HASH_SEARCH_CODE_MISMATCH: | |
| 3540 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 3541 | case HASH_SEARCH_CODE_EMPTY: | |
| 3542 | buckets[index].value = values[i]; | |
| 3543 | break; | |
| 3544 | default: | |
| 3545 | return exitCode; | |
| 3546 | } | |
| 3547 | } | |
| 3548 | return resultExitCode; | |
| 3549 | } | |
| 3550 | int intintLCGQuadraticOpenCompactHash_InnerInsertSingleNoOverwrite(char | |
| 3551 | *tableData, | |
| 3552 | int key, | |
| 3553 | int value) { | |
| 3554 | intintLCGQuadraticOpenCompactHash_Bucket *buckets = | |
| 3555 | (intintLCGQuadraticOpenCompactHash_Bucket *) & | |
| 3556 | tableData[sizeof(intintLCGQuadraticOpenCompactHash_TableData)]; | |
| 3557 | int index; | |
| 3558 | int exitCode; | |
| 3559 | intintLCGQuadraticOpenCompactHash_TableData *mytableData = | |
| 3560 | (intintLCGQuadraticOpenCompactHash_TableData *) tableData; | |
| 3561 | intintHash_CompressLCGData compressFuncData = | |
| 3562 | mytableData->compressFuncData; | |
| 3563 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 3564 | unsigned long int iteration = 0; | |
| 3565 | for (;;) { | |
| 3566 | index = | |
| 3567 | ((1 * iteration * iteration + 0 * iteration + | |
| 3568 | c) % | |
| 3569 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3570 | tableData)->numBuckets); | |
| 3571 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 3572 | buckets | |
| 3573 | [index]. | |
| 3574 | key = | |
| 3575 | key; | |
| 3576 | HASH_BUCKET_STATUS_EMPTY;} | |
| 3577 | ): buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 3578 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 3579 | break; | |
| 3580 | } else if (key == buckets[index].key) { | |
| 3581 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 3582 | break; | |
| 3583 | } else | |
| 3584 | if ((iteration > | |
| 3585 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3586 | tableData)->numBuckets)) { | |
| 3587 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 3588 | break; | |
| 3589 | } | |
| 3590 | iteration++; | |
| 3591 | } | |
| 3592 | switch (exitCode) { | |
| 3593 | case HASH_SEARCH_CODE_MATCH: | |
| 3594 | case HASH_SEARCH_CODE_MISMATCH: | |
| 3595 | return HASH_EXIT_CODE_OVERWRITE; | |
| 3596 | case HASH_SEARCH_CODE_EMPTY: | |
| 3597 | buckets[index].value = value; | |
| 3598 | return HASH_EXIT_CODE_NORMAL; | |
| 3599 | default: | |
| 3600 | return exitCode; | |
| 3601 | } | |
| 3602 | } | |
| 3603 | int intintLCGQuadraticOpenCompactHash_InnerInsertNoOverwrite(char *tableData, | |
| 3604 | unsigned int | |
| 3605 | numEntries, | |
| 3606 | int *keys, | |
| 3607 | int *values) { | |
| 3608 | intintLCGQuadraticOpenCompactHash_Bucket *buckets = | |
| 3609 | (intintLCGQuadraticOpenCompactHash_Bucket *) & | |
| 3610 | tableData[sizeof(intintLCGQuadraticOpenCompactHash_TableData)]; | |
| 3611 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 3612 | int key; | |
| 3613 | int value; | |
| 3614 | int index; | |
| 3615 | int exitCode; | |
| 3616 | uint i; | |
| 3617 | for (i = 0; i < numEntries; i++) { | |
| 3618 | key = keys[i]; | |
| 3619 | intintLCGQuadraticOpenCompactHash_TableData *mytableData = | |
| 3620 | (intintLCGQuadraticOpenCompactHash_TableData *) tableData; | |
| 3621 | intintHash_CompressLCGData compressFuncData = | |
| 3622 | mytableData->compressFuncData; | |
| 3623 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 3624 | unsigned long int iteration = 0; | |
| 3625 | for (;;) { | |
| 3626 | index = | |
| 3627 | ((1 * iteration * iteration + 0 * iteration + | |
| 3628 | c) % | |
| 3629 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3630 | tableData)->numBuckets); | |
| 3631 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 3632 | buckets | |
| 3633 | [index]. | |
| 3634 | key | |
| 3635 | = | |
| 3636 | key; | |
| 3637 | HASH_BUCKET_STATUS_EMPTY;} | |
| 3638 | ): buckets[index].key) == | |
| 3639 | HASH_BUCKET_STATUS_EMPTY) { | |
| 3640 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 3641 | break; | |
| 3642 | } else if (key == buckets[index].key) { | |
| 3643 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 3644 | break; | |
| 3645 | } else | |
| 3646 | if ((iteration > | |
| 3647 | ((intintLCGQuadraticOpenCompactHash_TableData | |
| 3648 | *) tableData)->numBuckets)) { | |
| 3649 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 3650 | break; | |
| 3651 | } | |
| 3652 | iteration++; | |
| 3653 | } | |
| 3654 | switch (exitCode) { | |
| 3655 | case HASH_SEARCH_CODE_MATCH: | |
| 3656 | case HASH_SEARCH_CODE_MISMATCH: | |
| 3657 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 3658 | break; | |
| 3659 | case HASH_SEARCH_CODE_EMPTY: | |
| 3660 | buckets[index].value = values[i]; | |
| 3661 | break; | |
| 3662 | default: | |
| 3663 | return exitCode; | |
| 3664 | } | |
| 3665 | } | |
| 3666 | return resultExitCode; | |
| 3667 | } | |
| 3668 | int intintLCGQuadraticOpenCompactHash_QuerySingle(intintHash_Table * table, | |
| 3669 | int key, int *valueOutput) { | |
| 3670 | return intintLCGQuadraticOpenCompactHash_InnerQuerySingle(table-> | |
| 3671 | tableData, | |
| 3672 | key, | |
| 3673 | valueOutput); | |
| 3674 | } | |
| 3675 | int intintLCGQuadraticOpenCompactHash_Query(intintHash_Table * table, | |
| 3676 | size_t numKeys, int *keys, | |
| 3677 | int *valuesOutput) { | |
| 3678 | return intintLCGQuadraticOpenCompactHash_InnerQuery(table->tableData, | |
| 3679 | numKeys, keys, | |
| 3680 | valuesOutput); | |
| 3681 | } | |
| 3682 | int intintLCGQuadraticOpenCompactHash_InsertSingle(intintHash_Table * table, | |
| 3683 | int key, int value) { | |
| 3684 | return intintLCGQuadraticOpenCompactHash_InnerInsertSingle(table-> | |
| 3685 | tableData, | |
| 3686 | key, value); | |
| 3687 | } | |
| 3688 | int intintLCGQuadraticOpenCompactHash_Insert(intintHash_Table * table, | |
| 3689 | size_t numEntries, int *keys, | |
| 3690 | int *values) { | |
| 3691 | return intintLCGQuadraticOpenCompactHash_InnerInsert(table->tableData, | |
| 3692 | numEntries, keys, | |
| 3693 | values); | |
| 3694 | } | |
| 3695 | int intintLCGQuadraticOpenCompactHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 3696 | table, int key, | |
| 3697 | int value) { | |
| 3698 | return | |
| 3699 | intintLCGQuadraticOpenCompactHash_InnerInsertSingleNoOverwrite | |
| 3700 | (table->tableData, key, value); | |
| 3701 | } | |
| 3702 | int intintLCGQuadraticOpenCompactHash_InsertNoOverwrite(intintHash_Table * | |
| 3703 | table, | |
| 3704 | size_t numEntries, | |
| 3705 | int *keys, | |
| 3706 | int *values) { | |
| 3707 | return intintLCGQuadraticOpenCompactHash_InnerInsertNoOverwrite(table-> | |
| 3708 | tableData, | |
| 3709 | numEntries, | |
| 3710 | keys, | |
| 3711 | values); | |
| 3712 | } | |
| 3713 | ||
| 3714 | typedef struct intintLCGQuadraticOpenCompactCLHash_TableData { | |
| 3715 | int hashID; | |
| 3716 | unsigned int numBuckets; | |
| 3717 | intintHash_CompressLCGData compressFuncData; | |
| 3718 | } intintLCGQuadraticOpenCompactCLHash_TableData; | |
| 3719 | typedef struct intintLCGQuadraticOpenCompactCLHash_Bucket { | |
| 3720 | int key; | |
| 3721 | int value; | |
| 3722 | } intintLCGQuadraticOpenCompactCLHash_Bucket; | |
| 3723 | intintHash_Table | |
| 3724 | *intintLCGQuadraticOpenCompactCLHash_CreateTable(intintHash_Factory * | |
| 3725 | factory, int hashIndex, | |
| 3726 | size_t keyRange, | |
| 3727 | size_t numEntries, | |
| 3728 | float loadFactor) { | |
| 3729 | intintHash_Table *table = | |
| 3730 | (intintHash_Table *) malloc(sizeof(intintHash_Table)); | |
| 3731 | table->destroyFunc = &intintLCGQuadraticOpenCompactCLHash_DestroyTable; | |
| 3732 | table->emptyFunc = &intintLCGQuadraticOpenCompactCLHash_EmptyTable; | |
| 3733 | table->queryFunc = &intintLCGQuadraticOpenCompactCLHash_Query; | |
| 3734 | table->querySingleFunc = | |
| 3735 | &intintLCGQuadraticOpenCompactCLHash_QuerySingle; | |
| 3736 | table->insertFunc = &intintLCGQuadraticOpenCompactCLHash_Insert; | |
| 3737 | table->insertSingleFunc = | |
| 3738 | &intintLCGQuadraticOpenCompactCLHash_InsertSingle; | |
| 3739 | table->insertNoOverwriteFunc = | |
| 3740 | &intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite; | |
| 3741 | table->insertSingleNoOverwriteFunc = | |
| 3742 | &intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite; | |
| 3743 | table->tableData = | |
| 3744 | (char *) | |
| 3745 | malloc(sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)); | |
| 3746 | ((intintLCGQuadraticOpenCompactCLHash_TableData *) table->tableData)-> | |
| 3747 | hashID = LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID; | |
| 3748 | table->context = factory->context; | |
| 3749 | table->queue = factory->queue; | |
| 3750 | table->program = factory->program; | |
| 3751 | table->localWorkSize = factory->localWorkSize; | |
| 3752 | table->utilProgram = factory->utilProgram[hashIndex]; | |
| 3753 | table->emptyKernel = factory->emptyKernel[hashIndex]; | |
| 3754 | table->emptyKernelLocalWorkSize = | |
| 3755 | factory->emptyKernelLocalWorkSize[hashIndex]; | |
| 3756 | table->querySingleKernel = factory->querySingleKernel[hashIndex]; | |
| 3757 | table->insertSingleKernel = factory->insertSingleKernel[hashIndex]; | |
| 3758 | table->insertSingleNoOverwriteKernel = | |
| 3759 | factory->insertSingleNoOverwriteKernel[hashIndex]; | |
| 3760 | clRetainContext(table->context); | |
| 3761 | clRetainCommandQueue(table->queue); | |
| 3762 | clRetainProgram(table->program); | |
| 3763 | clRetainProgram(table->utilProgram); | |
| 3764 | clRetainKernel(table->emptyKernel); | |
| 3765 | clRetainKernel(table->querySingleKernel); | |
| 3766 | clRetainKernel(table->insertSingleKernel); | |
| 3767 | clRetainKernel(table->insertSingleNoOverwriteKernel);; | |
| 3768 | ((intintLCGQuadraticOpenCompactCLHash_TableData *) table->tableData)-> | |
| 3769 | numBuckets = (unsigned int)((double)numEntries / loadFactor); | |
| 3770 | ((intintLCGQuadraticOpenCompactCLHash_TableData *) table->tableData)-> | |
| 3771 | compressFuncData.a = HASH_LCG_A; | |
| 3772 | ((intintLCGQuadraticOpenCompactCLHash_TableData *) table->tableData)-> | |
| 3773 | compressFuncData.c = HASH_LCG_C; | |
| 3774 | ((intintLCGQuadraticOpenCompactCLHash_TableData *) table->tableData)-> | |
| 3775 | compressFuncData.m = HASH_LCG_M; | |
| 3776 | ((intintLCGQuadraticOpenCompactCLHash_TableData *) table->tableData)-> | |
| 3777 | compressFuncData.n = | |
| 3778 | ((intintLCGQuadraticOpenCompactCLHash_TableData *) table-> | |
| 3779 | tableData)->numBuckets; | |
| 3780 | ((intintLCGQuadraticOpenCompactCLHash_TableData *) table->tableData)-> | |
| 3781 | numBuckets = | |
| 3782 | largestProthPrimeUnder(((intintLCGQuadraticOpenCompactCLHash_TableData *) table->tableData)->numBuckets); | |
| 3783 | char *tempHashData = | |
| 3784 | (char *)malloc(sizeof(intintLCGQuadraticOpenCompactCLHash_TableData) | |
| 3785 | + | |
| 3786 | ((intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 3787 | table->tableData)->numBuckets * | |
| 3788 | sizeof(intintLCGQuadraticOpenCompactCLHash_Bucket)); | |
| 3789 | memcpy(tempHashData, table->tableData, | |
| 3790 | sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)); | |
| 3791 | free(table->tableData); | |
| 3792 | table->tableData = tempHashData; | |
| 3793 | cl_int err; | |
| 3794 | table->tableDataBuffer = | |
| 3795 | clCreateBuffer(table->context, CL_MEM_READ_WRITE, | |
| 3796 | sizeof(intintLCGQuadraticOpenCompactHash_TableData) + | |
| 3797 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3798 | table->tableData)->numBuckets * | |
| 3799 | sizeof(intintLCGQuadraticOpenCompactHash_Bucket), | |
| 3800 | NULL, &err); | |
| 3801 | CLHash_Utilities_HandleError(err, | |
| 3802 | "intintLCGQuadraticOpenCompactCLHash_InitTable", | |
| 3803 | "clCreateBuffer"); | |
| 3804 | err = | |
| 3805 | clEnqueueWriteBuffer(table->queue, table->tableDataBuffer, CL_TRUE, | |
| 3806 | 0, | |
| 3807 | sizeof | |
| 3808 | (intintLCGQuadraticOpenCompactHash_TableData), | |
| 3809 | table->tableData, 0, NULL, NULL); | |
| 3810 | CLHash_Utilities_HandleError(err, | |
| 3811 | "intintLCGQuadraticOpenCompactCLHash_InitTable", | |
| 3812 | "clEnqueueWriteBuffer"); | |
| 3813 | return table; | |
| 3814 | } | |
| 3815 | int intintLCGQuadraticOpenCompactCLHash_CreateFactory(intintHash_Factory * | |
| 3816 | factory, int hashIndex) { | |
| 3817 | factory->createFunc[hashIndex] = | |
| 3818 | &intintLCGQuadraticOpenCompactCLHash_CreateTable; | |
| 3819 | factory->destroyFunc[hashIndex] = | |
| 3820 | &intintLCGQuadraticOpenCompactCLHash_DestroyFactory; | |
| 3821 | cl_int error; | |
| 3822 | cl_device_id device; | |
| 3823 | error = | |
| 3824 | clGetContextInfo(factory->context, CL_CONTEXT_DEVICES, | |
| 3825 | sizeof(device), &device, NULL); | |
| 3826 | CLHash_Utilities_HandleError(error, "intintHash_CreateFactory", | |
| 3827 | "clGetContextInfo"); | |
| 3828 | factory->querySingleKernel[hashIndex] = | |
| 3829 | clCreateKernel(factory->program, | |
| 3830 | "intintLCGQuadraticOpenCompactCLHash_RangeQuerySingle", | |
| 3831 | &error); | |
| 3832 | CLHash_Utilities_HandleError(error, | |
| 3833 | "intintLCGQuadraticOpenCompactCLHash_CreateFactory", | |
| 3834 | "clCreateKernel"); | |
| 3835 | factory->insertSingleKernel[hashIndex] = | |
| 3836 | clCreateKernel(factory->program, | |
| 3837 | "intintLCGQuadraticOpenCompactCLHash_RangeInsertSingle", | |
| 3838 | &error); | |
| 3839 | CLHash_Utilities_HandleError(error, | |
| 3840 | "intintLCGQuadraticOpenCompactCLHash_CreateFactory", | |
| 3841 | "clCreateKernel"); | |
| 3842 | factory->insertSingleNoOverwriteKernel[hashIndex] = | |
| 3843 | clCreateKernel(factory->program, | |
| 3844 | "intintLCGQuadraticOpenCompactCLHash_RangeInsertSingleNoOverwrite", | |
| 3845 | &error); | |
| 3846 | CLHash_Utilities_HandleError(error, | |
| 3847 | "intintLCGQuadraticOpenCompactCLHash_CreateFactory", | |
| 3848 | "clCreateKernel"); | |
| 3849 | factory->utilProgram[hashIndex] = | |
| 3850 | CLHash_Utilities_BuildProgramString(factory->context, device, | |
| 3851 | "static inline unsigned int intintHash_CompressIdentity(char data, int hashCode){ return hashCode; } typedef struct intintHash_CompressLCGData{ long unsigned int a; long unsigned int c; unsigned int m; unsigned int n; }intintHash_CompressLCGData; static inline unsigned int intintHash_CompressLCG(intintHash_CompressLCGData compressLCGData, int hashCode){ return ((compressLCGData.a * hashCode + compressLCGData.c) % compressLCGData.m) % compressLCGData.n; } typedef struct intintLCGQuadraticOpenCompactCLHash_TableData{ int hashID; unsigned int numBuckets; intintHash_CompressLCGData compressFuncData; }intintLCGQuadraticOpenCompactCLHash_TableData; typedef struct intintLCGQuadraticOpenCompactCLHash_Bucket{ int key; int value; }intintLCGQuadraticOpenCompactCLHash_Bucket; __kernel void intintLCGQuadraticOpenCompactCLHash_Empty(__global char *tableData){ int index = get_global_id(0); if(index >= ((__global intintLCGQuadraticOpenCompactCLHash_TableData*)tableData)->numBuckets){ return; } __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets = (__global intintLCGQuadraticOpenCompactCLHash_Bucket*)&tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)]; buckets[index].key = -1;/*HASH_BUCKET_STATUS_EMPTY*/ }"); | |
| 3852 | factory->emptyKernel[hashIndex] = | |
| 3853 | clCreateKernel(factory->utilProgram[hashIndex], | |
| 3854 | "intintLCGQuadraticOpenCompactCLHash_Empty", &error); | |
| 3855 | CLHash_Utilities_HandleError(error, | |
| 3856 | "intintLCGQuadraticOpenCompactCLHash_CreateFactory", | |
| 3857 | "clCreateKernel"); | |
| 3858 | error = | |
| 3859 | clGetKernelWorkGroupInfo(factory->emptyKernel[hashIndex], device, | |
| 3860 | CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), | |
| 3861 | &factory-> | |
| 3862 | emptyKernelLocalWorkSize[hashIndex], NULL); | |
| 3863 | CLHash_Utilities_HandleError(error, | |
| 3864 | "intintLCGQuadraticOpenCompactCLHash_CreateFactory", | |
| 3865 | "clGetKernelWorkGroupInfo");;; | |
| 3866 | return HASH_EXIT_CODE_NORMAL; | |
| 3867 | } | |
| 3868 | int intintLCGQuadraticOpenCompactCLHash_DestroyFactory(intintHash_Factory * | |
| 3869 | factory, | |
| 3870 | int hashIndex) {; | |
| 3871 | clReleaseKernel(factory->emptyKernel[hashIndex]); | |
| 3872 | clReleaseProgram(factory->utilProgram[hashIndex]); | |
| 3873 | clReleaseKernel(factory->querySingleKernel[hashIndex]); | |
| 3874 | clReleaseKernel(factory->insertSingleKernel[hashIndex]); | |
| 3875 | clReleaseKernel(factory->insertSingleNoOverwriteKernel[hashIndex]);; | |
| 3876 | return HASH_EXIT_CODE_NORMAL; | |
| 3877 | } | |
| 3878 | int intintLCGQuadraticOpenCompactCLHash_DestroyTable(intintHash_Table * table) { | |
| 3879 | int exitCode = 0; | |
| 3880 | clReleaseMemObject(table->tableDataBuffer); | |
| 3881 | clReleaseContext(table->context); | |
| 3882 | clReleaseCommandQueue(table->queue); | |
| 3883 | clReleaseProgram(table->utilProgram); | |
| 3884 | clReleaseKernel(table->emptyKernel); | |
| 3885 | clReleaseProgram(table->program); | |
| 3886 | clReleaseKernel(table->querySingleKernel); | |
| 3887 | clReleaseKernel(table->insertSingleKernel); | |
| 3888 | clReleaseKernel(table->insertSingleNoOverwriteKernel); | |
| 3889 | free(table->tableData); | |
| 3890 | free(table); | |
| 3891 | return exitCode; | |
| 3892 | } | |
| 3893 | int intintLCGQuadraticOpenCompactCLHash_EmptyTable(intintHash_Table * table) { | |
| 3894 | int exitCode = 0; | |
| 3895 | cl_int err; | |
| 3896 | err = | |
| 3897 | clSetKernelArg(table->emptyKernel, 0, sizeof(cl_mem), | |
| 3898 | &table->tableDataBuffer); | |
| 3899 | CLHash_Utilities_HandleError(err, | |
| 3900 | "intintLCGQuadraticOpenCompactCLHash_EmptyTable", | |
| 3901 | "clSetKernelArg"); | |
| 3902 | const size_t groupWorkSize = | |
| 3903 | roundUpToNearest(((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3904 | table->tableData)->numBuckets, | |
| 3905 | table->emptyKernelLocalWorkSize); | |
| 3906 | err = | |
| 3907 | clEnqueueNDRangeKernel(table->queue, table->emptyKernel, 1, 0, | |
| 3908 | &groupWorkSize, | |
| 3909 | (const size_t *)&table-> | |
| 3910 | emptyKernelLocalWorkSize, 0, NULL, NULL); | |
| 3911 | CLHash_Utilities_HandleError(err, | |
| 3912 | "intintLCGQuadraticOpenCompactCLHash_EmptyTable", | |
| 3913 | "clEnqueueNDRangeKernel"); | |
| 3914 | exitCode = HASH_EXIT_CODE_NORMAL;; | |
| 3915 | return exitCode; | |
| 3916 | } | |
| 3917 | int intintLCGQuadraticOpenCompactCLHash_QuerySingle(intintHash_Table * table, | |
| 3918 | int key, int *valueOutput) { | |
| 3919 | return intintLCGQuadraticOpenCompactCLHash_Query(table, 1, &key, | |
| 3920 | valueOutput); | |
| 3921 | } | |
| 3922 | int intintLCGQuadraticOpenCompactCLHash_Query(intintHash_Table * table, | |
| 3923 | size_t numKeys, int *keys, | |
| 3924 | int *valuesOutput) { | |
| 3925 | cl_int err; | |
| 3926 | cl_mem keysBuffer = | |
| 3927 | clCreateBuffer(table->context, | |
| 3928 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 3929 | sizeof(int) * numKeys, keys, &err); | |
| 3930 | CLHash_Utilities_HandleError(err, | |
| 3931 | "intintLCGQuadraticOpenCompactCLHash_Query", | |
| 3932 | "clCreateBuffer"); | |
| 3933 | cl_mem valuesOutputBuffer = | |
| 3934 | clCreateBuffer(table->context, CL_MEM_WRITE_ONLY, | |
| 3935 | sizeof(int) * numKeys, NULL, &err); | |
| 3936 | CLHash_Utilities_HandleError(err, | |
| 3937 | "intintLCGQuadraticOpenCompactCLHash_Query", | |
| 3938 | "clCreateBuffer"); | |
| 3939 | intintLCGQuadraticOpenCompactCLHash_BufferQuery(table, numKeys, | |
| 3940 | keysBuffer, | |
| 3941 | valuesOutputBuffer); | |
| 3942 | err = | |
| 3943 | clEnqueueReadBuffer(table->queue, valuesOutputBuffer, CL_TRUE, 0, | |
| 3944 | sizeof(int) * numKeys, valuesOutput, 0, NULL, | |
| 3945 | NULL); | |
| 3946 | CLHash_Utilities_HandleError(err, | |
| 3947 | "intintLCGQuadraticOpenCompactCLHash_Query", | |
| 3948 | "clEnqueueReadBuffer"); | |
| 3949 | clReleaseMemObject(keysBuffer); | |
| 3950 | clReleaseMemObject(valuesOutputBuffer); | |
| 3951 | return HASH_EXIT_CODE_NORMAL; | |
| 3952 | } | |
| 3953 | int intintLCGQuadraticOpenCompactCLHash_BufferQuery(intintHash_Table * table, | |
| 3954 | size_t numKeys, | |
| 3955 | cl_mem keysBuffer, | |
| 3956 | cl_mem valuesOutputBuffer) { | |
| 3957 | cl_int err; | |
| 3958 | err = | |
| 3959 | clSetKernelArg(table->querySingleKernel, 0, sizeof(cl_mem), | |
| 3960 | &table->tableDataBuffer); | |
| 3961 | CLHash_Utilities_HandleError(err, | |
| 3962 | "intintLCGQuadraticOpenCompactCLHash_BufferQuery", | |
| 3963 | "clSetKernelArg"); | |
| 3964 | err = | |
| 3965 | clSetKernelArg(table->querySingleKernel, 1, sizeof(unsigned int), | |
| 3966 | &numKeys); | |
| 3967 | CLHash_Utilities_HandleError(err, | |
| 3968 | "intintLCGQuadraticOpenCompactCLHash_BufferQuery", | |
| 3969 | "clSetKernelArg"); | |
| 3970 | err = | |
| 3971 | clSetKernelArg(table->querySingleKernel, 2, sizeof(cl_mem), | |
| 3972 | &keysBuffer); | |
| 3973 | CLHash_Utilities_HandleError(err, | |
| 3974 | "intintLCGQuadraticOpenCompactCLHash_BufferQuery", | |
| 3975 | "clSetKernelArg"); | |
| 3976 | err = | |
| 3977 | clSetKernelArg(table->querySingleKernel, 3, sizeof(cl_mem), | |
| 3978 | &valuesOutputBuffer); | |
| 3979 | CLHash_Utilities_HandleError(err, | |
| 3980 | "intintLCGQuadraticOpenCompactCLHash_BufferQuery", | |
| 3981 | "clSetKernelArg"); | |
| 3982 | const size_t groupWorkSize = | |
| 3983 | roundUpToNearest(numKeys, table->localWorkSize); | |
| 3984 | err = | |
| 3985 | clEnqueueNDRangeKernel(table->queue, table->querySingleKernel, 1, 0, | |
| 3986 | &groupWorkSize, | |
| 3987 | (const size_t *)&table->localWorkSize, 0, | |
| 3988 | NULL, NULL); | |
| 3989 | CLHash_Utilities_HandleError(err, | |
| 3990 | "intintLCGQuadraticOpenCompactCLHash_BufferQuery", | |
| 3991 | "clEnqueueNDRangeKernel"); | |
| 3992 | clFinish(table->queue); | |
| 3993 | return HASH_EXIT_CODE_NORMAL; | |
| 3994 | } | |
| 3995 | int intintLCGQuadraticOpenCompactCLHash_InsertSingle(intintHash_Table * table, | |
| 3996 | int key, int value) { | |
| 3997 | return intintLCGQuadraticOpenCompactCLHash_Insert(table, 1, &key, | |
| 3998 | &value); | |
| 3999 | } | |
| 4000 | int intintLCGQuadraticOpenCompactCLHash_Insert(intintHash_Table * table, | |
| 4001 | size_t numEntries, int *keys, | |
| 4002 | int *values) { | |
| 4003 | cl_int err; | |
| 4004 | cl_mem keysBuffer = | |
| 4005 | clCreateBuffer(table->context, | |
| 4006 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 4007 | sizeof(int) * numEntries, keys, &err); | |
| 4008 | CLHash_Utilities_HandleError(err, | |
| 4009 | "intintLCGQuadraticOpenCompactCLHash_Insert", | |
| 4010 | "clCreateBuffer"); | |
| 4011 | cl_mem valuesBuffer = | |
| 4012 | clCreateBuffer(table->context, | |
| 4013 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 4014 | sizeof(int) * numEntries, values, &err); | |
| 4015 | CLHash_Utilities_HandleError(err, | |
| 4016 | "intintLCGQuadraticOpenCompactCLHash_Insert", | |
| 4017 | "clCreateBuffer"); | |
| 4018 | intintLCGQuadraticOpenCompactCLHash_BufferInsert(table, numEntries, | |
| 4019 | keysBuffer, | |
| 4020 | valuesBuffer); | |
| 4021 | clReleaseMemObject(keysBuffer); | |
| 4022 | clReleaseMemObject(valuesBuffer); | |
| 4023 | return HASH_EXIT_CODE_NORMAL; | |
| 4024 | } | |
| 4025 | int intintLCGQuadraticOpenCompactCLHash_BufferInsert(intintHash_Table * table, | |
| 4026 | size_t numEntries, | |
| 4027 | cl_mem keysBuffer, | |
| 4028 | cl_mem valuesBuffer) { | |
| 4029 | cl_int err; | |
| 4030 | err = | |
| 4031 | clSetKernelArg(table->insertSingleKernel, 0, sizeof(cl_mem), | |
| 4032 | &table->tableDataBuffer); | |
| 4033 | CLHash_Utilities_HandleError(err, | |
| 4034 | "intintLCGQuadraticOpenCompactCLHash_BufferInsert", | |
| 4035 | "clSetKernelArg"); | |
| 4036 | err = | |
| 4037 | clSetKernelArg(table->insertSingleKernel, 1, sizeof(unsigned int), | |
| 4038 | &numEntries); | |
| 4039 | CLHash_Utilities_HandleError(err, | |
| 4040 | "intintLCGQuadraticOpenCompactCLHash_BufferInsert", | |
| 4041 | "clSetKernelArg"); | |
| 4042 | err = | |
| 4043 | clSetKernelArg(table->insertSingleKernel, 2, sizeof(cl_mem), | |
| 4044 | &keysBuffer); | |
| 4045 | CLHash_Utilities_HandleError(err, | |
| 4046 | "intintLCGQuadraticOpenCompactCLHash_BufferInsert", | |
| 4047 | "clSetKernelArg"); | |
| 4048 | err = | |
| 4049 | clSetKernelArg(table->insertSingleKernel, 3, sizeof(cl_mem), | |
| 4050 | &valuesBuffer); | |
| 4051 | CLHash_Utilities_HandleError(err, | |
| 4052 | "intintLCGQuadraticOpenCompactCLHash_BufferInsert", | |
| 4053 | "clSetKernelArg"); | |
| 4054 | const size_t groupWorkSize = | |
| 4055 | roundUpToNearest(numEntries, table->localWorkSize); | |
| 4056 | err = | |
| 4057 | clEnqueueNDRangeKernel(table->queue, table->insertSingleKernel, 1, | |
| 4058 | 0, &groupWorkSize, | |
| 4059 | (const size_t *)&table->localWorkSize, 0, | |
| 4060 | NULL, NULL); | |
| 4061 | CLHash_Utilities_HandleError(err, NULL, "clEnqueueNDRangeKernel"); | |
| 4062 | return (0); | |
| 4063 | } | |
| 4064 | int intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite(intintHash_Table | |
| 4065 | * table, | |
| 4066 | int key, | |
| 4067 | int value) { | |
| 4068 | return intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite(table, 1, | |
| 4069 | &key, | |
| 4070 | &value); | |
| 4071 | } | |
| 4072 | int intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite(intintHash_Table * | |
| 4073 | table, | |
| 4074 | size_t numEntries, | |
| 4075 | int *keys, | |
| 4076 | int *values) { | |
| 4077 | cl_int err; | |
| 4078 | cl_mem keysBuffer = | |
| 4079 | clCreateBuffer(table->context, | |
| 4080 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 4081 | sizeof(int) * numEntries, keys, &err); | |
| 4082 | CLHash_Utilities_HandleError(err, | |
| 4083 | "intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite", | |
| 4084 | "clCreateBuffer"); | |
| 4085 | cl_mem valuesBuffer = | |
| 4086 | clCreateBuffer(table->context, | |
| 4087 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 4088 | sizeof(int) * numEntries, values, &err); | |
| 4089 | CLHash_Utilities_HandleError(err, | |
| 4090 | "intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite", | |
| 4091 | "clCreateBuffer"); | |
| 4092 | intintLCGQuadraticOpenCompactCLHash_BufferInsertNoOverwrite(table, | |
| 4093 | numEntries, | |
| 4094 | keysBuffer, | |
| 4095 | valuesBuffer); | |
| 4096 | clReleaseMemObject(keysBuffer); | |
| 4097 | clReleaseMemObject(valuesBuffer); | |
| 4098 | return HASH_EXIT_CODE_NORMAL; | |
| 4099 | } | |
| 4100 | int intintLCGQuadraticOpenCompactCLHash_BufferInsertNoOverwrite(intintHash_Table | |
| 4101 | * table, | |
| 4102 | size_t | |
| 4103 | numEntries, | |
| 4104 | cl_mem | |
| 4105 | keysBuffer, | |
| 4106 | cl_mem | |
| 4107 | valuesBuffer) { | |
| 4108 | cl_int err; | |
| 4109 | err = | |
| 4110 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 0, | |
| 4111 | sizeof(cl_mem), &table->tableDataBuffer); | |
| 4112 | CLHash_Utilities_HandleError(err, | |
| 4113 | "intintLCGQuadraticOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 4114 | "clSetKernelArg"); | |
| 4115 | err = | |
| 4116 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 1, | |
| 4117 | sizeof(unsigned int), &numEntries); | |
| 4118 | CLHash_Utilities_HandleError(err, | |
| 4119 | "intintLCGQuadraticOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 4120 | "ClSetKernelArg"); | |
| 4121 | err = | |
| 4122 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 2, | |
| 4123 | sizeof(cl_mem), &keysBuffer); | |
| 4124 | CLHash_Utilities_HandleError(err, | |
| 4125 | "intintLCGQuadraticOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 4126 | "clSetKernelArg"); | |
| 4127 | err = | |
| 4128 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 3, | |
| 4129 | sizeof(cl_mem), &valuesBuffer); | |
| 4130 | CLHash_Utilities_HandleError(err, | |
| 4131 | "intintLCGQuadraticOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 4132 | "clSetKernelArg"); | |
| 4133 | const size_t groupWorkSize = | |
| 4134 | roundUpToNearest(numEntries, table->localWorkSize); | |
| 4135 | err = | |
| 4136 | clEnqueueNDRangeKernel(table->queue, | |
| 4137 | table->insertSingleNoOverwriteKernel, 1, 0, | |
| 4138 | &groupWorkSize, | |
| 4139 | (const size_t *)&table->localWorkSize, 0, | |
| 4140 | NULL, NULL); | |
| 4141 | CLHash_Utilities_HandleError(err, | |
| 4142 | "intintLCGQuadraticOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 4143 | "clEnqueueNDRangeKernel"); | |
| 4144 | return (0); | |
| 4145 | } | |
| 4146 | const char *HashFactory_source = | |
| 4147 | "\n" | |
| 4148 | "/* Copyright (C) 1991-2012 Free Software Foundation, Inc.\n" | |
| 4149 | " This file is part of the GNU C Library.\n" | |
| 4150 | "\n" | |
| 4151 | " The GNU C Library is free software; you can redistribute it and/or\n" | |
| 4152 | " modify it under the terms of the GNU Lesser General Public\n" | |
| 4153 | " License as published by the Free Software Foundation; either\n" | |
| 4154 | " version 2.1 of the License, or (at your option) any later version.\n" | |
| 4155 | "\n" | |
| 4156 | " The GNU C Library is distributed in the hope that it will be useful,\n" | |
| 4157 | " but WITHOUT ANY WARRANTY; without even the implied warranty of\n" | |
| 4158 | " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n" | |
| 4159 | " Lesser General Public License for more details.\n" | |
| 4160 | "\n" | |
| 4161 | " You should have received a copy of the GNU Lesser General Public\n" | |
| 4162 | " License along with the GNU C Library; if not, see\n" | |
| 4163 | " <http://www.gnu.org/licenses/>. */\n" | |
| 4164 | "/* This header is separate from features.h so that the compiler can\n" | |
| 4165 | " include it implicitly at the start of every compilation. It must\n" | |
| 4166 | " not itself include <features.h> or any other header that includes\n" | |
| 4167 | " <features.h> because the implicit include comes before any feature\n" | |
| 4168 | " test macros that may be defined in a source file before it first\n" | |
| 4169 | " explicitly includes a system header. GCC knows the name of this\n" | |
| 4170 | " header in order to preinclude it. */\n" | |
| 4171 | "/* We do support the IEC 559 math functionality, real and complex. */\n" | |
| 4172 | "/* wchar_t uses ISO/IEC 10646 (2nd ed., published 2011-03-15) /\n" | |
| 4173 | " Unicode 6.0. */\n" | |
| 4174 | "/* We do not support C11 <threads.h>. */\n" | |
| 4175 | "/* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced\n" | |
| 4176 | " * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National \n" | |
| 4177 | " * Laboratory (LANL), which is operated by Los Alamos National Security, LLC\n" | |
| 4178 | " * for the U.S. Department of Energy. The U.S. Government has rights to use,\n" | |
| 4179 | " * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS\n" | |
| 4180 | " * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR\n" | |
| 4181 | " * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified\n" | |
| 4182 | " * to produce derivative works, such modified software should be clearly marked,\n" | |
| 4183 | " * so as not to confuse it with the version available from LANL. \n" | |
| 4184 | " *\n" | |
| 4185 | " * Licensed under the Apache License, Version 2.0 (the ""License""); you may not\n" | |
| 4186 | " * use this file except in compliance with the License. You may obtain a copy\n" | |
| 4187 | " * of the License at \n" | |
| 4188 | " *\n" | |
| 4189 | " * http://www.apache.org/licenses/LICENSE-2.0\n" | |
| 4190 | " *\n" | |
| 4191 | " * Unless required by applicable law or agreed to in writing, software distributed\n" | |
| 4192 | " * under the License is distributed on an ""AS IS"" BASIS, WITHOUT WARRANTIES OR\n" | |
| 4193 | " * CONDITIONS OF ANY KIND, either express or implied. See the License for the\n" | |
| 4194 | " * specific language governing permissions and limitations under the License.\n" | |
| 4195 | " *\n" | |
| 4196 | " * Under this license, it is required to include a reference to this work. We\n" | |
| 4197 | " * request that each derivative work contain a reference to LANL Copyright \n" | |
| 4198 | " * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly\n" | |
| 4199 | " * measured. In addition, it is requested that a modifier is included as in\n" | |
| 4200 | " * the following example:\n" | |
| 4201 | " *\n" | |
| 4202 | " * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003\n" | |
| 4203 | " *\n" | |
| 4204 | " * This is LANL Copyright Disclosure C14043/LA-CC-14-003\n" | |
| 4205 | " */\n" | |
| 4206 | "int intintIdentityPerfectCLHash_InsertSingle(__global char *tableData,\n" | |
| 4207 | " int key, int value);\n" | |
| 4208 | "int intintIdentityPerfectCLHash_InnerInsertSingle(__global char *tableData,\n" | |
| 4209 | " int key, int value);\n" | |
| 4210 | "int intintHash_InsertSingle(__global char *tableData, int key, int value);\n" | |
| 4211 | "int intintIdentityPerfectCLHash_InnerQuery(__global char *tableData,\n" | |
| 4212 | " unsigned int numKeys,\n" | |
| 4213 | " __global int *keys,\n" | |
| 4214 | " __global int *valuesOutput);\n" | |
| 4215 | "int intintIdentityPerfectCLHash_InnerQuerySingle(__global char *tableData,\n" | |
| 4216 | " int key,\n" | |
| 4217 | " __global int *valueOutput);\n" | |
| 4218 | "int intintIdentityPerfectCLHash_InnerInsert(__global char *tableData,\n" | |
| 4219 | " unsigned int numEntries,\n" | |
| 4220 | " __global int *keys,\n" | |
| 4221 | " __global int *values);\n" | |
| 4222 | "int intintIdentityPerfectCLHash_InnerInsertSingleNoOverwrite(__global char\n" | |
| 4223 | " *tableData,\n" | |
| 4224 | " int key,\n" | |
| 4225 | " int value);\n" | |
| 4226 | "int intintIdentityPerfectCLHash_InnerInsertNoOverwrite(__global char *tableData,\n" | |
| 4227 | " unsigned int numEntries,\n" | |
| 4228 | " __global int *keys,\n" | |
| 4229 | " __global int *values);\n" | |
| 4230 | "int intintIdentityPerfectCLHash_QuerySingle(__global char *tableData, int key,\n" | |
| 4231 | " __global int *valueOutput);\n" | |
| 4232 | "int intintIdentityPerfectCLHash_QuerySingle(__global char *tableData, int key,\n" | |
| 4233 | " __global int *valueOutput);\n" | |
| 4234 | "int intintIdentityPerfectCLHash_Query(__global char *tableData, size_t numKeys,\n" | |
| 4235 | " __global int *keys,\n" | |
| 4236 | " __global int *valuesOutput);\n" | |
| 4237 | "int intintIdentityPerfectCLHash_Insert(__global char *tableData,\n" | |
| 4238 | " size_t numEntries, __global int *keys,\n" | |
| 4239 | " __global int *values);\n" | |
| 4240 | "int intintIdentityPerfectCLHash_InsertSingleNoOverwrite(__global char\n" | |
| 4241 | " *tableData, int key,\n" | |
| 4242 | " int value);\n" | |
| 4243 | "int intintIdentityPerfectCLHash_InsertNoOverwrite(__global char *tableData,\n" | |
| 4244 | " size_t numEntries,\n" | |
| 4245 | " __global int *keys,\n" | |
| 4246 | " __global int *values);\n" | |
| 4247 | "int intintIdentitySentinelPerfectCLHash_InnerInsertNoOverwrite(__global char\n" | |
| 4248 | " *tableData,\n" | |
| 4249 | " unsigned int\n" | |
| 4250 | " numEntries,\n" | |
| 4251 | " __global int\n" | |
| 4252 | " *keys,\n" | |
| 4253 | " __global int\n" | |
| 4254 | " *values);\n" | |
| 4255 | "int intintIdentitySentinelPerfectCLHash_InnerQuerySingle(__global char\n" | |
| 4256 | " *tableData, int key,\n" | |
| 4257 | " __global int\n" | |
| 4258 | " *valueOutput);\n" | |
| 4259 | "int intintIdentitySentinelPerfectCLHash_InnerQuery(__global char *tableData,\n" | |
| 4260 | " unsigned int numKeys,\n" | |
| 4261 | " __global int *keys,\n" | |
| 4262 | " __global int *valuesOutput);\n" | |
| 4263 | "int intintIdentitySentinelPerfectCLHash_InnerInsertSingle(__global char\n" | |
| 4264 | " *tableData, int key,\n" | |
| 4265 | " int value);\n" | |
| 4266 | "int intintIdentitySentinelPerfectCLHash_InnerInsert(__global char *tableData,\n" | |
| 4267 | " unsigned int numEntries,\n" | |
| 4268 | " __global int *keys,\n" | |
| 4269 | " __global int *values);\n" | |
| 4270 | "int intintIdentitySentinelPerfectCLHash_InnerInsertSingleNoOverwrite(__global\n" | |
| 4271 | " char\n" | |
| 4272 | " *tableData,\n" | |
| 4273 | " int key,\n" | |
| 4274 | " int value);\n" | |
| 4275 | "int intintIdentitySentinelPerfectCLHash_QuerySingle(__global char *tableData,\n" | |
| 4276 | " int key,\n" | |
| 4277 | " __global int *valueOutput);\n" | |
| 4278 | "int intintIdentitySentinelPerfectCLHash_Query(__global char *tableData,\n" | |
| 4279 | " size_t numKeys,\n" | |
| 4280 | " __global int *keys,\n" | |
| 4281 | " __global int *valuesOutput);\n" | |
| 4282 | "int intintIdentitySentinelPerfectCLHash_InsertSingle(__global char *tableData,\n" | |
| 4283 | " int key, int value);\n" | |
| 4284 | "int intintIdentitySentinelPerfectCLHash_Insert(__global char *tableData,\n" | |
| 4285 | " size_t numEntries,\n" | |
| 4286 | " __global int *keys,\n" | |
| 4287 | " __global int *values);\n" | |
| 4288 | "int intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite(__global char\n" | |
| 4289 | " *tableData,\n" | |
| 4290 | " int key,\n" | |
| 4291 | " int value);\n" | |
| 4292 | "int intintIdentitySentinelPerfectCLHash_InsertNoOverwrite(__global char\n" | |
| 4293 | " *tableData,\n" | |
| 4294 | " size_t numEntries,\n" | |
| 4295 | " __global int *keys,\n" | |
| 4296 | " __global int *values);\n" | |
| 4297 | "int intintLCGLinearOpenCompactCLHash_InnerQuerySingle(__global char *tableData,\n" | |
| 4298 | " int key,\n" | |
| 4299 | " __global int\n" | |
| 4300 | " *valueOutput);\n" | |
| 4301 | "int intintLCGLinearOpenCompactCLHash_QuerySingle(__global char *tableData,\n" | |
| 4302 | " int key,\n" | |
| 4303 | " __global int *valueOutput);\n" | |
| 4304 | "int intintLCGLinearOpenCompactCLHash_Query(__global char *tableData,\n" | |
| 4305 | " size_t numKeys, __global int *keys,\n" | |
| 4306 | " __global int *valuesOutput);\n" | |
| 4307 | "int intintLCGLinearOpenCompactCLHash_InsertSingle(__global char *tableData,\n" | |
| 4308 | " int key, int value);\n" | |
| 4309 | "int intintLCGLinearOpenCompactCLHash_Insert(__global char *tableData,\n" | |
| 4310 | " size_t numEntries,\n" | |
| 4311 | " __global int *keys,\n" | |
| 4312 | " __global int *values);\n" | |
| 4313 | "int intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite(__global char\n" | |
| 4314 | " *tableData,\n" | |
| 4315 | " int key,\n" | |
| 4316 | " int value);\n" | |
| 4317 | "int intintLCGLinearOpenCompactCLHash_InsertNoOverwrite(__global char *tableData,\n" | |
| 4318 | " size_t numEntries,\n" | |
| 4319 | " __global int *keys,\n" | |
| 4320 | " __global int *values);\n" | |
| 4321 | "int intintLCGLinearOpenCompactCLHash_InnerQuery(__global char *tableData,\n" | |
| 4322 | " unsigned int numKeys,\n" | |
| 4323 | " __global int *keys,\n" | |
| 4324 | " __global int *valuesOutput);\n" | |
| 4325 | "int intintLCGLinearOpenCompactCLHash_InnerInsertNoOverwrite(__global char\n" | |
| 4326 | " *tableData,\n" | |
| 4327 | " unsigned int\n" | |
| 4328 | " numEntries,\n" | |
| 4329 | " __global int *keys,\n" | |
| 4330 | " __global int\n" | |
| 4331 | " *values);\n" | |
| 4332 | "int intintLCGLinearOpenCompactCLHash_InnerInsertSingle(__global char *tableData,\n" | |
| 4333 | " int key, int value);\n" | |
| 4334 | "int intintLCGLinearOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global char\n" | |
| 4335 | " *tableData,\n" | |
| 4336 | " int key,\n" | |
| 4337 | " int value);\n" | |
| 4338 | "int intintLCGLinearOpenCompactCLHash_InnerInsert(__global char *tableData,\n" | |
| 4339 | " unsigned int numEntries,\n" | |
| 4340 | " __global int *keys,\n" | |
| 4341 | " __global int *values);\n" | |
| 4342 | "int intintLCGQuadraticOpenCompactCLHash_InnerQuerySingle(__global char\n" | |
| 4343 | " *tableData, int key,\n" | |
| 4344 | " __global int\n" | |
| 4345 | " *valueOutput);\n" | |
| 4346 | "int intintLCGQuadraticOpenCompactCLHash_InnerQuery(__global char *tableData,\n" | |
| 4347 | " unsigned int numKeys,\n" | |
| 4348 | " __global int *keys,\n" | |
| 4349 | " __global int *valuesOutput);\n" | |
| 4350 | "int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingle(__global char\n" | |
| 4351 | " *tableData, int key,\n" | |
| 4352 | " int value);\n" | |
| 4353 | "int intintLCGQuadraticOpenCompactCLHash_InnerInsert(__global char *tableData,\n" | |
| 4354 | " unsigned int numEntries,\n" | |
| 4355 | " __global int *keys,\n" | |
| 4356 | " __global int *values);\n" | |
| 4357 | "int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global\n" | |
| 4358 | " char\n" | |
| 4359 | " *tableData,\n" | |
| 4360 | " int key,\n" | |
| 4361 | " int value);\n" | |
| 4362 | "int intintLCGQuadraticOpenCompactCLHash_InnerInsertNoOverwrite(__global char\n" | |
| 4363 | " *tableData,\n" | |
| 4364 | " unsigned int\n" | |
| 4365 | " numEntries,\n" | |
| 4366 | " __global int\n" | |
| 4367 | " *keys,\n" | |
| 4368 | " __global int\n" | |
| 4369 | " *values);\n" | |
| 4370 | "int intintLCGQuadraticOpenCompactCLHash_QuerySingle(__global char *tableData,\n" | |
| 4371 | " int key,\n" | |
| 4372 | " __global int *valueOutput);\n" | |
| 4373 | "int intintLCGQuadraticOpenCompactCLHash_Query(__global char *tableData,\n" | |
| 4374 | " size_t numKeys,\n" | |
| 4375 | " __global int *keys,\n" | |
| 4376 | " __global int *valuesOutput);\n" | |
| 4377 | "int intintLCGQuadraticOpenCompactCLHash_InsertSingle(__global char *tableData,\n" | |
| 4378 | " int key, int value);\n" | |
| 4379 | "int intintLCGQuadraticOpenCompactCLHash_Insert(__global char *tableData,\n" | |
| 4380 | " size_t numEntries,\n" | |
| 4381 | " __global int *keys,\n" | |
| 4382 | " __global int *values);\n" | |
| 4383 | "int intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite(__global char\n" | |
| 4384 | " *tableData,\n" | |
| 4385 | " int key,\n" | |
| 4386 | " int value);\n" | |
| 4387 | "int intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite(__global char\n" | |
| 4388 | " *tableData,\n" | |
| 4389 | " size_t numEntries,\n" | |
| 4390 | " __global int *keys,\n" | |
| 4391 | " __global int *values);\n" | |
| 4392 | "int intintHash_Query(__global char *tableData, unsigned int numKeys,\n" | |
| 4393 | " __global int *keys, __global int *valuesOutput);\n" | |
| 4394 | "int intintHash_QuerySingle(__global char *tableData, int key,\n" | |
| 4395 | " __global int *valueOutput);\n" | |
| 4396 | "int intintHash_Insert(__global char *tableData, unsigned int numEntries,\n" | |
| 4397 | " __global int *keys, __global int *values);\n" | |
| 4398 | "int intintHash_InsertNoOverwrite(__global char *tableData,\n" | |
| 4399 | " unsigned int numEntries, __global int *keys,\n" | |
| 4400 | " __global int *values);\n" | |
| 4401 | "int intintHash_InsertSingleNoOverwrite(__global char *tableData, int key,\n" | |
| 4402 | " int value);\n" | |
| 4403 | "#define HASH_REPORT_NEVER /**/ 0\n" | |
| 4404 | "#define HASH_REPORT_CYCLE /**/ 1\n" | |
| 4405 | "#define HASH_REPORT_END /****/ 2\n" | |
| 4406 | "//\n" | |
| 4407 | "#define HASH_EXIT_CODE_NORMAL /****************/ -1\n" | |
| 4408 | "#define HASH_EXIT_CODE_ERROR /*****************/ -2\n" | |
| 4409 | "#define HASH_EXIT_CODE_OVERWRITE /*************/ -3\n" | |
| 4410 | "#define HASH_EXIT_CODE_KEY_DNE /***************/ -4\n" | |
| 4411 | "#define HASH_EXIT_CODE_CYCLE /*****************/ -5\n" | |
| 4412 | "#define HASH_EXIT_CODE_MAX_ENTRIES_EXCEEDED /**/ -6\n" | |
| 4413 | "#define HASH_EXIT_CODE_BUCKET_INDEX_OOB /******/ -7\n" | |
| 4414 | "//\n" | |
| 4415 | "#define HASH_SEARCH_CODE_MATCH /*****/ 0\n" | |
| 4416 | "#define HASH_SEARCH_CODE_MISMATCH /**/ 1\n" | |
| 4417 | "#define HASH_SEARCH_CODE_EMPTY /*****/ 2\n" | |
| 4418 | "//\n" | |
| 4419 | "#define LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID /**/ 8\n" | |
| 4420 | "#define LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID /**/ 4\n" | |
| 4421 | "#define IDENTITY_SENTINEL_PERFECT_CL_HASH_ID /*******/ 2\n" | |
| 4422 | "#define IDENTITY_PERFECT_CL_HASH_ID /*******/ 1\n" | |
| 4423 | "//\n" | |
| 4424 | "#define HASH_BUCKET_STATUS_EMPTY /**/ -1\n" | |
| 4425 | "#define HASH_BUCKET_STATUS_FULL /***/ -2\n" | |
| 4426 | "#define HASH_BUCKET_STATUS_LOCK /***/ -3\n" | |
| 4427 | "static inline unsigned int intintHash_CompressIdentity(char data, int hashCode) {\n" | |
| 4428 | " return hashCode;\n" | |
| 4429 | "}\n" | |
| 4430 | "\n" | |
| 4431 | "typedef struct intintHash_CompressLCGData {\n" | |
| 4432 | " long unsigned int a;\n" | |
| 4433 | " long unsigned int c;\n" | |
| 4434 | " unsigned int m;\n" | |
| 4435 | " unsigned int n;\n" | |
| 4436 | "} intintHash_CompressLCGData;\n" | |
| 4437 | "static inline unsigned int intintHash_CompressLCG(intintHash_CompressLCGData\n" | |
| 4438 | " compressLCGData,\n" | |
| 4439 | " int hashCode) {\n" | |
| 4440 | " return ((compressLCGData.a * hashCode +\n" | |
| 4441 | " compressLCGData.c) % compressLCGData.m) % compressLCGData.n;\n" | |
| 4442 | "}\n" | |
| 4443 | "\n" | |
| 4444 | "typedef struct intintIdentityPerfectCLHash_TableData {\n" | |
| 4445 | " int hashID;\n" | |
| 4446 | " unsigned int numBuckets;\n" | |
| 4447 | " char compressFuncData;\n" | |
| 4448 | "} intintIdentityPerfectCLHash_TableData;\n" | |
| 4449 | "typedef struct intintIdentityPerfectCLHash_Bucket {\n" | |
| 4450 | " int key;\n" | |
| 4451 | " int value;\n" | |
| 4452 | "} intintIdentityPerfectCLHash_Bucket;\n" | |
| 4453 | "int intintIdentityPerfectCLHash_InnerQuerySingle(__global char *tableData,\n" | |
| 4454 | " int key,\n" | |
| 4455 | " __global int *valueOutput) {\n" | |
| 4456 | " __global intintIdentityPerfectCLHash_Bucket *buckets =\n" | |
| 4457 | " (__global intintIdentityPerfectCLHash_Bucket *) &\n" | |
| 4458 | " tableData[sizeof(intintIdentityPerfectCLHash_TableData)];\n" | |
| 4459 | " int index;\n" | |
| 4460 | " int exitCode;\n" | |
| 4461 | " index =\n" | |
| 4462 | " intintHash_CompressIdentity(((__global\n" | |
| 4463 | " intintIdentityPerfectCLHash_TableData\n" | |
| 4464 | " *) tableData)->compressFuncData, key);\n" | |
| 4465 | " if ((buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 4466 | " if (key == buckets[index].key) {\n" | |
| 4467 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4468 | " } else {\n" | |
| 4469 | " exitCode = HASH_SEARCH_CODE_MISMATCH;\n" | |
| 4470 | " }\n" | |
| 4471 | " } else {\n" | |
| 4472 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4473 | " }\n" | |
| 4474 | " switch (exitCode) {\n" | |
| 4475 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4476 | " *valueOutput = buckets[index].value;\n" | |
| 4477 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 4478 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4479 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4480 | " return HASH_EXIT_CODE_KEY_DNE;\n" | |
| 4481 | " default:\n" | |
| 4482 | " return exitCode;\n" | |
| 4483 | " }\n" | |
| 4484 | "}\n" | |
| 4485 | "int intintIdentityPerfectCLHash_InnerQuery(__global char *tableData,\n" | |
| 4486 | " unsigned int numKeys,\n" | |
| 4487 | " __global int *keys,\n" | |
| 4488 | " __global int *valuesOutput) {\n" | |
| 4489 | " __global intintIdentityPerfectCLHash_Bucket *buckets =\n" | |
| 4490 | " (__global intintIdentityPerfectCLHash_Bucket *) &\n" | |
| 4491 | " tableData[sizeof(intintIdentityPerfectCLHash_TableData)];\n" | |
| 4492 | " int key;\n" | |
| 4493 | " __global int *valueOutput;\n" | |
| 4494 | " int index;\n" | |
| 4495 | " int exitCode;\n" | |
| 4496 | " uint i;\n" | |
| 4497 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 4498 | " for (i = 0; i < numKeys; i++) {\n" | |
| 4499 | " key = keys[i];\n" | |
| 4500 | " valueOutput = &valuesOutput[i];\n" | |
| 4501 | " index =\n" | |
| 4502 | " intintHash_CompressIdentity(((__global\n" | |
| 4503 | " intintIdentityPerfectCLHash_TableData\n" | |
| 4504 | " *) tableData)->\n" | |
| 4505 | " compressFuncData, key);\n" | |
| 4506 | " if ((buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 4507 | " if (key == buckets[index].key) {\n" | |
| 4508 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4509 | " } else {\n" | |
| 4510 | " exitCode = HASH_SEARCH_CODE_MISMATCH;\n" | |
| 4511 | " }\n" | |
| 4512 | " } else {\n" | |
| 4513 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4514 | " }\n" | |
| 4515 | " switch (exitCode) {\n" | |
| 4516 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4517 | " *valueOutput = buckets[index].value;\n" | |
| 4518 | " break;\n" | |
| 4519 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4520 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4521 | " resultExitCode = HASH_EXIT_CODE_KEY_DNE;\n" | |
| 4522 | " break;\n" | |
| 4523 | " default:\n" | |
| 4524 | " return exitCode;\n" | |
| 4525 | " }\n" | |
| 4526 | " }\n" | |
| 4527 | " return resultExitCode;\n" | |
| 4528 | "}\n" | |
| 4529 | "int intintIdentityPerfectCLHash_InnerInsertSingle(__global char *tableData,\n" | |
| 4530 | " int key, int value) {\n" | |
| 4531 | " __global intintIdentityPerfectCLHash_Bucket *buckets =\n" | |
| 4532 | " (__global intintIdentityPerfectCLHash_Bucket *) &\n" | |
| 4533 | " tableData[sizeof(intintIdentityPerfectCLHash_TableData)];\n" | |
| 4534 | " int index;\n" | |
| 4535 | " int exitCode;\n" | |
| 4536 | " index =\n" | |
| 4537 | " intintHash_CompressIdentity(((__global\n" | |
| 4538 | " intintIdentityPerfectCLHash_TableData\n" | |
| 4539 | " *) tableData)->compressFuncData, key);\n" | |
| 4540 | " if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( {\n" | |
| 4541 | " buckets[index].\n" | |
| 4542 | " key = key;\n" | |
| 4543 | " HASH_BUCKET_STATUS_EMPTY;}\n" | |
| 4544 | " ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 4545 | " if (key == buckets[index].key) {\n" | |
| 4546 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4547 | " } else {\n" | |
| 4548 | " exitCode = HASH_SEARCH_CODE_MISMATCH;\n" | |
| 4549 | " }\n" | |
| 4550 | " } else {\n" | |
| 4551 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4552 | " }\n" | |
| 4553 | " switch (exitCode) {\n" | |
| 4554 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4555 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4556 | " buckets[index].value = value;\n" | |
| 4557 | " return HASH_EXIT_CODE_OVERWRITE;\n" | |
| 4558 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4559 | " buckets[index].value = value;\n" | |
| 4560 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 4561 | " default:\n" | |
| 4562 | " return exitCode;\n" | |
| 4563 | " }\n" | |
| 4564 | "}\n" | |
| 4565 | "int intintIdentityPerfectCLHash_InnerInsert(__global char *tableData,\n" | |
| 4566 | " unsigned int numEntries,\n" | |
| 4567 | " __global int *keys,\n" | |
| 4568 | " __global int *values) {\n" | |
| 4569 | " __global intintIdentityPerfectCLHash_Bucket *buckets =\n" | |
| 4570 | " (__global intintIdentityPerfectCLHash_Bucket *) &\n" | |
| 4571 | " tableData[sizeof(intintIdentityPerfectCLHash_TableData)];\n" | |
| 4572 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 4573 | " int key;\n" | |
| 4574 | " int value;\n" | |
| 4575 | " int index;\n" | |
| 4576 | " int exitCode;\n" | |
| 4577 | " uint i;\n" | |
| 4578 | " for (i = 0; i < numEntries; i++) {\n" | |
| 4579 | " key = keys[i];\n" | |
| 4580 | " index =\n" | |
| 4581 | " intintHash_CompressIdentity(((__global\n" | |
| 4582 | " intintIdentityPerfectCLHash_TableData\n" | |
| 4583 | " *) tableData)->\n" | |
| 4584 | " compressFuncData, key);\n" | |
| 4585 | " if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( {\n" | |
| 4586 | " buckets\n" | |
| 4587 | " [index].\n" | |
| 4588 | " key =\n" | |
| 4589 | " key;\n" | |
| 4590 | " HASH_BUCKET_STATUS_EMPTY;}\n" | |
| 4591 | " ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 4592 | " if (key == buckets[index].key) {\n" | |
| 4593 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4594 | " } else {\n" | |
| 4595 | " exitCode = HASH_SEARCH_CODE_MISMATCH;\n" | |
| 4596 | " }\n" | |
| 4597 | " } else {\n" | |
| 4598 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4599 | " }\n" | |
| 4600 | " switch (exitCode) {\n" | |
| 4601 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4602 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4603 | " resultExitCode = HASH_EXIT_CODE_OVERWRITE;\n" | |
| 4604 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4605 | " buckets[index].value = values[i];\n" | |
| 4606 | " break;\n" | |
| 4607 | " default:\n" | |
| 4608 | " return exitCode;\n" | |
| 4609 | " }\n" | |
| 4610 | " }\n" | |
| 4611 | " return resultExitCode;\n" | |
| 4612 | "}\n" | |
| 4613 | "int intintIdentityPerfectCLHash_InnerInsertSingleNoOverwrite(__global char\n" | |
| 4614 | " *tableData,\n" | |
| 4615 | " int key,\n" | |
| 4616 | " int value) {\n" | |
| 4617 | " __global intintIdentityPerfectCLHash_Bucket *buckets =\n" | |
| 4618 | " (__global intintIdentityPerfectCLHash_Bucket *) &\n" | |
| 4619 | " tableData[sizeof(intintIdentityPerfectCLHash_TableData)];\n" | |
| 4620 | " int index;\n" | |
| 4621 | " int exitCode;\n" | |
| 4622 | " index =\n" | |
| 4623 | " intintHash_CompressIdentity(((__global\n" | |
| 4624 | " intintIdentityPerfectCLHash_TableData\n" | |
| 4625 | " *) tableData)->compressFuncData, key);\n" | |
| 4626 | " if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( {\n" | |
| 4627 | " buckets[index].\n" | |
| 4628 | " key = key;\n" | |
| 4629 | " HASH_BUCKET_STATUS_EMPTY;}\n" | |
| 4630 | " ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 4631 | " if (key == buckets[index].key) {\n" | |
| 4632 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4633 | " } else {\n" | |
| 4634 | " exitCode = HASH_SEARCH_CODE_MISMATCH;\n" | |
| 4635 | " }\n" | |
| 4636 | " } else {\n" | |
| 4637 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4638 | " }\n" | |
| 4639 | " switch (exitCode) {\n" | |
| 4640 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4641 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4642 | " return HASH_EXIT_CODE_OVERWRITE;\n" | |
| 4643 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4644 | " buckets[index].value = value;\n" | |
| 4645 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 4646 | " default:\n" | |
| 4647 | " return exitCode;\n" | |
| 4648 | " }\n" | |
| 4649 | "}\n" | |
| 4650 | "int intintIdentityPerfectCLHash_InnerInsertNoOverwrite(__global char *tableData,\n" | |
| 4651 | " unsigned int numEntries,\n" | |
| 4652 | " __global int *keys,\n" | |
| 4653 | " __global int *values) {\n" | |
| 4654 | " __global intintIdentityPerfectCLHash_Bucket *buckets =\n" | |
| 4655 | " (__global intintIdentityPerfectCLHash_Bucket *) &\n" | |
| 4656 | " tableData[sizeof(intintIdentityPerfectCLHash_TableData)];\n" | |
| 4657 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 4658 | " int key;\n" | |
| 4659 | " int value;\n" | |
| 4660 | " int index;\n" | |
| 4661 | " int exitCode;\n" | |
| 4662 | " uint i;\n" | |
| 4663 | " for (i = 0; i < numEntries; i++) {\n" | |
| 4664 | " key = keys[i];\n" | |
| 4665 | " index =\n" | |
| 4666 | " intintHash_CompressIdentity(((__global\n" | |
| 4667 | " intintIdentityPerfectCLHash_TableData\n" | |
| 4668 | " *) tableData)->\n" | |
| 4669 | " compressFuncData, key);\n" | |
| 4670 | " if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( {\n" | |
| 4671 | " buckets\n" | |
| 4672 | " [index].\n" | |
| 4673 | " key =\n" | |
| 4674 | " key;\n" | |
| 4675 | " HASH_BUCKET_STATUS_EMPTY;}\n" | |
| 4676 | " ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 4677 | " if (key == buckets[index].key) {\n" | |
| 4678 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4679 | " } else {\n" | |
| 4680 | " exitCode = HASH_SEARCH_CODE_MISMATCH;\n" | |
| 4681 | " }\n" | |
| 4682 | " } else {\n" | |
| 4683 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4684 | " }\n" | |
| 4685 | " switch (exitCode) {\n" | |
| 4686 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4687 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4688 | " resultExitCode = HASH_EXIT_CODE_OVERWRITE;\n" | |
| 4689 | " break;\n" | |
| 4690 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4691 | " buckets[index].value = values[i];\n" | |
| 4692 | " break;\n" | |
| 4693 | " default:\n" | |
| 4694 | " return exitCode;\n" | |
| 4695 | " }\n" | |
| 4696 | " }\n" | |
| 4697 | " return resultExitCode;\n" | |
| 4698 | "}\n" | |
| 4699 | "int intintIdentityPerfectCLHash_QuerySingle(__global char *tableData, int key,\n" | |
| 4700 | " __global int *valueOutput) {\n" | |
| 4701 | " return intintIdentityPerfectCLHash_InnerQuerySingle(tableData, key,\n" | |
| 4702 | " valueOutput);\n" | |
| 4703 | "}\n" | |
| 4704 | "int intintIdentityPerfectCLHash_Query(__global char *tableData, size_t numKeys,\n" | |
| 4705 | " __global int *keys,\n" | |
| 4706 | " __global int *valuesOutput) {\n" | |
| 4707 | " return intintIdentityPerfectCLHash_InnerQuery(tableData, numKeys, keys,\n" | |
| 4708 | " valuesOutput);\n" | |
| 4709 | "}\n" | |
| 4710 | "int intintIdentityPerfectCLHash_InsertSingle(__global char *tableData, int key,\n" | |
| 4711 | " int value) {\n" | |
| 4712 | " return intintIdentityPerfectCLHash_InnerInsertSingle(tableData, key,\n" | |
| 4713 | " value);\n" | |
| 4714 | "}\n" | |
| 4715 | "int intintIdentityPerfectCLHash_Insert(__global char *tableData,\n" | |
| 4716 | " size_t numEntries, __global int *keys,\n" | |
| 4717 | " __global int *values) {\n" | |
| 4718 | " return intintIdentityPerfectCLHash_InnerInsert(tableData, numEntries,\n" | |
| 4719 | " keys, values);\n" | |
| 4720 | "}\n" | |
| 4721 | "int intintIdentityPerfectCLHash_InsertSingleNoOverwrite(__global char\n" | |
| 4722 | " *tableData, int key,\n" | |
| 4723 | " int value) {\n" | |
| 4724 | " return\n" | |
| 4725 | " intintIdentityPerfectCLHash_InnerInsertSingleNoOverwrite(tableData,\n" | |
| 4726 | " key,\n" | |
| 4727 | " value);\n" | |
| 4728 | "}\n" | |
| 4729 | "int intintIdentityPerfectCLHash_InsertNoOverwrite(__global char *tableData,\n" | |
| 4730 | " size_t numEntries,\n" | |
| 4731 | " __global int *keys,\n" | |
| 4732 | " __global int *values) {\n" | |
| 4733 | " return intintIdentityPerfectCLHash_InnerInsertNoOverwrite(tableData,\n" | |
| 4734 | " numEntries,\n" | |
| 4735 | " keys, values);\n" | |
| 4736 | "}\n" | |
| 4737 | "__kernel void intintIdentityPerfectCLHash_RangeQuerySingle(__global char\n" | |
| 4738 | " *tableData,\n" | |
| 4739 | " unsigned int\n" | |
| 4740 | " numQueries,\n" | |
| 4741 | " __global int *keys,\n" | |
| 4742 | " __global int\n" | |
| 4743 | " *valuesOutput) {\n" | |
| 4744 | " uint i = get_global_id(0);\n" | |
| 4745 | " if (i >= numQueries) {\n" | |
| 4746 | " return;\n" | |
| 4747 | " }\n" | |
| 4748 | " intintIdentityPerfectCLHash_InnerQuerySingle(tableData, keys[i],\n" | |
| 4749 | " valuesOutput + i);\n" | |
| 4750 | "}\n" | |
| 4751 | "__kernel void intintIdentityPerfectCLHash_RangeQuery(__global char *tableData,\n" | |
| 4752 | " unsigned int numQueries,\n" | |
| 4753 | " unsigned int numKeys,\n" | |
| 4754 | " __global int *keys,\n" | |
| 4755 | " __global int\n" | |
| 4756 | " *valuesOutput) {\n" | |
| 4757 | " uint i = get_global_id(0);\n" | |
| 4758 | " if (i >= numQueries) {\n" | |
| 4759 | " return;\n" | |
| 4760 | " }\n" | |
| 4761 | " intintIdentityPerfectCLHash_InnerQuery(tableData, numKeys,\n" | |
| 4762 | " keys + (i * numKeys),\n" | |
| 4763 | " valuesOutput + (i * numKeys));\n" | |
| 4764 | "}\n" | |
| 4765 | "__kernel void intintIdentityPerfectCLHash_RangeInsertSingle(__global char\n" | |
| 4766 | " *tableData,\n" | |
| 4767 | " unsigned int\n" | |
| 4768 | " numInsertions,\n" | |
| 4769 | " __global int *keys,\n" | |
| 4770 | " __global int\n" | |
| 4771 | " *values) {\n" | |
| 4772 | " uint i = get_global_id(0);\n" | |
| 4773 | " if (i >= numInsertions) {\n" | |
| 4774 | " return;\n" | |
| 4775 | " }\n" | |
| 4776 | " intintIdentityPerfectCLHash_InnerInsertSingle(tableData, keys[i],\n" | |
| 4777 | " values[i]);\n" | |
| 4778 | "}\n" | |
| 4779 | "__kernel void intintIdentityPerfectCLHash_RangeInsert(__global char *tableData,\n" | |
| 4780 | " unsigned int\n" | |
| 4781 | " numInsertions,\n" | |
| 4782 | " unsigned int numEntries,\n" | |
| 4783 | " __global int *keys,\n" | |
| 4784 | " __global int *values) {\n" | |
| 4785 | " uint i = get_global_id(0);\n" | |
| 4786 | " if (i >= numInsertions) {\n" | |
| 4787 | " return;\n" | |
| 4788 | " }\n" | |
| 4789 | " intintIdentityPerfectCLHash_InnerInsert(tableData, numEntries,\n" | |
| 4790 | " keys + (i * numEntries),\n" | |
| 4791 | " values + (i * numEntries));\n" | |
| 4792 | "}\n" | |
| 4793 | "__kernel void intintIdentityPerfectCLHash_RangeInsertSingleNoOverwrite(__global\n" | |
| 4794 | " char\n" | |
| 4795 | " *tableData,\n" | |
| 4796 | " unsigned\n" | |
| 4797 | " int\n" | |
| 4798 | " numInsertions,\n" | |
| 4799 | " __global\n" | |
| 4800 | " int\n" | |
| 4801 | " *keys,\n" | |
| 4802 | " __global\n" | |
| 4803 | " int\n" | |
| 4804 | " *values) \n" | |
| 4805 | "{\n" | |
| 4806 | " uint i = get_global_id(0);\n" | |
| 4807 | " if (i >= numInsertions) {\n" | |
| 4808 | " return;\n" | |
| 4809 | " }\n" | |
| 4810 | " intintIdentityPerfectCLHash_InnerInsertSingleNoOverwrite(tableData,\n" | |
| 4811 | " keys[i],\n" | |
| 4812 | " values[i]);\n" | |
| 4813 | "}\n" | |
| 4814 | "__kernel void intintIdentityPerfectCLHash_RangeInsertNoOverwrite(__global char\n" | |
| 4815 | " *tableData,\n" | |
| 4816 | " unsigned int\n" | |
| 4817 | " numInsertions,\n" | |
| 4818 | " unsigned int\n" | |
| 4819 | " numEntries,\n" | |
| 4820 | " __global int\n" | |
| 4821 | " *keys,\n" | |
| 4822 | " __global int\n" | |
| 4823 | " *values) {\n" | |
| 4824 | " uint i = get_global_id(0);\n" | |
| 4825 | " if (i >= numInsertions) {\n" | |
| 4826 | " return;\n" | |
| 4827 | " }\n" | |
| 4828 | " intintIdentityPerfectCLHash_InnerInsertNoOverwrite(tableData,\n" | |
| 4829 | " numEntries,\n" | |
| 4830 | " keys +\n" | |
| 4831 | " (i * numEntries),\n" | |
| 4832 | " values +\n" | |
| 4833 | " (i * numEntries));\n" | |
| 4834 | "}\n" | |
| 4835 | "\n" | |
| 4836 | "typedef struct intintIdentitySentinelPerfectCLHash_TableData {\n" | |
| 4837 | " int hashID;\n" | |
| 4838 | " unsigned int numBuckets;\n" | |
| 4839 | " char compressFuncData;\n" | |
| 4840 | " int emptyValue;\n" | |
| 4841 | "} intintIdentitySentinelPerfectCLHash_TableData;\n" | |
| 4842 | "typedef struct intintIdentitySentinelPerfectCLHash_Bucket {\n" | |
| 4843 | " int value;\n" | |
| 4844 | "} intintIdentitySentinelPerfectCLHash_Bucket;\n" | |
| 4845 | "int intintIdentitySentinelPerfectCLHash_InnerQuerySingle(__global char\n" | |
| 4846 | " *tableData, int key,\n" | |
| 4847 | " __global int\n" | |
| 4848 | " *valueOutput) {\n" | |
| 4849 | " __global intintIdentitySentinelPerfectCLHash_Bucket *buckets =\n" | |
| 4850 | " (__global intintIdentitySentinelPerfectCLHash_Bucket *) &\n" | |
| 4851 | " tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)];\n" | |
| 4852 | " int index;\n" | |
| 4853 | " int exitCode;\n" | |
| 4854 | " index =\n" | |
| 4855 | " intintHash_CompressIdentity(((__global\n" | |
| 4856 | " intintIdentitySentinelPerfectCLHash_TableData\n" | |
| 4857 | " *) tableData)->compressFuncData, key);\n" | |
| 4858 | " if (buckets[index].value !=\n" | |
| 4859 | " ((__global intintIdentitySentinelPerfectCLHash_TableData *)\n" | |
| 4860 | " tableData)->emptyValue) {\n" | |
| 4861 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4862 | " } else {\n" | |
| 4863 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4864 | " }\n" | |
| 4865 | " switch (exitCode) {\n" | |
| 4866 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4867 | " *valueOutput = buckets[index].value;\n" | |
| 4868 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 4869 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4870 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4871 | " return HASH_EXIT_CODE_KEY_DNE;\n" | |
| 4872 | " default:\n" | |
| 4873 | " return exitCode;\n" | |
| 4874 | " }\n" | |
| 4875 | "}\n" | |
| 4876 | "int intintIdentitySentinelPerfectCLHash_InnerQuery(__global char *tableData,\n" | |
| 4877 | " unsigned int numKeys,\n" | |
| 4878 | " __global int *keys,\n" | |
| 4879 | " __global int *valuesOutput) {\n" | |
| 4880 | " __global intintIdentitySentinelPerfectCLHash_Bucket *buckets =\n" | |
| 4881 | " (__global intintIdentitySentinelPerfectCLHash_Bucket *) &\n" | |
| 4882 | " tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)];\n" | |
| 4883 | " int key;\n" | |
| 4884 | " __global int *valueOutput;\n" | |
| 4885 | " int index;\n" | |
| 4886 | " int exitCode;\n" | |
| 4887 | " uint i;\n" | |
| 4888 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 4889 | " for (i = 0; i < numKeys; i++) {\n" | |
| 4890 | " key = keys[i];\n" | |
| 4891 | " valueOutput = &valuesOutput[i];\n" | |
| 4892 | " index =\n" | |
| 4893 | " intintHash_CompressIdentity(((__global\n" | |
| 4894 | " intintIdentitySentinelPerfectCLHash_TableData\n" | |
| 4895 | " *) tableData)->\n" | |
| 4896 | " compressFuncData, key);\n" | |
| 4897 | " if (buckets[index].value !=\n" | |
| 4898 | " ((__global intintIdentitySentinelPerfectCLHash_TableData *)\n" | |
| 4899 | " tableData)->emptyValue) {\n" | |
| 4900 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4901 | " } else {\n" | |
| 4902 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4903 | " }\n" | |
| 4904 | " switch (exitCode) {\n" | |
| 4905 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4906 | " *valueOutput = buckets[index].value;\n" | |
| 4907 | " break;\n" | |
| 4908 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4909 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4910 | " resultExitCode = HASH_EXIT_CODE_KEY_DNE;\n" | |
| 4911 | " break;\n" | |
| 4912 | " default:\n" | |
| 4913 | " return exitCode;\n" | |
| 4914 | " }\n" | |
| 4915 | " }\n" | |
| 4916 | " return resultExitCode;\n" | |
| 4917 | "}\n" | |
| 4918 | "int intintIdentitySentinelPerfectCLHash_InnerInsertSingle(__global char\n" | |
| 4919 | " *tableData, int key,\n" | |
| 4920 | " int value) {\n" | |
| 4921 | " __global intintIdentitySentinelPerfectCLHash_Bucket *buckets =\n" | |
| 4922 | " (__global intintIdentitySentinelPerfectCLHash_Bucket *) &\n" | |
| 4923 | " tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)];\n" | |
| 4924 | " int index;\n" | |
| 4925 | " int exitCode;\n" | |
| 4926 | " index =\n" | |
| 4927 | " intintHash_CompressIdentity(((__global\n" | |
| 4928 | " intintIdentitySentinelPerfectCLHash_TableData\n" | |
| 4929 | " *) tableData)->compressFuncData, key);\n" | |
| 4930 | " if (buckets[index].value !=\n" | |
| 4931 | " ((__global intintIdentitySentinelPerfectCLHash_TableData *)\n" | |
| 4932 | " tableData)->emptyValue) {\n" | |
| 4933 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4934 | " } else {\n" | |
| 4935 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4936 | " }\n" | |
| 4937 | " switch (exitCode) {\n" | |
| 4938 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4939 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4940 | " buckets[index].value = value;\n" | |
| 4941 | " return HASH_EXIT_CODE_OVERWRITE;\n" | |
| 4942 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4943 | " buckets[index].value = value;\n" | |
| 4944 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 4945 | " default:\n" | |
| 4946 | " return exitCode;\n" | |
| 4947 | " }\n" | |
| 4948 | "}\n" | |
| 4949 | "int intintIdentitySentinelPerfectCLHash_InnerInsert(__global char *tableData,\n" | |
| 4950 | " unsigned int numEntries,\n" | |
| 4951 | " __global int *keys,\n" | |
| 4952 | " __global int *values) {\n" | |
| 4953 | " __global intintIdentitySentinelPerfectCLHash_Bucket *buckets =\n" | |
| 4954 | " (__global intintIdentitySentinelPerfectCLHash_Bucket *) &\n" | |
| 4955 | " tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)];\n" | |
| 4956 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 4957 | " int key;\n" | |
| 4958 | " int value;\n" | |
| 4959 | " int index;\n" | |
| 4960 | " int exitCode;\n" | |
| 4961 | " uint i;\n" | |
| 4962 | " for (i = 0; i < numEntries; i++) {\n" | |
| 4963 | " key = keys[i];\n" | |
| 4964 | " index =\n" | |
| 4965 | " intintHash_CompressIdentity(((__global\n" | |
| 4966 | " intintIdentitySentinelPerfectCLHash_TableData\n" | |
| 4967 | " *) tableData)->\n" | |
| 4968 | " compressFuncData, key);\n" | |
| 4969 | " if (buckets[index].value !=\n" | |
| 4970 | " ((__global intintIdentitySentinelPerfectCLHash_TableData *)\n" | |
| 4971 | " tableData)->emptyValue) {\n" | |
| 4972 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4973 | " } else {\n" | |
| 4974 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4975 | " }\n" | |
| 4976 | " switch (exitCode) {\n" | |
| 4977 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4978 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4979 | " resultExitCode = HASH_EXIT_CODE_OVERWRITE;\n" | |
| 4980 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4981 | " buckets[index].value = values[i];\n" | |
| 4982 | " break;\n" | |
| 4983 | " default:\n" | |
| 4984 | " return exitCode;\n" | |
| 4985 | " }\n" | |
| 4986 | " }\n" | |
| 4987 | " return resultExitCode;\n" | |
| 4988 | "}\n" | |
| 4989 | "int intintIdentitySentinelPerfectCLHash_InnerInsertSingleNoOverwrite(__global\n" | |
| 4990 | " char\n" | |
| 4991 | " *tableData,\n" | |
| 4992 | " int key,\n" | |
| 4993 | " int value) \n" | |
| 4994 | "{\n" | |
| 4995 | " __global intintIdentitySentinelPerfectCLHash_Bucket *buckets =\n" | |
| 4996 | " (__global intintIdentitySentinelPerfectCLHash_Bucket *) &\n" | |
| 4997 | " tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)];\n" | |
| 4998 | " int index;\n" | |
| 4999 | " int exitCode;\n" | |
| 5000 | " index =\n" | |
| 5001 | " intintHash_CompressIdentity(((__global\n" | |
| 5002 | " intintIdentitySentinelPerfectCLHash_TableData\n" | |
| 5003 | " *) tableData)->compressFuncData, key);\n" | |
| 5004 | " if (buckets[index].value !=\n" | |
| 5005 | " ((__global intintIdentitySentinelPerfectCLHash_TableData *)\n" | |
| 5006 | " tableData)->emptyValue) {\n" | |
| 5007 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5008 | " } else {\n" | |
| 5009 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5010 | " }\n" | |
| 5011 | " switch (exitCode) {\n" | |
| 5012 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5013 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5014 | " return HASH_EXIT_CODE_OVERWRITE;\n" | |
| 5015 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5016 | " buckets[index].value = value;\n" | |
| 5017 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 5018 | " default:\n" | |
| 5019 | " return exitCode;\n" | |
| 5020 | " }\n" | |
| 5021 | "}\n" | |
| 5022 | "int intintIdentitySentinelPerfectCLHash_InnerInsertNoOverwrite(__global char\n" | |
| 5023 | " *tableData,\n" | |
| 5024 | " unsigned int\n" | |
| 5025 | " numEntries,\n" | |
| 5026 | " __global int\n" | |
| 5027 | " *keys,\n" | |
| 5028 | " __global int\n" | |
| 5029 | " *values) {\n" | |
| 5030 | " __global intintIdentitySentinelPerfectCLHash_Bucket *buckets =\n" | |
| 5031 | " (__global intintIdentitySentinelPerfectCLHash_Bucket *) &\n" | |
| 5032 | " tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)];\n" | |
| 5033 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 5034 | " int key;\n" | |
| 5035 | " int value;\n" | |
| 5036 | " int index;\n" | |
| 5037 | " int exitCode;\n" | |
| 5038 | " uint i;\n" | |
| 5039 | " for (i = 0; i < numEntries; i++) {\n" | |
| 5040 | " key = keys[i];\n" | |
| 5041 | " index =\n" | |
| 5042 | " intintHash_CompressIdentity(((__global\n" | |
| 5043 | " intintIdentitySentinelPerfectCLHash_TableData\n" | |
| 5044 | " *) tableData)->\n" | |
| 5045 | " compressFuncData, key);\n" | |
| 5046 | " if (buckets[index].value !=\n" | |
| 5047 | " ((__global intintIdentitySentinelPerfectCLHash_TableData *)\n" | |
| 5048 | " tableData)->emptyValue) {\n" | |
| 5049 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5050 | " } else {\n" | |
| 5051 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5052 | " }\n" | |
| 5053 | " switch (exitCode) {\n" | |
| 5054 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5055 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5056 | " resultExitCode = HASH_EXIT_CODE_OVERWRITE;\n" | |
| 5057 | " break;\n" | |
| 5058 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5059 | " buckets[index].value = values[i];\n" | |
| 5060 | " break;\n" | |
| 5061 | " default:\n" | |
| 5062 | " return exitCode;\n" | |
| 5063 | " }\n" | |
| 5064 | " }\n" | |
| 5065 | " return resultExitCode;\n" | |
| 5066 | "}\n" | |
| 5067 | "int intintIdentitySentinelPerfectCLHash_QuerySingle(__global char *tableData,\n" | |
| 5068 | " int key,\n" | |
| 5069 | " __global int *valueOutput) {\n" | |
| 5070 | " return intintIdentitySentinelPerfectCLHash_InnerQuerySingle(tableData,\n" | |
| 5071 | " key,\n" | |
| 5072 | " valueOutput);\n" | |
| 5073 | "}\n" | |
| 5074 | "int intintIdentitySentinelPerfectCLHash_Query(__global char *tableData,\n" | |
| 5075 | " size_t numKeys,\n" | |
| 5076 | " __global int *keys,\n" | |
| 5077 | " __global int *valuesOutput) {\n" | |
| 5078 | " return intintIdentitySentinelPerfectCLHash_InnerQuery(tableData,\n" | |
| 5079 | " numKeys, keys,\n" | |
| 5080 | " valuesOutput);\n" | |
| 5081 | "}\n" | |
| 5082 | "int intintIdentitySentinelPerfectCLHash_InsertSingle(__global char *tableData,\n" | |
| 5083 | " int key, int value) {\n" | |
| 5084 | " return intintIdentitySentinelPerfectCLHash_InnerInsertSingle(tableData,\n" | |
| 5085 | " key,\n" | |
| 5086 | " value);\n" | |
| 5087 | "}\n" | |
| 5088 | "int intintIdentitySentinelPerfectCLHash_Insert(__global char *tableData,\n" | |
| 5089 | " size_t numEntries,\n" | |
| 5090 | " __global int *keys,\n" | |
| 5091 | " __global int *values) {\n" | |
| 5092 | " return intintIdentitySentinelPerfectCLHash_InnerInsert(tableData,\n" | |
| 5093 | " numEntries, keys,\n" | |
| 5094 | " values);\n" | |
| 5095 | "}\n" | |
| 5096 | "int intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite(__global char\n" | |
| 5097 | " *tableData,\n" | |
| 5098 | " int key,\n" | |
| 5099 | " int value) {\n" | |
| 5100 | " return\n" | |
| 5101 | " intintIdentitySentinelPerfectCLHash_InnerInsertSingleNoOverwrite\n" | |
| 5102 | " (tableData, key, value);\n" | |
| 5103 | "}\n" | |
| 5104 | "int intintIdentitySentinelPerfectCLHash_InsertNoOverwrite(__global char\n" | |
| 5105 | " *tableData,\n" | |
| 5106 | " size_t numEntries,\n" | |
| 5107 | " __global int *keys,\n" | |
| 5108 | " __global int *values) \n" | |
| 5109 | "{\n" | |
| 5110 | " return\n" | |
| 5111 | " intintIdentitySentinelPerfectCLHash_InnerInsertNoOverwrite\n" | |
| 5112 | " (tableData, numEntries, keys, values);\n" | |
| 5113 | "}\n" | |
| 5114 | "__kernel void intintIdentitySentinelPerfectCLHash_RangeQuerySingle(__global char\n" | |
| 5115 | " *tableData,\n" | |
| 5116 | " unsigned int\n" | |
| 5117 | " numQueries,\n" | |
| 5118 | " __global int\n" | |
| 5119 | " *keys,\n" | |
| 5120 | " __global int\n" | |
| 5121 | " *valuesOutput) \n" | |
| 5122 | "{\n" | |
| 5123 | " uint i = get_global_id(0);\n" | |
| 5124 | " if (i >= numQueries) {\n" | |
| 5125 | " return;\n" | |
| 5126 | " }\n" | |
| 5127 | " intintIdentitySentinelPerfectCLHash_InnerQuerySingle(tableData, keys[i],\n" | |
| 5128 | " valuesOutput + i);\n" | |
| 5129 | "}\n" | |
| 5130 | "__kernel void intintIdentitySentinelPerfectCLHash_RangeQuery(__global char\n" | |
| 5131 | " *tableData,\n" | |
| 5132 | " unsigned int\n" | |
| 5133 | " numQueries,\n" | |
| 5134 | " unsigned int\n" | |
| 5135 | " numKeys,\n" | |
| 5136 | " __global int *keys,\n" | |
| 5137 | " __global int\n" | |
| 5138 | " *valuesOutput) {\n" | |
| 5139 | " uint i = get_global_id(0);\n" | |
| 5140 | " if (i >= numQueries) {\n" | |
| 5141 | " return;\n" | |
| 5142 | " }\n" | |
| 5143 | " intintIdentitySentinelPerfectCLHash_InnerQuery(tableData, numKeys,\n" | |
| 5144 | " keys + (i * numKeys),\n" | |
| 5145 | " valuesOutput +\n" | |
| 5146 | " (i * numKeys));\n" | |
| 5147 | "}\n" | |
| 5148 | "__kernel void intintIdentitySentinelPerfectCLHash_RangeInsertSingle(__global\n" | |
| 5149 | " char\n" | |
| 5150 | " *tableData,\n" | |
| 5151 | " unsigned int\n" | |
| 5152 | " numInsertions,\n" | |
| 5153 | " __global int\n" | |
| 5154 | " *keys,\n" | |
| 5155 | " __global int\n" | |
| 5156 | " *values) {\n" | |
| 5157 | " uint i = get_global_id(0);\n" | |
| 5158 | " if (i >= numInsertions) {\n" | |
| 5159 | " return;\n" | |
| 5160 | " }\n" | |
| 5161 | " intintIdentitySentinelPerfectCLHash_InnerInsertSingle(tableData,\n" | |
| 5162 | " keys[i],\n" | |
| 5163 | " values[i]);\n" | |
| 5164 | "}\n" | |
| 5165 | "__kernel void intintIdentitySentinelPerfectCLHash_RangeInsert(__global char\n" | |
| 5166 | " *tableData,\n" | |
| 5167 | " unsigned int\n" | |
| 5168 | " numInsertions,\n" | |
| 5169 | " unsigned int\n" | |
| 5170 | " numEntries,\n" | |
| 5171 | " __global int\n" | |
| 5172 | " *keys,\n" | |
| 5173 | " __global int\n" | |
| 5174 | " *values) {\n" | |
| 5175 | " uint i = get_global_id(0);\n" | |
| 5176 | " if (i >= numInsertions) {\n" | |
| 5177 | " return;\n" | |
| 5178 | " }\n" | |
| 5179 | " intintIdentitySentinelPerfectCLHash_InnerInsert(tableData, numEntries,\n" | |
| 5180 | " keys + (i * numEntries),\n" | |
| 5181 | " values +\n" | |
| 5182 | " (i * numEntries));\n" | |
| 5183 | "}\n" | |
| 5184 | "__kernel void\n" | |
| 5185 | "intintIdentitySentinelPerfectCLHash_RangeInsertSingleNoOverwrite(__global char\n" | |
| 5186 | " *tableData,\n" | |
| 5187 | " unsigned int\n" | |
| 5188 | " numInsertions,\n" | |
| 5189 | " __global int\n" | |
| 5190 | " *keys,\n" | |
| 5191 | " __global int\n" | |
| 5192 | " *values) {\n" | |
| 5193 | " uint i = get_global_id(0);\n" | |
| 5194 | " if (i >= numInsertions) {\n" | |
| 5195 | " return;\n" | |
| 5196 | " }\n" | |
| 5197 | " intintIdentitySentinelPerfectCLHash_InnerInsertSingleNoOverwrite\n" | |
| 5198 | " (tableData, keys[i], values[i]);\n" | |
| 5199 | "}\n" | |
| 5200 | "__kernel void\n" | |
| 5201 | "intintIdentitySentinelPerfectCLHash_RangeInsertNoOverwrite(__global char\n" | |
| 5202 | " *tableData,\n" | |
| 5203 | " unsigned int\n" | |
| 5204 | " numInsertions,\n" | |
| 5205 | " unsigned int\n" | |
| 5206 | " numEntries,\n" | |
| 5207 | " __global int *keys,\n" | |
| 5208 | " __global int\n" | |
| 5209 | " *values) {\n" | |
| 5210 | " uint i = get_global_id(0);\n" | |
| 5211 | " if (i >= numInsertions) {\n" | |
| 5212 | " return;\n" | |
| 5213 | " }\n" | |
| 5214 | " intintIdentitySentinelPerfectCLHash_InnerInsertNoOverwrite(tableData,\n" | |
| 5215 | " numEntries,\n" | |
| 5216 | " keys +\n" | |
| 5217 | " (i *\n" | |
| 5218 | " numEntries),\n" | |
| 5219 | " values +\n" | |
| 5220 | " (i *\n" | |
| 5221 | " numEntries));\n" | |
| 5222 | "}\n" | |
| 5223 | "\n" | |
| 5224 | "typedef struct intintLCGLinearOpenCompactCLHash_TableData {\n" | |
| 5225 | " int hashID;\n" | |
| 5226 | " unsigned int numBuckets;\n" | |
| 5227 | " intintHash_CompressLCGData compressFuncData;\n" | |
| 5228 | "} intintLCGLinearOpenCompactCLHash_TableData;\n" | |
| 5229 | "typedef struct intintLCGLinearOpenCompactCLHash_Bucket {\n" | |
| 5230 | " int key;\n" | |
| 5231 | " int value;\n" | |
| 5232 | "} intintLCGLinearOpenCompactCLHash_Bucket;\n" | |
| 5233 | "int intintLCGLinearOpenCompactCLHash_InnerQuerySingle(__global char *tableData,\n" | |
| 5234 | " int key,\n" | |
| 5235 | " __global int\n" | |
| 5236 | " *valueOutput) {\n" | |
| 5237 | " __global intintLCGLinearOpenCompactCLHash_Bucket *buckets =\n" | |
| 5238 | " (__global intintLCGLinearOpenCompactCLHash_Bucket *) &\n" | |
| 5239 | " tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)];\n" | |
| 5240 | " int index;\n" | |
| 5241 | " int exitCode;\n" | |
| 5242 | " __global intintLCGLinearOpenCompactCLHash_TableData *mytableData =\n" | |
| 5243 | " (__global intintLCGLinearOpenCompactCLHash_TableData *) tableData;\n" | |
| 5244 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5245 | " mytableData->compressFuncData;\n" | |
| 5246 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5247 | " unsigned long int iteration = 0;\n" | |
| 5248 | " for (;;) {\n" | |
| 5249 | " index =\n" | |
| 5250 | " ((1 * iteration +\n" | |
| 5251 | " c) %\n" | |
| 5252 | " ((__global intintLCGLinearOpenCompactCLHash_TableData *)\n" | |
| 5253 | " tableData)->numBuckets);\n" | |
| 5254 | " if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5255 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5256 | " break;\n" | |
| 5257 | " } else if (key == buckets[index].key) {\n" | |
| 5258 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5259 | " break;\n" | |
| 5260 | " } else if ((index == c && iteration > 0)) {\n" | |
| 5261 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5262 | " break;\n" | |
| 5263 | " }\n" | |
| 5264 | " iteration++;\n" | |
| 5265 | " }\n" | |
| 5266 | " switch (exitCode) {\n" | |
| 5267 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5268 | " *valueOutput = buckets[index].value;\n" | |
| 5269 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 5270 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5271 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5272 | " return HASH_EXIT_CODE_KEY_DNE;\n" | |
| 5273 | " default:\n" | |
| 5274 | " return exitCode;\n" | |
| 5275 | " }\n" | |
| 5276 | "}\n" | |
| 5277 | "int intintLCGLinearOpenCompactCLHash_InnerQuery(__global char *tableData,\n" | |
| 5278 | " unsigned int numKeys,\n" | |
| 5279 | " __global int *keys,\n" | |
| 5280 | " __global int *valuesOutput) {\n" | |
| 5281 | " __global intintLCGLinearOpenCompactCLHash_Bucket *buckets =\n" | |
| 5282 | " (__global intintLCGLinearOpenCompactCLHash_Bucket *) &\n" | |
| 5283 | " tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)];\n" | |
| 5284 | " int key;\n" | |
| 5285 | " __global int *valueOutput;\n" | |
| 5286 | " int index;\n" | |
| 5287 | " int exitCode;\n" | |
| 5288 | " uint i;\n" | |
| 5289 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 5290 | " for (i = 0; i < numKeys; i++) {\n" | |
| 5291 | " key = keys[i];\n" | |
| 5292 | " valueOutput = &valuesOutput[i];\n" | |
| 5293 | " __global intintLCGLinearOpenCompactCLHash_TableData *mytableData\n" | |
| 5294 | " =\n" | |
| 5295 | " (__global intintLCGLinearOpenCompactCLHash_TableData *)\n" | |
| 5296 | " tableData;\n" | |
| 5297 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5298 | " mytableData->compressFuncData;\n" | |
| 5299 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5300 | " unsigned long int iteration = 0;\n" | |
| 5301 | " for (;;) {\n" | |
| 5302 | " index =\n" | |
| 5303 | " ((1 * iteration +\n" | |
| 5304 | " c) %\n" | |
| 5305 | " ((__global\n" | |
| 5306 | " intintLCGLinearOpenCompactCLHash_TableData *)\n" | |
| 5307 | " tableData)->numBuckets);\n" | |
| 5308 | " if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5309 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5310 | " break;\n" | |
| 5311 | " } else if (key == buckets[index].key) {\n" | |
| 5312 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5313 | " break;\n" | |
| 5314 | " } else if ((index == c && iteration > 0)) {\n" | |
| 5315 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5316 | " break;\n" | |
| 5317 | " }\n" | |
| 5318 | " iteration++;\n" | |
| 5319 | " }\n" | |
| 5320 | " switch (exitCode) {\n" | |
| 5321 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5322 | " *valueOutput = buckets[index].value;\n" | |
| 5323 | " break;\n" | |
| 5324 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5325 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5326 | " resultExitCode = HASH_EXIT_CODE_KEY_DNE;\n" | |
| 5327 | " break;\n" | |
| 5328 | " default:\n" | |
| 5329 | " return exitCode;\n" | |
| 5330 | " }\n" | |
| 5331 | " }\n" | |
| 5332 | " return resultExitCode;\n" | |
| 5333 | "}\n" | |
| 5334 | "int intintLCGLinearOpenCompactCLHash_InnerInsertSingle(__global char *tableData,\n" | |
| 5335 | " int key, int value) {\n" | |
| 5336 | " __global intintLCGLinearOpenCompactCLHash_Bucket *buckets =\n" | |
| 5337 | " (__global intintLCGLinearOpenCompactCLHash_Bucket *) &\n" | |
| 5338 | " tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)];\n" | |
| 5339 | " int index;\n" | |
| 5340 | " int exitCode;\n" | |
| 5341 | " __global intintLCGLinearOpenCompactCLHash_TableData *mytableData =\n" | |
| 5342 | " (__global intintLCGLinearOpenCompactCLHash_TableData *) tableData;\n" | |
| 5343 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5344 | " mytableData->compressFuncData;\n" | |
| 5345 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5346 | " unsigned long int iteration = 0;\n" | |
| 5347 | " for (;;) {\n" | |
| 5348 | " index =\n" | |
| 5349 | " ((1 * iteration +\n" | |
| 5350 | " c) %\n" | |
| 5351 | " ((__global intintLCGLinearOpenCompactCLHash_TableData *)\n" | |
| 5352 | " tableData)->numBuckets);\n" | |
| 5353 | " if ((atomic_cmpxchg\n" | |
| 5354 | " (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY,\n" | |
| 5355 | " key)) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5356 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5357 | " break;\n" | |
| 5358 | " } else if (key == buckets[index].key) {\n" | |
| 5359 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5360 | " break;\n" | |
| 5361 | " } else if ((index == c && iteration > 0)) {\n" | |
| 5362 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5363 | " break;\n" | |
| 5364 | " }\n" | |
| 5365 | " iteration++;\n" | |
| 5366 | " }\n" | |
| 5367 | " switch (exitCode) {\n" | |
| 5368 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5369 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5370 | " buckets[index].value = value;\n" | |
| 5371 | " return HASH_EXIT_CODE_OVERWRITE;\n" | |
| 5372 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5373 | " buckets[index].value = value;\n" | |
| 5374 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 5375 | " default:\n" | |
| 5376 | " return exitCode;\n" | |
| 5377 | " }\n" | |
| 5378 | "}\n" | |
| 5379 | "int intintLCGLinearOpenCompactCLHash_InnerInsert(__global char *tableData,\n" | |
| 5380 | " unsigned int numEntries,\n" | |
| 5381 | " __global int *keys,\n" | |
| 5382 | " __global int *values) {\n" | |
| 5383 | " __global intintLCGLinearOpenCompactCLHash_Bucket *buckets =\n" | |
| 5384 | " (__global intintLCGLinearOpenCompactCLHash_Bucket *) &\n" | |
| 5385 | " tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)];\n" | |
| 5386 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 5387 | " int key;\n" | |
| 5388 | " int value;\n" | |
| 5389 | " int index;\n" | |
| 5390 | " int exitCode;\n" | |
| 5391 | " uint i;\n" | |
| 5392 | " for (i = 0; i < numEntries; i++) {\n" | |
| 5393 | " key = keys[i];\n" | |
| 5394 | " __global intintLCGLinearOpenCompactCLHash_TableData *mytableData\n" | |
| 5395 | " =\n" | |
| 5396 | " (__global intintLCGLinearOpenCompactCLHash_TableData *)\n" | |
| 5397 | " tableData;\n" | |
| 5398 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5399 | " mytableData->compressFuncData;\n" | |
| 5400 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5401 | " unsigned long int iteration = 0;\n" | |
| 5402 | " for (;;) {\n" | |
| 5403 | " index =\n" | |
| 5404 | " ((1 * iteration +\n" | |
| 5405 | " c) %\n" | |
| 5406 | " ((__global\n" | |
| 5407 | " intintLCGLinearOpenCompactCLHash_TableData *)\n" | |
| 5408 | " tableData)->numBuckets);\n" | |
| 5409 | " if ((atomic_cmpxchg\n" | |
| 5410 | " (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY,\n" | |
| 5411 | " key)) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5412 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5413 | " break;\n" | |
| 5414 | " } else if (key == buckets[index].key) {\n" | |
| 5415 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5416 | " break;\n" | |
| 5417 | " } else if ((index == c && iteration > 0)) {\n" | |
| 5418 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5419 | " break;\n" | |
| 5420 | " }\n" | |
| 5421 | " iteration++;\n" | |
| 5422 | " }\n" | |
| 5423 | " switch (exitCode) {\n" | |
| 5424 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5425 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5426 | " resultExitCode = HASH_EXIT_CODE_OVERWRITE;\n" | |
| 5427 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5428 | " buckets[index].value = values[i];\n" | |
| 5429 | " break;\n" | |
| 5430 | " default:\n" | |
| 5431 | " return exitCode;\n" | |
| 5432 | " }\n" | |
| 5433 | " }\n" | |
| 5434 | " return resultExitCode;\n" | |
| 5435 | "}\n" | |
| 5436 | "int intintLCGLinearOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global char\n" | |
| 5437 | " *tableData,\n" | |
| 5438 | " int key,\n" | |
| 5439 | " int value) {\n" | |
| 5440 | " __global intintLCGLinearOpenCompactCLHash_Bucket *buckets =\n" | |
| 5441 | " (__global intintLCGLinearOpenCompactCLHash_Bucket *) &\n" | |
| 5442 | " tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)];\n" | |
| 5443 | " int index;\n" | |
| 5444 | " int exitCode;\n" | |
| 5445 | " __global intintLCGLinearOpenCompactCLHash_TableData *mytableData =\n" | |
| 5446 | " (__global intintLCGLinearOpenCompactCLHash_TableData *) tableData;\n" | |
| 5447 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5448 | " mytableData->compressFuncData;\n" | |
| 5449 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5450 | " unsigned long int iteration = 0;\n" | |
| 5451 | " for (;;) {\n" | |
| 5452 | " index =\n" | |
| 5453 | " ((1 * iteration +\n" | |
| 5454 | " c) %\n" | |
| 5455 | " ((__global intintLCGLinearOpenCompactCLHash_TableData *)\n" | |
| 5456 | " tableData)->numBuckets);\n" | |
| 5457 | " if ((atomic_cmpxchg\n" | |
| 5458 | " (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY,\n" | |
| 5459 | " key)) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5460 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5461 | " break;\n" | |
| 5462 | " } else if (key == buckets[index].key) {\n" | |
| 5463 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5464 | " break;\n" | |
| 5465 | " } else if ((index == c && iteration > 0)) {\n" | |
| 5466 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5467 | " break;\n" | |
| 5468 | " }\n" | |
| 5469 | " iteration++;\n" | |
| 5470 | " }\n" | |
| 5471 | " switch (exitCode) {\n" | |
| 5472 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5473 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5474 | " return HASH_EXIT_CODE_OVERWRITE;\n" | |
| 5475 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5476 | " buckets[index].value = value;\n" | |
| 5477 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 5478 | " default:\n" | |
| 5479 | " return exitCode;\n" | |
| 5480 | " }\n" | |
| 5481 | "}\n" | |
| 5482 | "int intintLCGLinearOpenCompactCLHash_InnerInsertNoOverwrite(__global char\n" | |
| 5483 | " *tableData,\n" | |
| 5484 | " unsigned int\n" | |
| 5485 | " numEntries,\n" | |
| 5486 | " __global int *keys,\n" | |
| 5487 | " __global int\n" | |
| 5488 | " *values) {\n" | |
| 5489 | " __global intintLCGLinearOpenCompactCLHash_Bucket *buckets =\n" | |
| 5490 | " (__global intintLCGLinearOpenCompactCLHash_Bucket *) &\n" | |
| 5491 | " tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)];\n" | |
| 5492 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 5493 | " int key;\n" | |
| 5494 | " int value;\n" | |
| 5495 | " int index;\n" | |
| 5496 | " int exitCode;\n" | |
| 5497 | " uint i;\n" | |
| 5498 | " for (i = 0; i < numEntries; i++) {\n" | |
| 5499 | " key = keys[i];\n" | |
| 5500 | " __global intintLCGLinearOpenCompactCLHash_TableData *mytableData\n" | |
| 5501 | " =\n" | |
| 5502 | " (__global intintLCGLinearOpenCompactCLHash_TableData *)\n" | |
| 5503 | " tableData;\n" | |
| 5504 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5505 | " mytableData->compressFuncData;\n" | |
| 5506 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5507 | " unsigned long int iteration = 0;\n" | |
| 5508 | " for (;;) {\n" | |
| 5509 | " index =\n" | |
| 5510 | " ((1 * iteration +\n" | |
| 5511 | " c) %\n" | |
| 5512 | " ((__global\n" | |
| 5513 | " intintLCGLinearOpenCompactCLHash_TableData *)\n" | |
| 5514 | " tableData)->numBuckets);\n" | |
| 5515 | " if ((atomic_cmpxchg\n" | |
| 5516 | " (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY,\n" | |
| 5517 | " key)) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5518 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5519 | " break;\n" | |
| 5520 | " } else if (key == buckets[index].key) {\n" | |
| 5521 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5522 | " break;\n" | |
| 5523 | " } else if ((index == c && iteration > 0)) {\n" | |
| 5524 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5525 | " break;\n" | |
| 5526 | " }\n" | |
| 5527 | " iteration++;\n" | |
| 5528 | " }\n" | |
| 5529 | " switch (exitCode) {\n" | |
| 5530 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5531 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5532 | " resultExitCode = HASH_EXIT_CODE_OVERWRITE;\n" | |
| 5533 | " break;\n" | |
| 5534 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5535 | " buckets[index].value = values[i];\n" | |
| 5536 | " break;\n" | |
| 5537 | " default:\n" | |
| 5538 | " return exitCode;\n" | |
| 5539 | " }\n" | |
| 5540 | " }\n" | |
| 5541 | " return resultExitCode;\n" | |
| 5542 | "}\n" | |
| 5543 | "int intintLCGLinearOpenCompactCLHash_QuerySingle(__global char *tableData,\n" | |
| 5544 | " int key,\n" | |
| 5545 | " __global int *valueOutput) {\n" | |
| 5546 | " return intintLCGLinearOpenCompactCLHash_InnerQuerySingle(tableData, key,\n" | |
| 5547 | " valueOutput);\n" | |
| 5548 | "}\n" | |
| 5549 | "int intintLCGLinearOpenCompactCLHash_Query(__global char *tableData,\n" | |
| 5550 | " size_t numKeys, __global int *keys,\n" | |
| 5551 | " __global int *valuesOutput) {\n" | |
| 5552 | " return intintLCGLinearOpenCompactCLHash_InnerQuery(tableData, numKeys,\n" | |
| 5553 | " keys, valuesOutput);\n" | |
| 5554 | "}\n" | |
| 5555 | "int intintLCGLinearOpenCompactCLHash_InsertSingle(__global char *tableData,\n" | |
| 5556 | " int key, int value) {\n" | |
| 5557 | " return intintLCGLinearOpenCompactCLHash_InnerInsertSingle(tableData,\n" | |
| 5558 | " key, value);\n" | |
| 5559 | "}\n" | |
| 5560 | "int intintLCGLinearOpenCompactCLHash_Insert(__global char *tableData,\n" | |
| 5561 | " size_t numEntries,\n" | |
| 5562 | " __global int *keys,\n" | |
| 5563 | " __global int *values) {\n" | |
| 5564 | " return intintLCGLinearOpenCompactCLHash_InnerInsert(tableData,\n" | |
| 5565 | " numEntries, keys,\n" | |
| 5566 | " values);\n" | |
| 5567 | "}\n" | |
| 5568 | "int intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite(__global char\n" | |
| 5569 | " *tableData,\n" | |
| 5570 | " int key,\n" | |
| 5571 | " int value) {\n" | |
| 5572 | " return\n" | |
| 5573 | " intintLCGLinearOpenCompactCLHash_InnerInsertSingleNoOverwrite\n" | |
| 5574 | " (tableData, key, value);\n" | |
| 5575 | "}\n" | |
| 5576 | "int intintLCGLinearOpenCompactCLHash_InsertNoOverwrite(__global char *tableData,\n" | |
| 5577 | " size_t numEntries,\n" | |
| 5578 | " __global int *keys,\n" | |
| 5579 | " __global int *values) {\n" | |
| 5580 | " return\n" | |
| 5581 | " intintLCGLinearOpenCompactCLHash_InnerInsertNoOverwrite(tableData,\n" | |
| 5582 | " numEntries,\n" | |
| 5583 | " keys,\n" | |
| 5584 | " values);\n" | |
| 5585 | "}\n" | |
| 5586 | "__kernel void intintLCGLinearOpenCompactCLHash_RangeQuerySingle(__global char\n" | |
| 5587 | " *tableData,\n" | |
| 5588 | " unsigned int\n" | |
| 5589 | " numQueries,\n" | |
| 5590 | " __global int\n" | |
| 5591 | " *keys,\n" | |
| 5592 | " __global int\n" | |
| 5593 | " *valuesOutput) {\n" | |
| 5594 | " uint i = get_global_id(0);\n" | |
| 5595 | " if (i >= numQueries) {\n" | |
| 5596 | " return;\n" | |
| 5597 | " }\n" | |
| 5598 | " intintLCGLinearOpenCompactCLHash_InnerQuerySingle(tableData, keys[i],\n" | |
| 5599 | " valuesOutput + i);\n" | |
| 5600 | "}\n" | |
| 5601 | "__kernel void intintLCGLinearOpenCompactCLHash_RangeQuery(__global char\n" | |
| 5602 | " *tableData,\n" | |
| 5603 | " unsigned int\n" | |
| 5604 | " numQueries,\n" | |
| 5605 | " unsigned int numKeys,\n" | |
| 5606 | " __global int *keys,\n" | |
| 5607 | " __global int\n" | |
| 5608 | " *valuesOutput) {\n" | |
| 5609 | " uint i = get_global_id(0);\n" | |
| 5610 | " if (i >= numQueries) {\n" | |
| 5611 | " return;\n" | |
| 5612 | " }\n" | |
| 5613 | " intintLCGLinearOpenCompactCLHash_InnerQuery(tableData, numKeys,\n" | |
| 5614 | " keys + (i * numKeys),\n" | |
| 5615 | " valuesOutput +\n" | |
| 5616 | " (i * numKeys));\n" | |
| 5617 | "}\n" | |
| 5618 | "__kernel void intintLCGLinearOpenCompactCLHash_RangeInsertSingle(__global char\n" | |
| 5619 | " *tableData,\n" | |
| 5620 | " unsigned int\n" | |
| 5621 | " numInsertions,\n" | |
| 5622 | " __global int\n" | |
| 5623 | " *keys,\n" | |
| 5624 | " __global int\n" | |
| 5625 | " *values) {\n" | |
| 5626 | " uint i = get_global_id(0);\n" | |
| 5627 | " if (i >= numInsertions) {\n" | |
| 5628 | " return;\n" | |
| 5629 | " }\n" | |
| 5630 | " intintLCGLinearOpenCompactCLHash_InnerInsertSingle(tableData, keys[i],\n" | |
| 5631 | " values[i]);\n" | |
| 5632 | "}\n" | |
| 5633 | "__kernel void intintLCGLinearOpenCompactCLHash_RangeInsert(__global char\n" | |
| 5634 | " *tableData,\n" | |
| 5635 | " unsigned int\n" | |
| 5636 | " numInsertions,\n" | |
| 5637 | " unsigned int\n" | |
| 5638 | " numEntries,\n" | |
| 5639 | " __global int *keys,\n" | |
| 5640 | " __global int\n" | |
| 5641 | " *values) {\n" | |
| 5642 | " uint i = get_global_id(0);\n" | |
| 5643 | " if (i >= numInsertions) {\n" | |
| 5644 | " return;\n" | |
| 5645 | " }\n" | |
| 5646 | " intintLCGLinearOpenCompactCLHash_InnerInsert(tableData, numEntries,\n" | |
| 5647 | " keys + (i * numEntries),\n" | |
| 5648 | " values + (i * numEntries));\n" | |
| 5649 | "}\n" | |
| 5650 | "__kernel void\n" | |
| 5651 | "intintLCGLinearOpenCompactCLHash_RangeInsertSingleNoOverwrite(__global char\n" | |
| 5652 | " *tableData,\n" | |
| 5653 | " unsigned int\n" | |
| 5654 | " numInsertions,\n" | |
| 5655 | " __global int\n" | |
| 5656 | " *keys,\n" | |
| 5657 | " __global int\n" | |
| 5658 | " *values) {\n" | |
| 5659 | " uint i = get_global_id(0);\n" | |
| 5660 | " if (i >= numInsertions) {\n" | |
| 5661 | " return;\n" | |
| 5662 | " }\n" | |
| 5663 | " intintLCGLinearOpenCompactCLHash_InnerInsertSingleNoOverwrite(tableData,\n" | |
| 5664 | " keys[i],\n" | |
| 5665 | " values\n" | |
| 5666 | " [i]);\n" | |
| 5667 | "}\n" | |
| 5668 | "__kernel void intintLCGLinearOpenCompactCLHash_RangeInsertNoOverwrite(__global\n" | |
| 5669 | " char\n" | |
| 5670 | " *tableData,\n" | |
| 5671 | " unsigned\n" | |
| 5672 | " int\n" | |
| 5673 | " numInsertions,\n" | |
| 5674 | " unsigned\n" | |
| 5675 | " int\n" | |
| 5676 | " numEntries,\n" | |
| 5677 | " __global\n" | |
| 5678 | " int *keys,\n" | |
| 5679 | " __global\n" | |
| 5680 | " int\n" | |
| 5681 | " *values) {\n" | |
| 5682 | " uint i = get_global_id(0);\n" | |
| 5683 | " if (i >= numInsertions) {\n" | |
| 5684 | " return;\n" | |
| 5685 | " }\n" | |
| 5686 | " intintLCGLinearOpenCompactCLHash_InnerInsertNoOverwrite(tableData,\n" | |
| 5687 | " numEntries,\n" | |
| 5688 | " keys +\n" | |
| 5689 | " (i *\n" | |
| 5690 | " numEntries),\n" | |
| 5691 | " values +\n" | |
| 5692 | " (i *\n" | |
| 5693 | " numEntries));\n" | |
| 5694 | "}\n" | |
| 5695 | "\n" | |
| 5696 | "typedef struct intintLCGQuadraticOpenCompactCLHash_TableData {\n" | |
| 5697 | " int hashID;\n" | |
| 5698 | " unsigned int numBuckets;\n" | |
| 5699 | " intintHash_CompressLCGData compressFuncData;\n" | |
| 5700 | "} intintLCGQuadraticOpenCompactCLHash_TableData;\n" | |
| 5701 | "typedef struct intintLCGQuadraticOpenCompactCLHash_Bucket {\n" | |
| 5702 | " int key;\n" | |
| 5703 | " int value;\n" | |
| 5704 | "} intintLCGQuadraticOpenCompactCLHash_Bucket;\n" | |
| 5705 | "int intintLCGQuadraticOpenCompactCLHash_InnerQuerySingle(__global char\n" | |
| 5706 | " *tableData, int key,\n" | |
| 5707 | " __global int\n" | |
| 5708 | " *valueOutput) {\n" | |
| 5709 | " __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets =\n" | |
| 5710 | " (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) &\n" | |
| 5711 | " tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)];\n" | |
| 5712 | " int index;\n" | |
| 5713 | " int exitCode;\n" | |
| 5714 | " __global intintLCGQuadraticOpenCompactCLHash_TableData *mytableData =\n" | |
| 5715 | " (__global intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5716 | " tableData;\n" | |
| 5717 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5718 | " mytableData->compressFuncData;\n" | |
| 5719 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5720 | " unsigned long int iteration = 0;\n" | |
| 5721 | " for (;;) {\n" | |
| 5722 | " index =\n" | |
| 5723 | " ((1 * iteration * iteration + 0 * iteration +\n" | |
| 5724 | " c) %\n" | |
| 5725 | " ((__global intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5726 | " tableData)->numBuckets);\n" | |
| 5727 | " if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5728 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5729 | " break;\n" | |
| 5730 | " } else if (key == buckets[index].key) {\n" | |
| 5731 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5732 | " break;\n" | |
| 5733 | " } else\n" | |
| 5734 | " if ((iteration >\n" | |
| 5735 | " ((__global\n" | |
| 5736 | " intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5737 | " tableData)->numBuckets)) {\n" | |
| 5738 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5739 | " break;\n" | |
| 5740 | " }\n" | |
| 5741 | " iteration++;\n" | |
| 5742 | " }\n" | |
| 5743 | " switch (exitCode) {\n" | |
| 5744 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5745 | " *valueOutput = buckets[index].value;\n" | |
| 5746 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 5747 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5748 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5749 | " return HASH_EXIT_CODE_KEY_DNE;\n" | |
| 5750 | " default:\n" | |
| 5751 | " return exitCode;\n" | |
| 5752 | " }\n" | |
| 5753 | "}\n" | |
| 5754 | "int intintLCGQuadraticOpenCompactCLHash_InnerQuery(__global char *tableData,\n" | |
| 5755 | " unsigned int numKeys,\n" | |
| 5756 | " __global int *keys,\n" | |
| 5757 | " __global int *valuesOutput) {\n" | |
| 5758 | " __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets =\n" | |
| 5759 | " (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) &\n" | |
| 5760 | " tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)];\n" | |
| 5761 | " int key;\n" | |
| 5762 | " __global int *valueOutput;\n" | |
| 5763 | " int index;\n" | |
| 5764 | " int exitCode;\n" | |
| 5765 | " uint i;\n" | |
| 5766 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 5767 | " for (i = 0; i < numKeys; i++) {\n" | |
| 5768 | " key = keys[i];\n" | |
| 5769 | " valueOutput = &valuesOutput[i];\n" | |
| 5770 | " __global intintLCGQuadraticOpenCompactCLHash_TableData\n" | |
| 5771 | " *mytableData =\n" | |
| 5772 | " (__global intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5773 | " tableData;\n" | |
| 5774 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5775 | " mytableData->compressFuncData;\n" | |
| 5776 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5777 | " unsigned long int iteration = 0;\n" | |
| 5778 | " for (;;) {\n" | |
| 5779 | " index =\n" | |
| 5780 | " ((1 * iteration * iteration + 0 * iteration +\n" | |
| 5781 | " c) %\n" | |
| 5782 | " ((__global\n" | |
| 5783 | " intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5784 | " tableData)->numBuckets);\n" | |
| 5785 | " if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5786 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5787 | " break;\n" | |
| 5788 | " } else if (key == buckets[index].key) {\n" | |
| 5789 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5790 | " break;\n" | |
| 5791 | " } else\n" | |
| 5792 | " if ((iteration >\n" | |
| 5793 | " ((__global\n" | |
| 5794 | " intintLCGQuadraticOpenCompactCLHash_TableData\n" | |
| 5795 | " *) tableData)->numBuckets)) {\n" | |
| 5796 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5797 | " break;\n" | |
| 5798 | " }\n" | |
| 5799 | " iteration++;\n" | |
| 5800 | " }\n" | |
| 5801 | " switch (exitCode) {\n" | |
| 5802 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5803 | " *valueOutput = buckets[index].value;\n" | |
| 5804 | " break;\n" | |
| 5805 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5806 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5807 | " resultExitCode = HASH_EXIT_CODE_KEY_DNE;\n" | |
| 5808 | " break;\n" | |
| 5809 | " default:\n" | |
| 5810 | " return exitCode;\n" | |
| 5811 | " }\n" | |
| 5812 | " }\n" | |
| 5813 | " return resultExitCode;\n" | |
| 5814 | "}\n" | |
| 5815 | "int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingle(__global char\n" | |
| 5816 | " *tableData, int key,\n" | |
| 5817 | " int value) {\n" | |
| 5818 | " __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets =\n" | |
| 5819 | " (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) &\n" | |
| 5820 | " tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)];\n" | |
| 5821 | " int index;\n" | |
| 5822 | " int exitCode;\n" | |
| 5823 | " __global intintLCGQuadraticOpenCompactCLHash_TableData *mytableData =\n" | |
| 5824 | " (__global intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5825 | " tableData;\n" | |
| 5826 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5827 | " mytableData->compressFuncData;\n" | |
| 5828 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5829 | " unsigned long int iteration = 0;\n" | |
| 5830 | " for (;;) {\n" | |
| 5831 | " index =\n" | |
| 5832 | " ((1 * iteration * iteration + 0 * iteration +\n" | |
| 5833 | " c) %\n" | |
| 5834 | " ((__global intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5835 | " tableData)->numBuckets);\n" | |
| 5836 | " if ((atomic_cmpxchg\n" | |
| 5837 | " (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY,\n" | |
| 5838 | " key)) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5839 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5840 | " break;\n" | |
| 5841 | " } else if (key == buckets[index].key) {\n" | |
| 5842 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5843 | " break;\n" | |
| 5844 | " } else\n" | |
| 5845 | " if ((iteration >\n" | |
| 5846 | " ((__global\n" | |
| 5847 | " intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5848 | " tableData)->numBuckets)) {\n" | |
| 5849 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5850 | " break;\n" | |
| 5851 | " }\n" | |
| 5852 | " iteration++;\n" | |
| 5853 | " }\n" | |
| 5854 | " switch (exitCode) {\n" | |
| 5855 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5856 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5857 | " buckets[index].value = value;\n" | |
| 5858 | " return HASH_EXIT_CODE_OVERWRITE;\n" | |
| 5859 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5860 | " buckets[index].value = value;\n" | |
| 5861 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 5862 | " default:\n" | |
| 5863 | " return exitCode;\n" | |
| 5864 | " }\n" | |
| 5865 | "}\n" | |
| 5866 | "int intintLCGQuadraticOpenCompactCLHash_InnerInsert(__global char *tableData,\n" | |
| 5867 | " unsigned int numEntries,\n" | |
| 5868 | " __global int *keys,\n" | |
| 5869 | " __global int *values) {\n" | |
| 5870 | " __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets =\n" | |
| 5871 | " (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) &\n" | |
| 5872 | " tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)];\n" | |
| 5873 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 5874 | " int key;\n" | |
| 5875 | " int value;\n" | |
| 5876 | " int index;\n" | |
| 5877 | " int exitCode;\n" | |
| 5878 | " uint i;\n" | |
| 5879 | " for (i = 0; i < numEntries; i++) {\n" | |
| 5880 | " key = keys[i];\n" | |
| 5881 | " __global intintLCGQuadraticOpenCompactCLHash_TableData\n" | |
| 5882 | " *mytableData =\n" | |
| 5883 | " (__global intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5884 | " tableData;\n" | |
| 5885 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5886 | " mytableData->compressFuncData;\n" | |
| 5887 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5888 | " unsigned long int iteration = 0;\n" | |
| 5889 | " for (;;) {\n" | |
| 5890 | " index =\n" | |
| 5891 | " ((1 * iteration * iteration + 0 * iteration +\n" | |
| 5892 | " c) %\n" | |
| 5893 | " ((__global\n" | |
| 5894 | " intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5895 | " tableData)->numBuckets);\n" | |
| 5896 | " if ((atomic_cmpxchg\n" | |
| 5897 | " (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY,\n" | |
| 5898 | " key)) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5899 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5900 | " break;\n" | |
| 5901 | " } else if (key == buckets[index].key) {\n" | |
| 5902 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5903 | " break;\n" | |
| 5904 | " } else\n" | |
| 5905 | " if ((iteration >\n" | |
| 5906 | " ((__global\n" | |
| 5907 | " intintLCGQuadraticOpenCompactCLHash_TableData\n" | |
| 5908 | " *) tableData)->numBuckets)) {\n" | |
| 5909 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5910 | " break;\n" | |
| 5911 | " }\n" | |
| 5912 | " iteration++;\n" | |
| 5913 | " }\n" | |
| 5914 | " switch (exitCode) {\n" | |
| 5915 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5916 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5917 | " resultExitCode = HASH_EXIT_CODE_OVERWRITE;\n" | |
| 5918 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5919 | " buckets[index].value = values[i];\n" | |
| 5920 | " break;\n" | |
| 5921 | " default:\n" | |
| 5922 | " return exitCode;\n" | |
| 5923 | " }\n" | |
| 5924 | " }\n" | |
| 5925 | " return resultExitCode;\n" | |
| 5926 | "}\n" | |
| 5927 | "int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global\n" | |
| 5928 | " char\n" | |
| 5929 | " *tableData,\n" | |
| 5930 | " int key,\n" | |
| 5931 | " int value) \n" | |
| 5932 | "{\n" | |
| 5933 | " __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets =\n" | |
| 5934 | " (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) &\n" | |
| 5935 | " tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)];\n" | |
| 5936 | " int index;\n" | |
| 5937 | " int exitCode;\n" | |
| 5938 | " __global intintLCGQuadraticOpenCompactCLHash_TableData *mytableData =\n" | |
| 5939 | " (__global intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5940 | " tableData;\n" | |
| 5941 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5942 | " mytableData->compressFuncData;\n" | |
| 5943 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5944 | " unsigned long int iteration = 0;\n" | |
| 5945 | " for (;;) {\n" | |
| 5946 | " index =\n" | |
| 5947 | " ((1 * iteration * iteration + 0 * iteration +\n" | |
| 5948 | " c) %\n" | |
| 5949 | " ((__global intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5950 | " tableData)->numBuckets);\n" | |
| 5951 | " if ((atomic_cmpxchg\n" | |
| 5952 | " (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY,\n" | |
| 5953 | " key)) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5954 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5955 | " break;\n" | |
| 5956 | " } else if (key == buckets[index].key) {\n" | |
| 5957 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5958 | " break;\n" | |
| 5959 | " } else\n" | |
| 5960 | " if ((iteration >\n" | |
| 5961 | " ((__global\n" | |
| 5962 | " intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5963 | " tableData)->numBuckets)) {\n" | |
| 5964 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5965 | " break;\n" | |
| 5966 | " }\n" | |
| 5967 | " iteration++;\n" | |
| 5968 | " }\n" | |
| 5969 | " switch (exitCode) {\n" | |
| 5970 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5971 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5972 | " return HASH_EXIT_CODE_OVERWRITE;\n" | |
| 5973 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5974 | " buckets[index].value = value;\n" | |
| 5975 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 5976 | " default:\n" | |
| 5977 | " return exitCode;\n" | |
| 5978 | " }\n" | |
| 5979 | "}\n" | |
| 5980 | "int intintLCGQuadraticOpenCompactCLHash_InnerInsertNoOverwrite(__global char\n" | |
| 5981 | " *tableData,\n" | |
| 5982 | " unsigned int\n" | |
| 5983 | " numEntries,\n" | |
| 5984 | " __global int\n" | |
| 5985 | " *keys,\n" | |
| 5986 | " __global int\n" | |
| 5987 | " *values) {\n" | |
| 5988 | " __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets =\n" | |
| 5989 | " (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) &\n" | |
| 5990 | " tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)];\n" | |
| 5991 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 5992 | " int key;\n" | |
| 5993 | " int value;\n" | |
| 5994 | " int index;\n" | |
| 5995 | " int exitCode;\n" | |
| 5996 | " uint i;\n" | |
| 5997 | " for (i = 0; i < numEntries; i++) {\n" | |
| 5998 | " key = keys[i];\n" | |
| 5999 | " __global intintLCGQuadraticOpenCompactCLHash_TableData\n" | |
| 6000 | " *mytableData =\n" | |
| 6001 | " (__global intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 6002 | " tableData;\n" | |
| 6003 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 6004 | " mytableData->compressFuncData;\n" | |
| 6005 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 6006 | " unsigned long int iteration = 0;\n" | |
| 6007 | " for (;;) {\n" | |
| 6008 | " index =\n" | |
| 6009 | " ((1 * iteration * iteration + 0 * iteration +\n" | |
| 6010 | " c) %\n" | |
| 6011 | " ((__global\n" | |
| 6012 | " intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 6013 | " tableData)->numBuckets);\n" | |
| 6014 | " if ((atomic_cmpxchg\n" | |
| 6015 | " (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY,\n" | |
| 6016 | " key)) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 6017 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 6018 | " break;\n" | |
| 6019 | " } else if (key == buckets[index].key) {\n" | |
| 6020 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 6021 | " break;\n" | |
| 6022 | " } else\n" | |
| 6023 | " if ((iteration >\n" | |
| 6024 | " ((__global\n" | |
| 6025 | " intintLCGQuadraticOpenCompactCLHash_TableData\n" | |
| 6026 | " *) tableData)->numBuckets)) {\n" | |
| 6027 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 6028 | " break;\n" | |
| 6029 | " }\n" | |
| 6030 | " iteration++;\n" | |
| 6031 | " }\n" | |
| 6032 | " switch (exitCode) {\n" | |
| 6033 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 6034 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 6035 | " resultExitCode = HASH_EXIT_CODE_OVERWRITE;\n" | |
| 6036 | " break;\n" | |
| 6037 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 6038 | " buckets[index].value = values[i];\n" | |
| 6039 | " break;\n" | |
| 6040 | " default:\n" | |
| 6041 | " return exitCode;\n" | |
| 6042 | " }\n" | |
| 6043 | " }\n" | |
| 6044 | " return resultExitCode;\n" | |
| 6045 | "}\n" | |
| 6046 | "int intintLCGQuadraticOpenCompactCLHash_QuerySingle(__global char *tableData,\n" | |
| 6047 | " int key,\n" | |
| 6048 | " __global int *valueOutput) {\n" | |
| 6049 | " return intintLCGQuadraticOpenCompactCLHash_InnerQuerySingle(tableData,\n" | |
| 6050 | " key,\n" | |
| 6051 | " valueOutput);\n" | |
| 6052 | "}\n" | |
| 6053 | "int intintLCGQuadraticOpenCompactCLHash_Query(__global char *tableData,\n" | |
| 6054 | " size_t numKeys,\n" | |
| 6055 | " __global int *keys,\n" | |
| 6056 | " __global int *valuesOutput) {\n" | |
| 6057 | " return intintLCGQuadraticOpenCompactCLHash_InnerQuery(tableData,\n" | |
| 6058 | " numKeys, keys,\n" | |
| 6059 | " valuesOutput);\n" | |
| 6060 | "}\n" | |
| 6061 | "int intintLCGQuadraticOpenCompactCLHash_InsertSingle(__global char *tableData,\n" | |
| 6062 | " int key, int value) {\n" | |
| 6063 | " return intintLCGQuadraticOpenCompactCLHash_InnerInsertSingle(tableData,\n" | |
| 6064 | " key,\n" | |
| 6065 | " value);\n" | |
| 6066 | "}\n" | |
| 6067 | "int intintLCGQuadraticOpenCompactCLHash_Insert(__global char *tableData,\n" | |
| 6068 | " size_t numEntries,\n" | |
| 6069 | " __global int *keys,\n" | |
| 6070 | " __global int *values) {\n" | |
| 6071 | " return intintLCGQuadraticOpenCompactCLHash_InnerInsert(tableData,\n" | |
| 6072 | " numEntries, keys,\n" | |
| 6073 | " values);\n" | |
| 6074 | "}\n" | |
| 6075 | "int intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite(__global char\n" | |
| 6076 | " *tableData,\n" | |
| 6077 | " int key,\n" | |
| 6078 | " int value) {\n" | |
| 6079 | " return\n" | |
| 6080 | " intintLCGQuadraticOpenCompactCLHash_InnerInsertSingleNoOverwrite\n" | |
| 6081 | " (tableData, key, value);\n" | |
| 6082 | "}\n" | |
| 6083 | "int intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite(__global char\n" | |
| 6084 | " *tableData,\n" | |
| 6085 | " size_t numEntries,\n" | |
| 6086 | " __global int *keys,\n" | |
| 6087 | " __global int *values) \n" | |
| 6088 | "{\n" | |
| 6089 | " return\n" | |
| 6090 | " intintLCGQuadraticOpenCompactCLHash_InnerInsertNoOverwrite\n" | |
| 6091 | " (tableData, numEntries, keys, values);\n" | |
| 6092 | "}\n" | |
| 6093 | "__kernel void intintLCGQuadraticOpenCompactCLHash_RangeQuerySingle(__global char\n" | |
| 6094 | " *tableData,\n" | |
| 6095 | " unsigned int\n" | |
| 6096 | " numQueries,\n" | |
| 6097 | " __global int\n" | |
| 6098 | " *keys,\n" | |
| 6099 | " __global int\n" | |
| 6100 | " *valuesOutput) \n" | |
| 6101 | "{\n" | |
| 6102 | " uint i = get_global_id(0);\n" | |
| 6103 | " if (i >= numQueries) {\n" | |
| 6104 | " return;\n" | |
| 6105 | " }\n" | |
| 6106 | " intintLCGQuadraticOpenCompactCLHash_InnerQuerySingle(tableData, keys[i],\n" | |
| 6107 | " valuesOutput + i);\n" | |
| 6108 | "}\n" | |
| 6109 | "__kernel void intintLCGQuadraticOpenCompactCLHash_RangeQuery(__global char\n" | |
| 6110 | " *tableData,\n" | |
| 6111 | " unsigned int\n" | |
| 6112 | " numQueries,\n" | |
| 6113 | " unsigned int\n" | |
| 6114 | " numKeys,\n" | |
| 6115 | " __global int *keys,\n" | |
| 6116 | " __global int\n" | |
| 6117 | " *valuesOutput) {\n" | |
| 6118 | " uint i = get_global_id(0);\n" | |
| 6119 | " if (i >= numQueries) {\n" | |
| 6120 | " return;\n" | |
| 6121 | " }\n" | |
| 6122 | " intintLCGQuadraticOpenCompactCLHash_InnerQuery(tableData, numKeys,\n" | |
| 6123 | " keys + (i * numKeys),\n" | |
| 6124 | " valuesOutput +\n" | |
| 6125 | " (i * numKeys));\n" | |
| 6126 | "}\n" | |
| 6127 | "__kernel void intintLCGQuadraticOpenCompactCLHash_RangeInsertSingle(__global\n" | |
| 6128 | " char\n" | |
| 6129 | " *tableData,\n" | |
| 6130 | " unsigned int\n" | |
| 6131 | " numInsertions,\n" | |
| 6132 | " __global int\n" | |
| 6133 | " *keys,\n" | |
| 6134 | " __global int\n" | |
| 6135 | " *values) {\n" | |
| 6136 | " uint i = get_global_id(0);\n" | |
| 6137 | " if (i >= numInsertions) {\n" | |
| 6138 | " return;\n" | |
| 6139 | " }\n" | |
| 6140 | " intintLCGQuadraticOpenCompactCLHash_InnerInsertSingle(tableData,\n" | |
| 6141 | " keys[i],\n" | |
| 6142 | " values[i]);\n" | |
| 6143 | "}\n" | |
| 6144 | "__kernel void intintLCGQuadraticOpenCompactCLHash_RangeInsert(__global char\n" | |
| 6145 | " *tableData,\n" | |
| 6146 | " unsigned int\n" | |
| 6147 | " numInsertions,\n" | |
| 6148 | " unsigned int\n" | |
| 6149 | " numEntries,\n" | |
| 6150 | " __global int\n" | |
| 6151 | " *keys,\n" | |
| 6152 | " __global int\n" | |
| 6153 | " *values) {\n" | |
| 6154 | " uint i = get_global_id(0);\n" | |
| 6155 | " if (i >= numInsertions) {\n" | |
| 6156 | " return;\n" | |
| 6157 | " }\n" | |
| 6158 | " intintLCGQuadraticOpenCompactCLHash_InnerInsert(tableData, numEntries,\n" | |
| 6159 | " keys + (i * numEntries),\n" | |
| 6160 | " values +\n" | |
| 6161 | " (i * numEntries));\n" | |
| 6162 | "}\n" | |
| 6163 | "__kernel void\n" | |
| 6164 | "intintLCGQuadraticOpenCompactCLHash_RangeInsertSingleNoOverwrite(__global char\n" | |
| 6165 | " *tableData,\n" | |
| 6166 | " unsigned int\n" | |
| 6167 | " numInsertions,\n" | |
| 6168 | " __global int\n" | |
| 6169 | " *keys,\n" | |
| 6170 | " __global int\n" | |
| 6171 | " *values) {\n" | |
| 6172 | " uint i = get_global_id(0);\n" | |
| 6173 | " if (i >= numInsertions) {\n" | |
| 6174 | " return;\n" | |
| 6175 | " }\n" | |
| 6176 | " intintLCGQuadraticOpenCompactCLHash_InnerInsertSingleNoOverwrite\n" | |
| 6177 | " (tableData, keys[i], values[i]);\n" | |
| 6178 | "}\n" | |
| 6179 | "__kernel void\n" | |
| 6180 | "intintLCGQuadraticOpenCompactCLHash_RangeInsertNoOverwrite(__global char\n" | |
| 6181 | " *tableData,\n" | |
| 6182 | " unsigned int\n" | |
| 6183 | " numInsertions,\n" | |
| 6184 | " unsigned int\n" | |
| 6185 | " numEntries,\n" | |
| 6186 | " __global int *keys,\n" | |
| 6187 | " __global int\n" | |
| 6188 | " *values) {\n" | |
| 6189 | " uint i = get_global_id(0);\n" | |
| 6190 | " if (i >= numInsertions) {\n" | |
| 6191 | " return;\n" | |
| 6192 | " }\n" | |
| 6193 | " intintLCGQuadraticOpenCompactCLHash_InnerInsertNoOverwrite(tableData,\n" | |
| 6194 | " numEntries,\n" | |
| 6195 | " keys +\n" | |
| 6196 | " (i *\n" | |
| 6197 | " numEntries),\n" | |
| 6198 | " values +\n" | |
| 6199 | " (i *\n" | |
| 6200 | " numEntries));\n" | |
| 6201 | "}\n" | |
| 6202 | "__kernel void intintHash_RangeQuery(__global char *tableData,\n" | |
| 6203 | " unsigned int numQueries,\n" | |
| 6204 | " unsigned int numKeys, __global int *keys,\n" | |
| 6205 | " __global int *valuesOutput) {\n" | |
| 6206 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6207 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6208 | " return intintIdentityPerfectCLHash_RangeQuery(tableData,\n" | |
| 6209 | " numQueries,\n" | |
| 6210 | " numKeys, keys,\n" | |
| 6211 | " valuesOutput);\n" | |
| 6212 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6213 | " return intintIdentitySentinelPerfectCLHash_RangeQuery(tableData,\n" | |
| 6214 | " numQueries,\n" | |
| 6215 | " numKeys,\n" | |
| 6216 | " keys,\n" | |
| 6217 | " valuesOutput);\n" | |
| 6218 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6219 | " return intintLCGLinearOpenCompactCLHash_RangeQuery(tableData,\n" | |
| 6220 | " numQueries,\n" | |
| 6221 | " numKeys,\n" | |
| 6222 | " keys,\n" | |
| 6223 | " valuesOutput);\n" | |
| 6224 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6225 | " return intintLCGQuadraticOpenCompactCLHash_RangeQuery(tableData,\n" | |
| 6226 | " numQueries,\n" | |
| 6227 | " numKeys,\n" | |
| 6228 | " keys,\n" | |
| 6229 | " valuesOutput);\n" | |
| 6230 | " }\n" | |
| 6231 | "}\n" | |
| 6232 | "__kernel void intintHash_RangeQuerySingle(__global char *tableData,\n" | |
| 6233 | " unsigned int numQueries,\n" | |
| 6234 | " __global int *keys,\n" | |
| 6235 | " __global int *valueOutput) {\n" | |
| 6236 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6237 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6238 | " return intintIdentityPerfectCLHash_RangeQuerySingle(tableData,\n" | |
| 6239 | " numQueries,\n" | |
| 6240 | " keys,\n" | |
| 6241 | " valueOutput);\n" | |
| 6242 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6243 | " return\n" | |
| 6244 | " intintIdentitySentinelPerfectCLHash_RangeQuerySingle\n" | |
| 6245 | " (tableData, numQueries, keys, valueOutput);\n" | |
| 6246 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6247 | " return\n" | |
| 6248 | " intintLCGLinearOpenCompactCLHash_RangeQuerySingle(tableData,\n" | |
| 6249 | " numQueries,\n" | |
| 6250 | " keys,\n" | |
| 6251 | " valueOutput);\n" | |
| 6252 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6253 | " return\n" | |
| 6254 | " intintLCGQuadraticOpenCompactCLHash_RangeQuerySingle\n" | |
| 6255 | " (tableData, numQueries, keys, valueOutput);\n" | |
| 6256 | " }\n" | |
| 6257 | "}\n" | |
| 6258 | "__kernel void intintHash_RangeInsert(__global char *tableData,\n" | |
| 6259 | " unsigned int numInsertions,\n" | |
| 6260 | " unsigned int numEntries,\n" | |
| 6261 | " __global int *keys, __global int *values) {\n" | |
| 6262 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6263 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6264 | " return intintIdentityPerfectCLHash_RangeInsert(tableData,\n" | |
| 6265 | " numInsertions,\n" | |
| 6266 | " numEntries, keys,\n" | |
| 6267 | " values);\n" | |
| 6268 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6269 | " return\n" | |
| 6270 | " intintIdentitySentinelPerfectCLHash_RangeInsert(tableData,\n" | |
| 6271 | " numInsertions,\n" | |
| 6272 | " numEntries,\n" | |
| 6273 | " keys,\n" | |
| 6274 | " values);\n" | |
| 6275 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6276 | " return intintLCGLinearOpenCompactCLHash_RangeInsert(tableData,\n" | |
| 6277 | " numInsertions,\n" | |
| 6278 | " numEntries,\n" | |
| 6279 | " keys,\n" | |
| 6280 | " values);\n" | |
| 6281 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6282 | " return\n" | |
| 6283 | " intintLCGQuadraticOpenCompactCLHash_RangeInsert(tableData,\n" | |
| 6284 | " numInsertions,\n" | |
| 6285 | " numEntries,\n" | |
| 6286 | " keys,\n" | |
| 6287 | " values);\n" | |
| 6288 | " }\n" | |
| 6289 | "}\n" | |
| 6290 | "__kernel void intintHash_RangeInsertSingle(__global char *tableData,\n" | |
| 6291 | " unsigned int numInsertions,\n" | |
| 6292 | " __global int *keys,\n" | |
| 6293 | " __global int *values) {\n" | |
| 6294 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6295 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6296 | " return intintIdentityPerfectCLHash_RangeInsertSingle(tableData,\n" | |
| 6297 | " numInsertions,\n" | |
| 6298 | " keys,\n" | |
| 6299 | " values);\n" | |
| 6300 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6301 | " return\n" | |
| 6302 | " intintIdentitySentinelPerfectCLHash_RangeInsertSingle\n" | |
| 6303 | " (tableData, numInsertions, keys, values);\n" | |
| 6304 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6305 | " return\n" | |
| 6306 | " intintLCGLinearOpenCompactCLHash_RangeInsertSingle\n" | |
| 6307 | " (tableData, numInsertions, keys, values);\n" | |
| 6308 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6309 | " return\n" | |
| 6310 | " intintLCGQuadraticOpenCompactCLHash_RangeInsertSingle\n" | |
| 6311 | " (tableData, numInsertions, keys, values);\n" | |
| 6312 | " }\n" | |
| 6313 | "}\n" | |
| 6314 | "__kernel void intintHash_RangeInsertNoOverwrite(__global char *tableData,\n" | |
| 6315 | " unsigned int numInsertions,\n" | |
| 6316 | " unsigned int numEntries,\n" | |
| 6317 | " __global int *keys,\n" | |
| 6318 | " __global int *values) {\n" | |
| 6319 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6320 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6321 | " return\n" | |
| 6322 | " intintIdentityPerfectCLHash_RangeInsertNoOverwrite\n" | |
| 6323 | " (tableData, numInsertions, numEntries, keys, values);\n" | |
| 6324 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6325 | " return\n" | |
| 6326 | " intintIdentitySentinelPerfectCLHash_RangeInsertNoOverwrite\n" | |
| 6327 | " (tableData, numInsertions, numEntries, keys, values);\n" | |
| 6328 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6329 | " return\n" | |
| 6330 | " intintLCGLinearOpenCompactCLHash_RangeInsertNoOverwrite\n" | |
| 6331 | " (tableData, numInsertions, numEntries, keys, values);\n" | |
| 6332 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6333 | " return\n" | |
| 6334 | " intintLCGQuadraticOpenCompactCLHash_RangeInsertNoOverwrite\n" | |
| 6335 | " (tableData, numInsertions, numEntries, keys, values);\n" | |
| 6336 | " }\n" | |
| 6337 | "}\n" | |
| 6338 | "__kernel void intintHash_RangeInsertSingleNoOverwrite(__global char *tableData,\n" | |
| 6339 | " unsigned int\n" | |
| 6340 | " numInsertions,\n" | |
| 6341 | " __global int *keys,\n" | |
| 6342 | " __global int *values) {\n" | |
| 6343 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6344 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6345 | " return\n" | |
| 6346 | " intintIdentityPerfectCLHash_RangeInsertSingleNoOverwrite\n" | |
| 6347 | " (tableData, numInsertions, keys, values);\n" | |
| 6348 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6349 | " return\n" | |
| 6350 | " intintIdentitySentinelPerfectCLHash_RangeInsertSingleNoOverwrite\n" | |
| 6351 | " (tableData, numInsertions, keys, values);\n" | |
| 6352 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6353 | " return\n" | |
| 6354 | " intintLCGLinearOpenCompactCLHash_RangeInsertSingleNoOverwrite\n" | |
| 6355 | " (tableData, numInsertions, keys, values);\n" | |
| 6356 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6357 | " return\n" | |
| 6358 | " intintLCGQuadraticOpenCompactCLHash_RangeInsertSingleNoOverwrite\n" | |
| 6359 | " (tableData, numInsertions, keys, values);\n" | |
| 6360 | " }\n" | |
| 6361 | "}\n" | |
| 6362 | "int intintHash_Query(__global char *tableData, unsigned int numKeys,\n" | |
| 6363 | " __global int *keys, __global int *valuesOutput) {\n" | |
| 6364 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6365 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6366 | " return intintIdentityPerfectCLHash_Query(tableData, numKeys,\n" | |
| 6367 | " keys, valuesOutput);\n" | |
| 6368 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6369 | " return intintIdentitySentinelPerfectCLHash_Query(tableData,\n" | |
| 6370 | " numKeys, keys,\n" | |
| 6371 | " valuesOutput);\n" | |
| 6372 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6373 | " return intintLCGLinearOpenCompactCLHash_Query(tableData,\n" | |
| 6374 | " numKeys, keys,\n" | |
| 6375 | " valuesOutput);\n" | |
| 6376 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6377 | " return intintLCGQuadraticOpenCompactCLHash_Query(tableData,\n" | |
| 6378 | " numKeys, keys,\n" | |
| 6379 | " valuesOutput);\n" | |
| 6380 | " }\n" | |
| 6381 | " return HASH_EXIT_CODE_ERROR;\n" | |
| 6382 | "}\n" | |
| 6383 | "int intintHash_QuerySingle(__global char *tableData, int key,\n" | |
| 6384 | " __global int *valueOutput) {\n" | |
| 6385 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6386 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6387 | " return intintIdentityPerfectCLHash_QuerySingle(tableData, key,\n" | |
| 6388 | " valueOutput);\n" | |
| 6389 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6390 | " return\n" | |
| 6391 | " intintIdentitySentinelPerfectCLHash_QuerySingle(tableData,\n" | |
| 6392 | " key,\n" | |
| 6393 | " valueOutput);\n" | |
| 6394 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6395 | " return intintLCGLinearOpenCompactCLHash_QuerySingle(tableData,\n" | |
| 6396 | " key,\n" | |
| 6397 | " valueOutput);\n" | |
| 6398 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6399 | " return\n" | |
| 6400 | " intintLCGQuadraticOpenCompactCLHash_QuerySingle(tableData,\n" | |
| 6401 | " key,\n" | |
| 6402 | " valueOutput);\n" | |
| 6403 | " }\n" | |
| 6404 | " return HASH_EXIT_CODE_ERROR;\n" | |
| 6405 | "}\n" | |
| 6406 | "int intintHash_Insert(__global char *tableData, unsigned int numEntries,\n" | |
| 6407 | " __global int *keys, __global int *values) {\n" | |
| 6408 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6409 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6410 | " return intintIdentityPerfectCLHash_Insert(tableData, numEntries,\n" | |
| 6411 | " keys, values);\n" | |
| 6412 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6413 | " return intintIdentitySentinelPerfectCLHash_Insert(tableData,\n" | |
| 6414 | " numEntries,\n" | |
| 6415 | " keys, values);\n" | |
| 6416 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6417 | " return intintLCGLinearOpenCompactCLHash_Insert(tableData,\n" | |
| 6418 | " numEntries, keys,\n" | |
| 6419 | " values);\n" | |
| 6420 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6421 | " return intintLCGQuadraticOpenCompactCLHash_Insert(tableData,\n" | |
| 6422 | " numEntries,\n" | |
| 6423 | " keys, values);\n" | |
| 6424 | " }\n" | |
| 6425 | " return HASH_EXIT_CODE_ERROR;\n" | |
| 6426 | "}\n" | |
| 6427 | "int intintHash_InsertSingle(__global char *tableData, int key, int value) {\n" | |
| 6428 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6429 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6430 | " return intintIdentityPerfectCLHash_InsertSingle(tableData, key,\n" | |
| 6431 | " value);\n" | |
| 6432 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6433 | " return\n" | |
| 6434 | " intintIdentitySentinelPerfectCLHash_InsertSingle(tableData,\n" | |
| 6435 | " key,\n" | |
| 6436 | " value);\n" | |
| 6437 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6438 | " return intintLCGLinearOpenCompactCLHash_InsertSingle(tableData,\n" | |
| 6439 | " key,\n" | |
| 6440 | " value);\n" | |
| 6441 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6442 | " return\n" | |
| 6443 | " intintLCGQuadraticOpenCompactCLHash_InsertSingle(tableData,\n" | |
| 6444 | " key,\n" | |
| 6445 | " value);\n" | |
| 6446 | " }\n" | |
| 6447 | " return HASH_EXIT_CODE_ERROR;\n" | |
| 6448 | "}\n" | |
| 6449 | "int intintHash_InsertNoOverwrite(__global char *tableData,\n" | |
| 6450 | " unsigned int numEntries, __global int *keys,\n" | |
| 6451 | " __global int *values) {\n" | |
| 6452 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6453 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6454 | " return intintIdentityPerfectCLHash_InsertNoOverwrite(tableData,\n" | |
| 6455 | " numEntries,\n" | |
| 6456 | " keys,\n" | |
| 6457 | " values);\n" | |
| 6458 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6459 | " return\n" | |
| 6460 | " intintIdentitySentinelPerfectCLHash_InsertNoOverwrite\n" | |
| 6461 | " (tableData, numEntries, keys, values);\n" | |
| 6462 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6463 | " return\n" | |
| 6464 | " intintLCGLinearOpenCompactCLHash_InsertNoOverwrite\n" | |
| 6465 | " (tableData, numEntries, keys, values);\n" | |
| 6466 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6467 | " return\n" | |
| 6468 | " intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite\n" | |
| 6469 | " (tableData, numEntries, keys, values);\n" | |
| 6470 | " }\n" | |
| 6471 | " return HASH_EXIT_CODE_ERROR;\n" | |
| 6472 | "}\n" | |
| 6473 | "int intintHash_InsertSingleNoOverwrite(__global char *tableData, int key,\n" | |
| 6474 | " int value) {\n" | |
| 6475 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6476 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6477 | " return\n" | |
| 6478 | " intintIdentityPerfectCLHash_InsertSingleNoOverwrite\n" | |
| 6479 | " (tableData, key, value);\n" | |
| 6480 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6481 | " return\n" | |
| 6482 | " intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite\n" | |
| 6483 | " (tableData, key, value);\n" | |
| 6484 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6485 | " return\n" | |
| 6486 | " intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite\n" | |
| 6487 | " (tableData, key, value);\n" | |
| 6488 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6489 | " return\n" | |
| 6490 | " intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite\n" | |
| 6491 | " (tableData, key, value);\n" | |
| 6492 | " }\n" | |
| 6493 | " return HASH_EXIT_CODE_ERROR;\n" | |
| 6494 | "}\n" | |
| 6495 | ; |
| … | … | @@ -0,0 +1,2348 @@ |
| 1 | ||
| 2 | /* Copyright (C) 1991-2012 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public | |
| 7 | License as published by the Free Software Foundation; either | |
| 8 | version 2.1 of the License, or (at your option) any later version. | |
| 9 | ||
| 10 | The GNU C Library is distributed in the hope that it will be useful, | |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | Lesser General Public License for more details. | |
| 14 | ||
| 15 | You should have received a copy of the GNU Lesser General Public | |
| 16 | License along with the GNU C Library; if not, see | |
| 17 | <http://www.gnu.org/licenses/>. */ | |
| 18 | /* This header is separate from features.h so that the compiler can | |
| 19 | include it implicitly at the start of every compilation. It must | |
| 20 | not itself include <features.h> or any other header that includes | |
| 21 | <features.h> because the implicit include comes before any feature | |
| 22 | test macros that may be defined in a source file before it first | |
| 23 | explicitly includes a system header. GCC knows the name of this | |
| 24 | header in order to preinclude it. */ | |
| 25 | /* We do support the IEC 559 math functionality, real and complex. */ | |
| 26 | /* wchar_t uses ISO/IEC 10646 (2nd ed., published 2011-03-15) / | |
| 27 | Unicode 6.0. */ | |
| 28 | /* We do not support C11 <threads.h>. */ | |
| 29 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 30 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 31 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 32 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 33 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 34 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 35 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 36 | * to produce derivative works, such modified software should be clearly marked, | |
| 37 | * so as not to confuse it with the version available from LANL. | |
| 38 | * | |
| 39 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 40 | * use this file except in compliance with the License. You may obtain a copy | |
| 41 | * of the License at | |
| 42 | * | |
| 43 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 44 | * | |
| 45 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 46 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 47 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 48 | * specific language governing permissions and limitations under the License. | |
| 49 | * | |
| 50 | * Under this license, it is required to include a reference to this work. We | |
| 51 | * request that each derivative work contain a reference to LANL Copyright | |
| 52 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 53 | * measured. In addition, it is requested that a modifier is included as in | |
| 54 | * the following example: | |
| 55 | * | |
| 56 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 57 | * | |
| 58 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 59 | */ | |
| 60 | int intintIdentityPerfectCLHash_InsertSingle(__global char *tableData, | |
| 61 | int key, int value); | |
| 62 | int intintIdentityPerfectCLHash_InnerInsertSingle(__global char *tableData, | |
| 63 | int key, int value); | |
| 64 | int intintHash_InsertSingle(__global char *tableData, int key, int value); | |
| 65 | int intintIdentityPerfectCLHash_InnerQuery(__global char *tableData, | |
| 66 | unsigned int numKeys, | |
| 67 | __global int *keys, | |
| 68 | __global int *valuesOutput); | |
| 69 | int intintIdentityPerfectCLHash_InnerQuerySingle(__global char *tableData, | |
| 70 | int key, | |
| 71 | __global int *valueOutput); | |
| 72 | int intintIdentityPerfectCLHash_InnerInsert(__global char *tableData, | |
| 73 | unsigned int numEntries, | |
| 74 | __global int *keys, | |
| 75 | __global int *values); | |
| 76 | int intintIdentityPerfectCLHash_InnerInsertSingleNoOverwrite(__global char | |
| 77 | *tableData, | |
| 78 | int key, | |
| 79 | int value); | |
| 80 | int intintIdentityPerfectCLHash_InnerInsertNoOverwrite(__global char *tableData, | |
| 81 | unsigned int numEntries, | |
| 82 | __global int *keys, | |
| 83 | __global int *values); | |
| 84 | int intintIdentityPerfectCLHash_QuerySingle(__global char *tableData, int key, | |
| 85 | __global int *valueOutput); | |
| 86 | int intintIdentityPerfectCLHash_QuerySingle(__global char *tableData, int key, | |
| 87 | __global int *valueOutput); | |
| 88 | int intintIdentityPerfectCLHash_Query(__global char *tableData, size_t numKeys, | |
| 89 | __global int *keys, | |
| 90 | __global int *valuesOutput); | |
| 91 | int intintIdentityPerfectCLHash_Insert(__global char *tableData, | |
| 92 | size_t numEntries, __global int *keys, | |
| 93 | __global int *values); | |
| 94 | int intintIdentityPerfectCLHash_InsertSingleNoOverwrite(__global char | |
| 95 | *tableData, int key, | |
| 96 | int value); | |
| 97 | int intintIdentityPerfectCLHash_InsertNoOverwrite(__global char *tableData, | |
| 98 | size_t numEntries, | |
| 99 | __global int *keys, | |
| 100 | __global int *values); | |
| 101 | int intintIdentitySentinelPerfectCLHash_InnerInsertNoOverwrite(__global char | |
| 102 | *tableData, | |
| 103 | unsigned int | |
| 104 | numEntries, | |
| 105 | __global int | |
| 106 | *keys, | |
| 107 | __global int | |
| 108 | *values); | |
| 109 | int intintIdentitySentinelPerfectCLHash_InnerQuerySingle(__global char | |
| 110 | *tableData, int key, | |
| 111 | __global int | |
| 112 | *valueOutput); | |
| 113 | int intintIdentitySentinelPerfectCLHash_InnerQuery(__global char *tableData, | |
| 114 | unsigned int numKeys, | |
| 115 | __global int *keys, | |
| 116 | __global int *valuesOutput); | |
| 117 | int intintIdentitySentinelPerfectCLHash_InnerInsertSingle(__global char | |
| 118 | *tableData, int key, | |
| 119 | int value); | |
| 120 | int intintIdentitySentinelPerfectCLHash_InnerInsert(__global char *tableData, | |
| 121 | unsigned int numEntries, | |
| 122 | __global int *keys, | |
| 123 | __global int *values); | |
| 124 | int intintIdentitySentinelPerfectCLHash_InnerInsertSingleNoOverwrite(__global | |
| 125 | char | |
| 126 | *tableData, | |
| 127 | int key, | |
| 128 | int value); | |
| 129 | int intintIdentitySentinelPerfectCLHash_QuerySingle(__global char *tableData, | |
| 130 | int key, | |
| 131 | __global int *valueOutput); | |
| 132 | int intintIdentitySentinelPerfectCLHash_Query(__global char *tableData, | |
| 133 | size_t numKeys, | |
| 134 | __global int *keys, | |
| 135 | __global int *valuesOutput); | |
| 136 | int intintIdentitySentinelPerfectCLHash_InsertSingle(__global char *tableData, | |
| 137 | int key, int value); | |
| 138 | int intintIdentitySentinelPerfectCLHash_Insert(__global char *tableData, | |
| 139 | size_t numEntries, | |
| 140 | __global int *keys, | |
| 141 | __global int *values); | |
| 142 | int intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite(__global char | |
| 143 | *tableData, | |
| 144 | int key, | |
| 145 | int value); | |
| 146 | int intintIdentitySentinelPerfectCLHash_InsertNoOverwrite(__global char | |
| 147 | *tableData, | |
| 148 | size_t numEntries, | |
| 149 | __global int *keys, | |
| 150 | __global int *values); | |
| 151 | int intintLCGLinearOpenCompactCLHash_InnerQuerySingle(__global char *tableData, | |
| 152 | int key, | |
| 153 | __global int | |
| 154 | *valueOutput); | |
| 155 | int intintLCGLinearOpenCompactCLHash_QuerySingle(__global char *tableData, | |
| 156 | int key, | |
| 157 | __global int *valueOutput); | |
| 158 | int intintLCGLinearOpenCompactCLHash_Query(__global char *tableData, | |
| 159 | size_t numKeys, __global int *keys, | |
| 160 | __global int *valuesOutput); | |
| 161 | int intintLCGLinearOpenCompactCLHash_InsertSingle(__global char *tableData, | |
| 162 | int key, int value); | |
| 163 | int intintLCGLinearOpenCompactCLHash_Insert(__global char *tableData, | |
| 164 | size_t numEntries, | |
| 165 | __global int *keys, | |
| 166 | __global int *values); | |
| 167 | int intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite(__global char | |
| 168 | *tableData, | |
| 169 | int key, | |
| 170 | int value); | |
| 171 | int intintLCGLinearOpenCompactCLHash_InsertNoOverwrite(__global char *tableData, | |
| 172 | size_t numEntries, | |
| 173 | __global int *keys, | |
| 174 | __global int *values); | |
| 175 | int intintLCGLinearOpenCompactCLHash_InnerQuery(__global char *tableData, | |
| 176 | unsigned int numKeys, | |
| 177 | __global int *keys, | |
| 178 | __global int *valuesOutput); | |
| 179 | int intintLCGLinearOpenCompactCLHash_InnerInsertNoOverwrite(__global char | |
| 180 | *tableData, | |
| 181 | unsigned int | |
| 182 | numEntries, | |
| 183 | __global int *keys, | |
| 184 | __global int | |
| 185 | *values); | |
| 186 | int intintLCGLinearOpenCompactCLHash_InnerInsertSingle(__global char *tableData, | |
| 187 | int key, int value); | |
| 188 | int intintLCGLinearOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global char | |
| 189 | *tableData, | |
| 190 | int key, | |
| 191 | int value); | |
| 192 | int intintLCGLinearOpenCompactCLHash_InnerInsert(__global char *tableData, | |
| 193 | unsigned int numEntries, | |
| 194 | __global int *keys, | |
| 195 | __global int *values); | |
| 196 | int intintLCGQuadraticOpenCompactCLHash_InnerQuerySingle(__global char | |
| 197 | *tableData, int key, | |
| 198 | __global int | |
| 199 | *valueOutput); | |
| 200 | int intintLCGQuadraticOpenCompactCLHash_InnerQuery(__global char *tableData, | |
| 201 | unsigned int numKeys, | |
| 202 | __global int *keys, | |
| 203 | __global int *valuesOutput); | |
| 204 | int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingle(__global char | |
| 205 | *tableData, int key, | |
| 206 | int value); | |
| 207 | int intintLCGQuadraticOpenCompactCLHash_InnerInsert(__global char *tableData, | |
| 208 | unsigned int numEntries, | |
| 209 | __global int *keys, | |
| 210 | __global int *values); | |
| 211 | int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global | |
| 212 | char | |
| 213 | *tableData, | |
| 214 | int key, | |
| 215 | int value); | |
| 216 | int intintLCGQuadraticOpenCompactCLHash_InnerInsertNoOverwrite(__global char | |
| 217 | *tableData, | |
| 218 | unsigned int | |
| 219 | numEntries, | |
| 220 | __global int | |
| 221 | *keys, | |
| 222 | __global int | |
| 223 | *values); | |
| 224 | int intintLCGQuadraticOpenCompactCLHash_QuerySingle(__global char *tableData, | |
| 225 | int key, | |
| 226 | __global int *valueOutput); | |
| 227 | int intintLCGQuadraticOpenCompactCLHash_Query(__global char *tableData, | |
| 228 | size_t numKeys, | |
| 229 | __global int *keys, | |
| 230 | __global int *valuesOutput); | |
| 231 | int intintLCGQuadraticOpenCompactCLHash_InsertSingle(__global char *tableData, | |
| 232 | int key, int value); | |
| 233 | int intintLCGQuadraticOpenCompactCLHash_Insert(__global char *tableData, | |
| 234 | size_t numEntries, | |
| 235 | __global int *keys, | |
| 236 | __global int *values); | |
| 237 | int intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite(__global char | |
| 238 | *tableData, | |
| 239 | int key, | |
| 240 | int value); | |
| 241 | int intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite(__global char | |
| 242 | *tableData, | |
| 243 | size_t numEntries, | |
| 244 | __global int *keys, | |
| 245 | __global int *values); | |
| 246 | int intintHash_Query(__global char *tableData, unsigned int numKeys, | |
| 247 | __global int *keys, __global int *valuesOutput); | |
| 248 | int intintHash_QuerySingle(__global char *tableData, int key, | |
| 249 | __global int *valueOutput); | |
| 250 | int intintHash_Insert(__global char *tableData, unsigned int numEntries, | |
| 251 | __global int *keys, __global int *values); | |
| 252 | int intintHash_InsertNoOverwrite(__global char *tableData, | |
| 253 | unsigned int numEntries, __global int *keys, | |
| 254 | __global int *values); | |
| 255 | int intintHash_InsertSingleNoOverwrite(__global char *tableData, int key, | |
| 256 | int value); | |
| 257 | #define HASH_REPORT_NEVER /**/ 0 | |
| 258 | #define HASH_REPORT_CYCLE /**/ 1 | |
| 259 | #define HASH_REPORT_END /****/ 2 | |
| 260 | // | |
| 261 | #define HASH_EXIT_CODE_NORMAL /****************/ -1 | |
| 262 | #define HASH_EXIT_CODE_ERROR /*****************/ -2 | |
| 263 | #define HASH_EXIT_CODE_OVERWRITE /*************/ -3 | |
| 264 | #define HASH_EXIT_CODE_KEY_DNE /***************/ -4 | |
| 265 | #define HASH_EXIT_CODE_CYCLE /*****************/ -5 | |
| 266 | #define HASH_EXIT_CODE_MAX_ENTRIES_EXCEEDED /**/ -6 | |
| 267 | #define HASH_EXIT_CODE_BUCKET_INDEX_OOB /******/ -7 | |
| 268 | // | |
| 269 | #define HASH_SEARCH_CODE_MATCH /*****/ 0 | |
| 270 | #define HASH_SEARCH_CODE_MISMATCH /**/ 1 | |
| 271 | #define HASH_SEARCH_CODE_EMPTY /*****/ 2 | |
| 272 | // | |
| 273 | #define LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID /**/ 8 | |
| 274 | #define LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID /**/ 4 | |
| 275 | #define IDENTITY_SENTINEL_PERFECT_CL_HASH_ID /*******/ 2 | |
| 276 | #define IDENTITY_PERFECT_CL_HASH_ID /*******/ 1 | |
| 277 | // | |
| 278 | #define HASH_BUCKET_STATUS_EMPTY /**/ -1 | |
| 279 | #define HASH_BUCKET_STATUS_FULL /***/ -2 | |
| 280 | #define HASH_BUCKET_STATUS_LOCK /***/ -3 | |
| 281 | static inline unsigned int intintHash_CompressIdentity(char data, int hashCode) { | |
| 282 | return hashCode; | |
| 283 | } | |
| 284 | ||
| 285 | typedef struct intintHash_CompressLCGData { | |
| 286 | long unsigned int a; | |
| 287 | long unsigned int c; | |
| 288 | unsigned int m; | |
| 289 | unsigned int n; | |
| 290 | } intintHash_CompressLCGData; | |
| 291 | static inline unsigned int intintHash_CompressLCG(intintHash_CompressLCGData | |
| 292 | compressLCGData, | |
| 293 | int hashCode) { | |
| 294 | return ((compressLCGData.a * hashCode + | |
| 295 | compressLCGData.c) % compressLCGData.m) % compressLCGData.n; | |
| 296 | } | |
| 297 | ||
| 298 | typedef struct intintIdentityPerfectCLHash_TableData { | |
| 299 | int hashID; | |
| 300 | unsigned int numBuckets; | |
| 301 | char compressFuncData; | |
| 302 | } intintIdentityPerfectCLHash_TableData; | |
| 303 | typedef struct intintIdentityPerfectCLHash_Bucket { | |
| 304 | int key; | |
| 305 | int value; | |
| 306 | } intintIdentityPerfectCLHash_Bucket; | |
| 307 | int intintIdentityPerfectCLHash_InnerQuerySingle(__global char *tableData, | |
| 308 | int key, | |
| 309 | __global int *valueOutput) { | |
| 310 | __global intintIdentityPerfectCLHash_Bucket *buckets = | |
| 311 | (__global intintIdentityPerfectCLHash_Bucket *) & | |
| 312 | tableData[sizeof(intintIdentityPerfectCLHash_TableData)]; | |
| 313 | int index; | |
| 314 | int exitCode; | |
| 315 | index = | |
| 316 | intintHash_CompressIdentity(((__global | |
| 317 | intintIdentityPerfectCLHash_TableData | |
| 318 | *) tableData)->compressFuncData, key); | |
| 319 | if ((buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 320 | if (key == buckets[index].key) { | |
| 321 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 322 | } else { | |
| 323 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 324 | } | |
| 325 | } else { | |
| 326 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 327 | } | |
| 328 | switch (exitCode) { | |
| 329 | case HASH_SEARCH_CODE_MATCH: | |
| 330 | *valueOutput = buckets[index].value; | |
| 331 | return HASH_EXIT_CODE_NORMAL; | |
| 332 | case HASH_SEARCH_CODE_MISMATCH: | |
| 333 | case HASH_SEARCH_CODE_EMPTY: | |
| 334 | return HASH_EXIT_CODE_KEY_DNE; | |
| 335 | default: | |
| 336 | return exitCode; | |
| 337 | } | |
| 338 | } | |
| 339 | int intintIdentityPerfectCLHash_InnerQuery(__global char *tableData, | |
| 340 | unsigned int numKeys, | |
| 341 | __global int *keys, | |
| 342 | __global int *valuesOutput) { | |
| 343 | __global intintIdentityPerfectCLHash_Bucket *buckets = | |
| 344 | (__global intintIdentityPerfectCLHash_Bucket *) & | |
| 345 | tableData[sizeof(intintIdentityPerfectCLHash_TableData)]; | |
| 346 | int key; | |
| 347 | __global int *valueOutput; | |
| 348 | int index; | |
| 349 | int exitCode; | |
| 350 | uint i; | |
| 351 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 352 | for (i = 0; i < numKeys; i++) { | |
| 353 | key = keys[i]; | |
| 354 | valueOutput = &valuesOutput[i]; | |
| 355 | index = | |
| 356 | intintHash_CompressIdentity(((__global | |
| 357 | intintIdentityPerfectCLHash_TableData | |
| 358 | *) tableData)-> | |
| 359 | compressFuncData, key); | |
| 360 | if ((buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 361 | if (key == buckets[index].key) { | |
| 362 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 363 | } else { | |
| 364 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 365 | } | |
| 366 | } else { | |
| 367 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 368 | } | |
| 369 | switch (exitCode) { | |
| 370 | case HASH_SEARCH_CODE_MATCH: | |
| 371 | *valueOutput = buckets[index].value; | |
| 372 | break; | |
| 373 | case HASH_SEARCH_CODE_MISMATCH: | |
| 374 | case HASH_SEARCH_CODE_EMPTY: | |
| 375 | resultExitCode = HASH_EXIT_CODE_KEY_DNE; | |
| 376 | break; | |
| 377 | default: | |
| 378 | return exitCode; | |
| 379 | } | |
| 380 | } | |
| 381 | return resultExitCode; | |
| 382 | } | |
| 383 | int intintIdentityPerfectCLHash_InnerInsertSingle(__global char *tableData, | |
| 384 | int key, int value) { | |
| 385 | __global intintIdentityPerfectCLHash_Bucket *buckets = | |
| 386 | (__global intintIdentityPerfectCLHash_Bucket *) & | |
| 387 | tableData[sizeof(intintIdentityPerfectCLHash_TableData)]; | |
| 388 | int index; | |
| 389 | int exitCode; | |
| 390 | index = | |
| 391 | intintHash_CompressIdentity(((__global | |
| 392 | intintIdentityPerfectCLHash_TableData | |
| 393 | *) tableData)->compressFuncData, key); | |
| 394 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 395 | buckets[index]. | |
| 396 | key = key; | |
| 397 | HASH_BUCKET_STATUS_EMPTY;} | |
| 398 | ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 399 | if (key == buckets[index].key) { | |
| 400 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 401 | } else { | |
| 402 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 403 | } | |
| 404 | } else { | |
| 405 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 406 | } | |
| 407 | switch (exitCode) { | |
| 408 | case HASH_SEARCH_CODE_MATCH: | |
| 409 | case HASH_SEARCH_CODE_MISMATCH: | |
| 410 | buckets[index].value = value; | |
| 411 | return HASH_EXIT_CODE_OVERWRITE; | |
| 412 | case HASH_SEARCH_CODE_EMPTY: | |
| 413 | buckets[index].value = value; | |
| 414 | return HASH_EXIT_CODE_NORMAL; | |
| 415 | default: | |
| 416 | return exitCode; | |
| 417 | } | |
| 418 | } | |
| 419 | int intintIdentityPerfectCLHash_InnerInsert(__global char *tableData, | |
| 420 | unsigned int numEntries, | |
| 421 | __global int *keys, | |
| 422 | __global int *values) { | |
| 423 | __global intintIdentityPerfectCLHash_Bucket *buckets = | |
| 424 | (__global intintIdentityPerfectCLHash_Bucket *) & | |
| 425 | tableData[sizeof(intintIdentityPerfectCLHash_TableData)]; | |
| 426 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 427 | int key; | |
| 428 | int value; | |
| 429 | int index; | |
| 430 | int exitCode; | |
| 431 | uint i; | |
| 432 | for (i = 0; i < numEntries; i++) { | |
| 433 | key = keys[i]; | |
| 434 | index = | |
| 435 | intintHash_CompressIdentity(((__global | |
| 436 | intintIdentityPerfectCLHash_TableData | |
| 437 | *) tableData)-> | |
| 438 | compressFuncData, key); | |
| 439 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 440 | buckets | |
| 441 | [index]. | |
| 442 | key = | |
| 443 | key; | |
| 444 | HASH_BUCKET_STATUS_EMPTY;} | |
| 445 | ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 446 | if (key == buckets[index].key) { | |
| 447 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 448 | } else { | |
| 449 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 450 | } | |
| 451 | } else { | |
| 452 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 453 | } | |
| 454 | switch (exitCode) { | |
| 455 | case HASH_SEARCH_CODE_MATCH: | |
| 456 | case HASH_SEARCH_CODE_MISMATCH: | |
| 457 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 458 | case HASH_SEARCH_CODE_EMPTY: | |
| 459 | buckets[index].value = values[i]; | |
| 460 | break; | |
| 461 | default: | |
| 462 | return exitCode; | |
| 463 | } | |
| 464 | } | |
| 465 | return resultExitCode; | |
| 466 | } | |
| 467 | int intintIdentityPerfectCLHash_InnerInsertSingleNoOverwrite(__global char | |
| 468 | *tableData, | |
| 469 | int key, | |
| 470 | int value) { | |
| 471 | __global intintIdentityPerfectCLHash_Bucket *buckets = | |
| 472 | (__global intintIdentityPerfectCLHash_Bucket *) & | |
| 473 | tableData[sizeof(intintIdentityPerfectCLHash_TableData)]; | |
| 474 | int index; | |
| 475 | int exitCode; | |
| 476 | index = | |
| 477 | intintHash_CompressIdentity(((__global | |
| 478 | intintIdentityPerfectCLHash_TableData | |
| 479 | *) tableData)->compressFuncData, key); | |
| 480 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 481 | buckets[index]. | |
| 482 | key = key; | |
| 483 | HASH_BUCKET_STATUS_EMPTY;} | |
| 484 | ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 485 | if (key == buckets[index].key) { | |
| 486 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 487 | } else { | |
| 488 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 489 | } | |
| 490 | } else { | |
| 491 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 492 | } | |
| 493 | switch (exitCode) { | |
| 494 | case HASH_SEARCH_CODE_MATCH: | |
| 495 | case HASH_SEARCH_CODE_MISMATCH: | |
| 496 | return HASH_EXIT_CODE_OVERWRITE; | |
| 497 | case HASH_SEARCH_CODE_EMPTY: | |
| 498 | buckets[index].value = value; | |
| 499 | return HASH_EXIT_CODE_NORMAL; | |
| 500 | default: | |
| 501 | return exitCode; | |
| 502 | } | |
| 503 | } | |
| 504 | int intintIdentityPerfectCLHash_InnerInsertNoOverwrite(__global char *tableData, | |
| 505 | unsigned int numEntries, | |
| 506 | __global int *keys, | |
| 507 | __global int *values) { | |
| 508 | __global intintIdentityPerfectCLHash_Bucket *buckets = | |
| 509 | (__global intintIdentityPerfectCLHash_Bucket *) & | |
| 510 | tableData[sizeof(intintIdentityPerfectCLHash_TableData)]; | |
| 511 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 512 | int key; | |
| 513 | int value; | |
| 514 | int index; | |
| 515 | int exitCode; | |
| 516 | uint i; | |
| 517 | for (i = 0; i < numEntries; i++) { | |
| 518 | key = keys[i]; | |
| 519 | index = | |
| 520 | intintHash_CompressIdentity(((__global | |
| 521 | intintIdentityPerfectCLHash_TableData | |
| 522 | *) tableData)-> | |
| 523 | compressFuncData, key); | |
| 524 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 525 | buckets | |
| 526 | [index]. | |
| 527 | key = | |
| 528 | key; | |
| 529 | HASH_BUCKET_STATUS_EMPTY;} | |
| 530 | ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 531 | if (key == buckets[index].key) { | |
| 532 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 533 | } else { | |
| 534 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 535 | } | |
| 536 | } else { | |
| 537 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 538 | } | |
| 539 | switch (exitCode) { | |
| 540 | case HASH_SEARCH_CODE_MATCH: | |
| 541 | case HASH_SEARCH_CODE_MISMATCH: | |
| 542 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 543 | break; | |
| 544 | case HASH_SEARCH_CODE_EMPTY: | |
| 545 | buckets[index].value = values[i]; | |
| 546 | break; | |
| 547 | default: | |
| 548 | return exitCode; | |
| 549 | } | |
| 550 | } | |
| 551 | return resultExitCode; | |
| 552 | } | |
| 553 | int intintIdentityPerfectCLHash_QuerySingle(__global char *tableData, int key, | |
| 554 | __global int *valueOutput) { | |
| 555 | return intintIdentityPerfectCLHash_InnerQuerySingle(tableData, key, | |
| 556 | valueOutput); | |
| 557 | } | |
| 558 | int intintIdentityPerfectCLHash_Query(__global char *tableData, size_t numKeys, | |
| 559 | __global int *keys, | |
| 560 | __global int *valuesOutput) { | |
| 561 | return intintIdentityPerfectCLHash_InnerQuery(tableData, numKeys, keys, | |
| 562 | valuesOutput); | |
| 563 | } | |
| 564 | int intintIdentityPerfectCLHash_InsertSingle(__global char *tableData, int key, | |
| 565 | int value) { | |
| 566 | return intintIdentityPerfectCLHash_InnerInsertSingle(tableData, key, | |
| 567 | value); | |
| 568 | } | |
| 569 | int intintIdentityPerfectCLHash_Insert(__global char *tableData, | |
| 570 | size_t numEntries, __global int *keys, | |
| 571 | __global int *values) { | |
| 572 | return intintIdentityPerfectCLHash_InnerInsert(tableData, numEntries, | |
| 573 | keys, values); | |
| 574 | } | |
| 575 | int intintIdentityPerfectCLHash_InsertSingleNoOverwrite(__global char | |
| 576 | *tableData, int key, | |
| 577 | int value) { | |
| 578 | return | |
| 579 | intintIdentityPerfectCLHash_InnerInsertSingleNoOverwrite(tableData, | |
| 580 | key, | |
| 581 | value); | |
| 582 | } | |
| 583 | int intintIdentityPerfectCLHash_InsertNoOverwrite(__global char *tableData, | |
| 584 | size_t numEntries, | |
| 585 | __global int *keys, | |
| 586 | __global int *values) { | |
| 587 | return intintIdentityPerfectCLHash_InnerInsertNoOverwrite(tableData, | |
| 588 | numEntries, | |
| 589 | keys, values); | |
| 590 | } | |
| 591 | __kernel void intintIdentityPerfectCLHash_RangeQuerySingle(__global char | |
| 592 | *tableData, | |
| 593 | unsigned int | |
| 594 | numQueries, | |
| 595 | __global int *keys, | |
| 596 | __global int | |
| 597 | *valuesOutput) { | |
| 598 | uint i = get_global_id(0); | |
| 599 | if (i >= numQueries) { | |
| 600 | return; | |
| 601 | } | |
| 602 | intintIdentityPerfectCLHash_InnerQuerySingle(tableData, keys[i], | |
| 603 | valuesOutput + i); | |
| 604 | } | |
| 605 | __kernel void intintIdentityPerfectCLHash_RangeQuery(__global char *tableData, | |
| 606 | unsigned int numQueries, | |
| 607 | unsigned int numKeys, | |
| 608 | __global int *keys, | |
| 609 | __global int | |
| 610 | *valuesOutput) { | |
| 611 | uint i = get_global_id(0); | |
| 612 | if (i >= numQueries) { | |
| 613 | return; | |
| 614 | } | |
| 615 | intintIdentityPerfectCLHash_InnerQuery(tableData, numKeys, | |
| 616 | keys + (i * numKeys), | |
| 617 | valuesOutput + (i * numKeys)); | |
| 618 | } | |
| 619 | __kernel void intintIdentityPerfectCLHash_RangeInsertSingle(__global char | |
| 620 | *tableData, | |
| 621 | unsigned int | |
| 622 | numInsertions, | |
| 623 | __global int *keys, | |
| 624 | __global int | |
| 625 | *values) { | |
| 626 | uint i = get_global_id(0); | |
| 627 | if (i >= numInsertions) { | |
| 628 | return; | |
| 629 | } | |
| 630 | intintIdentityPerfectCLHash_InnerInsertSingle(tableData, keys[i], | |
| 631 | values[i]); | |
| 632 | } | |
| 633 | __kernel void intintIdentityPerfectCLHash_RangeInsert(__global char *tableData, | |
| 634 | unsigned int | |
| 635 | numInsertions, | |
| 636 | unsigned int numEntries, | |
| 637 | __global int *keys, | |
| 638 | __global int *values) { | |
| 639 | uint i = get_global_id(0); | |
| 640 | if (i >= numInsertions) { | |
| 641 | return; | |
| 642 | } | |
| 643 | intintIdentityPerfectCLHash_InnerInsert(tableData, numEntries, | |
| 644 | keys + (i * numEntries), | |
| 645 | values + (i * numEntries)); | |
| 646 | } | |
| 647 | __kernel void intintIdentityPerfectCLHash_RangeInsertSingleNoOverwrite(__global | |
| 648 | char | |
| 649 | *tableData, | |
| 650 | unsigned | |
| 651 | int | |
| 652 | numInsertions, | |
| 653 | __global | |
| 654 | int | |
| 655 | *keys, | |
| 656 | __global | |
| 657 | int | |
| 658 | *values) | |
| 659 | { | |
| 660 | uint i = get_global_id(0); | |
| 661 | if (i >= numInsertions) { | |
| 662 | return; | |
| 663 | } | |
| 664 | intintIdentityPerfectCLHash_InnerInsertSingleNoOverwrite(tableData, | |
| 665 | keys[i], | |
| 666 | values[i]); | |
| 667 | } | |
| 668 | __kernel void intintIdentityPerfectCLHash_RangeInsertNoOverwrite(__global char | |
| 669 | *tableData, | |
| 670 | unsigned int | |
| 671 | numInsertions, | |
| 672 | unsigned int | |
| 673 | numEntries, | |
| 674 | __global int | |
| 675 | *keys, | |
| 676 | __global int | |
| 677 | *values) { | |
| 678 | uint i = get_global_id(0); | |
| 679 | if (i >= numInsertions) { | |
| 680 | return; | |
| 681 | } | |
| 682 | intintIdentityPerfectCLHash_InnerInsertNoOverwrite(tableData, | |
| 683 | numEntries, | |
| 684 | keys + | |
| 685 | (i * numEntries), | |
| 686 | values + | |
| 687 | (i * numEntries)); | |
| 688 | } | |
| 689 | ||
| 690 | typedef struct intintIdentitySentinelPerfectCLHash_TableData { | |
| 691 | int hashID; | |
| 692 | unsigned int numBuckets; | |
| 693 | char compressFuncData; | |
| 694 | int emptyValue; | |
| 695 | } intintIdentitySentinelPerfectCLHash_TableData; | |
| 696 | typedef struct intintIdentitySentinelPerfectCLHash_Bucket { | |
| 697 | int value; | |
| 698 | } intintIdentitySentinelPerfectCLHash_Bucket; | |
| 699 | int intintIdentitySentinelPerfectCLHash_InnerQuerySingle(__global char | |
| 700 | *tableData, int key, | |
| 701 | __global int | |
| 702 | *valueOutput) { | |
| 703 | __global intintIdentitySentinelPerfectCLHash_Bucket *buckets = | |
| 704 | (__global intintIdentitySentinelPerfectCLHash_Bucket *) & | |
| 705 | tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)]; | |
| 706 | int index; | |
| 707 | int exitCode; | |
| 708 | index = | |
| 709 | intintHash_CompressIdentity(((__global | |
| 710 | intintIdentitySentinelPerfectCLHash_TableData | |
| 711 | *) tableData)->compressFuncData, key); | |
| 712 | if (buckets[index].value != | |
| 713 | ((__global intintIdentitySentinelPerfectCLHash_TableData *) | |
| 714 | tableData)->emptyValue) { | |
| 715 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 716 | } else { | |
| 717 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 718 | } | |
| 719 | switch (exitCode) { | |
| 720 | case HASH_SEARCH_CODE_MATCH: | |
| 721 | *valueOutput = buckets[index].value; | |
| 722 | return HASH_EXIT_CODE_NORMAL; | |
| 723 | case HASH_SEARCH_CODE_MISMATCH: | |
| 724 | case HASH_SEARCH_CODE_EMPTY: | |
| 725 | return HASH_EXIT_CODE_KEY_DNE; | |
| 726 | default: | |
| 727 | return exitCode; | |
| 728 | } | |
| 729 | } | |
| 730 | int intintIdentitySentinelPerfectCLHash_InnerQuery(__global char *tableData, | |
| 731 | unsigned int numKeys, | |
| 732 | __global int *keys, | |
| 733 | __global int *valuesOutput) { | |
| 734 | __global intintIdentitySentinelPerfectCLHash_Bucket *buckets = | |
| 735 | (__global intintIdentitySentinelPerfectCLHash_Bucket *) & | |
| 736 | tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)]; | |
| 737 | int key; | |
| 738 | __global int *valueOutput; | |
| 739 | int index; | |
| 740 | int exitCode; | |
| 741 | uint i; | |
| 742 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 743 | for (i = 0; i < numKeys; i++) { | |
| 744 | key = keys[i]; | |
| 745 | valueOutput = &valuesOutput[i]; | |
| 746 | index = | |
| 747 | intintHash_CompressIdentity(((__global | |
| 748 | intintIdentitySentinelPerfectCLHash_TableData | |
| 749 | *) tableData)-> | |
| 750 | compressFuncData, key); | |
| 751 | if (buckets[index].value != | |
| 752 | ((__global intintIdentitySentinelPerfectCLHash_TableData *) | |
| 753 | tableData)->emptyValue) { | |
| 754 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 755 | } else { | |
| 756 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 757 | } | |
| 758 | switch (exitCode) { | |
| 759 | case HASH_SEARCH_CODE_MATCH: | |
| 760 | *valueOutput = buckets[index].value; | |
| 761 | break; | |
| 762 | case HASH_SEARCH_CODE_MISMATCH: | |
| 763 | case HASH_SEARCH_CODE_EMPTY: | |
| 764 | resultExitCode = HASH_EXIT_CODE_KEY_DNE; | |
| 765 | break; | |
| 766 | default: | |
| 767 | return exitCode; | |
| 768 | } | |
| 769 | } | |
| 770 | return resultExitCode; | |
| 771 | } | |
| 772 | int intintIdentitySentinelPerfectCLHash_InnerInsertSingle(__global char | |
| 773 | *tableData, int key, | |
| 774 | int value) { | |
| 775 | __global intintIdentitySentinelPerfectCLHash_Bucket *buckets = | |
| 776 | (__global intintIdentitySentinelPerfectCLHash_Bucket *) & | |
| 777 | tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)]; | |
| 778 | int index; | |
| 779 | int exitCode; | |
| 780 | index = | |
| 781 | intintHash_CompressIdentity(((__global | |
| 782 | intintIdentitySentinelPerfectCLHash_TableData | |
| 783 | *) tableData)->compressFuncData, key); | |
| 784 | if (buckets[index].value != | |
| 785 | ((__global intintIdentitySentinelPerfectCLHash_TableData *) | |
| 786 | tableData)->emptyValue) { | |
| 787 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 788 | } else { | |
| 789 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 790 | } | |
| 791 | switch (exitCode) { | |
| 792 | case HASH_SEARCH_CODE_MATCH: | |
| 793 | case HASH_SEARCH_CODE_MISMATCH: | |
| 794 | buckets[index].value = value; | |
| 795 | return HASH_EXIT_CODE_OVERWRITE; | |
| 796 | case HASH_SEARCH_CODE_EMPTY: | |
| 797 | buckets[index].value = value; | |
| 798 | return HASH_EXIT_CODE_NORMAL; | |
| 799 | default: | |
| 800 | return exitCode; | |
| 801 | } | |
| 802 | } | |
| 803 | int intintIdentitySentinelPerfectCLHash_InnerInsert(__global char *tableData, | |
| 804 | unsigned int numEntries, | |
| 805 | __global int *keys, | |
| 806 | __global int *values) { | |
| 807 | __global intintIdentitySentinelPerfectCLHash_Bucket *buckets = | |
| 808 | (__global intintIdentitySentinelPerfectCLHash_Bucket *) & | |
| 809 | tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)]; | |
| 810 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 811 | int key; | |
| 812 | int value; | |
| 813 | int index; | |
| 814 | int exitCode; | |
| 815 | uint i; | |
| 816 | for (i = 0; i < numEntries; i++) { | |
| 817 | key = keys[i]; | |
| 818 | index = | |
| 819 | intintHash_CompressIdentity(((__global | |
| 820 | intintIdentitySentinelPerfectCLHash_TableData | |
| 821 | *) tableData)-> | |
| 822 | compressFuncData, key); | |
| 823 | if (buckets[index].value != | |
| 824 | ((__global intintIdentitySentinelPerfectCLHash_TableData *) | |
| 825 | tableData)->emptyValue) { | |
| 826 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 827 | } else { | |
| 828 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 829 | } | |
| 830 | switch (exitCode) { | |
| 831 | case HASH_SEARCH_CODE_MATCH: | |
| 832 | case HASH_SEARCH_CODE_MISMATCH: | |
| 833 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 834 | case HASH_SEARCH_CODE_EMPTY: | |
| 835 | buckets[index].value = values[i]; | |
| 836 | break; | |
| 837 | default: | |
| 838 | return exitCode; | |
| 839 | } | |
| 840 | } | |
| 841 | return resultExitCode; | |
| 842 | } | |
| 843 | int intintIdentitySentinelPerfectCLHash_InnerInsertSingleNoOverwrite(__global | |
| 844 | char | |
| 845 | *tableData, | |
| 846 | int key, | |
| 847 | int value) | |
| 848 | { | |
| 849 | __global intintIdentitySentinelPerfectCLHash_Bucket *buckets = | |
| 850 | (__global intintIdentitySentinelPerfectCLHash_Bucket *) & | |
| 851 | tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)]; | |
| 852 | int index; | |
| 853 | int exitCode; | |
| 854 | index = | |
| 855 | intintHash_CompressIdentity(((__global | |
| 856 | intintIdentitySentinelPerfectCLHash_TableData | |
| 857 | *) tableData)->compressFuncData, key); | |
| 858 | if (buckets[index].value != | |
| 859 | ((__global intintIdentitySentinelPerfectCLHash_TableData *) | |
| 860 | tableData)->emptyValue) { | |
| 861 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 862 | } else { | |
| 863 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 864 | } | |
| 865 | switch (exitCode) { | |
| 866 | case HASH_SEARCH_CODE_MATCH: | |
| 867 | case HASH_SEARCH_CODE_MISMATCH: | |
| 868 | return HASH_EXIT_CODE_OVERWRITE; | |
| 869 | case HASH_SEARCH_CODE_EMPTY: | |
| 870 | buckets[index].value = value; | |
| 871 | return HASH_EXIT_CODE_NORMAL; | |
| 872 | default: | |
| 873 | return exitCode; | |
| 874 | } | |
| 875 | } | |
| 876 | int intintIdentitySentinelPerfectCLHash_InnerInsertNoOverwrite(__global char | |
| 877 | *tableData, | |
| 878 | unsigned int | |
| 879 | numEntries, | |
| 880 | __global int | |
| 881 | *keys, | |
| 882 | __global int | |
| 883 | *values) { | |
| 884 | __global intintIdentitySentinelPerfectCLHash_Bucket *buckets = | |
| 885 | (__global intintIdentitySentinelPerfectCLHash_Bucket *) & | |
| 886 | tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)]; | |
| 887 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 888 | int key; | |
| 889 | int value; | |
| 890 | int index; | |
| 891 | int exitCode; | |
| 892 | uint i; | |
| 893 | for (i = 0; i < numEntries; i++) { | |
| 894 | key = keys[i]; | |
| 895 | index = | |
| 896 | intintHash_CompressIdentity(((__global | |
| 897 | intintIdentitySentinelPerfectCLHash_TableData | |
| 898 | *) tableData)-> | |
| 899 | compressFuncData, key); | |
| 900 | if (buckets[index].value != | |
| 901 | ((__global intintIdentitySentinelPerfectCLHash_TableData *) | |
| 902 | tableData)->emptyValue) { | |
| 903 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 904 | } else { | |
| 905 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 906 | } | |
| 907 | switch (exitCode) { | |
| 908 | case HASH_SEARCH_CODE_MATCH: | |
| 909 | case HASH_SEARCH_CODE_MISMATCH: | |
| 910 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 911 | break; | |
| 912 | case HASH_SEARCH_CODE_EMPTY: | |
| 913 | buckets[index].value = values[i]; | |
| 914 | break; | |
| 915 | default: | |
| 916 | return exitCode; | |
| 917 | } | |
| 918 | } | |
| 919 | return resultExitCode; | |
| 920 | } | |
| 921 | int intintIdentitySentinelPerfectCLHash_QuerySingle(__global char *tableData, | |
| 922 | int key, | |
| 923 | __global int *valueOutput) { | |
| 924 | return intintIdentitySentinelPerfectCLHash_InnerQuerySingle(tableData, | |
| 925 | key, | |
| 926 | valueOutput); | |
| 927 | } | |
| 928 | int intintIdentitySentinelPerfectCLHash_Query(__global char *tableData, | |
| 929 | size_t numKeys, | |
| 930 | __global int *keys, | |
| 931 | __global int *valuesOutput) { | |
| 932 | return intintIdentitySentinelPerfectCLHash_InnerQuery(tableData, | |
| 933 | numKeys, keys, | |
| 934 | valuesOutput); | |
| 935 | } | |
| 936 | int intintIdentitySentinelPerfectCLHash_InsertSingle(__global char *tableData, | |
| 937 | int key, int value) { | |
| 938 | return intintIdentitySentinelPerfectCLHash_InnerInsertSingle(tableData, | |
| 939 | key, | |
| 940 | value); | |
| 941 | } | |
| 942 | int intintIdentitySentinelPerfectCLHash_Insert(__global char *tableData, | |
| 943 | size_t numEntries, | |
| 944 | __global int *keys, | |
| 945 | __global int *values) { | |
| 946 | return intintIdentitySentinelPerfectCLHash_InnerInsert(tableData, | |
| 947 | numEntries, keys, | |
| 948 | values); | |
| 949 | } | |
| 950 | int intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite(__global char | |
| 951 | *tableData, | |
| 952 | int key, | |
| 953 | int value) { | |
| 954 | return | |
| 955 | intintIdentitySentinelPerfectCLHash_InnerInsertSingleNoOverwrite | |
| 956 | (tableData, key, value); | |
| 957 | } | |
| 958 | int intintIdentitySentinelPerfectCLHash_InsertNoOverwrite(__global char | |
| 959 | *tableData, | |
| 960 | size_t numEntries, | |
| 961 | __global int *keys, | |
| 962 | __global int *values) | |
| 963 | { | |
| 964 | return | |
| 965 | intintIdentitySentinelPerfectCLHash_InnerInsertNoOverwrite | |
| 966 | (tableData, numEntries, keys, values); | |
| 967 | } | |
| 968 | __kernel void intintIdentitySentinelPerfectCLHash_RangeQuerySingle(__global char | |
| 969 | *tableData, | |
| 970 | unsigned int | |
| 971 | numQueries, | |
| 972 | __global int | |
| 973 | *keys, | |
| 974 | __global int | |
| 975 | *valuesOutput) | |
| 976 | { | |
| 977 | uint i = get_global_id(0); | |
| 978 | if (i >= numQueries) { | |
| 979 | return; | |
| 980 | } | |
| 981 | intintIdentitySentinelPerfectCLHash_InnerQuerySingle(tableData, keys[i], | |
| 982 | valuesOutput + i); | |
| 983 | } | |
| 984 | __kernel void intintIdentitySentinelPerfectCLHash_RangeQuery(__global char | |
| 985 | *tableData, | |
| 986 | unsigned int | |
| 987 | numQueries, | |
| 988 | unsigned int | |
| 989 | numKeys, | |
| 990 | __global int *keys, | |
| 991 | __global int | |
| 992 | *valuesOutput) { | |
| 993 | uint i = get_global_id(0); | |
| 994 | if (i >= numQueries) { | |
| 995 | return; | |
| 996 | } | |
| 997 | intintIdentitySentinelPerfectCLHash_InnerQuery(tableData, numKeys, | |
| 998 | keys + (i * numKeys), | |
| 999 | valuesOutput + | |
| 1000 | (i * numKeys)); | |
| 1001 | } | |
| 1002 | __kernel void intintIdentitySentinelPerfectCLHash_RangeInsertSingle(__global | |
| 1003 | char | |
| 1004 | *tableData, | |
| 1005 | unsigned int | |
| 1006 | numInsertions, | |
| 1007 | __global int | |
| 1008 | *keys, | |
| 1009 | __global int | |
| 1010 | *values) { | |
| 1011 | uint i = get_global_id(0); | |
| 1012 | if (i >= numInsertions) { | |
| 1013 | return; | |
| 1014 | } | |
| 1015 | intintIdentitySentinelPerfectCLHash_InnerInsertSingle(tableData, | |
| 1016 | keys[i], | |
| 1017 | values[i]); | |
| 1018 | } | |
| 1019 | __kernel void intintIdentitySentinelPerfectCLHash_RangeInsert(__global char | |
| 1020 | *tableData, | |
| 1021 | unsigned int | |
| 1022 | numInsertions, | |
| 1023 | unsigned int | |
| 1024 | numEntries, | |
| 1025 | __global int | |
| 1026 | *keys, | |
| 1027 | __global int | |
| 1028 | *values) { | |
| 1029 | uint i = get_global_id(0); | |
| 1030 | if (i >= numInsertions) { | |
| 1031 | return; | |
| 1032 | } | |
| 1033 | intintIdentitySentinelPerfectCLHash_InnerInsert(tableData, numEntries, | |
| 1034 | keys + (i * numEntries), | |
| 1035 | values + | |
| 1036 | (i * numEntries)); | |
| 1037 | } | |
| 1038 | __kernel void | |
| 1039 | intintIdentitySentinelPerfectCLHash_RangeInsertSingleNoOverwrite(__global char | |
| 1040 | *tableData, | |
| 1041 | unsigned int | |
| 1042 | numInsertions, | |
| 1043 | __global int | |
| 1044 | *keys, | |
| 1045 | __global int | |
| 1046 | *values) { | |
| 1047 | uint i = get_global_id(0); | |
| 1048 | if (i >= numInsertions) { | |
| 1049 | return; | |
| 1050 | } | |
| 1051 | intintIdentitySentinelPerfectCLHash_InnerInsertSingleNoOverwrite | |
| 1052 | (tableData, keys[i], values[i]); | |
| 1053 | } | |
| 1054 | __kernel void | |
| 1055 | intintIdentitySentinelPerfectCLHash_RangeInsertNoOverwrite(__global char | |
| 1056 | *tableData, | |
| 1057 | unsigned int | |
| 1058 | numInsertions, | |
| 1059 | unsigned int | |
| 1060 | numEntries, | |
| 1061 | __global int *keys, | |
| 1062 | __global int | |
| 1063 | *values) { | |
| 1064 | uint i = get_global_id(0); | |
| 1065 | if (i >= numInsertions) { | |
| 1066 | return; | |
| 1067 | } | |
| 1068 | intintIdentitySentinelPerfectCLHash_InnerInsertNoOverwrite(tableData, | |
| 1069 | numEntries, | |
| 1070 | keys + | |
| 1071 | (i * | |
| 1072 | numEntries), | |
| 1073 | values + | |
| 1074 | (i * | |
| 1075 | numEntries)); | |
| 1076 | } | |
| 1077 | ||
| 1078 | typedef struct intintLCGLinearOpenCompactCLHash_TableData { | |
| 1079 | int hashID; | |
| 1080 | unsigned int numBuckets; | |
| 1081 | intintHash_CompressLCGData compressFuncData; | |
| 1082 | } intintLCGLinearOpenCompactCLHash_TableData; | |
| 1083 | typedef struct intintLCGLinearOpenCompactCLHash_Bucket { | |
| 1084 | int key; | |
| 1085 | int value; | |
| 1086 | } intintLCGLinearOpenCompactCLHash_Bucket; | |
| 1087 | int intintLCGLinearOpenCompactCLHash_InnerQuerySingle(__global char *tableData, | |
| 1088 | int key, | |
| 1089 | __global int | |
| 1090 | *valueOutput) { | |
| 1091 | __global intintLCGLinearOpenCompactCLHash_Bucket *buckets = | |
| 1092 | (__global intintLCGLinearOpenCompactCLHash_Bucket *) & | |
| 1093 | tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)]; | |
| 1094 | int index; | |
| 1095 | int exitCode; | |
| 1096 | __global intintLCGLinearOpenCompactCLHash_TableData *mytableData = | |
| 1097 | (__global intintLCGLinearOpenCompactCLHash_TableData *) tableData; | |
| 1098 | intintHash_CompressLCGData compressFuncData = | |
| 1099 | mytableData->compressFuncData; | |
| 1100 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1101 | unsigned long int iteration = 0; | |
| 1102 | for (;;) { | |
| 1103 | index = | |
| 1104 | ((1 * iteration + | |
| 1105 | c) % | |
| 1106 | ((__global intintLCGLinearOpenCompactCLHash_TableData *) | |
| 1107 | tableData)->numBuckets); | |
| 1108 | if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1109 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1110 | break; | |
| 1111 | } else if (key == buckets[index].key) { | |
| 1112 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1113 | break; | |
| 1114 | } else if ((index == c && iteration > 0)) { | |
| 1115 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1116 | break; | |
| 1117 | } | |
| 1118 | iteration++; | |
| 1119 | } | |
| 1120 | switch (exitCode) { | |
| 1121 | case HASH_SEARCH_CODE_MATCH: | |
| 1122 | *valueOutput = buckets[index].value; | |
| 1123 | return HASH_EXIT_CODE_NORMAL; | |
| 1124 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1125 | case HASH_SEARCH_CODE_EMPTY: | |
| 1126 | return HASH_EXIT_CODE_KEY_DNE; | |
| 1127 | default: | |
| 1128 | return exitCode; | |
| 1129 | } | |
| 1130 | } | |
| 1131 | int intintLCGLinearOpenCompactCLHash_InnerQuery(__global char *tableData, | |
| 1132 | unsigned int numKeys, | |
| 1133 | __global int *keys, | |
| 1134 | __global int *valuesOutput) { | |
| 1135 | __global intintLCGLinearOpenCompactCLHash_Bucket *buckets = | |
| 1136 | (__global intintLCGLinearOpenCompactCLHash_Bucket *) & | |
| 1137 | tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)]; | |
| 1138 | int key; | |
| 1139 | __global int *valueOutput; | |
| 1140 | int index; | |
| 1141 | int exitCode; | |
| 1142 | uint i; | |
| 1143 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1144 | for (i = 0; i < numKeys; i++) { | |
| 1145 | key = keys[i]; | |
| 1146 | valueOutput = &valuesOutput[i]; | |
| 1147 | __global intintLCGLinearOpenCompactCLHash_TableData *mytableData | |
| 1148 | = | |
| 1149 | (__global intintLCGLinearOpenCompactCLHash_TableData *) | |
| 1150 | tableData; | |
| 1151 | intintHash_CompressLCGData compressFuncData = | |
| 1152 | mytableData->compressFuncData; | |
| 1153 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1154 | unsigned long int iteration = 0; | |
| 1155 | for (;;) { | |
| 1156 | index = | |
| 1157 | ((1 * iteration + | |
| 1158 | c) % | |
| 1159 | ((__global | |
| 1160 | intintLCGLinearOpenCompactCLHash_TableData *) | |
| 1161 | tableData)->numBuckets); | |
| 1162 | if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1163 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1164 | break; | |
| 1165 | } else if (key == buckets[index].key) { | |
| 1166 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1167 | break; | |
| 1168 | } else if ((index == c && iteration > 0)) { | |
| 1169 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1170 | break; | |
| 1171 | } | |
| 1172 | iteration++; | |
| 1173 | } | |
| 1174 | switch (exitCode) { | |
| 1175 | case HASH_SEARCH_CODE_MATCH: | |
| 1176 | *valueOutput = buckets[index].value; | |
| 1177 | break; | |
| 1178 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1179 | case HASH_SEARCH_CODE_EMPTY: | |
| 1180 | resultExitCode = HASH_EXIT_CODE_KEY_DNE; | |
| 1181 | break; | |
| 1182 | default: | |
| 1183 | return exitCode; | |
| 1184 | } | |
| 1185 | } | |
| 1186 | return resultExitCode; | |
| 1187 | } | |
| 1188 | int intintLCGLinearOpenCompactCLHash_InnerInsertSingle(__global char *tableData, | |
| 1189 | int key, int value) { | |
| 1190 | __global intintLCGLinearOpenCompactCLHash_Bucket *buckets = | |
| 1191 | (__global intintLCGLinearOpenCompactCLHash_Bucket *) & | |
| 1192 | tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)]; | |
| 1193 | int index; | |
| 1194 | int exitCode; | |
| 1195 | __global intintLCGLinearOpenCompactCLHash_TableData *mytableData = | |
| 1196 | (__global intintLCGLinearOpenCompactCLHash_TableData *) tableData; | |
| 1197 | intintHash_CompressLCGData compressFuncData = | |
| 1198 | mytableData->compressFuncData; | |
| 1199 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1200 | unsigned long int iteration = 0; | |
| 1201 | for (;;) { | |
| 1202 | index = | |
| 1203 | ((1 * iteration + | |
| 1204 | c) % | |
| 1205 | ((__global intintLCGLinearOpenCompactCLHash_TableData *) | |
| 1206 | tableData)->numBuckets); | |
| 1207 | if ((atomic_cmpxchg | |
| 1208 | (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY, | |
| 1209 | key)) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1210 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1211 | break; | |
| 1212 | } else if (key == buckets[index].key) { | |
| 1213 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1214 | break; | |
| 1215 | } else if ((index == c && iteration > 0)) { | |
| 1216 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1217 | break; | |
| 1218 | } | |
| 1219 | iteration++; | |
| 1220 | } | |
| 1221 | switch (exitCode) { | |
| 1222 | case HASH_SEARCH_CODE_MATCH: | |
| 1223 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1224 | buckets[index].value = value; | |
| 1225 | return HASH_EXIT_CODE_OVERWRITE; | |
| 1226 | case HASH_SEARCH_CODE_EMPTY: | |
| 1227 | buckets[index].value = value; | |
| 1228 | return HASH_EXIT_CODE_NORMAL; | |
| 1229 | default: | |
| 1230 | return exitCode; | |
| 1231 | } | |
| 1232 | } | |
| 1233 | int intintLCGLinearOpenCompactCLHash_InnerInsert(__global char *tableData, | |
| 1234 | unsigned int numEntries, | |
| 1235 | __global int *keys, | |
| 1236 | __global int *values) { | |
| 1237 | __global intintLCGLinearOpenCompactCLHash_Bucket *buckets = | |
| 1238 | (__global intintLCGLinearOpenCompactCLHash_Bucket *) & | |
| 1239 | tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)]; | |
| 1240 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1241 | int key; | |
| 1242 | int value; | |
| 1243 | int index; | |
| 1244 | int exitCode; | |
| 1245 | uint i; | |
| 1246 | for (i = 0; i < numEntries; i++) { | |
| 1247 | key = keys[i]; | |
| 1248 | __global intintLCGLinearOpenCompactCLHash_TableData *mytableData | |
| 1249 | = | |
| 1250 | (__global intintLCGLinearOpenCompactCLHash_TableData *) | |
| 1251 | tableData; | |
| 1252 | intintHash_CompressLCGData compressFuncData = | |
| 1253 | mytableData->compressFuncData; | |
| 1254 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1255 | unsigned long int iteration = 0; | |
| 1256 | for (;;) { | |
| 1257 | index = | |
| 1258 | ((1 * iteration + | |
| 1259 | c) % | |
| 1260 | ((__global | |
| 1261 | intintLCGLinearOpenCompactCLHash_TableData *) | |
| 1262 | tableData)->numBuckets); | |
| 1263 | if ((atomic_cmpxchg | |
| 1264 | (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY, | |
| 1265 | key)) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1266 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1267 | break; | |
| 1268 | } else if (key == buckets[index].key) { | |
| 1269 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1270 | break; | |
| 1271 | } else if ((index == c && iteration > 0)) { | |
| 1272 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1273 | break; | |
| 1274 | } | |
| 1275 | iteration++; | |
| 1276 | } | |
| 1277 | switch (exitCode) { | |
| 1278 | case HASH_SEARCH_CODE_MATCH: | |
| 1279 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1280 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 1281 | case HASH_SEARCH_CODE_EMPTY: | |
| 1282 | buckets[index].value = values[i]; | |
| 1283 | break; | |
| 1284 | default: | |
| 1285 | return exitCode; | |
| 1286 | } | |
| 1287 | } | |
| 1288 | return resultExitCode; | |
| 1289 | } | |
| 1290 | int intintLCGLinearOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global char | |
| 1291 | *tableData, | |
| 1292 | int key, | |
| 1293 | int value) { | |
| 1294 | __global intintLCGLinearOpenCompactCLHash_Bucket *buckets = | |
| 1295 | (__global intintLCGLinearOpenCompactCLHash_Bucket *) & | |
| 1296 | tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)]; | |
| 1297 | int index; | |
| 1298 | int exitCode; | |
| 1299 | __global intintLCGLinearOpenCompactCLHash_TableData *mytableData = | |
| 1300 | (__global intintLCGLinearOpenCompactCLHash_TableData *) tableData; | |
| 1301 | intintHash_CompressLCGData compressFuncData = | |
| 1302 | mytableData->compressFuncData; | |
| 1303 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1304 | unsigned long int iteration = 0; | |
| 1305 | for (;;) { | |
| 1306 | index = | |
| 1307 | ((1 * iteration + | |
| 1308 | c) % | |
| 1309 | ((__global intintLCGLinearOpenCompactCLHash_TableData *) | |
| 1310 | tableData)->numBuckets); | |
| 1311 | if ((atomic_cmpxchg | |
| 1312 | (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY, | |
| 1313 | key)) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1314 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1315 | break; | |
| 1316 | } else if (key == buckets[index].key) { | |
| 1317 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1318 | break; | |
| 1319 | } else if ((index == c && iteration > 0)) { | |
| 1320 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1321 | break; | |
| 1322 | } | |
| 1323 | iteration++; | |
| 1324 | } | |
| 1325 | switch (exitCode) { | |
| 1326 | case HASH_SEARCH_CODE_MATCH: | |
| 1327 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1328 | return HASH_EXIT_CODE_OVERWRITE; | |
| 1329 | case HASH_SEARCH_CODE_EMPTY: | |
| 1330 | buckets[index].value = value; | |
| 1331 | return HASH_EXIT_CODE_NORMAL; | |
| 1332 | default: | |
| 1333 | return exitCode; | |
| 1334 | } | |
| 1335 | } | |
| 1336 | int intintLCGLinearOpenCompactCLHash_InnerInsertNoOverwrite(__global char | |
| 1337 | *tableData, | |
| 1338 | unsigned int | |
| 1339 | numEntries, | |
| 1340 | __global int *keys, | |
| 1341 | __global int | |
| 1342 | *values) { | |
| 1343 | __global intintLCGLinearOpenCompactCLHash_Bucket *buckets = | |
| 1344 | (__global intintLCGLinearOpenCompactCLHash_Bucket *) & | |
| 1345 | tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)]; | |
| 1346 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1347 | int key; | |
| 1348 | int value; | |
| 1349 | int index; | |
| 1350 | int exitCode; | |
| 1351 | uint i; | |
| 1352 | for (i = 0; i < numEntries; i++) { | |
| 1353 | key = keys[i]; | |
| 1354 | __global intintLCGLinearOpenCompactCLHash_TableData *mytableData | |
| 1355 | = | |
| 1356 | (__global intintLCGLinearOpenCompactCLHash_TableData *) | |
| 1357 | tableData; | |
| 1358 | intintHash_CompressLCGData compressFuncData = | |
| 1359 | mytableData->compressFuncData; | |
| 1360 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1361 | unsigned long int iteration = 0; | |
| 1362 | for (;;) { | |
| 1363 | index = | |
| 1364 | ((1 * iteration + | |
| 1365 | c) % | |
| 1366 | ((__global | |
| 1367 | intintLCGLinearOpenCompactCLHash_TableData *) | |
| 1368 | tableData)->numBuckets); | |
| 1369 | if ((atomic_cmpxchg | |
| 1370 | (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY, | |
| 1371 | key)) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1372 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1373 | break; | |
| 1374 | } else if (key == buckets[index].key) { | |
| 1375 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1376 | break; | |
| 1377 | } else if ((index == c && iteration > 0)) { | |
| 1378 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1379 | break; | |
| 1380 | } | |
| 1381 | iteration++; | |
| 1382 | } | |
| 1383 | switch (exitCode) { | |
| 1384 | case HASH_SEARCH_CODE_MATCH: | |
| 1385 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1386 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 1387 | break; | |
| 1388 | case HASH_SEARCH_CODE_EMPTY: | |
| 1389 | buckets[index].value = values[i]; | |
| 1390 | break; | |
| 1391 | default: | |
| 1392 | return exitCode; | |
| 1393 | } | |
| 1394 | } | |
| 1395 | return resultExitCode; | |
| 1396 | } | |
| 1397 | int intintLCGLinearOpenCompactCLHash_QuerySingle(__global char *tableData, | |
| 1398 | int key, | |
| 1399 | __global int *valueOutput) { | |
| 1400 | return intintLCGLinearOpenCompactCLHash_InnerQuerySingle(tableData, key, | |
| 1401 | valueOutput); | |
| 1402 | } | |
| 1403 | int intintLCGLinearOpenCompactCLHash_Query(__global char *tableData, | |
| 1404 | size_t numKeys, __global int *keys, | |
| 1405 | __global int *valuesOutput) { | |
| 1406 | return intintLCGLinearOpenCompactCLHash_InnerQuery(tableData, numKeys, | |
| 1407 | keys, valuesOutput); | |
| 1408 | } | |
| 1409 | int intintLCGLinearOpenCompactCLHash_InsertSingle(__global char *tableData, | |
| 1410 | int key, int value) { | |
| 1411 | return intintLCGLinearOpenCompactCLHash_InnerInsertSingle(tableData, | |
| 1412 | key, value); | |
| 1413 | } | |
| 1414 | int intintLCGLinearOpenCompactCLHash_Insert(__global char *tableData, | |
| 1415 | size_t numEntries, | |
| 1416 | __global int *keys, | |
| 1417 | __global int *values) { | |
| 1418 | return intintLCGLinearOpenCompactCLHash_InnerInsert(tableData, | |
| 1419 | numEntries, keys, | |
| 1420 | values); | |
| 1421 | } | |
| 1422 | int intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite(__global char | |
| 1423 | *tableData, | |
| 1424 | int key, | |
| 1425 | int value) { | |
| 1426 | return | |
| 1427 | intintLCGLinearOpenCompactCLHash_InnerInsertSingleNoOverwrite | |
| 1428 | (tableData, key, value); | |
| 1429 | } | |
| 1430 | int intintLCGLinearOpenCompactCLHash_InsertNoOverwrite(__global char *tableData, | |
| 1431 | size_t numEntries, | |
| 1432 | __global int *keys, | |
| 1433 | __global int *values) { | |
| 1434 | return | |
| 1435 | intintLCGLinearOpenCompactCLHash_InnerInsertNoOverwrite(tableData, | |
| 1436 | numEntries, | |
| 1437 | keys, | |
| 1438 | values); | |
| 1439 | } | |
| 1440 | __kernel void intintLCGLinearOpenCompactCLHash_RangeQuerySingle(__global char | |
| 1441 | *tableData, | |
| 1442 | unsigned int | |
| 1443 | numQueries, | |
| 1444 | __global int | |
| 1445 | *keys, | |
| 1446 | __global int | |
| 1447 | *valuesOutput) { | |
| 1448 | uint i = get_global_id(0); | |
| 1449 | if (i >= numQueries) { | |
| 1450 | return; | |
| 1451 | } | |
| 1452 | intintLCGLinearOpenCompactCLHash_InnerQuerySingle(tableData, keys[i], | |
| 1453 | valuesOutput + i); | |
| 1454 | } | |
| 1455 | __kernel void intintLCGLinearOpenCompactCLHash_RangeQuery(__global char | |
| 1456 | *tableData, | |
| 1457 | unsigned int | |
| 1458 | numQueries, | |
| 1459 | unsigned int numKeys, | |
| 1460 | __global int *keys, | |
| 1461 | __global int | |
| 1462 | *valuesOutput) { | |
| 1463 | uint i = get_global_id(0); | |
| 1464 | if (i >= numQueries) { | |
| 1465 | return; | |
| 1466 | } | |
| 1467 | intintLCGLinearOpenCompactCLHash_InnerQuery(tableData, numKeys, | |
| 1468 | keys + (i * numKeys), | |
| 1469 | valuesOutput + | |
| 1470 | (i * numKeys)); | |
| 1471 | } | |
| 1472 | __kernel void intintLCGLinearOpenCompactCLHash_RangeInsertSingle(__global char | |
| 1473 | *tableData, | |
| 1474 | unsigned int | |
| 1475 | numInsertions, | |
| 1476 | __global int | |
| 1477 | *keys, | |
| 1478 | __global int | |
| 1479 | *values) { | |
| 1480 | uint i = get_global_id(0); | |
| 1481 | if (i >= numInsertions) { | |
| 1482 | return; | |
| 1483 | } | |
| 1484 | intintLCGLinearOpenCompactCLHash_InnerInsertSingle(tableData, keys[i], | |
| 1485 | values[i]); | |
| 1486 | } | |
| 1487 | __kernel void intintLCGLinearOpenCompactCLHash_RangeInsert(__global char | |
| 1488 | *tableData, | |
| 1489 | unsigned int | |
| 1490 | numInsertions, | |
| 1491 | unsigned int | |
| 1492 | numEntries, | |
| 1493 | __global int *keys, | |
| 1494 | __global int | |
| 1495 | *values) { | |
| 1496 | uint i = get_global_id(0); | |
| 1497 | if (i >= numInsertions) { | |
| 1498 | return; | |
| 1499 | } | |
| 1500 | intintLCGLinearOpenCompactCLHash_InnerInsert(tableData, numEntries, | |
| 1501 | keys + (i * numEntries), | |
| 1502 | values + (i * numEntries)); | |
| 1503 | } | |
| 1504 | __kernel void | |
| 1505 | intintLCGLinearOpenCompactCLHash_RangeInsertSingleNoOverwrite(__global char | |
| 1506 | *tableData, | |
| 1507 | unsigned int | |
| 1508 | numInsertions, | |
| 1509 | __global int | |
| 1510 | *keys, | |
| 1511 | __global int | |
| 1512 | *values) { | |
| 1513 | uint i = get_global_id(0); | |
| 1514 | if (i >= numInsertions) { | |
| 1515 | return; | |
| 1516 | } | |
| 1517 | intintLCGLinearOpenCompactCLHash_InnerInsertSingleNoOverwrite(tableData, | |
| 1518 | keys[i], | |
| 1519 | values | |
| 1520 | [i]); | |
| 1521 | } | |
| 1522 | __kernel void intintLCGLinearOpenCompactCLHash_RangeInsertNoOverwrite(__global | |
| 1523 | char | |
| 1524 | *tableData, | |
| 1525 | unsigned | |
| 1526 | int | |
| 1527 | numInsertions, | |
| 1528 | unsigned | |
| 1529 | int | |
| 1530 | numEntries, | |
| 1531 | __global | |
| 1532 | int *keys, | |
| 1533 | __global | |
| 1534 | int | |
| 1535 | *values) { | |
| 1536 | uint i = get_global_id(0); | |
| 1537 | if (i >= numInsertions) { | |
| 1538 | return; | |
| 1539 | } | |
| 1540 | intintLCGLinearOpenCompactCLHash_InnerInsertNoOverwrite(tableData, | |
| 1541 | numEntries, | |
| 1542 | keys + | |
| 1543 | (i * | |
| 1544 | numEntries), | |
| 1545 | values + | |
| 1546 | (i * | |
| 1547 | numEntries)); | |
| 1548 | } | |
| 1549 | ||
| 1550 | typedef struct intintLCGQuadraticOpenCompactCLHash_TableData { | |
| 1551 | int hashID; | |
| 1552 | unsigned int numBuckets; | |
| 1553 | intintHash_CompressLCGData compressFuncData; | |
| 1554 | } intintLCGQuadraticOpenCompactCLHash_TableData; | |
| 1555 | typedef struct intintLCGQuadraticOpenCompactCLHash_Bucket { | |
| 1556 | int key; | |
| 1557 | int value; | |
| 1558 | } intintLCGQuadraticOpenCompactCLHash_Bucket; | |
| 1559 | int intintLCGQuadraticOpenCompactCLHash_InnerQuerySingle(__global char | |
| 1560 | *tableData, int key, | |
| 1561 | __global int | |
| 1562 | *valueOutput) { | |
| 1563 | __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets = | |
| 1564 | (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) & | |
| 1565 | tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)]; | |
| 1566 | int index; | |
| 1567 | int exitCode; | |
| 1568 | __global intintLCGQuadraticOpenCompactCLHash_TableData *mytableData = | |
| 1569 | (__global intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1570 | tableData; | |
| 1571 | intintHash_CompressLCGData compressFuncData = | |
| 1572 | mytableData->compressFuncData; | |
| 1573 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1574 | unsigned long int iteration = 0; | |
| 1575 | for (;;) { | |
| 1576 | index = | |
| 1577 | ((1 * iteration * iteration + 0 * iteration + | |
| 1578 | c) % | |
| 1579 | ((__global intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1580 | tableData)->numBuckets); | |
| 1581 | if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1582 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1583 | break; | |
| 1584 | } else if (key == buckets[index].key) { | |
| 1585 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1586 | break; | |
| 1587 | } else | |
| 1588 | if ((iteration > | |
| 1589 | ((__global | |
| 1590 | intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1591 | tableData)->numBuckets)) { | |
| 1592 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1593 | break; | |
| 1594 | } | |
| 1595 | iteration++; | |
| 1596 | } | |
| 1597 | switch (exitCode) { | |
| 1598 | case HASH_SEARCH_CODE_MATCH: | |
| 1599 | *valueOutput = buckets[index].value; | |
| 1600 | return HASH_EXIT_CODE_NORMAL; | |
| 1601 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1602 | case HASH_SEARCH_CODE_EMPTY: | |
| 1603 | return HASH_EXIT_CODE_KEY_DNE; | |
| 1604 | default: | |
| 1605 | return exitCode; | |
| 1606 | } | |
| 1607 | } | |
| 1608 | int intintLCGQuadraticOpenCompactCLHash_InnerQuery(__global char *tableData, | |
| 1609 | unsigned int numKeys, | |
| 1610 | __global int *keys, | |
| 1611 | __global int *valuesOutput) { | |
| 1612 | __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets = | |
| 1613 | (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) & | |
| 1614 | tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)]; | |
| 1615 | int key; | |
| 1616 | __global int *valueOutput; | |
| 1617 | int index; | |
| 1618 | int exitCode; | |
| 1619 | uint i; | |
| 1620 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1621 | for (i = 0; i < numKeys; i++) { | |
| 1622 | key = keys[i]; | |
| 1623 | valueOutput = &valuesOutput[i]; | |
| 1624 | __global intintLCGQuadraticOpenCompactCLHash_TableData | |
| 1625 | *mytableData = | |
| 1626 | (__global intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1627 | tableData; | |
| 1628 | intintHash_CompressLCGData compressFuncData = | |
| 1629 | mytableData->compressFuncData; | |
| 1630 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1631 | unsigned long int iteration = 0; | |
| 1632 | for (;;) { | |
| 1633 | index = | |
| 1634 | ((1 * iteration * iteration + 0 * iteration + | |
| 1635 | c) % | |
| 1636 | ((__global | |
| 1637 | intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1638 | tableData)->numBuckets); | |
| 1639 | if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1640 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1641 | break; | |
| 1642 | } else if (key == buckets[index].key) { | |
| 1643 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1644 | break; | |
| 1645 | } else | |
| 1646 | if ((iteration > | |
| 1647 | ((__global | |
| 1648 | intintLCGQuadraticOpenCompactCLHash_TableData | |
| 1649 | *) tableData)->numBuckets)) { | |
| 1650 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1651 | break; | |
| 1652 | } | |
| 1653 | iteration++; | |
| 1654 | } | |
| 1655 | switch (exitCode) { | |
| 1656 | case HASH_SEARCH_CODE_MATCH: | |
| 1657 | *valueOutput = buckets[index].value; | |
| 1658 | break; | |
| 1659 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1660 | case HASH_SEARCH_CODE_EMPTY: | |
| 1661 | resultExitCode = HASH_EXIT_CODE_KEY_DNE; | |
| 1662 | break; | |
| 1663 | default: | |
| 1664 | return exitCode; | |
| 1665 | } | |
| 1666 | } | |
| 1667 | return resultExitCode; | |
| 1668 | } | |
| 1669 | int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingle(__global char | |
| 1670 | *tableData, int key, | |
| 1671 | int value) { | |
| 1672 | __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets = | |
| 1673 | (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) & | |
| 1674 | tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)]; | |
| 1675 | int index; | |
| 1676 | int exitCode; | |
| 1677 | __global intintLCGQuadraticOpenCompactCLHash_TableData *mytableData = | |
| 1678 | (__global intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1679 | tableData; | |
| 1680 | intintHash_CompressLCGData compressFuncData = | |
| 1681 | mytableData->compressFuncData; | |
| 1682 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1683 | unsigned long int iteration = 0; | |
| 1684 | for (;;) { | |
| 1685 | index = | |
| 1686 | ((1 * iteration * iteration + 0 * iteration + | |
| 1687 | c) % | |
| 1688 | ((__global intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1689 | tableData)->numBuckets); | |
| 1690 | if ((atomic_cmpxchg | |
| 1691 | (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY, | |
| 1692 | key)) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1693 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1694 | break; | |
| 1695 | } else if (key == buckets[index].key) { | |
| 1696 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1697 | break; | |
| 1698 | } else | |
| 1699 | if ((iteration > | |
| 1700 | ((__global | |
| 1701 | intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1702 | tableData)->numBuckets)) { | |
| 1703 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1704 | break; | |
| 1705 | } | |
| 1706 | iteration++; | |
| 1707 | } | |
| 1708 | switch (exitCode) { | |
| 1709 | case HASH_SEARCH_CODE_MATCH: | |
| 1710 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1711 | buckets[index].value = value; | |
| 1712 | return HASH_EXIT_CODE_OVERWRITE; | |
| 1713 | case HASH_SEARCH_CODE_EMPTY: | |
| 1714 | buckets[index].value = value; | |
| 1715 | return HASH_EXIT_CODE_NORMAL; | |
| 1716 | default: | |
| 1717 | return exitCode; | |
| 1718 | } | |
| 1719 | } | |
| 1720 | int intintLCGQuadraticOpenCompactCLHash_InnerInsert(__global char *tableData, | |
| 1721 | unsigned int numEntries, | |
| 1722 | __global int *keys, | |
| 1723 | __global int *values) { | |
| 1724 | __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets = | |
| 1725 | (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) & | |
| 1726 | tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)]; | |
| 1727 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1728 | int key; | |
| 1729 | int value; | |
| 1730 | int index; | |
| 1731 | int exitCode; | |
| 1732 | uint i; | |
| 1733 | for (i = 0; i < numEntries; i++) { | |
| 1734 | key = keys[i]; | |
| 1735 | __global intintLCGQuadraticOpenCompactCLHash_TableData | |
| 1736 | *mytableData = | |
| 1737 | (__global intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1738 | tableData; | |
| 1739 | intintHash_CompressLCGData compressFuncData = | |
| 1740 | mytableData->compressFuncData; | |
| 1741 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1742 | unsigned long int iteration = 0; | |
| 1743 | for (;;) { | |
| 1744 | index = | |
| 1745 | ((1 * iteration * iteration + 0 * iteration + | |
| 1746 | c) % | |
| 1747 | ((__global | |
| 1748 | intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1749 | tableData)->numBuckets); | |
| 1750 | if ((atomic_cmpxchg | |
| 1751 | (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY, | |
| 1752 | key)) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1753 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1754 | break; | |
| 1755 | } else if (key == buckets[index].key) { | |
| 1756 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1757 | break; | |
| 1758 | } else | |
| 1759 | if ((iteration > | |
| 1760 | ((__global | |
| 1761 | intintLCGQuadraticOpenCompactCLHash_TableData | |
| 1762 | *) tableData)->numBuckets)) { | |
| 1763 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1764 | break; | |
| 1765 | } | |
| 1766 | iteration++; | |
| 1767 | } | |
| 1768 | switch (exitCode) { | |
| 1769 | case HASH_SEARCH_CODE_MATCH: | |
| 1770 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1771 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 1772 | case HASH_SEARCH_CODE_EMPTY: | |
| 1773 | buckets[index].value = values[i]; | |
| 1774 | break; | |
| 1775 | default: | |
| 1776 | return exitCode; | |
| 1777 | } | |
| 1778 | } | |
| 1779 | return resultExitCode; | |
| 1780 | } | |
| 1781 | int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global | |
| 1782 | char | |
| 1783 | *tableData, | |
| 1784 | int key, | |
| 1785 | int value) | |
| 1786 | { | |
| 1787 | __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets = | |
| 1788 | (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) & | |
| 1789 | tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)]; | |
| 1790 | int index; | |
| 1791 | int exitCode; | |
| 1792 | __global intintLCGQuadraticOpenCompactCLHash_TableData *mytableData = | |
| 1793 | (__global intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1794 | tableData; | |
| 1795 | intintHash_CompressLCGData compressFuncData = | |
| 1796 | mytableData->compressFuncData; | |
| 1797 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1798 | unsigned long int iteration = 0; | |
| 1799 | for (;;) { | |
| 1800 | index = | |
| 1801 | ((1 * iteration * iteration + 0 * iteration + | |
| 1802 | c) % | |
| 1803 | ((__global intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1804 | tableData)->numBuckets); | |
| 1805 | if ((atomic_cmpxchg | |
| 1806 | (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY, | |
| 1807 | key)) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1808 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1809 | break; | |
| 1810 | } else if (key == buckets[index].key) { | |
| 1811 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1812 | break; | |
| 1813 | } else | |
| 1814 | if ((iteration > | |
| 1815 | ((__global | |
| 1816 | intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1817 | tableData)->numBuckets)) { | |
| 1818 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1819 | break; | |
| 1820 | } | |
| 1821 | iteration++; | |
| 1822 | } | |
| 1823 | switch (exitCode) { | |
| 1824 | case HASH_SEARCH_CODE_MATCH: | |
| 1825 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1826 | return HASH_EXIT_CODE_OVERWRITE; | |
| 1827 | case HASH_SEARCH_CODE_EMPTY: | |
| 1828 | buckets[index].value = value; | |
| 1829 | return HASH_EXIT_CODE_NORMAL; | |
| 1830 | default: | |
| 1831 | return exitCode; | |
| 1832 | } | |
| 1833 | } | |
| 1834 | int intintLCGQuadraticOpenCompactCLHash_InnerInsertNoOverwrite(__global char | |
| 1835 | *tableData, | |
| 1836 | unsigned int | |
| 1837 | numEntries, | |
| 1838 | __global int | |
| 1839 | *keys, | |
| 1840 | __global int | |
| 1841 | *values) { | |
| 1842 | __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets = | |
| 1843 | (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) & | |
| 1844 | tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)]; | |
| 1845 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1846 | int key; | |
| 1847 | int value; | |
| 1848 | int index; | |
| 1849 | int exitCode; | |
| 1850 | uint i; | |
| 1851 | for (i = 0; i < numEntries; i++) { | |
| 1852 | key = keys[i]; | |
| 1853 | __global intintLCGQuadraticOpenCompactCLHash_TableData | |
| 1854 | *mytableData = | |
| 1855 | (__global intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1856 | tableData; | |
| 1857 | intintHash_CompressLCGData compressFuncData = | |
| 1858 | mytableData->compressFuncData; | |
| 1859 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1860 | unsigned long int iteration = 0; | |
| 1861 | for (;;) { | |
| 1862 | index = | |
| 1863 | ((1 * iteration * iteration + 0 * iteration + | |
| 1864 | c) % | |
| 1865 | ((__global | |
| 1866 | intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1867 | tableData)->numBuckets); | |
| 1868 | if ((atomic_cmpxchg | |
| 1869 | (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY, | |
| 1870 | key)) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1871 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1872 | break; | |
| 1873 | } else if (key == buckets[index].key) { | |
| 1874 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1875 | break; | |
| 1876 | } else | |
| 1877 | if ((iteration > | |
| 1878 | ((__global | |
| 1879 | intintLCGQuadraticOpenCompactCLHash_TableData | |
| 1880 | *) tableData)->numBuckets)) { | |
| 1881 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1882 | break; | |
| 1883 | } | |
| 1884 | iteration++; | |
| 1885 | } | |
| 1886 | switch (exitCode) { | |
| 1887 | case HASH_SEARCH_CODE_MATCH: | |
| 1888 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1889 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 1890 | break; | |
| 1891 | case HASH_SEARCH_CODE_EMPTY: | |
| 1892 | buckets[index].value = values[i]; | |
| 1893 | break; | |
| 1894 | default: | |
| 1895 | return exitCode; | |
| 1896 | } | |
| 1897 | } | |
| 1898 | return resultExitCode; | |
| 1899 | } | |
| 1900 | int intintLCGQuadraticOpenCompactCLHash_QuerySingle(__global char *tableData, | |
| 1901 | int key, | |
| 1902 | __global int *valueOutput) { | |
| 1903 | return intintLCGQuadraticOpenCompactCLHash_InnerQuerySingle(tableData, | |
| 1904 | key, | |
| 1905 | valueOutput); | |
| 1906 | } | |
| 1907 | int intintLCGQuadraticOpenCompactCLHash_Query(__global char *tableData, | |
| 1908 | size_t numKeys, | |
| 1909 | __global int *keys, | |
| 1910 | __global int *valuesOutput) { | |
| 1911 | return intintLCGQuadraticOpenCompactCLHash_InnerQuery(tableData, | |
| 1912 | numKeys, keys, | |
| 1913 | valuesOutput); | |
| 1914 | } | |
| 1915 | int intintLCGQuadraticOpenCompactCLHash_InsertSingle(__global char *tableData, | |
| 1916 | int key, int value) { | |
| 1917 | return intintLCGQuadraticOpenCompactCLHash_InnerInsertSingle(tableData, | |
| 1918 | key, | |
| 1919 | value); | |
| 1920 | } | |
| 1921 | int intintLCGQuadraticOpenCompactCLHash_Insert(__global char *tableData, | |
| 1922 | size_t numEntries, | |
| 1923 | __global int *keys, | |
| 1924 | __global int *values) { | |
| 1925 | return intintLCGQuadraticOpenCompactCLHash_InnerInsert(tableData, | |
| 1926 | numEntries, keys, | |
| 1927 | values); | |
| 1928 | } | |
| 1929 | int intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite(__global char | |
| 1930 | *tableData, | |
| 1931 | int key, | |
| 1932 | int value) { | |
| 1933 | return | |
| 1934 | intintLCGQuadraticOpenCompactCLHash_InnerInsertSingleNoOverwrite | |
| 1935 | (tableData, key, value); | |
| 1936 | } | |
| 1937 | int intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite(__global char | |
| 1938 | *tableData, | |
| 1939 | size_t numEntries, | |
| 1940 | __global int *keys, | |
| 1941 | __global int *values) | |
| 1942 | { | |
| 1943 | return | |
| 1944 | intintLCGQuadraticOpenCompactCLHash_InnerInsertNoOverwrite | |
| 1945 | (tableData, numEntries, keys, values); | |
| 1946 | } | |
| 1947 | __kernel void intintLCGQuadraticOpenCompactCLHash_RangeQuerySingle(__global char | |
| 1948 | *tableData, | |
| 1949 | unsigned int | |
| 1950 | numQueries, | |
| 1951 | __global int | |
| 1952 | *keys, | |
| 1953 | __global int | |
| 1954 | *valuesOutput) | |
| 1955 | { | |
| 1956 | uint i = get_global_id(0); | |
| 1957 | if (i >= numQueries) { | |
| 1958 | return; | |
| 1959 | } | |
| 1960 | intintLCGQuadraticOpenCompactCLHash_InnerQuerySingle(tableData, keys[i], | |
| 1961 | valuesOutput + i); | |
| 1962 | } | |
| 1963 | __kernel void intintLCGQuadraticOpenCompactCLHash_RangeQuery(__global char | |
| 1964 | *tableData, | |
| 1965 | unsigned int | |
| 1966 | numQueries, | |
| 1967 | unsigned int | |
| 1968 | numKeys, | |
| 1969 | __global int *keys, | |
| 1970 | __global int | |
| 1971 | *valuesOutput) { | |
| 1972 | uint i = get_global_id(0); | |
| 1973 | if (i >= numQueries) { | |
| 1974 | return; | |
| 1975 | } | |
| 1976 | intintLCGQuadraticOpenCompactCLHash_InnerQuery(tableData, numKeys, | |
| 1977 | keys + (i * numKeys), | |
| 1978 | valuesOutput + | |
| 1979 | (i * numKeys)); | |
| 1980 | } | |
| 1981 | __kernel void intintLCGQuadraticOpenCompactCLHash_RangeInsertSingle(__global | |
| 1982 | char | |
| 1983 | *tableData, | |
| 1984 | unsigned int | |
| 1985 | numInsertions, | |
| 1986 | __global int | |
| 1987 | *keys, | |
| 1988 | __global int | |
| 1989 | *values) { | |
| 1990 | uint i = get_global_id(0); | |
| 1991 | if (i >= numInsertions) { | |
| 1992 | return; | |
| 1993 | } | |
| 1994 | intintLCGQuadraticOpenCompactCLHash_InnerInsertSingle(tableData, | |
| 1995 | keys[i], | |
| 1996 | values[i]); | |
| 1997 | } | |
| 1998 | __kernel void intintLCGQuadraticOpenCompactCLHash_RangeInsert(__global char | |
| 1999 | *tableData, | |
| 2000 | unsigned int | |
| 2001 | numInsertions, | |
| 2002 | unsigned int | |
| 2003 | numEntries, | |
| 2004 | __global int | |
| 2005 | *keys, | |
| 2006 | __global int | |
| 2007 | *values) { | |
| 2008 | uint i = get_global_id(0); | |
| 2009 | if (i >= numInsertions) { | |
| 2010 | return; | |
| 2011 | } | |
| 2012 | intintLCGQuadraticOpenCompactCLHash_InnerInsert(tableData, numEntries, | |
| 2013 | keys + (i * numEntries), | |
| 2014 | values + | |
| 2015 | (i * numEntries)); | |
| 2016 | } | |
| 2017 | __kernel void | |
| 2018 | intintLCGQuadraticOpenCompactCLHash_RangeInsertSingleNoOverwrite(__global char | |
| 2019 | *tableData, | |
| 2020 | unsigned int | |
| 2021 | numInsertions, | |
| 2022 | __global int | |
| 2023 | *keys, | |
| 2024 | __global int | |
| 2025 | *values) { | |
| 2026 | uint i = get_global_id(0); | |
| 2027 | if (i >= numInsertions) { | |
| 2028 | return; | |
| 2029 | } | |
| 2030 | intintLCGQuadraticOpenCompactCLHash_InnerInsertSingleNoOverwrite | |
| 2031 | (tableData, keys[i], values[i]); | |
| 2032 | } | |
| 2033 | __kernel void | |
| 2034 | intintLCGQuadraticOpenCompactCLHash_RangeInsertNoOverwrite(__global char | |
| 2035 | *tableData, | |
| 2036 | unsigned int | |
| 2037 | numInsertions, | |
| 2038 | unsigned int | |
| 2039 | numEntries, | |
| 2040 | __global int *keys, | |
| 2041 | __global int | |
| 2042 | *values) { | |
| 2043 | uint i = get_global_id(0); | |
| 2044 | if (i >= numInsertions) { | |
| 2045 | return; | |
| 2046 | } | |
| 2047 | intintLCGQuadraticOpenCompactCLHash_InnerInsertNoOverwrite(tableData, | |
| 2048 | numEntries, | |
| 2049 | keys + | |
| 2050 | (i * | |
| 2051 | numEntries), | |
| 2052 | values + | |
| 2053 | (i * | |
| 2054 | numEntries)); | |
| 2055 | } | |
| 2056 | __kernel void intintHash_RangeQuery(__global char *tableData, | |
| 2057 | unsigned int numQueries, | |
| 2058 | unsigned int numKeys, __global int *keys, | |
| 2059 | __global int *valuesOutput) { | |
| 2060 | switch (((__global int *)tableData)[0]) { | |
| 2061 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2062 | return intintIdentityPerfectCLHash_RangeQuery(tableData, | |
| 2063 | numQueries, | |
| 2064 | numKeys, keys, | |
| 2065 | valuesOutput); | |
| 2066 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2067 | return intintIdentitySentinelPerfectCLHash_RangeQuery(tableData, | |
| 2068 | numQueries, | |
| 2069 | numKeys, | |
| 2070 | keys, | |
| 2071 | valuesOutput); | |
| 2072 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2073 | return intintLCGLinearOpenCompactCLHash_RangeQuery(tableData, | |
| 2074 | numQueries, | |
| 2075 | numKeys, | |
| 2076 | keys, | |
| 2077 | valuesOutput); | |
| 2078 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2079 | return intintLCGQuadraticOpenCompactCLHash_RangeQuery(tableData, | |
| 2080 | numQueries, | |
| 2081 | numKeys, | |
| 2082 | keys, | |
| 2083 | valuesOutput); | |
| 2084 | } | |
| 2085 | } | |
| 2086 | __kernel void intintHash_RangeQuerySingle(__global char *tableData, | |
| 2087 | unsigned int numQueries, | |
| 2088 | __global int *keys, | |
| 2089 | __global int *valueOutput) { | |
| 2090 | switch (((__global int *)tableData)[0]) { | |
| 2091 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2092 | return intintIdentityPerfectCLHash_RangeQuerySingle(tableData, | |
| 2093 | numQueries, | |
| 2094 | keys, | |
| 2095 | valueOutput); | |
| 2096 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2097 | return | |
| 2098 | intintIdentitySentinelPerfectCLHash_RangeQuerySingle | |
| 2099 | (tableData, numQueries, keys, valueOutput); | |
| 2100 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2101 | return | |
| 2102 | intintLCGLinearOpenCompactCLHash_RangeQuerySingle(tableData, | |
| 2103 | numQueries, | |
| 2104 | keys, | |
| 2105 | valueOutput); | |
| 2106 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2107 | return | |
| 2108 | intintLCGQuadraticOpenCompactCLHash_RangeQuerySingle | |
| 2109 | (tableData, numQueries, keys, valueOutput); | |
| 2110 | } | |
| 2111 | } | |
| 2112 | __kernel void intintHash_RangeInsert(__global char *tableData, | |
| 2113 | unsigned int numInsertions, | |
| 2114 | unsigned int numEntries, | |
| 2115 | __global int *keys, __global int *values) { | |
| 2116 | switch (((__global int *)tableData)[0]) { | |
| 2117 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2118 | return intintIdentityPerfectCLHash_RangeInsert(tableData, | |
| 2119 | numInsertions, | |
| 2120 | numEntries, keys, | |
| 2121 | values); | |
| 2122 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2123 | return | |
| 2124 | intintIdentitySentinelPerfectCLHash_RangeInsert(tableData, | |
| 2125 | numInsertions, | |
| 2126 | numEntries, | |
| 2127 | keys, | |
| 2128 | values); | |
| 2129 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2130 | return intintLCGLinearOpenCompactCLHash_RangeInsert(tableData, | |
| 2131 | numInsertions, | |
| 2132 | numEntries, | |
| 2133 | keys, | |
| 2134 | values); | |
| 2135 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2136 | return | |
| 2137 | intintLCGQuadraticOpenCompactCLHash_RangeInsert(tableData, | |
| 2138 | numInsertions, | |
| 2139 | numEntries, | |
| 2140 | keys, | |
| 2141 | values); | |
| 2142 | } | |
| 2143 | } | |
| 2144 | __kernel void intintHash_RangeInsertSingle(__global char *tableData, | |
| 2145 | unsigned int numInsertions, | |
| 2146 | __global int *keys, | |
| 2147 | __global int *values) { | |
| 2148 | switch (((__global int *)tableData)[0]) { | |
| 2149 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2150 | return intintIdentityPerfectCLHash_RangeInsertSingle(tableData, | |
| 2151 | numInsertions, | |
| 2152 | keys, | |
| 2153 | values); | |
| 2154 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2155 | return | |
| 2156 | intintIdentitySentinelPerfectCLHash_RangeInsertSingle | |
| 2157 | (tableData, numInsertions, keys, values); | |
| 2158 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2159 | return | |
| 2160 | intintLCGLinearOpenCompactCLHash_RangeInsertSingle | |
| 2161 | (tableData, numInsertions, keys, values); | |
| 2162 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2163 | return | |
| 2164 | intintLCGQuadraticOpenCompactCLHash_RangeInsertSingle | |
| 2165 | (tableData, numInsertions, keys, values); | |
| 2166 | } | |
| 2167 | } | |
| 2168 | __kernel void intintHash_RangeInsertNoOverwrite(__global char *tableData, | |
| 2169 | unsigned int numInsertions, | |
| 2170 | unsigned int numEntries, | |
| 2171 | __global int *keys, | |
| 2172 | __global int *values) { | |
| 2173 | switch (((__global int *)tableData)[0]) { | |
| 2174 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2175 | return | |
| 2176 | intintIdentityPerfectCLHash_RangeInsertNoOverwrite | |
| 2177 | (tableData, numInsertions, numEntries, keys, values); | |
| 2178 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2179 | return | |
| 2180 | intintIdentitySentinelPerfectCLHash_RangeInsertNoOverwrite | |
| 2181 | (tableData, numInsertions, numEntries, keys, values); | |
| 2182 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2183 | return | |
| 2184 | intintLCGLinearOpenCompactCLHash_RangeInsertNoOverwrite | |
| 2185 | (tableData, numInsertions, numEntries, keys, values); | |
| 2186 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2187 | return | |
| 2188 | intintLCGQuadraticOpenCompactCLHash_RangeInsertNoOverwrite | |
| 2189 | (tableData, numInsertions, numEntries, keys, values); | |
| 2190 | } | |
| 2191 | } | |
| 2192 | __kernel void intintHash_RangeInsertSingleNoOverwrite(__global char *tableData, | |
| 2193 | unsigned int | |
| 2194 | numInsertions, | |
| 2195 | __global int *keys, | |
| 2196 | __global int *values) { | |
| 2197 | switch (((__global int *)tableData)[0]) { | |
| 2198 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2199 | return | |
| 2200 | intintIdentityPerfectCLHash_RangeInsertSingleNoOverwrite | |
| 2201 | (tableData, numInsertions, keys, values); | |
| 2202 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2203 | return | |
| 2204 | intintIdentitySentinelPerfectCLHash_RangeInsertSingleNoOverwrite | |
| 2205 | (tableData, numInsertions, keys, values); | |
| 2206 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2207 | return | |
| 2208 | intintLCGLinearOpenCompactCLHash_RangeInsertSingleNoOverwrite | |
| 2209 | (tableData, numInsertions, keys, values); | |
| 2210 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2211 | return | |
| 2212 | intintLCGQuadraticOpenCompactCLHash_RangeInsertSingleNoOverwrite | |
| 2213 | (tableData, numInsertions, keys, values); | |
| 2214 | } | |
| 2215 | } | |
| 2216 | int intintHash_Query(__global char *tableData, unsigned int numKeys, | |
| 2217 | __global int *keys, __global int *valuesOutput) { | |
| 2218 | switch (((__global int *)tableData)[0]) { | |
| 2219 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2220 | return intintIdentityPerfectCLHash_Query(tableData, numKeys, | |
| 2221 | keys, valuesOutput); | |
| 2222 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2223 | return intintIdentitySentinelPerfectCLHash_Query(tableData, | |
| 2224 | numKeys, keys, | |
| 2225 | valuesOutput); | |
| 2226 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2227 | return intintLCGLinearOpenCompactCLHash_Query(tableData, | |
| 2228 | numKeys, keys, | |
| 2229 | valuesOutput); | |
| 2230 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2231 | return intintLCGQuadraticOpenCompactCLHash_Query(tableData, | |
| 2232 | numKeys, keys, | |
| 2233 | valuesOutput); | |
| 2234 | } | |
| 2235 | return HASH_EXIT_CODE_ERROR; | |
| 2236 | } | |
| 2237 | int intintHash_QuerySingle(__global char *tableData, int key, | |
| 2238 | __global int *valueOutput) { | |
| 2239 | switch (((__global int *)tableData)[0]) { | |
| 2240 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2241 | return intintIdentityPerfectCLHash_QuerySingle(tableData, key, | |
| 2242 | valueOutput); | |
| 2243 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2244 | return | |
| 2245 | intintIdentitySentinelPerfectCLHash_QuerySingle(tableData, | |
| 2246 | key, | |
| 2247 | valueOutput); | |
| 2248 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2249 | return intintLCGLinearOpenCompactCLHash_QuerySingle(tableData, | |
| 2250 | key, | |
| 2251 | valueOutput); | |
| 2252 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2253 | return | |
| 2254 | intintLCGQuadraticOpenCompactCLHash_QuerySingle(tableData, | |
| 2255 | key, | |
| 2256 | valueOutput); | |
| 2257 | } | |
| 2258 | return HASH_EXIT_CODE_ERROR; | |
| 2259 | } | |
| 2260 | int intintHash_Insert(__global char *tableData, unsigned int numEntries, | |
| 2261 | __global int *keys, __global int *values) { | |
| 2262 | switch (((__global int *)tableData)[0]) { | |
| 2263 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2264 | return intintIdentityPerfectCLHash_Insert(tableData, numEntries, | |
| 2265 | keys, values); | |
| 2266 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2267 | return intintIdentitySentinelPerfectCLHash_Insert(tableData, | |
| 2268 | numEntries, | |
| 2269 | keys, values); | |
| 2270 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2271 | return intintLCGLinearOpenCompactCLHash_Insert(tableData, | |
| 2272 | numEntries, keys, | |
| 2273 | values); | |
| 2274 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2275 | return intintLCGQuadraticOpenCompactCLHash_Insert(tableData, | |
| 2276 | numEntries, | |
| 2277 | keys, values); | |
| 2278 | } | |
| 2279 | return HASH_EXIT_CODE_ERROR; | |
| 2280 | } | |
| 2281 | int intintHash_InsertSingle(__global char *tableData, int key, int value) { | |
| 2282 | switch (((__global int *)tableData)[0]) { | |
| 2283 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2284 | return intintIdentityPerfectCLHash_InsertSingle(tableData, key, | |
| 2285 | value); | |
| 2286 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2287 | return | |
| 2288 | intintIdentitySentinelPerfectCLHash_InsertSingle(tableData, | |
| 2289 | key, | |
| 2290 | value); | |
| 2291 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2292 | return intintLCGLinearOpenCompactCLHash_InsertSingle(tableData, | |
| 2293 | key, | |
| 2294 | value); | |
| 2295 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2296 | return | |
| 2297 | intintLCGQuadraticOpenCompactCLHash_InsertSingle(tableData, | |
| 2298 | key, | |
| 2299 | value); | |
| 2300 | } | |
| 2301 | return HASH_EXIT_CODE_ERROR; | |
| 2302 | } | |
| 2303 | int intintHash_InsertNoOverwrite(__global char *tableData, | |
| 2304 | unsigned int numEntries, __global int *keys, | |
| 2305 | __global int *values) { | |
| 2306 | switch (((__global int *)tableData)[0]) { | |
| 2307 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2308 | return intintIdentityPerfectCLHash_InsertNoOverwrite(tableData, | |
| 2309 | numEntries, | |
| 2310 | keys, | |
| 2311 | values); | |
| 2312 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2313 | return | |
| 2314 | intintIdentitySentinelPerfectCLHash_InsertNoOverwrite | |
| 2315 | (tableData, numEntries, keys, values); | |
| 2316 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2317 | return | |
| 2318 | intintLCGLinearOpenCompactCLHash_InsertNoOverwrite | |
| 2319 | (tableData, numEntries, keys, values); | |
| 2320 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2321 | return | |
| 2322 | intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite | |
| 2323 | (tableData, numEntries, keys, values); | |
| 2324 | } | |
| 2325 | return HASH_EXIT_CODE_ERROR; | |
| 2326 | } | |
| 2327 | int intintHash_InsertSingleNoOverwrite(__global char *tableData, int key, | |
| 2328 | int value) { | |
| 2329 | switch (((__global int *)tableData)[0]) { | |
| 2330 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2331 | return | |
| 2332 | intintIdentityPerfectCLHash_InsertSingleNoOverwrite | |
| 2333 | (tableData, key, value); | |
| 2334 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2335 | return | |
| 2336 | intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite | |
| 2337 | (tableData, key, value); | |
| 2338 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2339 | return | |
| 2340 | intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite | |
| 2341 | (tableData, key, value); | |
| 2342 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2343 | return | |
| 2344 | intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite | |
| 2345 | (tableData, key, value); | |
| 2346 | } | |
| 2347 | return HASH_EXIT_CODE_ERROR; | |
| 2348 | } |
| … | … | @@ -0,0 +1,230 @@ |
| 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 | #define GLOBAL __global | |
| 34 | ||
| 35 | int intintIdentityPerfectCLHash_InsertSingle(__global char *tableData, | |
| 36 | int key, int value); | |
| 37 | int intintIdentityPerfectCLHash_InnerInsertSingle(__global char *tableData, | |
| 38 | int key, int value); | |
| 39 | int intintHash_InsertSingle(__global char *tableData, int key, int value); | |
| 40 | int intintIdentityPerfectCLHash_InnerQuery(__global char *tableData, | |
| 41 | unsigned int numKeys, | |
| 42 | __global int *keys, | |
| 43 | __global int *valuesOutput); | |
| 44 | int intintIdentityPerfectCLHash_InnerQuerySingle(__global char *tableData, | |
| 45 | int key, | |
| 46 | __global int *valueOutput); | |
| 47 | int intintIdentityPerfectCLHash_InnerInsert(__global char *tableData, | |
| 48 | unsigned int numEntries, | |
| 49 | __global int *keys, | |
| 50 | __global int *values); | |
| 51 | int intintIdentityPerfectCLHash_InnerInsertSingleNoOverwrite(__global char | |
| 52 | *tableData, | |
| 53 | int key, | |
| 54 | int value); | |
| 55 | int intintIdentityPerfectCLHash_InnerInsertNoOverwrite(__global char *tableData, | |
| 56 | unsigned int numEntries, | |
| 57 | __global int *keys, | |
| 58 | __global int *values); | |
| 59 | int intintIdentityPerfectCLHash_QuerySingle(__global char *tableData, int key, | |
| 60 | __global int *valueOutput); | |
| 61 | int intintIdentityPerfectCLHash_QuerySingle(__global char *tableData, int key, | |
| 62 | __global int *valueOutput); | |
| 63 | int intintIdentityPerfectCLHash_Query(__global char *tableData, size_t numKeys, | |
| 64 | __global int *keys, | |
| 65 | __global int *valuesOutput); | |
| 66 | int intintIdentityPerfectCLHash_Insert(__global char *tableData, | |
| 67 | size_t numEntries, __global int *keys, | |
| 68 | __global int *values); | |
| 69 | int intintIdentityPerfectCLHash_InsertSingleNoOverwrite(__global char | |
| 70 | *tableData, int key, | |
| 71 | int value); | |
| 72 | int intintIdentityPerfectCLHash_InsertNoOverwrite(__global char *tableData, | |
| 73 | size_t numEntries, | |
| 74 | __global int *keys, | |
| 75 | __global int *values); | |
| 76 | int intintIdentitySentinelPerfectCLHash_InnerInsertNoOverwrite(__global char *tableData, | |
| 77 | unsigned int numEntries, | |
| 78 | __global int *keys, | |
| 79 | __global int *values); | |
| 80 | int intintIdentitySentinelPerfectCLHash_InnerQuerySingle(__global char *tableData, int key, | |
| 81 | __global int *valueOutput); | |
| 82 | int intintIdentitySentinelPerfectCLHash_InnerQuery(__global char *tableData, | |
| 83 | unsigned int numKeys, | |
| 84 | __global int *keys, | |
| 85 | __global int *valuesOutput); | |
| 86 | int intintIdentitySentinelPerfectCLHash_InnerInsertSingle(__global char *tableData, int key, | |
| 87 | int value); | |
| 88 | int intintIdentitySentinelPerfectCLHash_InnerInsert(__global char *tableData, | |
| 89 | unsigned int numEntries, | |
| 90 | __global int *keys, | |
| 91 | __global int *values); | |
| 92 | int intintIdentitySentinelPerfectCLHash_InnerInsertSingleNoOverwrite(__global char *tableData, | |
| 93 | int key, | |
| 94 | int value); | |
| 95 | int intintIdentitySentinelPerfectCLHash_QuerySingle(__global char *tableData, | |
| 96 | int key, | |
| 97 | __global int *valueOutput); | |
| 98 | int intintIdentitySentinelPerfectCLHash_Query(__global char *tableData, | |
| 99 | size_t numKeys, | |
| 100 | __global int *keys, | |
| 101 | __global int *valuesOutput); | |
| 102 | int intintIdentitySentinelPerfectCLHash_InsertSingle(__global char *tableData, | |
| 103 | int key, int value); | |
| 104 | int intintIdentitySentinelPerfectCLHash_Insert(__global char *tableData, | |
| 105 | size_t numEntries, | |
| 106 | __global int *keys, | |
| 107 | __global int *values); | |
| 108 | int intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite(__global char | |
| 109 | *tableData, | |
| 110 | int key, | |
| 111 | int value); | |
| 112 | int intintIdentitySentinelPerfectCLHash_InsertNoOverwrite(__global char *tableData, | |
| 113 | size_t numEntries, | |
| 114 | __global int *keys, | |
| 115 | __global int *values); | |
| 116 | int intintLCGLinearOpenCompactCLHash_InnerQuerySingle(__global char *tableData, | |
| 117 | int key, | |
| 118 | __global int *valueOutput); | |
| 119 | int intintLCGLinearOpenCompactCLHash_QuerySingle(__global char *tableData, | |
| 120 | int key, | |
| 121 | __global int *valueOutput); | |
| 122 | int intintLCGLinearOpenCompactCLHash_Query(__global char *tableData, | |
| 123 | size_t numKeys, __global int *keys, | |
| 124 | __global int *valuesOutput); | |
| 125 | int intintLCGLinearOpenCompactCLHash_InsertSingle(__global char *tableData, | |
| 126 | int key, int value); | |
| 127 | int intintLCGLinearOpenCompactCLHash_Insert(__global char *tableData, | |
| 128 | size_t numEntries, | |
| 129 | __global int *keys, | |
| 130 | __global int *values); | |
| 131 | int intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite(__global char | |
| 132 | *tableData, | |
| 133 | int key, | |
| 134 | int value); | |
| 135 | int intintLCGLinearOpenCompactCLHash_InsertNoOverwrite(__global char *tableData, | |
| 136 | size_t numEntries, | |
| 137 | __global int *keys, | |
| 138 | __global int *values); | |
| 139 | int intintLCGLinearOpenCompactCLHash_InnerQuery(__global char *tableData, | |
| 140 | unsigned int numKeys, | |
| 141 | __global int *keys, | |
| 142 | __global int *valuesOutput); | |
| 143 | int intintLCGLinearOpenCompactCLHash_InnerInsertNoOverwrite(__global char *tableData, | |
| 144 | unsigned int numEntries, | |
| 145 | __global int *keys, | |
| 146 | __global int *values); | |
| 147 | int intintLCGLinearOpenCompactCLHash_InnerInsertSingle(__global char *tableData, | |
| 148 | int key, int value); | |
| 149 | int intintLCGLinearOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global char *tableData, | |
| 150 | int key, int value); | |
| 151 | int intintLCGLinearOpenCompactCLHash_InnerInsert(__global char *tableData, | |
| 152 | unsigned int numEntries, | |
| 153 | __global int *keys, | |
| 154 | __global int *values); | |
| 155 | int intintLCGQuadraticOpenCompactCLHash_InnerQuerySingle(__global char *tableData, int key, | |
| 156 | __global int *valueOutput); | |
| 157 | int intintLCGQuadraticOpenCompactCLHash_InnerQuery(__global char *tableData, | |
| 158 | unsigned int numKeys, | |
| 159 | __global int *keys, | |
| 160 | __global int *valuesOutput); | |
| 161 | int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingle(__global char *tableData, int key, | |
| 162 | int value); | |
| 163 | int intintLCGQuadraticOpenCompactCLHash_InnerInsert(__global char *tableData, | |
| 164 | unsigned int numEntries, | |
| 165 | __global int *keys, | |
| 166 | __global int *values); | |
| 167 | int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global char *tableData, | |
| 168 | int key, int value); | |
| 169 | int intintLCGQuadraticOpenCompactCLHash_InnerInsertNoOverwrite(__global char *tableData, | |
| 170 | unsigned int numEntries, | |
| 171 | __global int *keys, | |
| 172 | __global int *values); | |
| 173 | int intintLCGQuadraticOpenCompactCLHash_QuerySingle(__global char *tableData, | |
| 174 | int key, | |
| 175 | __global int *valueOutput); | |
| 176 | int intintLCGQuadraticOpenCompactCLHash_Query(__global char *tableData, | |
| 177 | size_t numKeys, | |
| 178 | __global int *keys, | |
| 179 | __global int *valuesOutput); | |
| 180 | int intintLCGQuadraticOpenCompactCLHash_InsertSingle(__global char *tableData, | |
| 181 | int key, int value); | |
| 182 | int intintLCGQuadraticOpenCompactCLHash_Insert(__global char *tableData, | |
| 183 | size_t numEntries, | |
| 184 | __global int *keys, | |
| 185 | __global int *values); | |
| 186 | int intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite(__global char | |
| 187 | *tableData, | |
| 188 | int key, | |
| 189 | int value); | |
| 190 | int intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite(__global char *tableData, | |
| 191 | size_t numEntries, | |
| 192 | __global int *keys, | |
| 193 | __global int *values); | |
| 194 | int intintHash_Query(__global char *tableData, unsigned int numKeys, | |
| 195 | __global int *keys, __global int *valuesOutput); | |
| 196 | int intintHash_QuerySingle(__global char *tableData, int key, | |
| 197 | __global int *valueOutput); | |
| 198 | int intintHash_Insert(__global char *tableData, unsigned int numEntries, | |
| 199 | __global int *keys, __global int *values); | |
| 200 | int intintHash_InsertNoOverwrite(__global char *tableData, | |
| 201 | unsigned int numEntries, __global int *keys, | |
| 202 | __global int *values); | |
| 203 | int intintHash_InsertSingleNoOverwrite(__global char *tableData, int key, | |
| 204 | int value); | |
| 205 | #define DELAY(X) X | |
| 206 | DELAY(#define HASH_REPORT_NEVER /**/ 0) | |
| 207 | DELAY(#define HASH_REPORT_CYCLE /**/ 1) | |
| 208 | DELAY(#define HASH_REPORT_END /****/ 2) | |
| 209 | // | |
| 210 | DELAY(#define HASH_EXIT_CODE_NORMAL /****************/ -1) | |
| 211 | DELAY(#define HASH_EXIT_CODE_ERROR /*****************/ -2) | |
| 212 | DELAY(#define HASH_EXIT_CODE_OVERWRITE /*************/ -3) | |
| 213 | DELAY(#define HASH_EXIT_CODE_KEY_DNE /***************/ -4) | |
| 214 | DELAY(#define HASH_EXIT_CODE_CYCLE /*****************/ -5) | |
| 215 | DELAY(#define HASH_EXIT_CODE_MAX_ENTRIES_EXCEEDED /**/ -6) | |
| 216 | DELAY(#define HASH_EXIT_CODE_BUCKET_INDEX_OOB /******/ -7) | |
| 217 | // | |
| 218 | DELAY(#define HASH_SEARCH_CODE_MATCH /*****/ 0) | |
| 219 | DELAY(#define HASH_SEARCH_CODE_MISMATCH /**/ 1) | |
| 220 | DELAY(#define HASH_SEARCH_CODE_EMPTY /*****/ 2) | |
| 221 | // | |
| 222 | DELAY(#define LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID /**/ 8) | |
| 223 | DELAY(#define LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID /**/ 4) | |
| 224 | DELAY(#define IDENTITY_SENTINEL_PERFECT_CL_HASH_ID /*******/ 2) | |
| 225 | DELAY(#define IDENTITY_PERFECT_CL_HASH_ID /*******/ 1) | |
| 226 | // | |
| 227 | DELAY(#define HASH_BUCKET_STATUS_EMPTY /**/ -1) | |
| 228 | DELAY(#define HASH_BUCKET_STATUS_FULL /***/ -2) | |
| 229 | DELAY(#define HASH_BUCKET_STATUS_LOCK /***/ -3) | |
| 230 | HASH_KERN_DEFINE(intint, int, int) |
| … | … | @@ -0,0 +1,372 @@ |
| 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 "perfectHash.cm" | |
| 34 | #include "compactHash.cm" | |
| 35 | #include "HashFactory.hm" | |
| 36 | ||
| 37 | #define HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE) \ | |
| 38 | \ | |
| 39 | struct NAME##Hash_Table_{\ | |
| 40 | char* tableData;\ | |
| 41 | cl_mem tableDataBuffer;\ | |
| 42 | int (*destroyFunc)(NAME##Hash_Table*);\ | |
| 43 | int (*emptyFunc)(NAME##Hash_Table*);\ | |
| 44 | int (*queryFunc)(NAME##Hash_Table*, size_t, KEY_TYPE*, VALUE_TYPE*);\ | |
| 45 | int (*querySingleFunc)(NAME##Hash_Table*, KEY_TYPE, VALUE_TYPE*);\ | |
| 46 | int (*insertFunc)(NAME##Hash_Table*, size_t, KEY_TYPE*, VALUE_TYPE*);\ | |
| 47 | int (*insertSingleFunc)(NAME##Hash_Table*, KEY_TYPE, VALUE_TYPE);\ | |
| 48 | int (*insertNoOverwriteFunc)(NAME##Hash_Table*, size_t, KEY_TYPE*, VALUE_TYPE*);\ | |
| 49 | int (*insertSingleNoOverwriteFunc)(NAME##Hash_Table*, KEY_TYPE, VALUE_TYPE);\ | |
| 50 | int (*bufferQueryFunc)(NAME##Hash_Table*, size_t, cl_mem, cl_mem);\ | |
| 51 | int (*bufferInsertFunc)(NAME##Hash_Table*, size_t, cl_mem, cl_mem);\ | |
| 52 | int (*bufferInsertNoOverwriteFunc)(NAME##Hash_Table*, size_t, cl_mem, cl_mem);\ | |
| 53 | cl_context context;\ | |
| 54 | cl_command_queue queue;\ | |
| 55 | cl_program utilProgram;\ | |
| 56 | cl_kernel emptyKernel;\ | |
| 57 | size_t emptyKernelLocalWorkSize;\ | |
| 58 | cl_program program;\ | |
| 59 | cl_kernel querySingleKernel;\ | |
| 60 | cl_kernel insertSingleKernel;\ | |
| 61 | cl_kernel insertSingleNoOverwriteKernel;\ | |
| 62 | size_t localWorkSize;\ | |
| 63 | };\ | |
| 64 | \ | |
| 65 | struct NAME##Hash_Factory_{\ | |
| 66 | cl_context context;\ | |
| 67 | cl_program program;\ | |
| 68 | cl_command_queue queue;\ | |
| 69 | int hashTypesAvailable;\ | |
| 70 | cl_program utilProgram[HASH_NUM_CL_HASHES];\ | |
| 71 | cl_kernel emptyKernel[HASH_NUM_CL_HASHES];\ | |
| 72 | size_t emptyKernelLocalWorkSize[HASH_NUM_CL_HASHES];\ | |
| 73 | cl_kernel querySingleKernel[HASH_NUM_CL_HASHES];\ | |
| 74 | cl_kernel insertSingleKernel[HASH_NUM_CL_HASHES];\ | |
| 75 | cl_kernel insertSingleNoOverwriteKernel[HASH_NUM_CL_HASHES];\ | |
| 76 | VALUE_TYPE emptyValue;\ | |
| 77 | size_t localWorkSize;\ | |
| 78 | NAME##Hash_Table* (*createFunc[HASH_NUM_HASHES])(NAME##Hash_Factory*, int hashIndex, size_t keyRange, size_t numEntries, float loadFactor);\ | |
| 79 | int (*destroyFunc[HASH_NUM_HASHES])(NAME##Hash_Factory*, int hashIndex);\ | |
| 80 | };\ | |
| 81 | \ | |
| 82 | NAME##Hash_Factory* NAME##Hash_CreateFactory(int hashTypes, VALUE_TYPE *emptyValue, size_t localWorkSize, cl_context *context, cl_command_queue *queue){\ | |
| 83 | if(hashTypes == 0){\ | |
| 84 | hashTypes = HASH_ALL_C_HASHES;\ | |
| 85 | }\ | |
| 86 | if(!(hashTypes & HASH_ALL_HASHES)){\ | |
| 87 | printf("Please specify a valid hash type to create.\n");\ | |
| 88 | exit(1);\ | |
| 89 | }\ | |
| 90 | hashTypes &= HASH_ALL_HASHES;\ | |
| 91 | if((hashTypes & HASH_SENTINEL_PERFECT_HASHES) == hashTypes && emptyValue == NULL){\ | |
| 92 | printf("emptyValue must be valid if a sentinel perfect hash is the only option available.\n");\ | |
| 93 | exit(1);\ | |
| 94 | }\ | |
| 95 | NAME##Hash_Factory *factory = (NAME##Hash_Factory*)malloc(sizeof(NAME##Hash_Factory));\ | |
| 96 | if(emptyValue == NULL){\ | |
| 97 | hashTypes &= !HASH_SENTINEL_PERFECT_HASHES;\ | |
| 98 | }else{\ | |
| 99 | factory->emptyValue = *emptyValue;\ | |
| 100 | }\ | |
| 101 | factory->hashTypesAvailable = hashTypes;\ | |
| 102 | if(hashTypes & HASH_ALL_CL_HASHES){\ | |
| 103 | if(localWorkSize == 0){\ | |
| 104 | factory->localWorkSize = HASH_DEFAULT_LOCAL_WORK_SIZE;\ | |
| 105 | }else{\ | |
| 106 | factory->localWorkSize = 1 << intLog2(localWorkSize);\ | |
| 107 | }\ | |
| 108 | if(context == NULL){\ | |
| 109 | CLHash_Utilities_CreateContext(&factory->context, &factory->queue);\ | |
| 110 | }else{\ | |
| 111 | factory->context = *context;\ | |
| 112 | clRetainContext(*context);\ | |
| 113 | if(queue == NULL){\ | |
| 114 | printf("Please specify a command queue for your context.\n");\ | |
| 115 | exit(-1);\ | |
| 116 | }\ | |
| 117 | factory->queue = *queue;\ | |
| 118 | clRetainCommandQueue(*queue);\ | |
| 119 | }\ | |
| 120 | cl_int error;\ | |
| 121 | cl_device_id device;\ | |
| 122 | error = clGetContextInfo(factory->context, CL_CONTEXT_DEVICES, sizeof(device), &device, NULL);\ | |
| 123 | CLHash_Utilities_HandleError(error, STRINGIFY(NAME##Hash_CreateFactory), "clGetContextInfo");\ | |
| 124 | factory->program = CLHash_Utilities_BuildProgramString(factory->context, device, Hash_GetKernelSourceString());\ | |
| 125 | }\ | |
| 126 | int hashType=1;\ | |
| 127 | for(int hashIndex = 0; hashIndex < HASH_NUM_HASHES; hashIndex++){\ | |
| 128 | hashType = 1 << hashIndex;\ | |
| 129 | switch(hashType & hashTypes){\ | |
| 130 | case IDENTITY_PERFECT_HASH_ID: NAME##IdentityPerfectHash_CreateFactory(factory, hashIndex); break;\ | |
| 131 | case IDENTITY_PERFECT_CL_HASH_ID: NAME##IdentityPerfectCLHash_CreateFactory(factory, hashIndex); break;\ | |
| 132 | case IDENTITY_SENTINEL_PERFECT_HASH_ID: NAME##IdentitySentinelPerfectHash_CreateFactory(factory, hashIndex); break;\ | |
| 133 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: NAME##IdentitySentinelPerfectCLHash_CreateFactory(factory, hashIndex); break;\ | |
| 134 | case LCG_LINEAR_OPEN_COMPACT_HASH_ID: NAME##LCGLinearOpenCompactHash_CreateFactory(factory, hashIndex); break;\ | |
| 135 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: NAME##LCGLinearOpenCompactCLHash_CreateFactory(factory, hashIndex); break;\ | |
| 136 | case LCG_QUADRATIC_OPEN_COMPACT_HASH_ID: NAME##LCGQuadraticOpenCompactHash_CreateFactory(factory, hashIndex); break;\ | |
| 137 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: NAME##LCGQuadraticOpenCompactCLHash_CreateFactory(factory, hashIndex); break;\ | |
| 138 | }\ | |
| 139 | }\ | |
| 140 | return factory;\ | |
| 141 | }\ | |
| 142 | \ | |
| 143 | int NAME##Hash_DestroyFactory(NAME##Hash_Factory *factory){\ | |
| 144 | int hashType;\ | |
| 145 | for(int hashIndex = 0; hashIndex < HASH_NUM_HASHES; hashType = 1 << hashIndex){\ | |
| 146 | switch(hashType & factory->hashTypesAvailable){\ | |
| 147 | case IDENTITY_PERFECT_HASH_ID: NAME##IdentityPerfectHash_DestroyFactory(factory, hashIndex); break;\ | |
| 148 | case IDENTITY_PERFECT_CL_HASH_ID: NAME##IdentityPerfectCLHash_DestroyFactory(factory, hashIndex); break;\ | |
| 149 | case IDENTITY_SENTINEL_PERFECT_HASH_ID: NAME##IdentitySentinelPerfectHash_DestroyFactory(factory, hashIndex); break;\ | |
| 150 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: NAME##IdentitySentinelPerfectCLHash_DestroyFactory(factory, hashIndex); break;\ | |
| 151 | case LCG_LINEAR_OPEN_COMPACT_HASH_ID: NAME##LCGLinearOpenCompactHash_DestroyFactory(factory, hashIndex); break;\ | |
| 152 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: NAME##LCGLinearOpenCompactCLHash_DestroyFactory(factory, hashIndex); break;\ | |
| 153 | case LCG_QUADRATIC_OPEN_COMPACT_HASH_ID: NAME##LCGQuadraticOpenCompactHash_DestroyFactory(factory, hashIndex); break;\ | |
| 154 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: NAME##LCGQuadraticOpenCompactCLHash_DestroyFactory(factory, hashIndex); break;\ | |
| 155 | }\ | |
| 156 | hashIndex++;\ | |
| 157 | }\ | |
| 158 | if(factory->hashTypesAvailable & HASH_ALL_CL_HASHES){\ | |
| 159 | clReleaseContext(factory->context);\ | |
| 160 | clReleaseCommandQueue(factory->queue);\ | |
| 161 | clReleaseProgram(factory->program);\ | |
| 162 | }\ | |
| 163 | free(factory);\ | |
| 164 | return(0);\ | |
| 165 | }\ | |
| 166 | \ | |
| 167 | NAME##Hash_Table* NAME##Hash_CreateTable(NAME##Hash_Factory* factory, int hashTypes, size_t keyRange, size_t numEntries, float loadFactor){\ | |
| 168 | if(loadFactor > 1.0 || loadFactor < HASH_MIN_LOAD_FACTOR){\ | |
| 169 | loadFactor = HASH_DEFAULT_LOAD_FACTOR;\ | |
| 170 | }\ | |
| 171 | if(hashTypes == 0){\ | |
| 172 | hashTypes = factory->hashTypesAvailable;\ | |
| 173 | if((hashTypes & HASH_ALL_CL_HASHES) && (hashTypes & HASH_ALL_C_HASHES)){\ | |
| 174 | hashTypes &= HASH_ALL_C_HASHES;\ | |
| 175 | }\ | |
| 176 | }\ | |
| 177 | if(!(hashTypes & factory->hashTypesAvailable)){\ | |
| 178 | printf("None of the selected hash types are supported by this factory.\n");\ | |
| 179 | exit(1);\ | |
| 180 | }\ | |
| 181 | hashTypes &= factory->hashTypesAvailable;\ | |
| 182 | if((hashTypes & HASH_ALL_CL_HASHES) && (hashTypes & HASH_ALL_C_HASHES)){\ | |
| 183 | printf("Please decide between OpenCL or C hash.\n");\ | |
| 184 | exit(1);\ | |
| 185 | }\ | |
| 186 | if((hashTypes & HASH_PERFECT_HASHES) == hashTypes && keyRange == 0){\ | |
| 187 | printf("keyRange must be set if a perfect hash is the only option available.\n");\ | |
| 188 | exit(1);\ | |
| 189 | }\ | |
| 190 | if((hashTypes & HASH_COMPACT_HASHES) == hashTypes && numEntries == 0){\ | |
| 191 | printf("numEntries must be set if a compact hash is the only option available.\n");\ | |
| 192 | exit(1);\ | |
| 193 | }\ | |
| 194 | if(numEntries == 0 && keyRange == 0){\ | |
| 195 | printf("either numEntries or keyRange must be set.\n");\ | |
| 196 | exit(1);\ | |
| 197 | }\ | |
| 198 | size_t perfectNumBuckets = keyRange;\ | |
| 199 | size_t compactNumBuckets = (size_t)(numEntries/loadFactor);\ | |
| 200 | int hashIndex;\ | |
| 201 | if((hashTypes & HASH_SENTINEL_PERFECT_HASHES) && ((hashTypes == (hashTypes & HASH_SENTINEL_PERFECT_HASHES)) || (compactNumBuckets == 0 || (perfectNumBuckets/compactNumBuckets < HASH_PERFECT_COMPACT_SWITCH_FACTOR)))){\ | |
| 202 | hashIndex = intLog2(hashTypes & HASH_SENTINEL_PERFECT_HASHES);\ | |
| 203 | }else if((hashTypes & HASH_NOSENTINEL_PERFECT_HASHES) && ((hashTypes == (hashTypes & HASH_PERFECT_HASHES)) || (compactNumBuckets == 0 || (perfectNumBuckets/compactNumBuckets < HASH_PERFECT_COMPACT_SWITCH_FACTOR)))){\ | |
| 204 | hashIndex = intLog2(hashTypes & HASH_NOSENTINEL_PERFECT_HASHES);\ | |
| 205 | }else if((hashTypes & HASH_LINEAR_COMPACT_HASHES) && ((hashTypes == (hashTypes & (HASH_PERFECT_HASHES | HASH_LINEAR_COMPACT_HASHES))) || ((hashTypes & HASH_COMPACT_HASHES & HASH_LINEAR_COMPACT_HASHES) == (hashTypes & HASH_COMPACT_HASHES) || loadFactor > 0.5))){\ | |
| 206 | hashIndex = intLog2(hashTypes & HASH_LINEAR_COMPACT_HASHES);\ | |
| 207 | }else{\ | |
| 208 | hashIndex = intLog2(hashTypes & HASH_QUADRATIC_COMPACT_HASHES);\ | |
| 209 | }\ | |
| 210 | NAME##Hash_Table *table = factory->createFunc[hashIndex](factory, hashIndex, keyRange, numEntries, loadFactor);\ | |
| 211 | return table;\ | |
| 212 | }\ | |
| 213 | \ | |
| 214 | int NAME##Hash_EmptyTable(NAME##Hash_Table *table){\ | |
| 215 | table->emptyFunc(table);\ | |
| 216 | return(0);\ | |
| 217 | }\ | |
| 218 | \ | |
| 219 | int NAME##Hash_DestroyTable(NAME##Hash_Table *table){\ | |
| 220 | table->destroyFunc(table);\ | |
| 221 | return(0);\ | |
| 222 | }\ | |
| 223 | \ | |
| 224 | cl_mem NAME##Hash_GetTableDataBuffer(NAME##Hash_Table *table){\ | |
| 225 | return table->tableDataBuffer;\ | |
| 226 | }\ | |
| 227 | \ | |
| 228 | cl_mem *NAME##Hash_GetTableDataBufferPtr(NAME##Hash_Table *table){\ | |
| 229 | return &table->tableDataBuffer;\ | |
| 230 | }\ | |
| 231 | \ | |
| 232 | int NAME##Hash_GetTableType(NAME##Hash_Table *table){\ | |
| 233 | return ((int*)table->tableData)[0];\ | |
| 234 | }\ | |
| 235 | \ | |
| 236 | int NAME##Hash_Query(NAME##Hash_Table *table, size_t numKeys, KEY_TYPE *keys, VALUE_TYPE *valuesOutput){\ | |
| 237 | table->queryFunc(table, numKeys, keys, valuesOutput);\ | |
| 238 | return(0);\ | |
| 239 | }\ | |
| 240 | \ | |
| 241 | int NAME##Hash_QuerySingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE *valueOutput){\ | |
| 242 | table->querySingleFunc(table, key, valueOutput);\ | |
| 243 | return(0);\ | |
| 244 | }\ | |
| 245 | \ | |
| 246 | int NAME##Hash_Insert(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values){\ | |
| 247 | table->insertFunc(table, numEntries, keys, values);\ | |
| 248 | return(0);\ | |
| 249 | }\ | |
| 250 | \ | |
| 251 | int NAME##Hash_InsertSingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value){\ | |
| 252 | table->insertSingleFunc(table, key, value);\ | |
| 253 | return(0);\ | |
| 254 | }\ | |
| 255 | \ | |
| 256 | int NAME##Hash_InsertNoOverwrite(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values){\ | |
| 257 | table->insertNoOverwriteFunc(table, numEntries, keys, values);\ | |
| 258 | return(0);\ | |
| 259 | }\ | |
| 260 | \ | |
| 261 | int NAME##Hash_InsertSingleNoOverwrite(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value){\ | |
| 262 | table->insertSingleNoOverwriteFunc(table, key, value);\ | |
| 263 | return(0);\ | |
| 264 | }\ | |
| 265 | int NAME##Hash_BufferQuery(NAME##Hash_Table *table, size_t numKeys, cl_mem keys, cl_mem valuesOutput){\ | |
| 266 | table->bufferQueryFunc(table, numKeys, keys, valuesOutput);\ | |
| 267 | return(0);\ | |
| 268 | }\ | |
| 269 | \ | |
| 270 | int NAME##Hash_BufferInsert(NAME##Hash_Table *table, size_t numEntries, cl_mem keys, cl_mem values){\ | |
| 271 | table->bufferInsertFunc(table, numEntries, keys, values);\ | |
| 272 | return(0);\ | |
| 273 | }\ | |
| 274 | \ | |
| 275 | int NAME##Hash_BufferInsertNoOverwrite(NAME##Hash_Table *table, size_t numEntries, cl_mem keys, cl_mem values){\ | |
| 276 | table->bufferInsertNoOverwriteFunc(table, numEntries, keys, values);\ | |
| 277 | return(0);\ | |
| 278 | }\ | |
| 279 | \ | |
| 280 | IDENTITY_PERFECT_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 281 | \ | |
| 282 | IDENTITY_PERFECT_CL_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 283 | \ | |
| 284 | IDENTITY_SENTINEL_PERFECT_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 285 | \ | |
| 286 | IDENTITY_SENTINEL_PERFECT_CL_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 287 | \ | |
| 288 | LCG_LINEAR_OPEN_COMPACT_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE, 1)\ | |
| 289 | \ | |
| 290 | LCG_LINEAR_OPEN_COMPACT_CL_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 291 | \ | |
| 292 | LCG_QUADRATIC_OPEN_COMPACT_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE, 1, 0)\ | |
| 293 | \ | |
| 294 | LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 295 | \ | |
| 296 | ||
| 297 | #define KERN_SWITCH_LOOKUP_EXP(NAME, FUNCTION_NAME, ...)\ | |
| 298 | switch(((__global int*)tableData)[0]){\ | |
| 299 | case IDENTITY_PERFECT_CL_HASH_ID: return NAME##IdentityPerfectCLHash_##FUNCTION_NAME(__VA_ARGS__);\ | |
| 300 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: return NAME##IdentitySentinelPerfectCLHash_##FUNCTION_NAME(__VA_ARGS__);\ | |
| 301 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: return NAME##LCGLinearOpenCompactCLHash_##FUNCTION_NAME(__VA_ARGS__);\ | |
| 302 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: return NAME##LCGQuadraticOpenCompactCLHash_##FUNCTION_NAME(__VA_ARGS__);\ | |
| 303 | }\ | |
| 304 | \ | |
| 305 | ||
| 306 | #define HASH_KERN_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 307 | \ | |
| 308 | HASH_H_TYPES_DECLARE(NAME, KEY_TYPE)\ | |
| 309 | \ | |
| 310 | IDENTITY_PERFECT_CL_HASH_KERN_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 311 | \ | |
| 312 | IDENTITY_SENTINEL_PERFECT_CL_HASH_KERN_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 313 | \ | |
| 314 | LCG_LINEAR_OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, KEY_TYPE, VALUE_TYPE, 1)\ | |
| 315 | \ | |
| 316 | LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, KEY_TYPE, VALUE_TYPE, 1, 0)\ | |
| 317 | \ | |
| 318 | __kernel void NAME##Hash_RangeQuery(__global char *tableData, unsigned int numQueries, unsigned int numKeys, __global KEY_TYPE *keys, __global VALUE_TYPE *valuesOutput){\ | |
| 319 | KERN_SWITCH_LOOKUP_EXP(NAME, RangeQuery, tableData, numQueries, numKeys, keys, valuesOutput)\ | |
| 320 | }\ | |
| 321 | \ | |
| 322 | __kernel void NAME##Hash_RangeQuerySingle(__global char *tableData, unsigned int numQueries, __global KEY_TYPE *keys, __global VALUE_TYPE *valueOutput){\ | |
| 323 | KERN_SWITCH_LOOKUP_EXP(NAME, RangeQuerySingle, tableData, numQueries, keys, valueOutput)\ | |
| 324 | }\ | |
| 325 | \ | |
| 326 | __kernel void NAME##Hash_RangeInsert(__global char *tableData, unsigned int numInsertions, unsigned int numEntries, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 327 | KERN_SWITCH_LOOKUP_EXP(NAME, RangeInsert, tableData, numInsertions, numEntries, keys, values)\ | |
| 328 | }\ | |
| 329 | \ | |
| 330 | __kernel void NAME##Hash_RangeInsertSingle(__global char *tableData, unsigned int numInsertions, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 331 | KERN_SWITCH_LOOKUP_EXP(NAME, RangeInsertSingle, tableData, numInsertions, keys, values)\ | |
| 332 | }\ | |
| 333 | \ | |
| 334 | __kernel void NAME##Hash_RangeInsertNoOverwrite(__global char *tableData, unsigned int numInsertions, unsigned int numEntries, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 335 | KERN_SWITCH_LOOKUP_EXP(NAME, RangeInsertNoOverwrite, tableData, numInsertions, numEntries, keys, values)\ | |
| 336 | }\ | |
| 337 | \ | |
| 338 | __kernel void NAME##Hash_RangeInsertSingleNoOverwrite(__global char *tableData, unsigned int numInsertions, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 339 | KERN_SWITCH_LOOKUP_EXP(NAME, RangeInsertSingleNoOverwrite, tableData, numInsertions, keys, values)\ | |
| 340 | }\ | |
| 341 | \ | |
| 342 | int NAME##Hash_Query(__global char *tableData, unsigned int numKeys, __global KEY_TYPE *keys, __global VALUE_TYPE *valuesOutput){\ | |
| 343 | KERN_SWITCH_LOOKUP_EXP(NAME, Query, tableData, numKeys, keys, valuesOutput)\ | |
| 344 | return HASH_EXIT_CODE_ERROR;\ | |
| 345 | }\ | |
| 346 | \ | |
| 347 | int NAME##Hash_QuerySingle(__global char *tableData, KEY_TYPE key, __global VALUE_TYPE *valueOutput){\ | |
| 348 | KERN_SWITCH_LOOKUP_EXP(NAME, QuerySingle, tableData, key, valueOutput)\ | |
| 349 | return HASH_EXIT_CODE_ERROR;\ | |
| 350 | }\ | |
| 351 | \ | |
| 352 | int NAME##Hash_Insert(__global char *tableData, unsigned int numEntries, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 353 | KERN_SWITCH_LOOKUP_EXP(NAME, Insert, tableData, numEntries, keys, values)\ | |
| 354 | return HASH_EXIT_CODE_ERROR;\ | |
| 355 | }\ | |
| 356 | \ | |
| 357 | int NAME##Hash_InsertSingle(__global char *tableData, KEY_TYPE key, VALUE_TYPE value){\ | |
| 358 | KERN_SWITCH_LOOKUP_EXP(NAME, InsertSingle, tableData, key, value)\ | |
| 359 | return HASH_EXIT_CODE_ERROR;\ | |
| 360 | }\ | |
| 361 | \ | |
| 362 | int NAME##Hash_InsertNoOverwrite(__global char *tableData, unsigned int numEntries, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 363 | KERN_SWITCH_LOOKUP_EXP(NAME, InsertNoOverwrite, tableData, numEntries, keys, values)\ | |
| 364 | return HASH_EXIT_CODE_ERROR;\ | |
| 365 | }\ | |
| 366 | \ | |
| 367 | int NAME##Hash_InsertSingleNoOverwrite(__global char *tableData, KEY_TYPE key, VALUE_TYPE value){\ | |
| 368 | KERN_SWITCH_LOOKUP_EXP(NAME, InsertSingleNoOverwrite, tableData, key, value)\ | |
| 369 | return HASH_EXIT_CODE_ERROR;\ | |
| 370 | }\ | |
| 371 | \ | |
| 372 |
| … | … | @@ -0,0 +1,225 @@ |
| 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 | #define GLOBAL | |
| 34 | ||
| 35 | #undef UNDEFINED | |
| 36 | #ifdef UNDEFINED | |
| 37 | /** | |
| 38 | * @file hash.cp | |
| 39 | * @author Peter Ahrens | |
| 40 | * @date Thu Jun 6 2013 | |
| 41 | */ | |
| 42 | #endif | |
| 43 | /** | |
| 44 | * @file hash.c | |
| 45 | * @author Peter Ahrens | |
| 46 | * @date Thu Jun 6 2013 | |
| 47 | */ | |
| 48 | // | |
| 49 | #define DELAY(x) x | |
| 50 | #define STRINGIFY_(x) #x | |
| 51 | #define STRINGIFY(x) STRINGIFY_(x) | |
| 52 | DELAY(#include "HashFactory.h") | |
| 53 | DELAY(#ifdef HAVE_OPENCL) | |
| 54 | DELAY(#ifdef __APPLE_CC__) | |
| 55 | DELAY(#include <OpenCL/OpenCL.h>) | |
| 56 | DELAY(#else) | |
| 57 | DELAY(#include <CL/cl.h>) | |
| 58 | DELAY(#endif) | |
| 59 | DELAY(#else) | |
| 60 | typedef int cl_kernel; | |
| 61 | DELAY(#define CL_CONTEXT_DEVICES 0) | |
| 62 | DELAY(#define CL_MEM_READ_WRITE 0) | |
| 63 | DELAY(#define CL_TRUE 1) | |
| 64 | DELAY(#define CL_MEM_READ_ONLY 0) | |
| 65 | DELAY(#define CL_MEM_COPY_HOST_PTR 0) | |
| 66 | DELAY(#define CL_MEM_WRITE_ONLY 0) | |
| 67 | DELAY(#define CL_KERNEL_WORK_GROUP_SIZE 128) | |
| 68 | int clRetainContext(int context) { return context; } | |
| 69 | int clRetainCommandQueue(int command_queue) { return command_queue; } | |
| 70 | int clGetContextInfo(int context, int param, size_t size, void *value, size_t *size_ret) { return 0; } | |
| 71 | int clReleaseContext(int context) { return context; } | |
| 72 | int clReleaseCommandQueue(int command_queue) { return command_queue; } | |
| 73 | int clReleaseProgram(int program) { return program; } | |
| 74 | int clRetainKernel(int kernel) { return kernel; } | |
| 75 | int clRetainProgram(int program) { return program; } | |
| 76 | cl_mem clCreateBuffer(int context, int flags, size_t size, void *value, int *size_ret) { return 0; } | |
| 77 | int clEnqueueWriteBuffer(int command_queue, void *buffer, int blocking_write, size_t offset, size_t cb, const void * ptr, | |
| 78 | uint nevents, const int *wait_list, int *event) { return 0; } | |
| 79 | int clEnqueueReadBuffer(int command_queue, void *buffer, int blocking_write, size_t offset, size_t cb, const void * ptr, | |
| 80 | uint nevents, const int *wait_list, int *event) { return 0; } | |
| 81 | int clCreateKernel(int program, const char *kernel_name, int *errcode_ret) { return 0; } | |
| 82 | int clReleaseKernel(int kernel) { return kernel; } | |
| 83 | int clReleaseMemObject(void * memobj) { return 0; } | |
| 84 | int clSetKernelArg(int kernel, uint arg_index, size_t arg_size, const void *arg_value) { return 0; } | |
| 85 | int clGetKernelWorkGroupInfo(int kernel, int device, int param_name, size_t size, void *value, size_t *size_ret) { return 0; } | |
| 86 | int clEnqueueNDRangeKernel(int command_queue, int kernel, uint work_dim, const size_t *offset, const size_t *size, const size_t *local_size, | |
| 87 | uint nevents, const int *wait_list, int *event) { return 0; } | |
| 88 | int clFinish(int command_queue) { return 0; } | |
| 89 | DELAY(#endif) | |
| 90 | DELAY(#define PRIME_NUM_CHECKS 20) | |
| 91 | typedef unsigned int uint; | |
| 92 | ||
| 93 | ||
| 94 | DELAY(#include <math.h>) | |
| 95 | #include "HashFactory.cm" | |
| 96 | ||
| 97 | #ifdef __cplusplus | |
| 98 | extern "C" | |
| 99 | { | |
| 100 | #endif | |
| 101 | ||
| 102 | static int reportLevel = 0; | |
| 103 | ||
| 104 | const char* HashFactory_source; | |
| 105 | ||
| 106 | const char* Hash_GetKernelSourceString(){ | |
| 107 | return HashFactory_source; | |
| 108 | } | |
| 109 | ||
| 110 | size_t roundUpToNearest(size_t x, size_t r){ | |
| 111 | return (((x - 1) / r) + 1) * r; | |
| 112 | } | |
| 113 | ||
| 114 | int modularPow(int base, int exponent, int modulus){ | |
| 115 | int result = 1; | |
| 116 | while (exponent){ | |
| 117 | if (exponent & 1) | |
| 118 | result = ((long long int)result * base) % modulus; | |
| 119 | exponent >>= 1; | |
| 120 | base = ((long long int)base * base) % modulus; | |
| 121 | } | |
| 122 | return result; | |
| 123 | } | |
| 124 | ||
| 125 | int largestProthPrimeUnder(int N){ | |
| 126 | if(N < 4){ | |
| 127 | return N; | |
| 128 | } | |
| 129 | //determine the nearest proth number | |
| 130 | int n; | |
| 131 | int m; | |
| 132 | frexp((double)N, &n); | |
| 133 | n /= 2; | |
| 134 | int s = 1 << n; | |
| 135 | int p = s * ((N - 1) / s) + 1; | |
| 136 | int i; | |
| 137 | int a; | |
| 138 | srand(p); | |
| 139 | while(p > 3){ | |
| 140 | //check if a proth number is prime | |
| 141 | for(i = 0; i < PRIME_NUM_CHECKS; i++){ | |
| 142 | a = rand(); | |
| 143 | if(modularPow(a, (p - 1) / 2, p) == p - 1){ | |
| 144 | return p; | |
| 145 | } | |
| 146 | } | |
| 147 | //determine the next proth number | |
| 148 | if(p - 1 == s * s / 4){ | |
| 149 | s /= 2; | |
| 150 | } | |
| 151 | p -= s; | |
| 152 | } | |
| 153 | return 3; | |
| 154 | } | |
| 155 | ||
| 156 | int smallestProthPrimeAbove(int N){ | |
| 157 | if(N < 4){ | |
| 158 | return N; | |
| 159 | } | |
| 160 | //determine the nearest proth number | |
| 161 | int n; | |
| 162 | int m; | |
| 163 | frexp((double)N, &n); | |
| 164 | n /= 2; | |
| 165 | int s = 1 << n; | |
| 166 | int p = s * ((N - 1) / s) + 1; | |
| 167 | int i; | |
| 168 | int a; | |
| 169 | srand(p); | |
| 170 | while(1){ | |
| 171 | //determine the next proth number | |
| 172 | if(p - 1 == s * s){ | |
| 173 | s *= 2; | |
| 174 | } | |
| 175 | p += s; | |
| 176 | //check if a proth number is prime | |
| 177 | for(i = 0; i < PRIME_NUM_CHECKS; i++){ | |
| 178 | a = rand(); | |
| 179 | if(modularPow(a, (p - 1) / 2, p) == p - 1){ | |
| 180 | return p; | |
| 181 | } | |
| 182 | } | |
| 183 | } | |
| 184 | return 3; | |
| 185 | } | |
| 186 | ||
| 187 | int intLog2(int n){ | |
| 188 | int result = 0; | |
| 189 | while(n >>= 1){ | |
| 190 | result++; | |
| 191 | } | |
| 192 | return result; | |
| 193 | } | |
| 194 | ||
| 195 | void Hash_SetReportLevel(int level){ | |
| 196 | reportLevel = level; | |
| 197 | } | |
| 198 | ||
| 199 | int Hash_GetReportLevel(){ | |
| 200 | return reportLevel; | |
| 201 | } | |
| 202 | ||
| 203 | char* Hash_ExitCodeString(int exitCode){ | |
| 204 | switch(exitCode){ | |
| 205 | case HASH_EXIT_CODE_NORMAL: return "Normal"; | |
| 206 | case HASH_EXIT_CODE_ERROR: return "Error"; | |
| 207 | case HASH_EXIT_CODE_OVERWRITE: return "Overwrite"; | |
| 208 | case HASH_EXIT_CODE_KEY_DNE: return "Key Does Not Exist"; | |
| 209 | case HASH_EXIT_CODE_CYCLE: return "Cycle"; | |
| 210 | case HASH_EXIT_CODE_MAX_ENTRIES_EXCEEDED: return "Maximum Number Of Entries Exceeded"; | |
| 211 | default: return "Unknown"; | |
| 212 | } | |
| 213 | } | |
| 214 | ||
| 215 | void Hash_ExitCodeDebug(int exitCode){ | |
| 216 | if(exitCode != HASH_EXIT_CODE_NORMAL){ | |
| 217 | printf("HashExitCode: %s\n", Hash_ExitCodeString(exitCode)); | |
| 218 | } | |
| 219 | } | |
| 220 | ||
| 221 | HASH_DEFINE(intint, int, int) | |
| 222 | ||
| 223 | #ifdef __cplusplus | |
| 224 | } | |
| 225 | #endif |
| … | … | @@ -0,0 +1,600 @@ |
| 1 | ||
| 2 | /* Copyright (C) 1991-2012 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public | |
| 7 | License as published by the Free Software Foundation; either | |
| 8 | version 2.1 of the License, or (at your option) any later version. | |
| 9 | ||
| 10 | The GNU C Library is distributed in the hope that it will be useful, | |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | Lesser General Public License for more details. | |
| 14 | ||
| 15 | You should have received a copy of the GNU Lesser General Public | |
| 16 | License along with the GNU C Library; if not, see | |
| 17 | <http://www.gnu.org/licenses/>. */ | |
| 18 | /* This header is separate from features.h so that the compiler can | |
| 19 | include it implicitly at the start of every compilation. It must | |
| 20 | not itself include <features.h> or any other header that includes | |
| 21 | <features.h> because the implicit include comes before any feature | |
| 22 | test macros that may be defined in a source file before it first | |
| 23 | explicitly includes a system header. GCC knows the name of this | |
| 24 | header in order to preinclude it. */ | |
| 25 | /* We do support the IEC 559 math functionality, real and complex. */ | |
| 26 | /* wchar_t uses ISO/IEC 10646 (2nd ed., published 2011-03-15) / | |
| 27 | Unicode 6.0. */ | |
| 28 | /* We do not support C11 <threads.h>. */ | |
| 29 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 30 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 31 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 32 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 33 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 34 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 35 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 36 | * to produce derivative works, such modified software should be clearly marked, | |
| 37 | * so as not to confuse it with the version available from LANL. | |
| 38 | * | |
| 39 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 40 | * use this file except in compliance with the License. You may obtain a copy | |
| 41 | * of the License at | |
| 42 | * | |
| 43 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 44 | * | |
| 45 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 46 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 47 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 48 | * specific language governing permissions and limitations under the License. | |
| 49 | * | |
| 50 | * Under this license, it is required to include a reference to this work. We | |
| 51 | * request that each derivative work contain a reference to LANL Copyright | |
| 52 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 53 | * measured. In addition, it is requested that a modifier is included as in | |
| 54 | * the following example: | |
| 55 | * | |
| 56 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 57 | * | |
| 58 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 59 | */ | |
| 60 | /** | |
| 61 | * @file HashFactory.h | |
| 62 | * @author Peter Ahrens | |
| 63 | * @date Thu Jun 6 2013 | |
| 64 | */ | |
| 65 | // | |
| 66 | #ifndef HASH_H | |
| 67 | #define HASH_H | |
| 68 | // | |
| 69 | #include <stdlib.h> | |
| 70 | #include <stdio.h> | |
| 71 | #include <stdarg.h> | |
| 72 | #include <string.h> | |
| 73 | // | |
| 74 | #ifdef HAVE_OPENCL | |
| 75 | #ifdef __APPLE_CC__ | |
| 76 | #include <OpenCL/OpenCL.h> | |
| 77 | #else | |
| 78 | #include <CL/cl.h> | |
| 79 | #endif | |
| 80 | #else | |
| 81 | typedef void *cl_mem; | |
| 82 | typedef int cl_context; | |
| 83 | typedef int cl_command_queue; | |
| 84 | typedef int cl_program; | |
| 85 | typedef int cl_device_id; | |
| 86 | typedef int cl_int; | |
| 87 | int clRetainContext(int context); | |
| 88 | int clRetainCommandQueue(int command_queue); | |
| 89 | int clGetContextInfo(int context, int param, size_t size, void *value, | |
| 90 | size_t * size_ret); | |
| 91 | int clReleaseContext(int context); | |
| 92 | int clReleaseCommandQueue(int command_queue); | |
| 93 | int clReleaseProgram(int program); | |
| 94 | int clRetainProgram(int program); | |
| 95 | int clRetainKernel(int kernel); | |
| 96 | cl_mem clCreateBuffer(int context, int flags, size_t size, void *value, | |
| 97 | int *size_ret); | |
| 98 | int clEnqueueWriteBuffer(int command_queue, void *buffer, int blocking_write, | |
| 99 | size_t offset, size_t cb, const void *ptr, | |
| 100 | uint nevents, const int *wait_list, int *event); | |
| 101 | int clEnqueueReadBuffer(int command_queue, void *buffer, int blocking_write, | |
| 102 | size_t offset, size_t cb, const void *ptr, uint nevents, | |
| 103 | const int *wait_list, int *event); | |
| 104 | int clCreateKernel(int program, const char *kernel_name, int *errcode_ret); | |
| 105 | int clReleaseKernel(int kernel); | |
| 106 | int clReleaseMemObject(void *memobj); | |
| 107 | int clSetKernelArg(int kernel, uint arg_index, size_t arg_size, | |
| 108 | const void *arg_value); | |
| 109 | int clGetKernelWorkGroupInfo(int kernel, int device, int param_name, | |
| 110 | size_t size, void *value, size_t * size_ret); | |
| 111 | int clEnqueueNDRangeKernel(int command_queue, int kernel, uint work_dim, | |
| 112 | const size_t * offset, const size_t * size, | |
| 113 | const size_t * local_size, uint nevents, | |
| 114 | const int *wait_list, int *event); | |
| 115 | int clFinish(int command_queue); | |
| 116 | #endif | |
| 117 | // | |
| 118 | #include "CLHash_Utilities.h" | |
| 119 | // | |
| 120 | // | |
| 121 | #include "HashFactory.hm" | |
| 122 | #include "HashFactory.cm" | |
| 123 | // | |
| 124 | #define HASH_REPORT_NEVER /**/ 0 | |
| 125 | #define HASH_REPORT_CYCLE /**/ 1 | |
| 126 | #define HASH_REPORT_END /****/ 2 | |
| 127 | // | |
| 128 | #define HASH_EXIT_CODE_NORMAL /****************/ -1 | |
| 129 | #define HASH_EXIT_CODE_ERROR /*****************/ -2 | |
| 130 | #define HASH_EXIT_CODE_OVERWRITE /*************/ -3 | |
| 131 | #define HASH_EXIT_CODE_KEY_DNE /***************/ -4 | |
| 132 | #define HASH_EXIT_CODE_CYCLE /*****************/ -5 | |
| 133 | #define HASH_EXIT_CODE_MAX_ENTRIES_EXCEEDED /**/ -6 | |
| 134 | #define HASH_EXIT_CODE_BUCKET_INDEX_OOB /******/ -7 | |
| 135 | // | |
| 136 | #define HASH_SEARCH_CODE_MATCH /*****/ 0 | |
| 137 | #define HASH_SEARCH_CODE_MISMATCH /**/ 1 | |
| 138 | #define HASH_SEARCH_CODE_EMPTY /*****/ 2 | |
| 139 | // | |
| 140 | #define HASH_NUM_HASHES /**/ 8 | |
| 141 | #define HASH_NUM_CL_HASHES /**/ 4 | |
| 142 | // | |
| 143 | #define LCG_QUADRATIC_OPEN_COMPACT_HASH_ID 128 | |
| 144 | #define LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID 8 | |
| 145 | #define LCG_LINEAR_OPEN_COMPACT_HASH_ID 64 | |
| 146 | #define LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID 4 | |
| 147 | #define IDENTITY_SENTINEL_PERFECT_HASH_ID 32 | |
| 148 | #define IDENTITY_SENTINEL_PERFECT_CL_HASH_ID 2 | |
| 149 | #define IDENTITY_PERFECT_HASH_ID 16 | |
| 150 | #define IDENTITY_PERFECT_CL_HASH_ID 1 | |
| 151 | // | |
| 152 | /** | |
| 153 | * HASH_ALL_CL_HASHES hash table types that run in an OpenCL context. | |
| 154 | */ | |
| 155 | #define HASH_ALL_CL_HASHES (IDENTITY_PERFECT_CL_HASH_ID | IDENTITY_SENTINEL_PERFECT_CL_HASH_ID | LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID | LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID) | |
| 156 | /** | |
| 157 | * HASH_ALL_C_HASHES hash table types that run on the host. | |
| 158 | */ | |
| 159 | #define HASH_ALL_C_HASHES (IDENTITY_PERFECT_HASH_ID | IDENTITY_SENTINEL_PERFECT_HASH_ID | LCG_LINEAR_OPEN_COMPACT_HASH_ID | LCG_QUADRATIC_OPEN_COMPACT_HASH_ID) | |
| 160 | /** | |
| 161 | * HASH_ALL_HASHES all hash table types. | |
| 162 | */ | |
| 163 | #define HASH_ALL_HASHES (HASH_ALL_CL_HASHES | HASH_ALL_C_HASHES) | |
| 164 | /** | |
| 165 | * HASH_NOSENTINEL_PERFECT_HASHES perfect hash table types that do not use a sentinel value to mark empty buckets. | |
| 166 | */ | |
| 167 | #define HASH_NOSENTINEL_PERFECT_HASHES (IDENTITY_PERFECT_HASH_ID | IDENTITY_PERFECT_CL_HASH_ID) | |
| 168 | /** | |
| 169 | * HASH_SENTINEL_PERFECT_HASHES perfect hash table types that use a sentinel value to mark empty buckets. | |
| 170 | */ | |
| 171 | #define HASH_SENTINEL_PERFECT_HASHES (IDENTITY_SENTINEL_PERFECT_HASH_ID | IDENTITY_SENTINEL_PERFECT_CL_HASH_ID) | |
| 172 | /** | |
| 173 | * HASH_PERFECT_HASHES perfect hash table types. | |
| 174 | */ | |
| 175 | #define HASH_PERFECT_HASHES (HASH_NOSENTINEL_PERFECT_HASHES | HASH_SENTINEL_PERFECT_HASHES) | |
| 176 | /** | |
| 177 | * HASH_QUADRATIC_COMPACT_HASHES compact hash table types that use a quadratic probe sequence. | |
| 178 | */ | |
| 179 | #define HASH_QUADRATIC_COMPACT_HASHES (LCG_QUADRATIC_OPEN_COMPACT_HASH_ID | LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID) | |
| 180 | /** | |
| 181 | * HASH_LINEAR_COMPACT_HASHES compact hash table types that use a linear probe sequence. | |
| 182 | */ | |
| 183 | #define HASH_LINEAR_COMPACT_HASHES (LCG_LINEAR_OPEN_COMPACT_HASH_ID | LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID) | |
| 184 | /** | |
| 185 | * HASH_COMPACT_HASHES compact hash table types that use a linear probe sequence. | |
| 186 | */ | |
| 187 | #define HASH_COMPACT_HASHES (HASH_QUADRATIC_COMPACT_HASHES | HASH_LINEAR_COMPACT_HASHES) | |
| 188 | // | |
| 189 | #define HASH_DEFAULT_LOCAL_WORK_SIZE /*******/ 64 | |
| 190 | #define HASH_DEFAULT_LOAD_FACTOR /*******/ 0.3 | |
| 191 | #define HASH_MIN_LOAD_FACTOR /*******/ 0.0009 | |
| 192 | #define HASH_PERFECT_COMPACT_SWITCH_FACTOR /*******/ 20 | |
| 193 | #define HASH_LCG_A /*******/ 2147483629 | |
| 194 | #define HASH_LCG_C /*******/ 2147483587 | |
| 195 | #define HASH_LCG_M /*******/ 2147483647 | |
| 196 | // | |
| 197 | #define HASH_BUCKET_STATUS_EMPTY /**/ -1 | |
| 198 | #define HASH_BUCKET_STATUS_FULL /***/ -2 | |
| 199 | #define HASH_BUCKET_STATUS_LOCK /***/ -3 | |
| 200 | /** | |
| 201 | * Hash_ExitCodeString will return a string representation of the given exit | |
| 202 | * code. | |
| 203 | * | |
| 204 | * @param exitCode | |
| 205 | * | |
| 206 | * @return A string representation of that exit code. | |
| 207 | */ | |
| 208 | char *Hash_ExitCodeString(int exitCode); | |
| 209 | /** | |
| 210 | * Hash_ExitCodeDebug will print a string representation of the given exit code | |
| 211 | * if it is not EXIT_CODE_NORMAL. | |
| 212 | * | |
| 213 | * @param exitCode | |
| 214 | */ | |
| 215 | void Hash_ExitCodeDebug(int exitCode); | |
| 216 | /** | |
| 217 | * Hash_SetReportLevel sets a static report level variable in hash.c. It should | |
| 218 | * be called before hash tables are created. | |
| 219 | * | |
| 220 | * @param level The level of data collection desired. | |
| 221 | */ | |
| 222 | void Hash_SetReportLevel(int level); | |
| 223 | /** | |
| 224 | * Hash_GetReportLevel gets this variable. | |
| 225 | * | |
| 226 | * @return The current report level. | |
| 227 | * Special Values: Meaning | |
| 228 | * HASH_REPORT_NEVER: The hash table will not collect data. This is the | |
| 229 | * default. A call to Hash_Report will return an empty | |
| 230 | * string. | |
| 231 | * HASH_REPORT_END: The hash table will collect data and calls to | |
| 232 | * Hash_Report will return summary information. | |
| 233 | * HASH_REPORT_CYCLE: The hash table will collect data and calls to | |
| 234 | * Hash_Report will return information related to the | |
| 235 | * last important call. | |
| 236 | */ | |
| 237 | int Hash_GetReportLevel(); | |
| 238 | const char *Hash_GetKernelSourceString(); | |
| 239 | int smallestProthPrimeAbove(int N); | |
| 240 | int largestProthPrimeUnder(int N); | |
| 241 | typedef struct intintHash_Table_ intintHash_Table; | |
| 242 | typedef struct intintCLHash_Table_ intintCLHash_Table; | |
| 243 | typedef struct intintHash_Factory_ intintHash_Factory; | |
| 244 | typedef struct intintCLHash_Factory_ intintCLHash_Factory; | |
| 245 | intintHash_Factory *intintHash_CreateFactory(int HashTypes, int *emptyValue, | |
| 246 | size_t localWorkSize, | |
| 247 | cl_context * context, | |
| 248 | cl_command_queue * queue); | |
| 249 | int intintHash_DestroyFactory(intintHash_Factory * factory); | |
| 250 | intintHash_Table *intintHash_CreateTable(intintHash_Factory * factory, | |
| 251 | int hashTypes, size_t keyRange, | |
| 252 | size_t numEntries, float loadFactor); | |
| 253 | int intintHash_EmptyTable(intintHash_Table * table); | |
| 254 | int intintHash_DestroyTable(intintHash_Table * table); | |
| 255 | cl_mem intintHash_GetTableDataBuffer(intintHash_Table * table); | |
| 256 | cl_mem *intintHash_GetTableDataBufferPtr(intintHash_Table * table); | |
| 257 | int intintHash_GetTableType(intintHash_Table * table); | |
| 258 | int intintHash_Query(intintHash_Table * table, size_t numKeys, int *keys, | |
| 259 | int *valuesOutput); | |
| 260 | int intintHash_QuerySingle(intintHash_Table * table, int key, int *valueOutput); | |
| 261 | int intintHash_Insert(intintHash_Table * table, size_t numEntries, int *keys, | |
| 262 | int *values); | |
| 263 | int intintHash_InsertSingle(intintHash_Table * table, int key, int value); | |
| 264 | int intintHash_InsertNoOverwrite(intintHash_Table * table, size_t numEntries, | |
| 265 | int *keys, int *values); | |
| 266 | int intintHash_InsertSingleNoOverwrite(intintHash_Table * table, int key, | |
| 267 | int value); | |
| 268 | int intintHash_BufferQuery(intintHash_Table * table, size_t numKeys, | |
| 269 | cl_mem keys, cl_mem valuesOutput); | |
| 270 | int intintHash_BufferInsert(intintHash_Table * table, size_t numEntries, | |
| 271 | cl_mem keys, cl_mem values); | |
| 272 | int intintHash_BufferInsertNoOverwrite(intintHash_Table * table, | |
| 273 | size_t numEntries, cl_mem keys, | |
| 274 | cl_mem values); | |
| 275 | static inline unsigned int intintHash_CompressIdentity(char data, int hashCode) { | |
| 276 | return hashCode; | |
| 277 | } | |
| 278 | ||
| 279 | typedef struct intintHash_CompressLCGData { | |
| 280 | long unsigned int a; | |
| 281 | long unsigned int c; | |
| 282 | unsigned int m; | |
| 283 | unsigned int n; | |
| 284 | } intintHash_CompressLCGData; | |
| 285 | static inline unsigned int intintHash_CompressLCG(intintHash_CompressLCGData | |
| 286 | compressLCGData, | |
| 287 | int hashCode) { | |
| 288 | return ((compressLCGData.a * hashCode + | |
| 289 | compressLCGData.c) % compressLCGData.m) % compressLCGData.n; | |
| 290 | } | |
| 291 | ||
| 292 | int intintIdentityPerfectHash_CreateFactory(intintHash_Factory * factory, | |
| 293 | int hashIndex); | |
| 294 | int intintIdentityPerfectHash_DestroyFactory(intintHash_Factory * factory, | |
| 295 | int hashIndex); | |
| 296 | intintHash_Table *intintIdentityPerfectHash_CreateTable(intintHash_Factory * | |
| 297 | factory, int hashIndex, | |
| 298 | size_t keyRange, | |
| 299 | size_t numEntries, | |
| 300 | float loadFactor); | |
| 301 | int intintIdentityPerfectHash_InitTable(intintHash_Table * table, va_list args); | |
| 302 | int intintIdentityPerfectHash_DestroyTable(intintHash_Table * table); | |
| 303 | char *intintIdentityPerfectHash_Report(intintHash_Table * table); | |
| 304 | int intintIdentityPerfectHash_EmptyTable(intintHash_Table * table); | |
| 305 | int intintIdentityPerfectHash_Query(intintHash_Table * table, size_t numKeys, | |
| 306 | int *keys, int *valuesOutput); | |
| 307 | int intintIdentityPerfectHash_QuerySingle(intintHash_Table * table, int key, | |
| 308 | int *valueOutput); | |
| 309 | int intintIdentityPerfectHash_Insert(intintHash_Table * table, | |
| 310 | size_t numEntries, int *keys, int *values); | |
| 311 | int intintIdentityPerfectHash_InsertSingle(intintHash_Table * table, int key, | |
| 312 | int value); | |
| 313 | int intintIdentityPerfectHash_InsertNoOverwrite(intintHash_Table * table, | |
| 314 | size_t numEntries, int *keys, | |
| 315 | int *values); | |
| 316 | int intintIdentityPerfectHash_InsertSingleNoOverwrite(intintHash_Table * table, | |
| 317 | int key, int value); | |
| 318 | int intintIdentityPerfectCLHash_CreateFactory(intintHash_Factory * factory, | |
| 319 | int hashIndex); | |
| 320 | int intintIdentityPerfectCLHash_DestroyFactory(intintHash_Factory * factory, | |
| 321 | int hashIndex); | |
| 322 | intintHash_Table *intintIdentityPerfectCLHash_CreateTable(intintHash_Factory * | |
| 323 | factory, | |
| 324 | int hashIndex, | |
| 325 | size_t keyRange, | |
| 326 | size_t numEntries, | |
| 327 | float loadFactor); | |
| 328 | int intintIdentityPerfectCLHash_InitTable(intintHash_Table * table, | |
| 329 | va_list args); | |
| 330 | int intintIdentityPerfectCLHash_DestroyTable(intintHash_Table * table); | |
| 331 | char *intintIdentityPerfectCLHash_Report(intintHash_Table * table); | |
| 332 | int intintIdentityPerfectCLHash_EmptyTable(intintHash_Table * table); | |
| 333 | int intintIdentityPerfectCLHash_Query(intintHash_Table * table, size_t numKeys, | |
| 334 | int *keys, int *valuesOutput); | |
| 335 | int intintIdentityPerfectCLHash_QuerySingle(intintHash_Table * table, int key, | |
| 336 | int *valueOutput); | |
| 337 | int intintIdentityPerfectCLHash_Insert(intintHash_Table * table, | |
| 338 | size_t numEntries, int *keys, | |
| 339 | int *values); | |
| 340 | int intintIdentityPerfectCLHash_InsertSingle(intintHash_Table * table, int key, | |
| 341 | int value); | |
| 342 | int intintIdentityPerfectCLHash_InsertNoOverwrite(intintHash_Table * table, | |
| 343 | size_t numEntries, int *keys, | |
| 344 | int *values); | |
| 345 | int intintIdentityPerfectCLHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 346 | table, int key, | |
| 347 | int value); | |
| 348 | int intintIdentityPerfectCLHash_BufferQuery(intintHash_Table * table, | |
| 349 | size_t numKeys, cl_mem keysBuffer, | |
| 350 | cl_mem valuesOutputBuffer); | |
| 351 | int intintIdentityPerfectCLHash_BufferInsert(intintHash_Table * table, | |
| 352 | size_t numEntries, | |
| 353 | cl_mem keysBuffer, | |
| 354 | cl_mem valuesBuffer); | |
| 355 | int intintIdentityPerfectCLHash_BufferInsertNoOverwrite(intintHash_Table * | |
| 356 | table, | |
| 357 | size_t numEntries, | |
| 358 | cl_mem keysBuffer, | |
| 359 | cl_mem valuesBuffer); | |
| 360 | int intintIdentitySentinelPerfectHash_CreateFactory(intintHash_Factory * | |
| 361 | factory, int hashIndex); | |
| 362 | int intintIdentitySentinelPerfectHash_DestroyFactory(intintHash_Factory * | |
| 363 | factory, int hashIndex); | |
| 364 | intintHash_Table | |
| 365 | *intintIdentitySentinelPerfectHash_CreateTable(intintHash_Factory * factory, | |
| 366 | int hashIndex, | |
| 367 | size_t keyRange, | |
| 368 | size_t numEntries, | |
| 369 | float loadFactor); | |
| 370 | int intintIdentitySentinelPerfectHash_InitTable(intintHash_Table * table, | |
| 371 | va_list args); | |
| 372 | int intintIdentitySentinelPerfectHash_DestroyTable(intintHash_Table * table); | |
| 373 | char *intintIdentitySentinelPerfectHash_Report(intintHash_Table * table); | |
| 374 | int intintIdentitySentinelPerfectHash_EmptyTable(intintHash_Table * table); | |
| 375 | int intintIdentitySentinelPerfectHash_Query(intintHash_Table * table, | |
| 376 | size_t numKeys, int *keys, | |
| 377 | int *valuesOutput); | |
| 378 | int intintIdentitySentinelPerfectHash_QuerySingle(intintHash_Table * table, | |
| 379 | int key, int *valueOutput); | |
| 380 | int intintIdentitySentinelPerfectHash_Insert(intintHash_Table * table, | |
| 381 | size_t numEntries, int *keys, | |
| 382 | int *values); | |
| 383 | int intintIdentitySentinelPerfectHash_InsertSingle(intintHash_Table * table, | |
| 384 | int key, int value); | |
| 385 | int intintIdentitySentinelPerfectHash_InsertNoOverwrite(intintHash_Table * | |
| 386 | table, | |
| 387 | size_t numEntries, | |
| 388 | int *keys, int *values); | |
| 389 | int intintIdentitySentinelPerfectHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 390 | table, int key, | |
| 391 | int value); | |
| 392 | int intintIdentitySentinelPerfectCLHash_CreateFactory(intintHash_Factory * | |
| 393 | factory, int hashIndex); | |
| 394 | int intintIdentitySentinelPerfectCLHash_DestroyFactory(intintHash_Factory * | |
| 395 | factory, int hashIndex); | |
| 396 | intintHash_Table | |
| 397 | *intintIdentitySentinelPerfectCLHash_CreateTable(intintHash_Factory * | |
| 398 | factory, int hashIndex, | |
| 399 | size_t keyRange, | |
| 400 | size_t numEntries, | |
| 401 | float loadFactor); | |
| 402 | int intintIdentitySentinelPerfectCLHash_InitTable(intintHash_Table * table, | |
| 403 | va_list args); | |
| 404 | int intintIdentitySentinelPerfectCLHash_DestroyTable(intintHash_Table * table); | |
| 405 | char *intintIdentitySentinelPerfectCLHash_Report(intintHash_Table * table); | |
| 406 | int intintIdentitySentinelPerfectCLHash_EmptyTable(intintHash_Table * table); | |
| 407 | int intintIdentitySentinelPerfectCLHash_Query(intintHash_Table * table, | |
| 408 | size_t numKeys, int *keys, | |
| 409 | int *valuesOutput); | |
| 410 | int intintIdentitySentinelPerfectCLHash_QuerySingle(intintHash_Table * table, | |
| 411 | int key, int *valueOutput); | |
| 412 | int intintIdentitySentinelPerfectCLHash_Insert(intintHash_Table * table, | |
| 413 | size_t numEntries, int *keys, | |
| 414 | int *values); | |
| 415 | int intintIdentitySentinelPerfectCLHash_InsertSingle(intintHash_Table * table, | |
| 416 | int key, int value); | |
| 417 | int intintIdentitySentinelPerfectCLHash_InsertNoOverwrite(intintHash_Table * | |
| 418 | table, | |
| 419 | size_t numEntries, | |
| 420 | int *keys, | |
| 421 | int *values); | |
| 422 | int intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite(intintHash_Table | |
| 423 | * table, | |
| 424 | int key, | |
| 425 | int value); | |
| 426 | int intintIdentitySentinelPerfectCLHash_BufferQuery(intintHash_Table * table, | |
| 427 | size_t numKeys, | |
| 428 | cl_mem keysBuffer, | |
| 429 | cl_mem valuesOutputBuffer); | |
| 430 | int intintIdentitySentinelPerfectCLHash_BufferInsert(intintHash_Table * table, | |
| 431 | size_t numEntries, | |
| 432 | cl_mem keysBuffer, | |
| 433 | cl_mem valuesBuffer); | |
| 434 | int intintIdentitySentinelPerfectCLHash_BufferInsertNoOverwrite(intintHash_Table | |
| 435 | * table, | |
| 436 | size_t | |
| 437 | numEntries, | |
| 438 | cl_mem | |
| 439 | keysBuffer, | |
| 440 | cl_mem | |
| 441 | valuesBuffer); | |
| 442 | int intintLCGLinearOpenCompactHash_CreateFactory(intintHash_Factory * factory, | |
| 443 | int hashIndex); | |
| 444 | int intintLCGLinearOpenCompactHash_DestroyFactory(intintHash_Factory * factory, | |
| 445 | int hashIndex); | |
| 446 | intintHash_Table *intintLCGLinearOpenCompactHash_CreateTable(intintHash_Factory | |
| 447 | * factory, | |
| 448 | int hashIndex, | |
| 449 | size_t keyRange, | |
| 450 | size_t numEntries, | |
| 451 | float loadFactor); | |
| 452 | int intintLCGLinearOpenCompactHash_InitTable(intintHash_Table * table, | |
| 453 | va_list args); | |
| 454 | int intintLCGLinearOpenCompactHash_DestroyTable(intintHash_Table * table); | |
| 455 | char *intintLCGLinearOpenCompactHash_Report(intintHash_Table * table); | |
| 456 | int intintLCGLinearOpenCompactHash_EmptyTable(intintHash_Table * table); | |
| 457 | int intintLCGLinearOpenCompactHash_Query(intintHash_Table * table, | |
| 458 | size_t numKeys, int *keys, | |
| 459 | int *valuesOutput); | |
| 460 | int intintLCGLinearOpenCompactHash_QuerySingle(intintHash_Table * table, | |
| 461 | int key, int *valueOutput); | |
| 462 | int intintLCGLinearOpenCompactHash_Insert(intintHash_Table * table, | |
| 463 | size_t numEntries, int *keys, | |
| 464 | int *values); | |
| 465 | int intintLCGLinearOpenCompactHash_InsertSingle(intintHash_Table * table, | |
| 466 | int key, int value); | |
| 467 | int intintLCGLinearOpenCompactHash_InsertNoOverwrite(intintHash_Table * table, | |
| 468 | size_t numEntries, | |
| 469 | int *keys, int *values); | |
| 470 | int intintLCGLinearOpenCompactHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 471 | table, int key, | |
| 472 | int value); | |
| 473 | int intintLCGLinearOpenCompactCLHash_CreateFactory(intintHash_Factory * factory, | |
| 474 | int hashIndex); | |
| 475 | int intintLCGLinearOpenCompactCLHash_DestroyFactory(intintHash_Factory * | |
| 476 | factory, int hashIndex); | |
| 477 | intintHash_Table | |
| 478 | *intintLCGLinearOpenCompactCLHash_CreateTable(intintHash_Factory * factory, | |
| 479 | int hashIndex, | |
| 480 | size_t keyRange, | |
| 481 | size_t numEntries, | |
| 482 | float loadFactor); | |
| 483 | int intintLCGLinearOpenCompactCLHash_InitTable(intintHash_Table * table, | |
| 484 | va_list args); | |
| 485 | int intintLCGLinearOpenCompactCLHash_DestroyTable(intintHash_Table * table); | |
| 486 | char *intintLCGLinearOpenCompactCLHash_Report(intintHash_Table * table); | |
| 487 | int intintLCGLinearOpenCompactCLHash_EmptyTable(intintHash_Table * table); | |
| 488 | int intintLCGLinearOpenCompactCLHash_Query(intintHash_Table * table, | |
| 489 | size_t numKeys, int *keys, | |
| 490 | int *valuesOutput); | |
| 491 | int intintLCGLinearOpenCompactCLHash_QuerySingle(intintHash_Table * table, | |
| 492 | int key, int *valueOutput); | |
| 493 | int intintLCGLinearOpenCompactCLHash_Insert(intintHash_Table * table, | |
| 494 | size_t numEntries, int *keys, | |
| 495 | int *values); | |
| 496 | int intintLCGLinearOpenCompactCLHash_InsertSingle(intintHash_Table * table, | |
| 497 | int key, int value); | |
| 498 | int intintLCGLinearOpenCompactCLHash_InsertNoOverwrite(intintHash_Table * table, | |
| 499 | size_t numEntries, | |
| 500 | int *keys, int *values); | |
| 501 | int intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 502 | table, int key, | |
| 503 | int value); | |
| 504 | int intintLCGLinearOpenCompactCLHash_BufferQuery(intintHash_Table * table, | |
| 505 | size_t numKeys, | |
| 506 | cl_mem keysBuffer, | |
| 507 | cl_mem valuesOutputBuffer); | |
| 508 | int intintLCGLinearOpenCompactCLHash_BufferInsert(intintHash_Table * table, | |
| 509 | size_t numEntries, | |
| 510 | cl_mem keysBuffer, | |
| 511 | cl_mem valuesBuffer); | |
| 512 | int intintLCGLinearOpenCompactCLHash_BufferInsertNoOverwrite(intintHash_Table * | |
| 513 | table, | |
| 514 | size_t numEntries, | |
| 515 | cl_mem keysBuffer, | |
| 516 | cl_mem | |
| 517 | valuesBuffer); | |
| 518 | int intintLCGQuadraticOpenCompactHash_CreateFactory(intintHash_Factory * | |
| 519 | factory, int hashIndex); | |
| 520 | int intintLCGQuadraticOpenCompactHash_DestroyFactory(intintHash_Factory * | |
| 521 | factory, int hashIndex); | |
| 522 | intintHash_Table | |
| 523 | *intintLCGQuadraticOpenCompactHash_CreateTable(intintHash_Factory * factory, | |
| 524 | int hashIndex, | |
| 525 | size_t keyRange, | |
| 526 | size_t numEntries, | |
| 527 | float loadFactor); | |
| 528 | int intintLCGQuadraticOpenCompactHash_InitTable(intintHash_Table * table, | |
| 529 | va_list args); | |
| 530 | int intintLCGQuadraticOpenCompactHash_DestroyTable(intintHash_Table * table); | |
| 531 | char *intintLCGQuadraticOpenCompactHash_Report(intintHash_Table * table); | |
| 532 | int intintLCGQuadraticOpenCompactHash_EmptyTable(intintHash_Table * table); | |
| 533 | int intintLCGQuadraticOpenCompactHash_Query(intintHash_Table * table, | |
| 534 | size_t numKeys, int *keys, | |
| 535 | int *valuesOutput); | |
| 536 | int intintLCGQuadraticOpenCompactHash_QuerySingle(intintHash_Table * table, | |
| 537 | int key, int *valueOutput); | |
| 538 | int intintLCGQuadraticOpenCompactHash_Insert(intintHash_Table * table, | |
| 539 | size_t numEntries, int *keys, | |
| 540 | int *values); | |
| 541 | int intintLCGQuadraticOpenCompactHash_InsertSingle(intintHash_Table * table, | |
| 542 | int key, int value); | |
| 543 | int intintLCGQuadraticOpenCompactHash_InsertNoOverwrite(intintHash_Table * | |
| 544 | table, | |
| 545 | size_t numEntries, | |
| 546 | int *keys, int *values); | |
| 547 | int intintLCGQuadraticOpenCompactHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 548 | table, int key, | |
| 549 | int value); | |
| 550 | int intintLCGQuadraticOpenCompactCLHash_CreateFactory(intintHash_Factory * | |
| 551 | factory, int hashIndex); | |
| 552 | int intintLCGQuadraticOpenCompactCLHash_DestroyFactory(intintHash_Factory * | |
| 553 | factory, int hashIndex); | |
| 554 | intintHash_Table | |
| 555 | *intintLCGQuadraticOpenCompactCLHash_CreateTable(intintHash_Factory * | |
| 556 | factory, int hashIndex, | |
| 557 | size_t keyRange, | |
| 558 | size_t numEntries, | |
| 559 | float loadFactor); | |
| 560 | int intintLCGQuadraticOpenCompactCLHash_InitTable(intintHash_Table * table, | |
| 561 | va_list args); | |
| 562 | int intintLCGQuadraticOpenCompactCLHash_DestroyTable(intintHash_Table * table); | |
| 563 | char *intintLCGQuadraticOpenCompactCLHash_Report(intintHash_Table * table); | |
| 564 | int intintLCGQuadraticOpenCompactCLHash_EmptyTable(intintHash_Table * table); | |
| 565 | int intintLCGQuadraticOpenCompactCLHash_Query(intintHash_Table * table, | |
| 566 | size_t numKeys, int *keys, | |
| 567 | int *valuesOutput); | |
| 568 | int intintLCGQuadraticOpenCompactCLHash_QuerySingle(intintHash_Table * table, | |
| 569 | int key, int *valueOutput); | |
| 570 | int intintLCGQuadraticOpenCompactCLHash_Insert(intintHash_Table * table, | |
| 571 | size_t numEntries, int *keys, | |
| 572 | int *values); | |
| 573 | int intintLCGQuadraticOpenCompactCLHash_InsertSingle(intintHash_Table * table, | |
| 574 | int key, int value); | |
| 575 | int intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite(intintHash_Table * | |
| 576 | table, | |
| 577 | size_t numEntries, | |
| 578 | int *keys, | |
| 579 | int *values); | |
| 580 | int intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite(intintHash_Table | |
| 581 | * table, | |
| 582 | int key, | |
| 583 | int value); | |
| 584 | int intintLCGQuadraticOpenCompactCLHash_BufferQuery(intintHash_Table * table, | |
| 585 | size_t numKeys, | |
| 586 | cl_mem keysBuffer, | |
| 587 | cl_mem valuesOutputBuffer); | |
| 588 | int intintLCGQuadraticOpenCompactCLHash_BufferInsert(intintHash_Table * table, | |
| 589 | size_t numEntries, | |
| 590 | cl_mem keysBuffer, | |
| 591 | cl_mem valuesBuffer); | |
| 592 | int intintLCGQuadraticOpenCompactCLHash_BufferInsertNoOverwrite(intintHash_Table | |
| 593 | * table, | |
| 594 | size_t | |
| 595 | numEntries, | |
| 596 | cl_mem | |
| 597 | keysBuffer, | |
| 598 | cl_mem | |
| 599 | valuesBuffer); | |
| 600 | #endif |
| … | … | @@ -0,0 +1,116 @@ |
| 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 "perfectHash.hm" | |
| 34 | #include "compactHash.hm" | |
| 35 | ||
| 36 | #define HASH_H_TYPES_DECLARE(NAME, KEY_TYPE)\ | |
| 37 | \ | |
| 38 | static inline unsigned int NAME##Hash_CompressIdentity(char data, int hashCode){\ | |
| 39 | return hashCode;\ | |
| 40 | }\ | |
| 41 | \ | |
| 42 | typedef struct NAME##Hash_CompressLCGData{\ | |
| 43 | long unsigned int a;\ | |
| 44 | long unsigned int c;\ | |
| 45 | unsigned int m;\ | |
| 46 | unsigned int n;\ | |
| 47 | }NAME##Hash_CompressLCGData;\ | |
| 48 | \ | |
| 49 | static inline unsigned int NAME##Hash_CompressLCG(NAME##Hash_CompressLCGData compressLCGData, int hashCode){\ | |
| 50 | return ((compressLCGData.a * hashCode + compressLCGData.c) % compressLCGData.m) % compressLCGData.n;\ | |
| 51 | }\ | |
| 52 | \ | |
| 53 | ||
| 54 | #define HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 55 | \ | |
| 56 | typedef struct NAME##Hash_Table_ NAME##Hash_Table;\ | |
| 57 | \ | |
| 58 | typedef struct NAME##CLHash_Table_ NAME##CLHash_Table;\ | |
| 59 | \ | |
| 60 | typedef struct NAME##Hash_Factory_ NAME##Hash_Factory;\ | |
| 61 | \ | |
| 62 | typedef struct NAME##CLHash_Factory_ NAME##CLHash_Factory;\ | |
| 63 | \ | |
| 64 | NAME##Hash_Factory* NAME##Hash_CreateFactory(int HashTypes, VALUE_TYPE *emptyValue, size_t localWorkSize, cl_context *context, cl_command_queue *queue);\ | |
| 65 | \ | |
| 66 | int NAME##Hash_DestroyFactory(NAME##Hash_Factory *factory);\ | |
| 67 | \ | |
| 68 | NAME##Hash_Table* NAME##Hash_CreateTable(NAME##Hash_Factory* factory, int hashTypes, size_t keyRange, size_t numEntries, float loadFactor);\ | |
| 69 | \ | |
| 70 | int NAME##Hash_EmptyTable(NAME##Hash_Table *table);\ | |
| 71 | \ | |
| 72 | int NAME##Hash_DestroyTable(NAME##Hash_Table *table);\ | |
| 73 | \ | |
| 74 | cl_mem NAME##Hash_GetTableDataBuffer(NAME##Hash_Table *table);\ | |
| 75 | \ | |
| 76 | cl_mem *NAME##Hash_GetTableDataBufferPtr(NAME##Hash_Table *table);\ | |
| 77 | \ | |
| 78 | int NAME##Hash_GetTableType(NAME##Hash_Table *table);\ | |
| 79 | \ | |
| 80 | int NAME##Hash_Query(NAME##Hash_Table *table, size_t numKeys, KEY_TYPE *keys, VALUE_TYPE *valuesOutput);\ | |
| 81 | \ | |
| 82 | int NAME##Hash_QuerySingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE *valueOutput);\ | |
| 83 | \ | |
| 84 | int NAME##Hash_Insert(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values);\ | |
| 85 | \ | |
| 86 | int NAME##Hash_InsertSingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value);\ | |
| 87 | \ | |
| 88 | int NAME##Hash_InsertNoOverwrite(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values);\ | |
| 89 | \ | |
| 90 | int NAME##Hash_InsertSingleNoOverwrite(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value);\ | |
| 91 | \ | |
| 92 | int NAME##Hash_BufferQuery(NAME##Hash_Table *table, size_t numKeys, cl_mem keys, cl_mem valuesOutput);\ | |
| 93 | \ | |
| 94 | int NAME##Hash_BufferInsert(NAME##Hash_Table *table, size_t numEntries, cl_mem keys, cl_mem values);\ | |
| 95 | \ | |
| 96 | int NAME##Hash_BufferInsertNoOverwrite(NAME##Hash_Table *table, size_t numEntries, cl_mem keys, cl_mem values);\ | |
| 97 | \ | |
| 98 | HASH_H_TYPES_DECLARE(NAME, KEY_TYPE)\ | |
| 99 | \ | |
| 100 | IDENTITY_PERFECT_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 101 | \ | |
| 102 | IDENTITY_PERFECT_CL_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 103 | \ | |
| 104 | IDENTITY_SENTINEL_PERFECT_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 105 | \ | |
| 106 | IDENTITY_SENTINEL_PERFECT_CL_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 107 | \ | |
| 108 | LCG_LINEAR_OPEN_COMPACT_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 109 | \ | |
| 110 | LCG_LINEAR_OPEN_COMPACT_CL_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 111 | \ | |
| 112 | LCG_QUADRATIC_OPEN_COMPACT_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 113 | \ | |
| 114 | LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 115 | \ | |
| 116 |
| … | … | @@ -0,0 +1,233 @@ |
| 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 | #undef UNDEFINED | |
| 34 | #ifdef UNDEFINED | |
| 35 | /** | |
| 36 | * @file hash.hp | |
| 37 | * @author Peter Ahrens | |
| 38 | * @date Thu Jun 6 2013 | |
| 39 | */ | |
| 40 | #endif | |
| 41 | /** | |
| 42 | * @file HashFactory.h | |
| 43 | * @author Peter Ahrens | |
| 44 | * @date Thu Jun 6 2013 | |
| 45 | */ | |
| 46 | // | |
| 47 | #define DELAY(x) x | |
| 48 | #define STRINGIFY_(x) #x | |
| 49 | #define STRINGIFY(x) STRINGIFY_(x) | |
| 50 | DELAY(#ifndef HASH_H) | |
| 51 | DELAY(#define HASH_H) | |
| 52 | // | |
| 53 | DELAY(#include <stdlib.h>) | |
| 54 | DELAY(#include <stdio.h>) | |
| 55 | DELAY(#include <stdarg.h>) | |
| 56 | DELAY(#include <string.h>) | |
| 57 | // | |
| 58 | DELAY(#ifdef HAVE_OPENCL) | |
| 59 | DELAY(#ifdef __APPLE_CC__) | |
| 60 | DELAY(#include <OpenCL/OpenCL.h>) | |
| 61 | DELAY(#else) | |
| 62 | DELAY(#include <CL/cl.h>) | |
| 63 | DELAY(#endif) | |
| 64 | DELAY(#else) | |
| 65 | typedef void * cl_mem; | |
| 66 | typedef int cl_context; | |
| 67 | typedef int cl_command_queue; | |
| 68 | typedef int cl_program; | |
| 69 | typedef int cl_device_id; | |
| 70 | typedef int cl_int; | |
| 71 | int clRetainContext(int context); | |
| 72 | int clRetainCommandQueue(int command_queue); | |
| 73 | int clGetContextInfo(int context, int param, size_t size, void *value, size_t *size_ret); | |
| 74 | int clReleaseContext(int context); | |
| 75 | int clReleaseCommandQueue(int command_queue); | |
| 76 | int clReleaseProgram(int program); | |
| 77 | int clRetainProgram(int program); | |
| 78 | int clRetainKernel(int kernel); | |
| 79 | cl_mem clCreateBuffer(int context, int flags, size_t size, void *value, int *size_ret); | |
| 80 | int clEnqueueWriteBuffer(int command_queue, void *buffer, int blocking_write, size_t offset, size_t cb, const void * ptr, | |
| 81 | uint nevents, const int *wait_list, int *event); | |
| 82 | int clEnqueueReadBuffer(int command_queue, void *buffer, int blocking_write, size_t offset, size_t cb, const void * ptr, | |
| 83 | uint nevents, const int *wait_list, int *event); | |
| 84 | int clCreateKernel(int program, const char *kernel_name, int *errcode_ret); | |
| 85 | int clReleaseKernel(int kernel); | |
| 86 | int clReleaseMemObject(void * memobj); | |
| 87 | int clSetKernelArg(int kernel, uint arg_index, size_t arg_size, const void *arg_value); | |
| 88 | int clGetKernelWorkGroupInfo(int kernel, int device, int param_name, size_t size, void *value, size_t *size_ret); | |
| 89 | int clEnqueueNDRangeKernel(int command_queue, int kernel, uint work_dim, const size_t *offset, const size_t *size, const size_t *local_size, | |
| 90 | uint nevents, const int *wait_list, int *event); | |
| 91 | int clFinish(int command_queue); | |
| 92 | DELAY(#endif) | |
| 93 | // | |
| 94 | DELAY(#include "CLHash_Utilities.h") | |
| 95 | // | |
| 96 | // | |
| 97 | DELAY(#include "HashFactory.hm") | |
| 98 | DELAY(#include "HashFactory.cm") | |
| 99 | // | |
| 100 | DELAY(#define HASH_REPORT_NEVER /**/ 0) | |
| 101 | DELAY(#define HASH_REPORT_CYCLE /**/ 1) | |
| 102 | DELAY(#define HASH_REPORT_END /****/ 2) | |
| 103 | // | |
| 104 | DELAY(#define HASH_EXIT_CODE_NORMAL /****************/ -1) | |
| 105 | DELAY(#define HASH_EXIT_CODE_ERROR /*****************/ -2) | |
| 106 | DELAY(#define HASH_EXIT_CODE_OVERWRITE /*************/ -3) | |
| 107 | DELAY(#define HASH_EXIT_CODE_KEY_DNE /***************/ -4) | |
| 108 | DELAY(#define HASH_EXIT_CODE_CYCLE /*****************/ -5) | |
| 109 | DELAY(#define HASH_EXIT_CODE_MAX_ENTRIES_EXCEEDED /**/ -6) | |
| 110 | DELAY(#define HASH_EXIT_CODE_BUCKET_INDEX_OOB /******/ -7) | |
| 111 | // | |
| 112 | DELAY(#define HASH_SEARCH_CODE_MATCH /*****/ 0) | |
| 113 | DELAY(#define HASH_SEARCH_CODE_MISMATCH /**/ 1) | |
| 114 | DELAY(#define HASH_SEARCH_CODE_EMPTY /*****/ 2) | |
| 115 | // | |
| 116 | DELAY(#define HASH_NUM_HASHES /**/ 8) | |
| 117 | DELAY(#define HASH_NUM_CL_HASHES /**/ 4) | |
| 118 | // | |
| 119 | DELAY(#define LCG_QUADRATIC_OPEN_COMPACT_HASH_ID 128) | |
| 120 | DELAY(#define LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID 8) | |
| 121 | DELAY(#define LCG_LINEAR_OPEN_COMPACT_HASH_ID 64) | |
| 122 | DELAY(#define LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID 4) | |
| 123 | DELAY(#define IDENTITY_SENTINEL_PERFECT_HASH_ID 32) | |
| 124 | DELAY(#define IDENTITY_SENTINEL_PERFECT_CL_HASH_ID 2) | |
| 125 | DELAY(#define IDENTITY_PERFECT_HASH_ID 16) | |
| 126 | DELAY(#define IDENTITY_PERFECT_CL_HASH_ID 1) | |
| 127 | // | |
| 128 | /** | |
| 129 | * HASH_ALL_CL_HASHES hash table types that run in an OpenCL context. | |
| 130 | */ | |
| 131 | DELAY(#define HASH_ALL_CL_HASHES (IDENTITY_PERFECT_CL_HASH_ID | IDENTITY_SENTINEL_PERFECT_CL_HASH_ID | LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID | LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID)) | |
| 132 | /** | |
| 133 | * HASH_ALL_C_HASHES hash table types that run on the host. | |
| 134 | */ | |
| 135 | DELAY(#define HASH_ALL_C_HASHES (IDENTITY_PERFECT_HASH_ID | IDENTITY_SENTINEL_PERFECT_HASH_ID | LCG_LINEAR_OPEN_COMPACT_HASH_ID | LCG_QUADRATIC_OPEN_COMPACT_HASH_ID)) | |
| 136 | /** | |
| 137 | * HASH_ALL_HASHES all hash table types. | |
| 138 | */ | |
| 139 | DELAY(#define HASH_ALL_HASHES (HASH_ALL_CL_HASHES | HASH_ALL_C_HASHES)) | |
| 140 | /** | |
| 141 | * HASH_NOSENTINEL_PERFECT_HASHES perfect hash table types that do not use a sentinel value to mark empty buckets. | |
| 142 | */ | |
| 143 | DELAY(#define HASH_NOSENTINEL_PERFECT_HASHES (IDENTITY_PERFECT_HASH_ID | IDENTITY_PERFECT_CL_HASH_ID)) | |
| 144 | /** | |
| 145 | * HASH_SENTINEL_PERFECT_HASHES perfect hash table types that use a sentinel value to mark empty buckets. | |
| 146 | */ | |
| 147 | DELAY(#define HASH_SENTINEL_PERFECT_HASHES (IDENTITY_SENTINEL_PERFECT_HASH_ID | IDENTITY_SENTINEL_PERFECT_CL_HASH_ID)) | |
| 148 | /** | |
| 149 | * HASH_PERFECT_HASHES perfect hash table types. | |
| 150 | */ | |
| 151 | DELAY(#define HASH_PERFECT_HASHES (HASH_NOSENTINEL_PERFECT_HASHES | HASH_SENTINEL_PERFECT_HASHES)) | |
| 152 | /** | |
| 153 | * HASH_QUADRATIC_COMPACT_HASHES compact hash table types that use a quadratic probe sequence. | |
| 154 | */ | |
| 155 | DELAY(#define HASH_QUADRATIC_COMPACT_HASHES (LCG_QUADRATIC_OPEN_COMPACT_HASH_ID | LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID)) | |
| 156 | /** | |
| 157 | * HASH_LINEAR_COMPACT_HASHES compact hash table types that use a linear probe sequence. | |
| 158 | */ | |
| 159 | DELAY(#define HASH_LINEAR_COMPACT_HASHES (LCG_LINEAR_OPEN_COMPACT_HASH_ID | LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID)) | |
| 160 | /** | |
| 161 | * HASH_COMPACT_HASHES compact hash table types that use a linear probe sequence. | |
| 162 | */ | |
| 163 | DELAY(#define HASH_COMPACT_HASHES (HASH_QUADRATIC_COMPACT_HASHES | HASH_LINEAR_COMPACT_HASHES)) | |
| 164 | // | |
| 165 | DELAY(#define HASH_DEFAULT_LOCAL_WORK_SIZE /*******/ 64) | |
| 166 | DELAY(#define HASH_DEFAULT_LOAD_FACTOR /*******/ 0.3) | |
| 167 | DELAY(#define HASH_MIN_LOAD_FACTOR /*******/ 0.0009) | |
| 168 | DELAY(#define HASH_PERFECT_COMPACT_SWITCH_FACTOR /*******/ 20) | |
| 169 | DELAY(#define HASH_LCG_A /*******/ 2147483629) | |
| 170 | DELAY(#define HASH_LCG_C /*******/ 2147483587) | |
| 171 | DELAY(#define HASH_LCG_M /*******/ 2147483647) | |
| 172 | // | |
| 173 | DELAY(#define HASH_BUCKET_STATUS_EMPTY /**/ -1) | |
| 174 | DELAY(#define HASH_BUCKET_STATUS_FULL /***/ -2) | |
| 175 | DELAY(#define HASH_BUCKET_STATUS_LOCK /***/ -3) | |
| 176 | ||
| 177 | #ifdef __cplusplus | |
| 178 | extern "C" | |
| 179 | { | |
| 180 | #endif | |
| 181 | ||
| 182 | /** | |
| 183 | * Hash_ExitCodeString will return a string representation of the given exit | |
| 184 | * code. | |
| 185 | * | |
| 186 | * @param exitCode | |
| 187 | * | |
| 188 | * @return A string representation of that exit code. | |
| 189 | */ | |
| 190 | char* Hash_ExitCodeString(int exitCode); | |
| 191 | ||
| 192 | /** | |
| 193 | * Hash_ExitCodeDebug will print a string representation of the given exit code | |
| 194 | * if it is not EXIT_CODE_NORMAL. | |
| 195 | * | |
| 196 | * @param exitCode | |
| 197 | */ | |
| 198 | void Hash_ExitCodeDebug(int exitCode); | |
| 199 | ||
| 200 | /** | |
| 201 | * Hash_SetReportLevel sets a static report level variable in hash.c. It should | |
| 202 | * be called before hash tables are created. | |
| 203 | * | |
| 204 | * @param level The level of data collection desired. | |
| 205 | */ | |
| 206 | void Hash_SetReportLevel(int level); | |
| 207 | ||
| 208 | /** | |
| 209 | * Hash_GetReportLevel gets this variable. | |
| 210 | * | |
| 211 | * @return The current report level. | |
| 212 | * Special Values: Meaning | |
| 213 | * HASH_REPORT_NEVER: The hash table will not collect data. This is the | |
| 214 | * default. A call to Hash_Report will return an empty | |
| 215 | * string. | |
| 216 | * HASH_REPORT_END: The hash table will collect data and calls to | |
| 217 | * Hash_Report will return summary information. | |
| 218 | * HASH_REPORT_CYCLE: The hash table will collect data and calls to | |
| 219 | * Hash_Report will return information related to the | |
| 220 | * last important call. | |
| 221 | */ | |
| 222 | int Hash_GetReportLevel(); | |
| 223 | ||
| 224 | const char *Hash_GetKernelSourceString(); | |
| 225 | int smallestProthPrimeAbove(int N); | |
| 226 | int largestProthPrimeUnder(int N); | |
| 227 | ||
| 228 | HASH_DECLARE(intint, int, int) | |
| 229 | ||
| 230 | #ifdef __cplusplus | |
| 231 | } | |
| 232 | #endif | |
| 233 | DELAY(#endif) |
| … | … | @@ -0,0 +1,35 @@ |
| 1 | default: HashFactory.c CLHash_Utilities.c HashFactory.cl libHashFactory.la | |
| 2 | all: HashFactory.c CLHash_Utilities.c HashFactory.cl libHashFactory.la | |
| 3 | test: hashTest | |
| 4 | ||
| 5 | AM_MAKEFLAGS = -j 4 | |
| 6 | ||
| 7 | DEFAULT_INCLUDES=-I. -I.. | |
| 8 | ||
| 9 | lib_LTLIBRARIES = libHashFactory.la | |
| 10 | include_HEADERS = HashFactory.h | |
| 11 | bin_PROGRAMS = hashTest | |
| 12 | ||
| 13 | hashTest_CPPFLAGS = -DHAVE_OPENCL -DHAVE_CL_DOUBLE -I$(OPENCL_INCLUDE) | |
| 14 | ||
| 15 | H_SRCS = HashFactory.h CLHash_Utilities.h | |
| 16 | ||
| 17 | C_SRCS = HashFactory.c CLHash_Utilities.c | |
| 18 | ||
| 19 | libHashFactory_la_SOURCES = ${C_SRCS} ${H_SRCS} | |
| 20 | hashTest_SOURCES = testHelper.c hashTest.c | |
| 21 | hashTest_LDADD = libHashFactory.la | |
| 22 | ||
| 23 | HashFactory.h: HashFactory.hp HashFactory.hm perfectHash.hm compactHash.hm | |
| 24 | ${CPREPROCESSOR} -CC -x c -imacros HashFactory.hm HashFactory.hp | ${INDENT} -linux -brf -o HashFactory.h | |
| 25 | ||
| 26 | HashFactory.c: HashFactory.cp HashFactory.cm HashFactory.cl perfectHash.cm compactHash.cm | |
| 27 | ${CPREPROCESSOR} -CC -x c -imacros HashFactory.cm HashFactory.cp | ${INDENT} -linux -brf -o HashFactory.c | |
| 28 | ./embed_source.pl HashFactory.cl >> HashFactory.c | |
| 29 | ||
| 30 | HashFactory.cl: HashFactory.clp HashFactory.cm perfectHash.cm compactHash.cm | |
| 31 | ${CPREPROCESSOR} -CC -x c -imacros HashFactory.cm HashFactory.clp | ${INDENT} -linux -brf -o HashFactory.cl | |
| 32 | ||
| 33 | EXTRA_DIST = perfectHash.cm perfectHash.hm primetest.c testHelper.h HashFactory.hp \ | |
| 34 | HashFactory.hm HashFactory.cp HashFactory.cm HashFactory.h HashFactory.c HashFactory.cl HashFactory.clp embed_source.pl \ | |
| 35 | compactHash.cm compactHash.hm baseHash.cm baseHash.hm |
| … | … | @@ -0,0 +1,781 @@ |
| 1 | # Makefile.in generated by automake 1.13.4 from Makefile.am. | |
| 2 | # @configure_input@ | |
| 3 | ||
| 4 | # Copyright (C) 1994-2013 Free Software Foundation, Inc. | |
| 5 | ||
| 6 | # This Makefile.in is free software; the Free Software Foundation | |
| 7 | # gives unlimited permission to copy and/or distribute it, | |
| 8 | # with or without modifications, as long as this notice is preserved. | |
| 9 | ||
| 10 | # This program is distributed in the hope that it will be useful, | |
| 11 | # but WITHOUT ANY WARRANTY, to the extent permitted by law; without | |
| 12 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A | |
| 13 | # PARTICULAR PURPOSE. | |
| 14 | ||
| 15 | @SET_MAKE@ | |
| 16 | ||
| 17 | ||
| 18 | ||
| 19 | VPATH = @srcdir@ | |
| 20 | am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' | |
| 21 | am__make_running_with_option = \ | |
| 22 | case $${target_option-} in \ | |
| 23 | ?) ;; \ | |
| 24 | *) echo "am__make_running_with_option: internal error: invalid" \ | |
| 25 | "target option '$${target_option-}' specified" >&2; \ | |
| 26 | exit 1;; \ | |
| 27 | esac; \ | |
| 28 | has_opt=no; \ | |
| 29 | sane_makeflags=$$MAKEFLAGS; \ | |
| 30 | if $(am__is_gnu_make); then \ | |
| 31 | sane_makeflags=$$MFLAGS; \ | |
| 32 | else \ | |
| 33 | case $$MAKEFLAGS in \ | |
| 34 | *\\[\ \ ]*) \ | |
| 35 | bs=\\; \ | |
| 36 | sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ | |
| 37 | | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ | |
| 38 | esac; \ | |
| 39 | fi; \ | |
| 40 | skip_next=no; \ | |
| 41 | strip_trailopt () \ | |
| 42 | { \ | |
| 43 | flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ | |
| 44 | }; \ | |
| 45 | for flg in $$sane_makeflags; do \ | |
| 46 | test $$skip_next = yes && { skip_next=no; continue; }; \ | |
| 47 | case $$flg in \ | |
| 48 | *=*|--*) continue;; \ | |
| 49 | -*I) strip_trailopt 'I'; skip_next=yes;; \ | |
| 50 | -*I?*) strip_trailopt 'I';; \ | |
| 51 | -*O) strip_trailopt 'O'; skip_next=yes;; \ | |
| 52 | -*O?*) strip_trailopt 'O';; \ | |
| 53 | -*l) strip_trailopt 'l'; skip_next=yes;; \ | |
| 54 | -*l?*) strip_trailopt 'l';; \ | |
| 55 | -[dEDm]) skip_next=yes;; \ | |
| 56 | -[JT]) skip_next=yes;; \ | |
| 57 | esac; \ | |
| 58 | case $$flg in \ | |
| 59 | *$$target_option*) has_opt=yes; break;; \ | |
| 60 | esac; \ | |
| 61 | done; \ | |
| 62 | test $$has_opt = yes | |
| 63 | am__make_dryrun = (target_option=n; $(am__make_running_with_option)) | |
| 64 | am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) | |
| 65 | pkgdatadir = $(datadir)/@PACKAGE@ | |
| 66 | pkgincludedir = $(includedir)/@PACKAGE@ | |
| 67 | pkglibdir = $(libdir)/@PACKAGE@ | |
| 68 | pkglibexecdir = $(libexecdir)/@PACKAGE@ | |
| 69 | am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd | |
| 70 | install_sh_DATA = $(install_sh) -c -m 644 | |
| 71 | install_sh_PROGRAM = $(install_sh) -c | |
| 72 | install_sh_SCRIPT = $(install_sh) -c | |
| 73 | INSTALL_HEADER = $(INSTALL_DATA) | |
| 74 | transform = $(program_transform_name) | |
| 75 | NORMAL_INSTALL = : | |
| 76 | PRE_INSTALL = : | |
| 77 | POST_INSTALL = : | |
| 78 | NORMAL_UNINSTALL = : | |
| 79 | PRE_UNINSTALL = : | |
| 80 | POST_UNINSTALL = : | |
| 81 | build_triplet = @build@ | |
| 82 | host_triplet = @host@ | |
| 83 | bin_PROGRAMS = hashTest$(EXEEXT) | |
| 84 | subdir = HashFactory | |
| 85 | DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ | |
| 86 | $(top_srcdir)/./config/depcomp $(include_HEADERS) README | |
| 87 | ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 | |
| 88 | am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ | |
| 89 | $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ | |
| 90 | $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ | |
| 91 | $(top_srcdir)/configure.ac | |
| 92 | am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ | |
| 93 | $(ACLOCAL_M4) | |
| 94 | mkinstalldirs = $(install_sh) -d | |
| 95 | CONFIG_CLEAN_FILES = | |
| 96 | CONFIG_CLEAN_VPATH_FILES = | |
| 97 | am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; | |
| 98 | am__vpath_adj = case $$p in \ | |
| 99 | $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ | |
| 100 | *) f=$$p;; \ | |
| 101 | esac; | |
| 102 | am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; | |
| 103 | am__install_max = 40 | |
| 104 | am__nobase_strip_setup = \ | |
| 105 | srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` | |
| 106 | am__nobase_strip = \ | |
| 107 | for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" | |
| 108 | am__nobase_list = $(am__nobase_strip_setup); \ | |
| 109 | for p in $$list; do echo "$$p $$p"; done | \ | |
| 110 | sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ | |
| 111 | $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ | |
| 112 | if (++n[$$2] == $(am__install_max)) \ | |
| 113 | { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ | |
| 114 | END { for (dir in files) print dir, files[dir] }' | |
| 115 | am__base_list = \ | |
| 116 | sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ | |
| 117 | sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | |
| 118 | am__uninstall_files_from_dir = { \ | |
| 119 | test -z "$$files" \ | |
| 120 | || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ | |
| 121 | || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ | |
| 122 | $(am__cd) "$$dir" && rm -f $$files; }; \ | |
| 123 | } | |
| 124 | am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \ | |
| 125 | "$(DESTDIR)$(includedir)" | |
| 126 | LTLIBRARIES = $(lib_LTLIBRARIES) | |
| 127 | libHashFactory_la_LIBADD = | |
| 128 | am__objects_1 = HashFactory.lo CLHash_Utilities.lo | |
| 129 | am__objects_2 = | |
| 130 | am_libHashFactory_la_OBJECTS = $(am__objects_1) $(am__objects_2) | |
| 131 | libHashFactory_la_OBJECTS = $(am_libHashFactory_la_OBJECTS) | |
| 132 | AM_V_lt = $(am__v_lt_@AM_V@) | |
| 133 | am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) | |
| 134 | am__v_lt_0 = --silent | |
| 135 | am__v_lt_1 = | |
| 136 | PROGRAMS = $(bin_PROGRAMS) | |
| 137 | am_hashTest_OBJECTS = hashTest-testHelper.$(OBJEXT) \ | |
| 138 | hashTest-hashTest.$(OBJEXT) | |
| 139 | hashTest_OBJECTS = $(am_hashTest_OBJECTS) | |
| 140 | hashTest_DEPENDENCIES = libHashFactory.la | |
| 141 | AM_V_P = $(am__v_P_@AM_V@) | |
| 142 | am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) | |
| 143 | am__v_P_0 = false | |
| 144 | am__v_P_1 = : | |
| 145 | AM_V_GEN = $(am__v_GEN_@AM_V@) | |
| 146 | am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) | |
| 147 | am__v_GEN_0 = @echo " GEN " $@; | |
| 148 | am__v_GEN_1 = | |
| 149 | AM_V_at = $(am__v_at_@AM_V@) | |
| 150 | am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) | |
| 151 | am__v_at_0 = @ | |
| 152 | am__v_at_1 = | |
| 153 | depcomp = $(SHELL) $(top_srcdir)/./config/depcomp | |
| 154 | am__depfiles_maybe = depfiles | |
| 155 | am__mv = mv -f | |
| 156 | COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ | |
| 157 | $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) | |
| 158 | LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ | |
| 159 | $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ | |
| 160 | $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ | |
| 161 | $(AM_CFLAGS) $(CFLAGS) | |
| 162 | AM_V_CC = $(am__v_CC_@AM_V@) | |
| 163 | am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) | |
| 164 | am__v_CC_0 = @echo " CC " $@; | |
| 165 | am__v_CC_1 = | |
| 166 | CCLD = $(CC) | |
| 167 | LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ | |
| 168 | $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ | |
| 169 | $(AM_LDFLAGS) $(LDFLAGS) -o $@ | |
| 170 | AM_V_CCLD = $(am__v_CCLD_@AM_V@) | |
| 171 | am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) | |
| 172 | am__v_CCLD_0 = @echo " CCLD " $@; | |
| 173 | am__v_CCLD_1 = | |
| 174 | SOURCES = $(libHashFactory_la_SOURCES) $(hashTest_SOURCES) | |
| 175 | DIST_SOURCES = $(libHashFactory_la_SOURCES) $(hashTest_SOURCES) | |
| 176 | am__can_run_installinfo = \ | |
| 177 | case $$AM_UPDATE_INFO_DIR in \ | |
| 178 | n|no|NO) false;; \ | |
| 179 | *) (install-info --version) >/dev/null 2>&1;; \ | |
| 180 | esac | |
| 181 | HEADERS = $(include_HEADERS) | |
| 182 | am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) | |
| 183 | # Read a list of newline-separated strings from the standard input, | |
| 184 | # and print each of them once, without duplicates. Input order is | |
| 185 | # *not* preserved. | |
| 186 | am__uniquify_input = $(AWK) '\ | |
| 187 | BEGIN { nonempty = 0; } \ | |
| 188 | { items[$$0] = 1; nonempty = 1; } \ | |
| 189 | END { if (nonempty) { for (i in items) print i; }; } \ | |
| 190 | ' | |
| 191 | # Make sure the list of sources is unique. This is necessary because, | |
| 192 | # e.g., the same source file might be shared among _SOURCES variables | |
| 193 | # for different programs/libraries. | |
| 194 | am__define_uniq_tagged_files = \ | |
| 195 | list='$(am__tagged_files)'; \ | |
| 196 | unique=`for i in $$list; do \ | |
| 197 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ | |
| 198 | done | $(am__uniquify_input)` | |
| 199 | ETAGS = etags | |
| 200 | CTAGS = ctags | |
| 201 | DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) | |
| 202 | ACLOCAL = @ACLOCAL@ | |
| 203 | AMTAR = @AMTAR@ | |
| 204 | AM_CPPFLAGS = @AM_CPPFLAGS@ | |
| 205 | AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ | |
| 206 | AR = @AR@ | |
| 207 | AUTOCONF = @AUTOCONF@ | |
| 208 | AUTOHEADER = @AUTOHEADER@ | |
| 209 | AUTOMAKE = @AUTOMAKE@ | |
| 210 | AWK = @AWK@ | |
| 211 | CC = @CC@ | |
| 212 | CCDEPMODE = @CCDEPMODE@ | |
| 213 | CFLAGS = @CFLAGS@ | |
| 214 | CPP = @CPP@ | |
| 215 | CPPFLAGS = @CPPFLAGS@ | |
| 216 | CPREPROCESSOR = @CPREPROCESSOR@ | |
| 217 | CXX = @CXX@ | |
| 218 | CXXCPP = @CXXCPP@ | |
| 219 | CXXDEPMODE = @CXXDEPMODE@ | |
| 220 | CXXFLAGS = @CXXFLAGS@ | |
| 221 | CYGPATH_W = @CYGPATH_W@ | |
| 222 | DEFS = @DEFS@ | |
| 223 | DEPDIR = @DEPDIR@ | |
| 224 | DLLTOOL = @DLLTOOL@ | |
| 225 | DSYMUTIL = @DSYMUTIL@ | |
| 226 | DUMPBIN = @DUMPBIN@ | |
| 227 | ECHO_C = @ECHO_C@ | |
| 228 | ECHO_N = @ECHO_N@ | |
| 229 | ECHO_T = @ECHO_T@ | |
| 230 | EGREP = @EGREP@ | |
| 231 | EXEEXT = @EXEEXT@ | |
| 232 | FGREP = @FGREP@ | |
| 233 | GREP = @GREP@ | |
| 234 | HAVE_ADDR2LINE = @HAVE_ADDR2LINE@ | |
| 235 | INDENT = @INDENT@ | |
| 236 | INSTALL = @INSTALL@ | |
| 237 | INSTALL_DATA = @INSTALL_DATA@ | |
| 238 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ | |
| 239 | INSTALL_SCRIPT = @INSTALL_SCRIPT@ | |
| 240 | INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ | |
| 241 | LD = @LD@ | |
| 242 | LDFLAGS = @LDFLAGS@ | |
| 243 | LIBOBJS = @LIBOBJS@ | |
| 244 | LIBS = @LIBS@ | |
| 245 | LIBTOOL = @LIBTOOL@ | |
| 246 | LIPO = @LIPO@ | |
| 247 | LN_S = @LN_S@ | |
| 248 | LTLIBOBJS = @LTLIBOBJS@ | |
| 249 | MAKEINFO = @MAKEINFO@ | |
| 250 | MANIFEST_TOOL = @MANIFEST_TOOL@ | |
| 251 | MKDIR_P = @MKDIR_P@ | |
| 252 | NM = @NM@ | |
| 253 | NMEDIT = @NMEDIT@ | |
| 254 | OBJDUMP = @OBJDUMP@ | |
| 255 | OBJEXT = @OBJEXT@ | |
| 256 | OTOOL = @OTOOL@ | |
| 257 | OTOOL64 = @OTOOL64@ | |
| 258 | PACKAGE = @PACKAGE@ | |
| 259 | PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ | |
| 260 | PACKAGE_NAME = @PACKAGE_NAME@ | |
| 261 | PACKAGE_STRING = @PACKAGE_STRING@ | |
| 262 | PACKAGE_TARNAME = @PACKAGE_TARNAME@ | |
| 263 | PACKAGE_URL = @PACKAGE_URL@ | |
| 264 | PACKAGE_VERSION = @PACKAGE_VERSION@ | |
| 265 | PATH_SEPARATOR = @PATH_SEPARATOR@ | |
| 266 | RANLIB = @RANLIB@ | |
| 267 | SED = @SED@ | |
| 268 | SET_MAKE = @SET_MAKE@ | |
| 269 | SHELL = @SHELL@ | |
| 270 | STRIP = @STRIP@ | |
| 271 | VERSION = @VERSION@ | |
| 272 | abs_builddir = @abs_builddir@ | |
| 273 | abs_srcdir = @abs_srcdir@ | |
| 274 | abs_top_builddir = @abs_top_builddir@ | |
| 275 | abs_top_srcdir = @abs_top_srcdir@ | |
| 276 | ac_ct_AR = @ac_ct_AR@ | |
| 277 | ac_ct_CC = @ac_ct_CC@ | |
| 278 | ac_ct_CXX = @ac_ct_CXX@ | |
| 279 | ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ | |
| 280 | am__include = @am__include@ | |
| 281 | am__leading_dot = @am__leading_dot@ | |
| 282 | am__quote = @am__quote@ | |
| 283 | am__tar = @am__tar@ | |
| 284 | am__untar = @am__untar@ | |
| 285 | bindir = @bindir@ | |
| 286 | build = @build@ | |
| 287 | build_alias = @build_alias@ | |
| 288 | build_cpu = @build_cpu@ | |
| 289 | build_os = @build_os@ | |
| 290 | build_vendor = @build_vendor@ | |
| 291 | builddir = @builddir@ | |
| 292 | datadir = @datadir@ | |
| 293 | datarootdir = @datarootdir@ | |
| 294 | docdir = @docdir@ | |
| 295 | dvidir = @dvidir@ | |
| 296 | exec_prefix = @exec_prefix@ | |
| 297 | host = @host@ | |
| 298 | host_alias = @host_alias@ | |
| 299 | host_cpu = @host_cpu@ | |
| 300 | host_os = @host_os@ | |
| 301 | host_vendor = @host_vendor@ | |
| 302 | htmldir = @htmldir@ | |
| 303 | includedir = @includedir@ | |
| 304 | infodir = @infodir@ | |
| 305 | install_sh = @install_sh@ | |
| 306 | libdir = @libdir@ | |
| 307 | libexecdir = @libexecdir@ | |
| 308 | localedir = @localedir@ | |
| 309 | localstatedir = @localstatedir@ | |
| 310 | lspci_found = @lspci_found@ | |
| 311 | mandir = @mandir@ | |
| 312 | mkdir_p = @mkdir_p@ | |
| 313 | oldincludedir = @oldincludedir@ | |
| 314 | pdfdir = @pdfdir@ | |
| 315 | prefix = @prefix@ | |
| 316 | program_transform_name = @program_transform_name@ | |
| 317 | psdir = @psdir@ | |
| 318 | sbindir = @sbindir@ | |
| 319 | sharedstatedir = @sharedstatedir@ | |
| 320 | srcdir = @srcdir@ | |
| 321 | sysconfdir = @sysconfdir@ | |
| 322 | target_alias = @target_alias@ | |
| 323 | top_build_prefix = @top_build_prefix@ | |
| 324 | top_builddir = @top_builddir@ | |
| 325 | top_srcdir = @top_srcdir@ | |
| 326 | AM_MAKEFLAGS = -j 4 | |
| 327 | DEFAULT_INCLUDES = -I. -I.. | |
| 328 | lib_LTLIBRARIES = libHashFactory.la | |
| 329 | include_HEADERS = HashFactory.h | |
| 330 | hashTest_CPPFLAGS = -DHAVE_OPENCL -DHAVE_CL_DOUBLE -I$(OPENCL_INCLUDE) | |
| 331 | H_SRCS = HashFactory.h CLHash_Utilities.h | |
| 332 | C_SRCS = HashFactory.c CLHash_Utilities.c | |
| 333 | libHashFactory_la_SOURCES = ${C_SRCS} ${H_SRCS} | |
| 334 | hashTest_SOURCES = testHelper.c hashTest.c | |
| 335 | hashTest_LDADD = libHashFactory.la | |
| 336 | EXTRA_DIST = perfectHash.cm perfectHash.hm primetest.c testHelper.h HashFactory.hp \ | |
| 337 | HashFactory.hm HashFactory.cp HashFactory.cm HashFactory.h HashFactory.c HashFactory.cl HashFactory.clp embed_source.pl \ | |
| 338 | compactHash.cm compactHash.hm baseHash.cm baseHash.hm | |
| 339 | ||
| 340 | all: all-am | |
| 341 | ||
| 342 | .SUFFIXES: | |
| 343 | .SUFFIXES: .c .lo .o .obj | |
| 344 | $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) | |
| 345 | @for dep in $?; do \ | |
| 346 | case '$(am__configure_deps)' in \ | |
| 347 | *$$dep*) \ | |
| 348 | ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ | |
| 349 | && { if test -f $@; then exit 0; else break; fi; }; \ | |
| 350 | exit 1;; \ | |
| 351 | esac; \ | |
| 352 | done; \ | |
| 353 | echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign HashFactory/Makefile'; \ | |
| 354 | $(am__cd) $(top_srcdir) && \ | |
| 355 | $(AUTOMAKE) --foreign HashFactory/Makefile | |
| 356 | .PRECIOUS: Makefile | |
| 357 | Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status | |
| 358 | @case '$?' in \ | |
| 359 | *config.status*) \ | |
| 360 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ | |
| 361 | *) \ | |
| 362 | echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ | |
| 363 | cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ | |
| 364 | esac; | |
| 365 | ||
| 366 | $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) | |
| 367 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh | |
| 368 | ||
| 369 | $(top_srcdir)/configure: $(am__configure_deps) | |
| 370 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh | |
| 371 | $(ACLOCAL_M4): $(am__aclocal_m4_deps) | |
| 372 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh | |
| 373 | $(am__aclocal_m4_deps): | |
| 374 | ||
| 375 | install-libLTLIBRARIES: $(lib_LTLIBRARIES) | |
| 376 | @$(NORMAL_INSTALL) | |
| 377 | @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ | |
| 378 | list2=; for p in $$list; do \ | |
| 379 | if test -f $$p; then \ | |
| 380 | list2="$$list2 $$p"; \ | |
| 381 | else :; fi; \ | |
| 382 | done; \ | |
| 383 | test -z "$$list2" || { \ | |
| 384 | echo " $(MKDIR_P) '$(DESTDIR)$(libdir)'"; \ | |
| 385 | $(MKDIR_P) "$(DESTDIR)$(libdir)" || exit 1; \ | |
| 386 | echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ | |
| 387 | $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ | |
| 388 | } | |
| 389 | ||
| 390 | uninstall-libLTLIBRARIES: | |
| 391 | @$(NORMAL_UNINSTALL) | |
| 392 | @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ | |
| 393 | for p in $$list; do \ | |
| 394 | $(am__strip_dir) \ | |
| 395 | echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \ | |
| 396 | $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \ | |
| 397 | done | |
| 398 | ||
| 399 | clean-libLTLIBRARIES: | |
| 400 | -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) | |
| 401 | @list='$(lib_LTLIBRARIES)'; \ | |
| 402 | locs=`for p in $$list; do echo $$p; done | \ | |
| 403 | sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ | |
| 404 | sort -u`; \ | |
| 405 | test -z "$$locs" || { \ | |
| 406 | echo rm -f $${locs}; \ | |
| 407 | rm -f $${locs}; \ | |
| 408 | } | |
| 409 | ||
| 410 | libHashFactory.la: $(libHashFactory_la_OBJECTS) $(libHashFactory_la_DEPENDENCIES) $(EXTRA_libHashFactory_la_DEPENDENCIES) | |
| 411 | $(AM_V_CCLD)$(LINK) -rpath $(libdir) $(libHashFactory_la_OBJECTS) $(libHashFactory_la_LIBADD) $(LIBS) | |
| 412 | install-binPROGRAMS: $(bin_PROGRAMS) | |
| 413 | @$(NORMAL_INSTALL) | |
| 414 | @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ | |
| 415 | if test -n "$$list"; then \ | |
| 416 | echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \ | |
| 417 | $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \ | |
| 418 | fi; \ | |
| 419 | for p in $$list; do echo "$$p $$p"; done | \ | |
| 420 | sed 's/$(EXEEXT)$$//' | \ | |
| 421 | while read p p1; do if test -f $$p \ | |
| 422 | || test -f $$p1 \ | |
| 423 | ; then echo "$$p"; echo "$$p"; else :; fi; \ | |
| 424 | done | \ | |
| 425 | sed -e 'p;s,.*/,,;n;h' \ | |
| 426 | -e 's|.*|.|' \ | |
| 427 | -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ | |
| 428 | sed 'N;N;N;s,\n, ,g' | \ | |
| 429 | $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ | |
| 430 | { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ | |
| 431 | if ($$2 == $$4) files[d] = files[d] " " $$1; \ | |
| 432 | else { print "f", $$3 "/" $$4, $$1; } } \ | |
| 433 | END { for (d in files) print "f", d, files[d] }' | \ | |
| 434 | while read type dir files; do \ | |
| 435 | if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ | |
| 436 | test -z "$$files" || { \ | |
| 437 | echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ | |
| 438 | $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ | |
| 439 | } \ | |
| 440 | ; done | |
| 441 | ||
| 442 | uninstall-binPROGRAMS: | |
| 443 | @$(NORMAL_UNINSTALL) | |
| 444 | @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ | |
| 445 | files=`for p in $$list; do echo "$$p"; done | \ | |
| 446 | sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ | |
| 447 | -e 's/$$/$(EXEEXT)/' \ | |
| 448 | `; \ | |
| 449 | test -n "$$list" || exit 0; \ | |
| 450 | echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ | |
| 451 | cd "$(DESTDIR)$(bindir)" && rm -f $$files | |
| 452 | ||
| 453 | clean-binPROGRAMS: | |
| 454 | @list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \ | |
| 455 | echo " rm -f" $$list; \ | |
| 456 | rm -f $$list || exit $$?; \ | |
| 457 | test -n "$(EXEEXT)" || exit 0; \ | |
| 458 | list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ | |
| 459 | echo " rm -f" $$list; \ | |
| 460 | rm -f $$list | |
| 461 | ||
| 462 | hashTest$(EXEEXT): $(hashTest_OBJECTS) $(hashTest_DEPENDENCIES) $(EXTRA_hashTest_DEPENDENCIES) | |
| 463 | @rm -f hashTest$(EXEEXT) | |
| 464 | $(AM_V_CCLD)$(LINK) $(hashTest_OBJECTS) $(hashTest_LDADD) $(LIBS) | |
| 465 | ||
| 466 | mostlyclean-compile: | |
| 467 | -rm -f *.$(OBJEXT) | |
| 468 | ||
| 469 | distclean-compile: | |
| 470 | -rm -f *.tab.c | |
| 471 | ||
| 472 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CLHash_Utilities.Plo@am__quote@ | |
| 473 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HashFactory.Plo@am__quote@ | |
| 474 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hashTest-hashTest.Po@am__quote@ | |
| 475 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hashTest-testHelper.Po@am__quote@ | |
| 476 | ||
| 477 | .c.o: | |
| 478 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< | |
| 479 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po | |
| 480 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ | |
| 481 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | |
| 482 | @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $< | |
| 483 | ||
| 484 | .c.obj: | |
| 485 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` | |
| 486 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po | |
| 487 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ | |
| 488 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | |
| 489 | @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'` | |
| 490 | ||
| 491 | .c.lo: | |
| 492 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< | |
| 493 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo | |
| 494 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ | |
| 495 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | |
| 496 | @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< | |
| 497 | ||
| 498 | hashTest-testHelper.o: testHelper.c | |
| 499 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hashTest_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hashTest-testHelper.o -MD -MP -MF $(DEPDIR)/hashTest-testHelper.Tpo -c -o hashTest-testHelper.o `test -f 'testHelper.c' || echo '$(srcdir)/'`testHelper.c | |
| 500 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hashTest-testHelper.Tpo $(DEPDIR)/hashTest-testHelper.Po | |
| 501 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='testHelper.c' object='hashTest-testHelper.o' libtool=no @AMDEPBACKSLASH@ | |
| 502 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | |
| 503 | @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hashTest_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hashTest-testHelper.o `test -f 'testHelper.c' || echo '$(srcdir)/'`testHelper.c | |
| 504 | ||
| 505 | hashTest-testHelper.obj: testHelper.c | |
| 506 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hashTest_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hashTest-testHelper.obj -MD -MP -MF $(DEPDIR)/hashTest-testHelper.Tpo -c -o hashTest-testHelper.obj `if test -f 'testHelper.c'; then $(CYGPATH_W) 'testHelper.c'; else $(CYGPATH_W) '$(srcdir)/testHelper.c'; fi` | |
| 507 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hashTest-testHelper.Tpo $(DEPDIR)/hashTest-testHelper.Po | |
| 508 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='testHelper.c' object='hashTest-testHelper.obj' libtool=no @AMDEPBACKSLASH@ | |
| 509 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | |
| 510 | @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hashTest_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hashTest-testHelper.obj `if test -f 'testHelper.c'; then $(CYGPATH_W) 'testHelper.c'; else $(CYGPATH_W) '$(srcdir)/testHelper.c'; fi` | |
| 511 | ||
| 512 | hashTest-hashTest.o: hashTest.c | |
| 513 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hashTest_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hashTest-hashTest.o -MD -MP -MF $(DEPDIR)/hashTest-hashTest.Tpo -c -o hashTest-hashTest.o `test -f 'hashTest.c' || echo '$(srcdir)/'`hashTest.c | |
| 514 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hashTest-hashTest.Tpo $(DEPDIR)/hashTest-hashTest.Po | |
| 515 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hashTest.c' object='hashTest-hashTest.o' libtool=no @AMDEPBACKSLASH@ | |
| 516 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | |
| 517 | @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hashTest_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hashTest-hashTest.o `test -f 'hashTest.c' || echo '$(srcdir)/'`hashTest.c | |
| 518 | ||
| 519 | hashTest-hashTest.obj: hashTest.c | |
| 520 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hashTest_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hashTest-hashTest.obj -MD -MP -MF $(DEPDIR)/hashTest-hashTest.Tpo -c -o hashTest-hashTest.obj `if test -f 'hashTest.c'; then $(CYGPATH_W) 'hashTest.c'; else $(CYGPATH_W) '$(srcdir)/hashTest.c'; fi` | |
| 521 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hashTest-hashTest.Tpo $(DEPDIR)/hashTest-hashTest.Po | |
| 522 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hashTest.c' object='hashTest-hashTest.obj' libtool=no @AMDEPBACKSLASH@ | |
| 523 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | |
| 524 | @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hashTest_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hashTest-hashTest.obj `if test -f 'hashTest.c'; then $(CYGPATH_W) 'hashTest.c'; else $(CYGPATH_W) '$(srcdir)/hashTest.c'; fi` | |
| 525 | ||
| 526 | mostlyclean-libtool: | |
| 527 | -rm -f *.lo | |
| 528 | ||
| 529 | clean-libtool: | |
| 530 | -rm -rf .libs _libs | |
| 531 | install-includeHEADERS: $(include_HEADERS) | |
| 532 | @$(NORMAL_INSTALL) | |
| 533 | @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \ | |
| 534 | if test -n "$$list"; then \ | |
| 535 | echo " $(MKDIR_P) '$(DESTDIR)$(includedir)'"; \ | |
| 536 | $(MKDIR_P) "$(DESTDIR)$(includedir)" || exit 1; \ | |
| 537 | fi; \ | |
| 538 | for p in $$list; do \ | |
| 539 | if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ | |
| 540 | echo "$$d$$p"; \ | |
| 541 | done | $(am__base_list) | \ | |
| 542 | while read files; do \ | |
| 543 | echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(includedir)'"; \ | |
| 544 | $(INSTALL_HEADER) $$files "$(DESTDIR)$(includedir)" || exit $$?; \ | |
| 545 | done | |
| 546 | ||
| 547 | uninstall-includeHEADERS: | |
| 548 | @$(NORMAL_UNINSTALL) | |
| 549 | @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \ | |
| 550 | files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ | |
| 551 | dir='$(DESTDIR)$(includedir)'; $(am__uninstall_files_from_dir) | |
| 552 | ||
| 553 | ID: $(am__tagged_files) | |
| 554 | $(am__define_uniq_tagged_files); mkid -fID $$unique | |
| 555 | tags: tags-am | |
| 556 | TAGS: tags | |
| 557 | ||
| 558 | tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) | |
| 559 | set x; \ | |
| 560 | here=`pwd`; \ | |
| 561 | $(am__define_uniq_tagged_files); \ | |
| 562 | shift; \ | |
| 563 | if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ | |
| 564 | test -n "$$unique" || unique=$$empty_fix; \ | |
| 565 | if test $$# -gt 0; then \ | |
| 566 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ | |
| 567 | "$$@" $$unique; \ | |
| 568 | else \ | |
| 569 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ | |
| 570 | $$unique; \ | |
| 571 | fi; \ | |
| 572 | fi | |
| 573 | ctags: ctags-am | |
| 574 | ||
| 575 | CTAGS: ctags | |
| 576 | ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) | |
| 577 | $(am__define_uniq_tagged_files); \ | |
| 578 | test -z "$(CTAGS_ARGS)$$unique" \ | |
| 579 | || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ | |
| 580 | $$unique | |
| 581 | ||
| 582 | GTAGS: | |
| 583 | here=`$(am__cd) $(top_builddir) && pwd` \ | |
| 584 | && $(am__cd) $(top_srcdir) \ | |
| 585 | && gtags -i $(GTAGS_ARGS) "$$here" | |
| 586 | cscopelist: cscopelist-am | |
| 587 | ||
| 588 | cscopelist-am: $(am__tagged_files) | |
| 589 | list='$(am__tagged_files)'; \ | |
| 590 | case "$(srcdir)" in \ | |
| 591 | [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ | |
| 592 | *) sdir=$(subdir)/$(srcdir) ;; \ | |
| 593 | esac; \ | |
| 594 | for i in $$list; do \ | |
| 595 | if test -f "$$i"; then \ | |
| 596 | echo "$(subdir)/$$i"; \ | |
| 597 | else \ | |
| 598 | echo "$$sdir/$$i"; \ | |
| 599 | fi; \ | |
| 600 | done >> $(top_builddir)/cscope.files | |
| 601 | ||
| 602 | distclean-tags: | |
| 603 | -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags | |
| 604 | ||
| 605 | distdir: $(DISTFILES) | |
| 606 | @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ | |
| 607 | topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ | |
| 608 | list='$(DISTFILES)'; \ | |
| 609 | dist_files=`for file in $$list; do echo $$file; done | \ | |
| 610 | sed -e "s|^$$srcdirstrip/||;t" \ | |
| 611 | -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ | |
| 612 | case $$dist_files in \ | |
| 613 | */*) $(MKDIR_P) `echo "$$dist_files" | \ | |
| 614 | sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ | |
| 615 | sort -u` ;; \ | |
| 616 | esac; \ | |
| 617 | for file in $$dist_files; do \ | |
| 618 | if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ | |
| 619 | if test -d $$d/$$file; then \ | |
| 620 | dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ | |
| 621 | if test -d "$(distdir)/$$file"; then \ | |
| 622 | find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ | |
| 623 | fi; \ | |
| 624 | if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ | |
| 625 | cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ | |
| 626 | find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ | |
| 627 | fi; \ | |
| 628 | cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ | |
| 629 | else \ | |
| 630 | test -f "$(distdir)/$$file" \ | |
| 631 | || cp -p $$d/$$file "$(distdir)/$$file" \ | |
| 632 | || exit 1; \ | |
| 633 | fi; \ | |
| 634 | done | |
| 635 | check-am: all-am | |
| 636 | check: check-am | |
| 637 | all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS) | |
| 638 | install-binPROGRAMS: install-libLTLIBRARIES | |
| 639 | ||
| 640 | installdirs: | |
| 641 | for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(includedir)"; do \ | |
| 642 | test -z "$$dir" || $(MKDIR_P) "$$dir"; \ | |
| 643 | done | |
| 644 | install: install-am | |
| 645 | install-exec: install-exec-am | |
| 646 | install-data: install-data-am | |
| 647 | uninstall: uninstall-am | |
| 648 | ||
| 649 | install-am: all-am | |
| 650 | @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am | |
| 651 | ||
| 652 | installcheck: installcheck-am | |
| 653 | install-strip: | |
| 654 | if test -z '$(STRIP)'; then \ | |
| 655 | $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ | |
| 656 | install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ | |
| 657 | install; \ | |
| 658 | else \ | |
| 659 | $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ | |
| 660 | install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ | |
| 661 | "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ | |
| 662 | fi | |
| 663 | mostlyclean-generic: | |
| 664 | ||
| 665 | clean-generic: | |
| 666 | ||
| 667 | distclean-generic: | |
| 668 | -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) | |
| 669 | -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) | |
| 670 | ||
| 671 | maintainer-clean-generic: | |
| 672 | @echo "This command is intended for maintainers to use" | |
| 673 | @echo "it deletes files that may require special tools to rebuild." | |
| 674 | clean: clean-am | |
| 675 | ||
| 676 | clean-am: clean-binPROGRAMS clean-generic clean-libLTLIBRARIES \ | |
| 677 | clean-libtool mostlyclean-am | |
| 678 | ||
| 679 | distclean: distclean-am | |
| 680 | -rm -rf ./$(DEPDIR) | |
| 681 | -rm -f Makefile | |
| 682 | distclean-am: clean-am distclean-compile distclean-generic \ | |
| 683 | distclean-tags | |
| 684 | ||
| 685 | dvi: dvi-am | |
| 686 | ||
| 687 | dvi-am: | |
| 688 | ||
| 689 | html: html-am | |
| 690 | ||
| 691 | html-am: | |
| 692 | ||
| 693 | info: info-am | |
| 694 | ||
| 695 | info-am: | |
| 696 | ||
| 697 | install-data-am: install-includeHEADERS | |
| 698 | ||
| 699 | install-dvi: install-dvi-am | |
| 700 | ||
| 701 | install-dvi-am: | |
| 702 | ||
| 703 | install-exec-am: install-binPROGRAMS install-libLTLIBRARIES | |
| 704 | ||
| 705 | install-html: install-html-am | |
| 706 | ||
| 707 | install-html-am: | |
| 708 | ||
| 709 | install-info: install-info-am | |
| 710 | ||
| 711 | install-info-am: | |
| 712 | ||
| 713 | install-man: | |
| 714 | ||
| 715 | install-pdf: install-pdf-am | |
| 716 | ||
| 717 | install-pdf-am: | |
| 718 | ||
| 719 | install-ps: install-ps-am | |
| 720 | ||
| 721 | install-ps-am: | |
| 722 | ||
| 723 | installcheck-am: | |
| 724 | ||
| 725 | maintainer-clean: maintainer-clean-am | |
| 726 | -rm -rf ./$(DEPDIR) | |
| 727 | -rm -f Makefile | |
| 728 | maintainer-clean-am: distclean-am maintainer-clean-generic | |
| 729 | ||
| 730 | mostlyclean: mostlyclean-am | |
| 731 | ||
| 732 | mostlyclean-am: mostlyclean-compile mostlyclean-generic \ | |
| 733 | mostlyclean-libtool | |
| 734 | ||
| 735 | pdf: pdf-am | |
| 736 | ||
| 737 | pdf-am: | |
| 738 | ||
| 739 | ps: ps-am | |
| 740 | ||
| 741 | ps-am: | |
| 742 | ||
| 743 | uninstall-am: uninstall-binPROGRAMS uninstall-includeHEADERS \ | |
| 744 | uninstall-libLTLIBRARIES | |
| 745 | ||
| 746 | .MAKE: install-am install-strip | |
| 747 | ||
| 748 | .PHONY: CTAGS GTAGS TAGS all all-am check check-am clean \ | |
| 749 | clean-binPROGRAMS clean-generic clean-libLTLIBRARIES \ | |
| 750 | clean-libtool cscopelist-am ctags ctags-am distclean \ | |
| 751 | distclean-compile distclean-generic distclean-libtool \ | |
| 752 | distclean-tags distdir dvi dvi-am html html-am info info-am \ | |
| 753 | install install-am install-binPROGRAMS install-data \ | |
| 754 | install-data-am install-dvi install-dvi-am install-exec \ | |
| 755 | install-exec-am install-html install-html-am \ | |
| 756 | install-includeHEADERS install-info install-info-am \ | |
| 757 | install-libLTLIBRARIES install-man install-pdf install-pdf-am \ | |
| 758 | install-ps install-ps-am install-strip installcheck \ | |
| 759 | installcheck-am installdirs maintainer-clean \ | |
| 760 | maintainer-clean-generic mostlyclean mostlyclean-compile \ | |
| 761 | mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ | |
| 762 | tags tags-am uninstall uninstall-am uninstall-binPROGRAMS \ | |
| 763 | uninstall-includeHEADERS uninstall-libLTLIBRARIES | |
| 764 | ||
| 765 | default: HashFactory.c CLHash_Utilities.c HashFactory.cl libHashFactory.la | |
| 766 | all: HashFactory.c CLHash_Utilities.c HashFactory.cl libHashFactory.la | |
| 767 | test: hashTest | |
| 768 | ||
| 769 | HashFactory.h: HashFactory.hp HashFactory.hm perfectHash.hm compactHash.hm | |
| 770 | ${CPREPROCESSOR} -CC -x c -imacros HashFactory.hm HashFactory.hp | ${INDENT} -linux -brf -o HashFactory.h | |
| 771 | ||
| 772 | HashFactory.c: HashFactory.cp HashFactory.cm HashFactory.cl perfectHash.cm compactHash.cm | |
| 773 | ${CPREPROCESSOR} -CC -x c -imacros HashFactory.cm HashFactory.cp | ${INDENT} -linux -brf -o HashFactory.c | |
| 774 | ./embed_source.pl HashFactory.cl >> HashFactory.c | |
| 775 | ||
| 776 | HashFactory.cl: HashFactory.clp HashFactory.cm perfectHash.cm compactHash.cm | |
| 777 | ${CPREPROCESSOR} -CC -x c -imacros HashFactory.cm HashFactory.clp | ${INDENT} -linux -brf -o HashFactory.cl | |
| 778 | ||
| 779 | # Tell versions [3.59,3.63) of GNU make to not export all variables. | |
| 780 | # Otherwise a system limit (for SysV at least) may be exceeded. | |
| 781 | .NOEXPORT: |
| … | … | @@ -0,0 +1,159 @@ |
| 1 | This code uses autoconf/automake/libtool for builds. To build the code: | |
| 2 | ||
| 3 | ./configure | |
| 4 | make | |
| 5 | ||
| 6 | A statically-loaded library will be built: libhash.la | |
| 7 | If you specify the targets (all, test) an executable will be built: hashTest | |
| 8 | ||
| 9 | You can run hashTest like this: | |
| 10 | ||
| 11 | ./hashTest | |
| 12 | ||
| 13 | TESTING: | |
| 14 | The output should look like this: | |
| 15 | ||
| 16 | HashTest STARTED | |
| 17 | intintIdentityPerfectHash Test STARTED | |
| 18 | Correct Hash Type Check: PASSED | |
| 19 | QuerySingle after Insert Check 1: PASSED | |
| 20 | QuerySingle after Insert Check 2: PASSED | |
| 21 | QuerySingle after Insert Check 3: PASSED | |
| 22 | QuerySingle after Insert Check 4: PASSED | |
| 23 | QuerySingle after Insert Check 5: PASSED | |
| 24 | QuerySingle after Insert Check 6: PASSED | |
| 25 | Query after InsertSingleNoOverwrite Check: PASSED | |
| 26 | Query after InsertSingle Check: PASSED | |
| 27 | Query after InsertNoOverwrite Check: PASSED | |
| 28 | intintIdentityPerfectHash Test FINISHED | |
| 29 | 100% (10/10) TESTS PASSED | |
| 30 | ||
| 31 | intintIdentitySentinelPerfectHash Test STARTED | |
| 32 | Correct Hash Type Check: PASSED | |
| 33 | QuerySingle after Insert Check 1: PASSED | |
| 34 | QuerySingle after Insert Check 2: PASSED | |
| 35 | QuerySingle after Insert Check 3: PASSED | |
| 36 | QuerySingle after Insert Check 4: PASSED | |
| 37 | QuerySingle after Insert Check 5: PASSED | |
| 38 | QuerySingle after Insert Check 6: PASSED | |
| 39 | Query after InsertSingleNoOverwrite Check: PASSED | |
| 40 | Query after InsertSingle Check: PASSED | |
| 41 | Query after InsertNoOverwrite Check: PASSED | |
| 42 | intintIdentitySentinelPerfectHash Test FINISHED | |
| 43 | 100% (10/10) TESTS PASSED | |
| 44 | ||
| 45 | intintLCGLinearOpenCompactHash Test STARTED | |
| 46 | Correct Hash Type Check: PASSED | |
| 47 | QuerySingle after Insert Check 1: PASSED | |
| 48 | QuerySingle after Insert Check 2: PASSED | |
| 49 | QuerySingle after Insert Check 3: PASSED | |
| 50 | QuerySingle after Insert Check 4: PASSED | |
| 51 | QuerySingle after Insert Check 5: PASSED | |
| 52 | QuerySingle after Insert Check 6: PASSED | |
| 53 | Query after InsertSingleNoOverwrite Check: PASSED | |
| 54 | Query after InsertSingle Check: PASSED | |
| 55 | Query after InsertNoOverwrite Check: PASSED | |
| 56 | intintLCGLinearOpenCompactHash Test FINISHED | |
| 57 | 100% (10/10) TESTS PASSED | |
| 58 | ||
| 59 | intintLCGQuadraticOpenCompactHash Test STARTED | |
| 60 | Correct Hash Type Check: PASSED | |
| 61 | QuerySingle after Insert Check 1: PASSED | |
| 62 | QuerySingle after Insert Check 2: PASSED | |
| 63 | QuerySingle after Insert Check 3: PASSED | |
| 64 | QuerySingle after Insert Check 4: PASSED | |
| 65 | QuerySingle after Insert Check 5: PASSED | |
| 66 | QuerySingle after Insert Check 6: PASSED | |
| 67 | Query after InsertSingleNoOverwrite Check: PASSED | |
| 68 | Query after InsertSingle Check: PASSED | |
| 69 | Query after InsertNoOverwrite Check: PASSED | |
| 70 | intintLCGQuadraticOpenCompactHash Test FINISHED | |
| 71 | 100% (10/10) TESTS PASSED | |
| 72 | ||
| 73 | intintIdentityPerfectCLHash Test STARTED | |
| 74 | Correct Hash Type Check: PASSED | |
| 75 | QuerySingle after Insert Check 1: PASSED | |
| 76 | QuerySingle after Insert Check 2: PASSED | |
| 77 | QuerySingle after Insert Check 3: PASSED | |
| 78 | QuerySingle after Insert Check 4: PASSED | |
| 79 | QuerySingle after Insert Check 5: PASSED | |
| 80 | QuerySingle after Insert Check 6: PASSED | |
| 81 | Query after InsertSingleNoOverwrite Check: PASSED | |
| 82 | Query after InsertSingle Check: PASSED | |
| 83 | Query after InsertNoOverwrite Check: PASSED | |
| 84 | intintIdentityPerfectCLHash Test FINISHED | |
| 85 | 100% (10/10) TESTS PASSED | |
| 86 | ||
| 87 | intintIdentitySentinelPerfectCLHash Test STARTED | |
| 88 | Correct Hash Type Check: PASSED | |
| 89 | QuerySingle after Insert Check 1: PASSED | |
| 90 | QuerySingle after Insert Check 2: PASSED | |
| 91 | QuerySingle after Insert Check 3: PASSED | |
| 92 | QuerySingle after Insert Check 4: PASSED | |
| 93 | QuerySingle after Insert Check 5: PASSED | |
| 94 | QuerySingle after Insert Check 6: PASSED | |
| 95 | Query after InsertSingleNoOverwrite Check: PASSED | |
| 96 | Query after InsertSingle Check: PASSED | |
| 97 | Query after InsertNoOverwrite Check: PASSED | |
| 98 | intintIdentitySentinelPerfectCLHash Test FINISHED | |
| 99 | 100% (10/10) TESTS PASSED | |
| 100 | ||
| 101 | intintLCGLinearOpenCompactCLHash Test STARTED | |
| 102 | Correct Hash Type Check: PASSED | |
| 103 | QuerySingle after Insert Check 1: PASSED | |
| 104 | QuerySingle after Insert Check 2: PASSED | |
| 105 | QuerySingle after Insert Check 3: PASSED | |
| 106 | QuerySingle after Insert Check 4: PASSED | |
| 107 | QuerySingle after Insert Check 5: PASSED | |
| 108 | QuerySingle after Insert Check 6: PASSED | |
| 109 | Query after InsertSingleNoOverwrite Check: PASSED | |
| 110 | Query after InsertSingle Check: PASSED | |
| 111 | Query after InsertNoOverwrite Check: PASSED | |
| 112 | intintLCGLinearOpenCompactHash Test FINISHED | |
| 113 | 100% (10/10) TESTS PASSED | |
| 114 | ||
| 115 | intintLCGQuadraticOpenCompactCLHash Test STARTED | |
| 116 | Correct Hash Type Check: PASSED | |
| 117 | QuerySingle after Insert Check 1: PASSED | |
| 118 | QuerySingle after Insert Check 2: PASSED | |
| 119 | QuerySingle after Insert Check 3: PASSED | |
| 120 | QuerySingle after Insert Check 4: PASSED | |
| 121 | QuerySingle after Insert Check 5: PASSED | |
| 122 | QuerySingle after Insert Check 6: PASSED | |
| 123 | Query after InsertSingleNoOverwrite Check: PASSED | |
| 124 | Query after InsertSingle Check: PASSED | |
| 125 | Query after InsertNoOverwrite Check: PASSED | |
| 126 | intintLCGQuadraticOpenCompactHash Test FINISHED | |
| 127 | 100% (10/10) TESTS PASSED | |
| 128 | ||
| 129 | hashTest FINISHED | |
| 130 | 100% (8/8) TESTS PASSED | |
| 131 | ||
| 132 | If an error occurs, the expected and observed values will be printed. | |
| 133 | ||
| 134 | USAGE: | |
| 135 | There are many ways to use this library. | |
| 136 | ||
| 137 | Terms: | |
| 138 | Entry: A key-value pair to be inserted into the hash table | |
| 139 | Key: In this library, a 32-bit or 64-bit integer greater than or equal to 0 used to access some associated value | |
| 140 | Value: Any data type (except for a pointer) accessed by some associated key. | |
| 141 | ||
| 142 | Function Names: | |
| 143 | Function names in this library are preceeded by a name related to the types of data they can hash. The convention within the library is to use the type of keys followed by the type of values as the name. For example, if you wanted to insert an integer key and character value into the appropriate table, you would call intcharHash_InsertSingle. For the remainder of this document, the example name will be keyval. | |
| 144 | ||
| 145 | Key-Value Types Supported: | |
| 146 | int-int | |
| 147 | ||
| 148 | Factories: | |
| 149 | In order to avoid compiling code on OpenCL devices an unnecessary number of times, the program files and related info necessary to create a hash table on an OpenCL device are stored in a factory. The type of the factory is keyvalHash_Factory. | |
| 150 | To create a hash table, one must first create a factory. To create a factory, call keyvalHash_CreateFactory. For example: | |
| 151 | keyvalHash_Factory *factory = keyvalHash_CreateFactory(HASH_ALL_HASH_TYPES, NULL, 0, NULL, NULL); | |
| 152 | To destroy the factory, call keyvalHash_DestroyFactory. | |
| 153 | ||
| 154 | Hash Tables: | |
| 155 | When one creates a hash table, they must supply a factory to create it. Memory for the buckets is allocated during creation, so some arguments specifying the size of the table must also be supplied. The type of the hash tables is keyvalHash_Table. To create a hash table, call keyvalHash_CreateTable. For example: | |
| 156 | keyvalHash_Table *table = keyvalHash_CreateTable(factory, HASH_COMPACT_HASHES, 0, 4, 0.5); | |
| 157 | To destroy the hash table, call keyvalHash_DestroyTable. | |
| 158 | ||
| 159 |
| … | … | @@ -0,0 +1,597 @@ |
| 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 | #undef UNDEFINED | |
| 34 | #ifdef UNDEFINED | |
| 35 | /** | |
| 36 | * @file hash.cm | |
| 37 | * @author Peter Ahrens | |
| 38 | * @date Thu Jun 6 2013 | |
| 39 | */ | |
| 40 | #endif | |
| 41 | ||
| 42 | #define HASH_COMPARE_HASH_INIT_EXP_WRAPPER(INIT_EXP) \ | |
| 43 | INIT_EXP\ | |
| 44 | table->compareFuncData = table->hashFuncData;\ | |
| 45 | \ | |
| 46 | ||
| 47 | #define KEY_VALUE_BASE_HASH_TYPES_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC_DATA)\ | |
| 48 | \ | |
| 49 | typedef struct NAME##MODIFIER##Hash_TableData{\ | |
| 50 | int hashID;\ | |
| 51 | unsigned int numBuckets;\ | |
| 52 | COMPRESS_FUNC_DATA compressFuncData;\ | |
| 53 | }NAME##MODIFIER##Hash_TableData;\ | |
| 54 | \ | |
| 55 | typedef struct NAME##MODIFIER##Hash_Bucket{\ | |
| 56 | KEY_TYPE key;\ | |
| 57 | VALUE_TYPE value;\ | |
| 58 | }NAME##MODIFIER##Hash_Bucket;\ | |
| 59 | \ | |
| 60 | ||
| 61 | #define SENTINEL_VALUE_BASE_HASH_TYPES_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC_DATA)\ | |
| 62 | \ | |
| 63 | typedef struct NAME##MODIFIER##Hash_TableData{\ | |
| 64 | int hashID;\ | |
| 65 | unsigned int numBuckets;\ | |
| 66 | COMPRESS_FUNC_DATA compressFuncData;\ | |
| 67 | VALUE_TYPE emptyValue;\ | |
| 68 | }NAME##MODIFIER##Hash_TableData;\ | |
| 69 | \ | |
| 70 | typedef struct NAME##MODIFIER##Hash_Bucket{\ | |
| 71 | VALUE_TYPE value;\ | |
| 72 | }NAME##MODIFIER##Hash_Bucket;\ | |
| 73 | \ | |
| 74 | ||
| 75 | #define BASE_HASH_UTIL(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, FACTORY_CREATE_EXP, FACTORY_DESTROY_EXP, CREATE_EXP, INIT_EXP, ALLOC_EXP, DESTROY_EXP, EMPTY_EXP)\ | |
| 76 | \ | |
| 77 | NAME##Hash_Table *NAME##MODIFIER##Hash_CreateTable(NAME##Hash_Factory* factory, int hashIndex, size_t keyRange, size_t numEntries, float loadFactor){\ | |
| 78 | NAME##Hash_Table* table = (NAME##Hash_Table*)malloc(sizeof(NAME##Hash_Table));\ | |
| 79 | table->destroyFunc= &NAME##MODIFIER##Hash_DestroyTable;\ | |
| 80 | table->emptyFunc = &NAME##MODIFIER##Hash_EmptyTable;\ | |
| 81 | table->queryFunc = &NAME##MODIFIER##Hash_Query;\ | |
| 82 | table->querySingleFunc = &NAME##MODIFIER##Hash_QuerySingle;\ | |
| 83 | table->insertFunc = &NAME##MODIFIER##Hash_Insert;\ | |
| 84 | table->insertSingleFunc = &NAME##MODIFIER##Hash_InsertSingle;\ | |
| 85 | table->insertNoOverwriteFunc = &NAME##MODIFIER##Hash_InsertNoOverwrite;\ | |
| 86 | table->insertSingleNoOverwriteFunc = &NAME##MODIFIER##Hash_InsertSingleNoOverwrite;\ | |
| 87 | table->tableData = (char*)malloc(sizeof(NAME##MODIFIER##Hash_TableData));\ | |
| 88 | ((NAME##MODIFIER##Hash_TableData*)table->tableData)->hashID = HASH_ID;\ | |
| 89 | CREATE_EXP\ | |
| 90 | INIT_EXP\ | |
| 91 | char* tempHashData = (char*)malloc(sizeof(NAME##MODIFIER##Hash_TableData) + ((NAME##MODIFIER##Hash_TableData*)table->tableData)->numBuckets * sizeof(NAME##MODIFIER##Hash_Bucket));\ | |
| 92 | memcpy(tempHashData, table->tableData, sizeof(NAME##MODIFIER##Hash_TableData));\ | |
| 93 | free(table->tableData);\ | |
| 94 | table->tableData = tempHashData;\ | |
| 95 | ALLOC_EXP\ | |
| 96 | return table;\ | |
| 97 | }\ | |
| 98 | \ | |
| 99 | int NAME##MODIFIER##Hash_CreateFactory(NAME##Hash_Factory *factory, int hashIndex){\ | |
| 100 | factory->createFunc[hashIndex] = &NAME##MODIFIER##Hash_CreateTable;\ | |
| 101 | factory->destroyFunc[hashIndex] = &NAME##MODIFIER##Hash_DestroyFactory;\ | |
| 102 | FACTORY_CREATE_EXP;\ | |
| 103 | return HASH_EXIT_CODE_NORMAL;\ | |
| 104 | }\ | |
| 105 | \ | |
| 106 | int NAME##MODIFIER##Hash_DestroyFactory(NAME##Hash_Factory* factory, int hashIndex){\ | |
| 107 | FACTORY_DESTROY_EXP;\ | |
| 108 | return HASH_EXIT_CODE_NORMAL;\ | |
| 109 | }\ | |
| 110 | \ | |
| 111 | int NAME##MODIFIER##Hash_DestroyTable(NAME##Hash_Table *table){\ | |
| 112 | int exitCode=0;\ | |
| 113 | DESTROY_EXP\ | |
| 114 | free(table->tableData);\ | |
| 115 | free(table);\ | |
| 116 | return exitCode;\ | |
| 117 | }\ | |
| 118 | \ | |
| 119 | int NAME##MODIFIER##Hash_EmptyTable(NAME##Hash_Table *table){\ | |
| 120 | int exitCode=0;\ | |
| 121 | EMPTY_EXP\ | |
| 122 | return exitCode;\ | |
| 123 | }\ | |
| 124 | \ | |
| 125 | ||
| 126 | #define HASH_READ_KEY_EXP (buckets[index].key) | |
| 127 | ||
| 128 | #define CMPXCHG_HASH_READ_KEY_EXP ((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ({buckets[index].key = key; HASH_BUCKET_STATUS_EMPTY;}) : buckets[index].key)\ | |
| 129 | ||
| 130 | #define BASE_HASH_METHODS(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, SEARCH_EXP, READ_KEY_EXP, CL_GLOBAL, ...) \ | |
| 131 | \ | |
| 132 | int NAME##MODIFIER##Hash_InnerQuerySingle(CL_GLOBAL char *tableData, KEY_TYPE key, CL_GLOBAL VALUE_TYPE *valueOutput){\ | |
| 133 | CL_GLOBAL NAME##MODIFIER##Hash_Bucket *buckets = (CL_GLOBAL NAME##MODIFIER##Hash_Bucket*)&tableData[sizeof(NAME##MODIFIER##Hash_TableData)];\ | |
| 134 | int index;\ | |
| 135 | int exitCode;\ | |
| 136 | SEARCH_EXP(NAME, MODIFIER, COMPRESS_FUNC, COMPRESS_FUNC_DATA, HASH_READ_KEY_EXP, CL_GLOBAL, ##__VA_ARGS__)\ | |
| 137 | switch(exitCode){\ | |
| 138 | case HASH_SEARCH_CODE_MATCH:\ | |
| 139 | *valueOutput = buckets[index].value;\ | |
| 140 | return HASH_EXIT_CODE_NORMAL;\ | |
| 141 | case HASH_SEARCH_CODE_MISMATCH:\ | |
| 142 | case HASH_SEARCH_CODE_EMPTY:\ | |
| 143 | return HASH_EXIT_CODE_KEY_DNE;\ | |
| 144 | default:\ | |
| 145 | return exitCode;\ | |
| 146 | }\ | |
| 147 | }\ | |
| 148 | \ | |
| 149 | int NAME##MODIFIER##Hash_InnerQuery(CL_GLOBAL char *tableData, unsigned int numKeys, CL_GLOBAL KEY_TYPE *keys, CL_GLOBAL VALUE_TYPE *valuesOutput){\ | |
| 150 | CL_GLOBAL NAME##MODIFIER##Hash_Bucket *buckets = (CL_GLOBAL NAME##MODIFIER##Hash_Bucket*)&tableData[sizeof(NAME##MODIFIER##Hash_TableData)];\ | |
| 151 | KEY_TYPE key;\ | |
| 152 | CL_GLOBAL VALUE_TYPE *valueOutput;\ | |
| 153 | int index;\ | |
| 154 | int exitCode;\ | |
| 155 | uint i;\ | |
| 156 | int resultExitCode = HASH_EXIT_CODE_NORMAL;\ | |
| 157 | for(i = 0; i < numKeys; i++){\ | |
| 158 | key = keys[i];\ | |
| 159 | valueOutput = &valuesOutput[i];\ | |
| 160 | SEARCH_EXP(NAME, MODIFIER, COMPRESS_FUNC, COMPRESS_FUNC_DATA, HASH_READ_KEY_EXP, CL_GLOBAL, ##__VA_ARGS__)\ | |
| 161 | switch(exitCode){\ | |
| 162 | case HASH_SEARCH_CODE_MATCH:\ | |
| 163 | *valueOutput = buckets[index].value;\ | |
| 164 | break;\ | |
| 165 | case HASH_SEARCH_CODE_MISMATCH:\ | |
| 166 | case HASH_SEARCH_CODE_EMPTY:\ | |
| 167 | resultExitCode = HASH_EXIT_CODE_KEY_DNE;\ | |
| 168 | break;\ | |
| 169 | default:\ | |
| 170 | return exitCode;\ | |
| 171 | }\ | |
| 172 | }\ | |
| 173 | return resultExitCode;\ | |
| 174 | }\ | |
| 175 | \ | |
| 176 | int NAME##MODIFIER##Hash_InnerInsertSingle(CL_GLOBAL char* tableData, KEY_TYPE key, VALUE_TYPE value){\ | |
| 177 | CL_GLOBAL NAME##MODIFIER##Hash_Bucket *buckets = (CL_GLOBAL NAME##MODIFIER##Hash_Bucket*)&tableData[sizeof(NAME##MODIFIER##Hash_TableData)];\ | |
| 178 | int index;\ | |
| 179 | int exitCode;\ | |
| 180 | SEARCH_EXP(NAME, MODIFIER, COMPRESS_FUNC, COMPRESS_FUNC_DATA, READ_KEY_EXP, CL_GLOBAL, ##__VA_ARGS__)\ | |
| 181 | switch(exitCode){\ | |
| 182 | case HASH_SEARCH_CODE_MATCH:\ | |
| 183 | case HASH_SEARCH_CODE_MISMATCH:\ | |
| 184 | buckets[index].value = value;\ | |
| 185 | return HASH_EXIT_CODE_OVERWRITE;\ | |
| 186 | case HASH_SEARCH_CODE_EMPTY:\ | |
| 187 | buckets[index].value = value;\ | |
| 188 | return HASH_EXIT_CODE_NORMAL;\ | |
| 189 | default:\ | |
| 190 | return exitCode;\ | |
| 191 | }\ | |
| 192 | }\ | |
| 193 | \ | |
| 194 | int NAME##MODIFIER##Hash_InnerInsert(CL_GLOBAL char *tableData, unsigned int numEntries, CL_GLOBAL KEY_TYPE *keys, CL_GLOBAL VALUE_TYPE *values){\ | |
| 195 | CL_GLOBAL NAME##MODIFIER##Hash_Bucket *buckets = (CL_GLOBAL NAME##MODIFIER##Hash_Bucket*)&tableData[sizeof(NAME##MODIFIER##Hash_TableData)];\ | |
| 196 | int resultExitCode = HASH_EXIT_CODE_NORMAL;\ | |
| 197 | KEY_TYPE key;\ | |
| 198 | VALUE_TYPE value;\ | |
| 199 | int index;\ | |
| 200 | int exitCode;\ | |
| 201 | uint i;\ | |
| 202 | for(i = 0; i < numEntries; i++){\ | |
| 203 | key = keys[i];\ | |
| 204 | SEARCH_EXP(NAME, MODIFIER, COMPRESS_FUNC, COMPRESS_FUNC_DATA, READ_KEY_EXP, CL_GLOBAL, ##__VA_ARGS__)\ | |
| 205 | switch(exitCode){\ | |
| 206 | case HASH_SEARCH_CODE_MATCH:\ | |
| 207 | case HASH_SEARCH_CODE_MISMATCH:\ | |
| 208 | resultExitCode = HASH_EXIT_CODE_OVERWRITE;\ | |
| 209 | case HASH_SEARCH_CODE_EMPTY:\ | |
| 210 | buckets[index].value = values[i];\ | |
| 211 | break;\ | |
| 212 | default:\ | |
| 213 | return exitCode;\ | |
| 214 | }\ | |
| 215 | }\ | |
| 216 | return resultExitCode;\ | |
| 217 | }\ | |
| 218 | \ | |
| 219 | int NAME##MODIFIER##Hash_InnerInsertSingleNoOverwrite(CL_GLOBAL char *tableData, KEY_TYPE key, VALUE_TYPE value){\ | |
| 220 | CL_GLOBAL NAME##MODIFIER##Hash_Bucket *buckets = (CL_GLOBAL NAME##MODIFIER##Hash_Bucket*)&tableData[sizeof(NAME##MODIFIER##Hash_TableData)];\ | |
| 221 | int index;\ | |
| 222 | int exitCode;\ | |
| 223 | SEARCH_EXP(NAME, MODIFIER, COMPRESS_FUNC, COMPRESS_FUNC_DATA, READ_KEY_EXP, CL_GLOBAL, ##__VA_ARGS__)\ | |
| 224 | switch(exitCode){\ | |
| 225 | case HASH_SEARCH_CODE_MATCH:\ | |
| 226 | case HASH_SEARCH_CODE_MISMATCH:\ | |
| 227 | return HASH_EXIT_CODE_OVERWRITE;\ | |
| 228 | case HASH_SEARCH_CODE_EMPTY:\ | |
| 229 | buckets[index].value = value;\ | |
| 230 | return HASH_EXIT_CODE_NORMAL;\ | |
| 231 | default:\ | |
| 232 | return exitCode;\ | |
| 233 | }\ | |
| 234 | }\ | |
| 235 | \ | |
| 236 | int NAME##MODIFIER##Hash_InnerInsertNoOverwrite(CL_GLOBAL char *tableData, unsigned int numEntries, CL_GLOBAL KEY_TYPE *keys, CL_GLOBAL VALUE_TYPE *values){\ | |
| 237 | CL_GLOBAL NAME##MODIFIER##Hash_Bucket *buckets = (CL_GLOBAL NAME##MODIFIER##Hash_Bucket*)&tableData[sizeof(NAME##MODIFIER##Hash_TableData)];\ | |
| 238 | int resultExitCode = HASH_EXIT_CODE_NORMAL;\ | |
| 239 | KEY_TYPE key;\ | |
| 240 | VALUE_TYPE value;\ | |
| 241 | int index;\ | |
| 242 | int exitCode;\ | |
| 243 | uint i;\ | |
| 244 | for(i = 0; i < numEntries; i++){\ | |
| 245 | key = keys[i];\ | |
| 246 | SEARCH_EXP(NAME, MODIFIER, COMPRESS_FUNC, COMPRESS_FUNC_DATA, READ_KEY_EXP, CL_GLOBAL, ##__VA_ARGS__)\ | |
| 247 | switch(exitCode){\ | |
| 248 | case HASH_SEARCH_CODE_MATCH:\ | |
| 249 | case HASH_SEARCH_CODE_MISMATCH:\ | |
| 250 | resultExitCode = HASH_EXIT_CODE_OVERWRITE;\ | |
| 251 | break;\ | |
| 252 | case HASH_SEARCH_CODE_EMPTY:\ | |
| 253 | buckets[index].value = values[i];\ | |
| 254 | break;\ | |
| 255 | default:\ | |
| 256 | return exitCode;\ | |
| 257 | }\ | |
| 258 | }\ | |
| 259 | return resultExitCode;\ | |
| 260 | }\ | |
| 261 | \ | |
| 262 | ||
| 263 | #define HASH_EMPTY_EXP(NAME, MODIFIER, INNER_EMPTY_EXP)\ | |
| 264 | NAME##MODIFIER##Hash_Bucket *buckets = (NAME##MODIFIER##Hash_Bucket*)&table->tableData[sizeof(NAME##MODIFIER##Hash_TableData)];\ | |
| 265 | int index;\ | |
| 266 | for(index = 0; index < ((NAME##MODIFIER##Hash_TableData*)table->tableData)->numBuckets; index++){\ | |
| 267 | INNER_EMPTY_EXP\ | |
| 268 | }\ | |
| 269 | exitCode = HASH_EXIT_CODE_NORMAL;\ | |
| 270 | \ | |
| 271 | ||
| 272 | #define KEY_VALUE_HASH_INNER_EMPTY_EXP buckets[index].key = HASH_BUCKET_STATUS_EMPTY; | |
| 273 | ||
| 274 | #define SENTINEL_VALUE_HASH_INNER_EMPTY_EXP(NAME, MODIFIER) buckets[index].value = ((NAME##MODIFIER##Hash_TableData*)table->tableData)->emptyValue; | |
| 275 | ||
| 276 | #define BASE_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, BASE_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, FACTORY_CREATE_EXP, CREATE_EXP, INIT_EXP, SEARCH_EXP, INNER_EMPTY_EXP, ...)\ | |
| 277 | \ | |
| 278 | BASE_TYPES_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC_DATA)\ | |
| 279 | \ | |
| 280 | BASE_HASH_UTIL(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, FACTORY_CREATE_EXP, , CREATE_EXP, INIT_EXP, , , HASH_EMPTY_EXP(NAME, MODIFIER, INNER_EMPTY_EXP))\ | |
| 281 | \ | |
| 282 | BASE_HASH_METHODS(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, SEARCH_EXP, CMPXCHG_HASH_READ_KEY_EXP, ,##__VA_ARGS__)\ | |
| 283 | \ | |
| 284 | int NAME##MODIFIER##Hash_QuerySingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE *valueOutput){\ | |
| 285 | return NAME##MODIFIER##Hash_InnerQuerySingle(table->tableData, key, valueOutput);\ | |
| 286 | }\ | |
| 287 | \ | |
| 288 | int NAME##MODIFIER##Hash_Query(NAME##Hash_Table *table, size_t numKeys, KEY_TYPE *keys, VALUE_TYPE *valuesOutput){\ | |
| 289 | return NAME##MODIFIER##Hash_InnerQuery(table->tableData, numKeys, keys, valuesOutput);\ | |
| 290 | }\ | |
| 291 | \ | |
| 292 | int NAME##MODIFIER##Hash_InsertSingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value){\ | |
| 293 | return NAME##MODIFIER##Hash_InnerInsertSingle(table->tableData, key, value);\ | |
| 294 | }\ | |
| 295 | \ | |
| 296 | int NAME##MODIFIER##Hash_Insert(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values){\ | |
| 297 | return NAME##MODIFIER##Hash_InnerInsert(table->tableData, numEntries, keys, values);\ | |
| 298 | }\ | |
| 299 | \ | |
| 300 | int NAME##MODIFIER##Hash_InsertSingleNoOverwrite(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value){\ | |
| 301 | return NAME##MODIFIER##Hash_InnerInsertSingleNoOverwrite(table->tableData, key, value);\ | |
| 302 | }\ | |
| 303 | \ | |
| 304 | int NAME##MODIFIER##Hash_InsertNoOverwrite(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values){\ | |
| 305 | return NAME##MODIFIER##Hash_InnerInsertNoOverwrite(table->tableData, numEntries, keys, values);\ | |
| 306 | }\ | |
| 307 | \ | |
| 308 | ||
| 309 | #define CL_FACTORY_CREATE_EXP(NAME, MODIFIER, FACTORY_CREATE_EXP, UTIL_PROGRAM_SOURCE)\ | |
| 310 | cl_int error;\ | |
| 311 | cl_device_id device;\ | |
| 312 | error = clGetContextInfo(factory->context, CL_CONTEXT_DEVICES, sizeof(device), &device, NULL);\ | |
| 313 | CLHash_Utilities_HandleError(error, STRINGIFY(NAME##Hash_CreateFactory), "clGetContextInfo");\ | |
| 314 | factory->querySingleKernel[hashIndex] = clCreateKernel(factory->program, STRINGIFY(NAME##MODIFIER##CLHash_RangeQuerySingle), &error);\ | |
| 315 | CLHash_Utilities_HandleError(error, STRINGIFY(NAME##MODIFIER##CLHash_CreateFactory), "clCreateKernel");\ | |
| 316 | factory->insertSingleKernel[hashIndex] = clCreateKernel(factory->program, STRINGIFY(NAME##MODIFIER##CLHash_RangeInsertSingle), &error);\ | |
| 317 | CLHash_Utilities_HandleError(error, STRINGIFY(NAME##MODIFIER##CLHash_CreateFactory), "clCreateKernel");\ | |
| 318 | factory->insertSingleNoOverwriteKernel[hashIndex] = clCreateKernel(factory->program, STRINGIFY(NAME##MODIFIER##CLHash_RangeInsertSingleNoOverwrite), &error);\ | |
| 319 | CLHash_Utilities_HandleError(error, STRINGIFY(NAME##MODIFIER##CLHash_CreateFactory), "clCreateKernel");\ | |
| 320 | factory->utilProgram[hashIndex] = CLHash_Utilities_BuildProgramString(factory->context, device, UTIL_PROGRAM_SOURCE);\ | |
| 321 | factory->emptyKernel[hashIndex] = clCreateKernel(factory->utilProgram[hashIndex], STRINGIFY(NAME##MODIFIER##CLHash_Empty), &error);\ | |
| 322 | CLHash_Utilities_HandleError(error, STRINGIFY(NAME##MODIFIER##CLHash_CreateFactory), "clCreateKernel");\ | |
| 323 | error = clGetKernelWorkGroupInfo(factory->emptyKernel[hashIndex], device, CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), &factory->emptyKernelLocalWorkSize[hashIndex], NULL);\ | |
| 324 | CLHash_Utilities_HandleError(error, STRINGIFY(NAME##MODIFIER##CLHash_CreateFactory), "clGetKernelWorkGroupInfo");\ | |
| 325 | FACTORY_CREATE_EXP;\ | |
| 326 | \ | |
| 327 | ||
| 328 | #define CL_FACTORY_DESTROY_EXP(NAME, MODIFIER, FACTORY_DESTROY_EXP)\ | |
| 329 | FACTORY_DESTROY_EXP;\ | |
| 330 | clReleaseKernel(factory->emptyKernel[hashIndex]);\ | |
| 331 | clReleaseProgram(factory->utilProgram[hashIndex]);\ | |
| 332 | clReleaseKernel(factory->querySingleKernel[hashIndex]);\ | |
| 333 | clReleaseKernel(factory->insertSingleKernel[hashIndex]);\ | |
| 334 | clReleaseKernel(factory->insertSingleNoOverwriteKernel[hashIndex]);\ | |
| 335 | \ | |
| 336 | ||
| 337 | #define CL_CREATE_EXP(NAME, MODIFIER, CREATE_EXP)\ | |
| 338 | table->context = factory->context;\ | |
| 339 | table->queue = factory->queue;\ | |
| 340 | table->program = factory->program;\ | |
| 341 | table->localWorkSize = factory->localWorkSize;\ | |
| 342 | table->utilProgram = factory->utilProgram[hashIndex];\ | |
| 343 | table->emptyKernel = factory->emptyKernel[hashIndex];\ | |
| 344 | table->emptyKernelLocalWorkSize = factory->emptyKernelLocalWorkSize[hashIndex];\ | |
| 345 | table->querySingleKernel = factory->querySingleKernel[hashIndex];\ | |
| 346 | table->insertSingleKernel = factory->insertSingleKernel[hashIndex];\ | |
| 347 | table->insertSingleNoOverwriteKernel = factory->insertSingleNoOverwriteKernel[hashIndex];\ | |
| 348 | clRetainContext(table->context);\ | |
| 349 | clRetainCommandQueue(table->queue);\ | |
| 350 | clRetainProgram(table->program);\ | |
| 351 | clRetainProgram(table->utilProgram);\ | |
| 352 | clRetainKernel(table->emptyKernel);\ | |
| 353 | clRetainKernel(table->querySingleKernel);\ | |
| 354 | clRetainKernel(table->insertSingleKernel);\ | |
| 355 | clRetainKernel(table->insertSingleNoOverwriteKernel);\ | |
| 356 | CREATE_EXP;\ | |
| 357 | \ | |
| 358 | ||
| 359 | #define CL_ALLOC_EXP(NAME, MODIFIER)\ | |
| 360 | cl_int err;\ | |
| 361 | table->tableDataBuffer = clCreateBuffer(table->context, CL_MEM_READ_WRITE, sizeof(NAME##MODIFIER##Hash_TableData) + ((NAME##MODIFIER##Hash_TableData*)table->tableData)->numBuckets * sizeof(NAME##MODIFIER##Hash_Bucket), NULL, &err);\ | |
| 362 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_InitTable), "clCreateBuffer");\ | |
| 363 | err = clEnqueueWriteBuffer(table->queue, table->tableDataBuffer, CL_TRUE, 0, sizeof(NAME##MODIFIER##Hash_TableData), table->tableData, 0, NULL, NULL);\ | |
| 364 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_InitTable), "clEnqueueWriteBuffer");\ | |
| 365 | \ | |
| 366 | ||
| 367 | #define CL_EMPTY_EXP(NAME, MODIFIER, EMPTY_EXP)\ | |
| 368 | cl_int err;\ | |
| 369 | err = clSetKernelArg(table->emptyKernel, 0, sizeof(cl_mem), &table->tableDataBuffer);\ | |
| 370 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_EmptyTable), "clSetKernelArg");\ | |
| 371 | const size_t groupWorkSize = roundUpToNearest(((NAME##MODIFIER##Hash_TableData*)table->tableData)->numBuckets, table->emptyKernelLocalWorkSize);\ | |
| 372 | err = clEnqueueNDRangeKernel(table->queue, table->emptyKernel, 1, 0, &groupWorkSize, (const size_t*)&table->emptyKernelLocalWorkSize, 0, NULL, NULL);\ | |
| 373 | \ | |
| 374 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_EmptyTable), "clEnqueueNDRangeKernel");\ | |
| 375 | exitCode = HASH_EXIT_CODE_NORMAL;\ | |
| 376 | EMPTY_EXP;\ | |
| 377 | \ | |
| 378 | ||
| 379 | #define CL_DESTROY_EXP(NAME)\ | |
| 380 | clReleaseMemObject(table->tableDataBuffer);\ | |
| 381 | clReleaseContext(table->context);\ | |
| 382 | clReleaseCommandQueue(table->queue);\ | |
| 383 | clReleaseProgram(table->utilProgram);\ | |
| 384 | clReleaseKernel(table->emptyKernel);\ | |
| 385 | clReleaseProgram(table->program);\ | |
| 386 | clReleaseKernel(table->querySingleKernel);\ | |
| 387 | clReleaseKernel(table->insertSingleKernel);\ | |
| 388 | clReleaseKernel(table->insertSingleNoOverwriteKernel);\ | |
| 389 | \ | |
| 390 | ||
| 391 | #define KEY_VALUE_CL_HASH_INNER_EMPTY_EXP buckets[index].key = -1;/*HASH_BUCKET_STATUS_EMPTY*/ | |
| 392 | ||
| 393 | #define SENTINEL_VALUE_CL_HASH_INNER_EMPTY_EXP(NAME, MODIFIER) buckets[index].value = ((__global NAME##MODIFIER##Hash_TableData*)tableData)->emptyValue; | |
| 394 | ||
| 395 | #define CL_UTIL_PROGRAM(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, BASE_TYPES_DEFINE, COMPRESS_FUNC_DATA, INNER_EMPTY_EXP)\ | |
| 396 | \ | |
| 397 | HASH_H_TYPES_DECLARE(NAME, KEY_TYPE)\ | |
| 398 | \ | |
| 399 | BASE_TYPES_DEFINE(NAME, MODIFIER##CL, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC_DATA)\ | |
| 400 | \ | |
| 401 | __kernel void NAME##MODIFIER##CLHash_Empty(__global char *tableData){\ | |
| 402 | int index = get_global_id(0);\ | |
| 403 | if(index >= ((__global NAME##MODIFIER##CLHash_TableData*)tableData)->numBuckets){\ | |
| 404 | return;\ | |
| 405 | }\ | |
| 406 | __global NAME##MODIFIER##CLHash_Bucket *buckets = (__global NAME##MODIFIER##CLHash_Bucket*)&tableData[sizeof(NAME##MODIFIER##CLHash_TableData)];\ | |
| 407 | INNER_EMPTY_EXP\ | |
| 408 | }\ | |
| 409 | \ | |
| 410 | ||
| 411 | #define ATOMIC_CMPXCHG_HASH_READ_KEY_EXP (atomic_cmpxchg(&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY, key))\ | |
| 412 | ||
| 413 | #define CL_HASH_KERN_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, BASE_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, READ_KEY_EXP, SEARCH_EXP, ...) \ | |
| 414 | \ | |
| 415 | BASE_TYPES_DEFINE(NAME, MODIFIER##CL, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC_DATA)\ | |
| 416 | \ | |
| 417 | BASE_HASH_METHODS(NAME, MODIFIER##CL, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, SEARCH_EXP, READ_KEY_EXP, __global, ##__VA_ARGS__) \ | |
| 418 | \ | |
| 419 | int NAME##MODIFIER##CLHash_QuerySingle(__global char *tableData, KEY_TYPE key, __global VALUE_TYPE *valueOutput){\ | |
| 420 | return NAME##MODIFIER##CLHash_InnerQuerySingle(tableData, key, valueOutput);\ | |
| 421 | }\ | |
| 422 | \ | |
| 423 | int NAME##MODIFIER##CLHash_Query(__global char *tableData, size_t numKeys, __global KEY_TYPE *keys, __global VALUE_TYPE *valuesOutput){\ | |
| 424 | return NAME##MODIFIER##CLHash_InnerQuery(tableData, numKeys, keys, valuesOutput);\ | |
| 425 | }\ | |
| 426 | \ | |
| 427 | int NAME##MODIFIER##CLHash_InsertSingle(__global char *tableData, KEY_TYPE key, VALUE_TYPE value){\ | |
| 428 | return NAME##MODIFIER##CLHash_InnerInsertSingle(tableData, key, value);\ | |
| 429 | }\ | |
| 430 | \ | |
| 431 | int NAME##MODIFIER##CLHash_Insert(__global char *tableData, size_t numEntries, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 432 | return NAME##MODIFIER##CLHash_InnerInsert(tableData, numEntries, keys, values);\ | |
| 433 | }\ | |
| 434 | \ | |
| 435 | int NAME##MODIFIER##CLHash_InsertSingleNoOverwrite(__global char *tableData, KEY_TYPE key, VALUE_TYPE value){\ | |
| 436 | return NAME##MODIFIER##CLHash_InnerInsertSingleNoOverwrite(tableData, key, value);\ | |
| 437 | }\ | |
| 438 | \ | |
| 439 | int NAME##MODIFIER##CLHash_InsertNoOverwrite(__global char *tableData, size_t numEntries, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 440 | return NAME##MODIFIER##CLHash_InnerInsertNoOverwrite(tableData, numEntries, keys, values);\ | |
| 441 | }\ | |
| 442 | \ | |
| 443 | __kernel void NAME##MODIFIER##CLHash_RangeQuerySingle(__global char *tableData, unsigned int numQueries, __global KEY_TYPE *keys, __global VALUE_TYPE *valuesOutput){\ | |
| 444 | uint i = get_global_id(0);\ | |
| 445 | if(i >= numQueries){\ | |
| 446 | return;\ | |
| 447 | }\ | |
| 448 | NAME##MODIFIER##CLHash_InnerQuerySingle(tableData, keys[i], valuesOutput + i);\ | |
| 449 | }\ | |
| 450 | \ | |
| 451 | __kernel void NAME##MODIFIER##CLHash_RangeQuery(__global char *tableData, unsigned int numQueries, unsigned int numKeys, __global KEY_TYPE *keys, __global VALUE_TYPE *valuesOutput){\ | |
| 452 | uint i = get_global_id(0);\ | |
| 453 | if(i >= numQueries){\ | |
| 454 | return;\ | |
| 455 | }\ | |
| 456 | NAME##MODIFIER##CLHash_InnerQuery(tableData, numKeys, keys + (i*numKeys), valuesOutput + (i*numKeys));\ | |
| 457 | }\ | |
| 458 | \ | |
| 459 | __kernel void NAME##MODIFIER##CLHash_RangeInsertSingle(__global char *tableData, unsigned int numInsertions, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 460 | uint i = get_global_id(0);\ | |
| 461 | if(i >= numInsertions){\ | |
| 462 | return;\ | |
| 463 | }\ | |
| 464 | NAME##MODIFIER##CLHash_InnerInsertSingle(tableData, keys[i], values[i]);\ | |
| 465 | }\ | |
| 466 | \ | |
| 467 | __kernel void NAME##MODIFIER##CLHash_RangeInsert(__global char *tableData, unsigned int numInsertions, unsigned int numEntries, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 468 | uint i = get_global_id(0);\ | |
| 469 | if(i >= numInsertions){\ | |
| 470 | return;\ | |
| 471 | }\ | |
| 472 | NAME##MODIFIER##CLHash_InnerInsert(tableData, numEntries, keys + (i*numEntries), values + (i*numEntries));\ | |
| 473 | }\ | |
| 474 | \ | |
| 475 | __kernel void NAME##MODIFIER##CLHash_RangeInsertSingleNoOverwrite(__global char* tableData, unsigned int numInsertions, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 476 | uint i = get_global_id(0);\ | |
| 477 | if(i >= numInsertions){\ | |
| 478 | return;\ | |
| 479 | }\ | |
| 480 | NAME##MODIFIER##CLHash_InnerInsertSingleNoOverwrite(tableData, keys[i], values[i]);\ | |
| 481 | }\ | |
| 482 | \ | |
| 483 | __kernel void NAME##MODIFIER##CLHash_RangeInsertNoOverwrite(__global char *tableData, unsigned int numInsertions, unsigned int numEntries, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 484 | uint i = get_global_id(0);\ | |
| 485 | if(i >= numInsertions){\ | |
| 486 | return;\ | |
| 487 | }\ | |
| 488 | NAME##MODIFIER##CLHash_InnerInsertNoOverwrite(tableData, numEntries, keys + (i*numEntries), values + (i*numEntries));\ | |
| 489 | }\ | |
| 490 | \ | |
| 491 | ||
| 492 | #define CL_BASE_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, BASE_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, FACTORY_CREATE_EXP, CREATE_EXP, INIT_EXP, INNER_EMPTY_EXP, ...)\ | |
| 493 | \ | |
| 494 | BASE_TYPES_DEFINE(NAME, MODIFIER##CL, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC_DATA)\ | |
| 495 | \ | |
| 496 | BASE_HASH_UTIL(NAME, MODIFIER##CL, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, CL_FACTORY_CREATE_EXP(NAME, MODIFIER, FACTORY_CREATE_EXP, STRINGIFY(CL_UTIL_PROGRAM(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, BASE_TYPES_DEFINE, COMPRESS_FUNC_DATA, INNER_EMPTY_EXP))), CL_FACTORY_DESTROY_EXP(NAME, MODIFIER, ), CL_CREATE_EXP(NAME, MODIFIER, CREATE_EXP), INIT_EXP, CL_ALLOC_EXP(NAME, MODIFIER), CL_DESTROY_EXP(NAME), CL_EMPTY_EXP(NAME, MODIFIER, ))\ | |
| 497 | \ | |
| 498 | int NAME##MODIFIER##CLHash_QuerySingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE *valueOutput){\ | |
| 499 | return NAME##MODIFIER##CLHash_Query(table, 1, &key, valueOutput);\ | |
| 500 | }\ | |
| 501 | \ | |
| 502 | int NAME##MODIFIER##CLHash_Query(NAME##Hash_Table *table, size_t numKeys, KEY_TYPE *keys, VALUE_TYPE *valuesOutput){\ | |
| 503 | cl_int err;\ | |
| 504 | cl_mem keysBuffer = clCreateBuffer(table->context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(KEY_TYPE) * numKeys, keys, &err);\ | |
| 505 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_Query), "clCreateBuffer");\ | |
| 506 | cl_mem valuesOutputBuffer = clCreateBuffer(table->context, CL_MEM_WRITE_ONLY, sizeof(VALUE_TYPE) * numKeys, NULL, &err);\ | |
| 507 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_Query), "clCreateBuffer");\ | |
| 508 | NAME##MODIFIER##CLHash_BufferQuery(table, numKeys, keysBuffer, valuesOutputBuffer);\ | |
| 509 | err = clEnqueueReadBuffer(table->queue, valuesOutputBuffer, CL_TRUE, 0, sizeof(VALUE_TYPE) * numKeys, valuesOutput, 0, NULL, NULL);\ | |
| 510 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_Query), "clEnqueueReadBuffer");\ | |
| 511 | clReleaseMemObject(keysBuffer);\ | |
| 512 | clReleaseMemObject(valuesOutputBuffer);\ | |
| 513 | return HASH_EXIT_CODE_NORMAL;\ | |
| 514 | }\ | |
| 515 | \ | |
| 516 | int NAME##MODIFIER##CLHash_BufferQuery(NAME##Hash_Table *table, size_t numKeys, cl_mem keysBuffer, cl_mem valuesOutputBuffer){\ | |
| 517 | cl_int err;\ | |
| 518 | err = clSetKernelArg(table->querySingleKernel, 0, sizeof(cl_mem), &table->tableDataBuffer);\ | |
| 519 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferQuery), "clSetKernelArg");\ | |
| 520 | err = clSetKernelArg(table->querySingleKernel, 1, sizeof(unsigned int), &numKeys);\ | |
| 521 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferQuery), "clSetKernelArg");\ | |
| 522 | err = clSetKernelArg(table->querySingleKernel, 2, sizeof(cl_mem), &keysBuffer);\ | |
| 523 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferQuery), "clSetKernelArg");\ | |
| 524 | err = clSetKernelArg(table->querySingleKernel, 3, sizeof(cl_mem), &valuesOutputBuffer);\ | |
| 525 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferQuery), "clSetKernelArg");\ | |
| 526 | const size_t groupWorkSize = roundUpToNearest(numKeys, table->localWorkSize);\ | |
| 527 | err = clEnqueueNDRangeKernel(table->queue, table->querySingleKernel, 1, 0, &groupWorkSize, (const size_t*)&table->localWorkSize, 0, NULL, NULL);\ | |
| 528 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferQuery), "clEnqueueNDRangeKernel");\ | |
| 529 | clFinish(table->queue);\ | |
| 530 | return HASH_EXIT_CODE_NORMAL;\ | |
| 531 | }\ | |
| 532 | \ | |
| 533 | int NAME##MODIFIER##CLHash_InsertSingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value){\ | |
| 534 | return NAME##MODIFIER##CLHash_Insert(table, 1, &key, &value);\ | |
| 535 | }\ | |
| 536 | \ | |
| 537 | int NAME##MODIFIER##CLHash_Insert(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values){\ | |
| 538 | cl_int err;\ | |
| 539 | cl_mem keysBuffer = clCreateBuffer(table->context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(KEY_TYPE) * numEntries, keys, &err);\ | |
| 540 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_Insert), "clCreateBuffer");\ | |
| 541 | cl_mem valuesBuffer = clCreateBuffer(table->context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(VALUE_TYPE) * numEntries, values, &err);\ | |
| 542 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_Insert), "clCreateBuffer");\ | |
| 543 | NAME##MODIFIER##CLHash_BufferInsert(table, numEntries, keysBuffer, valuesBuffer);\ | |
| 544 | clReleaseMemObject(keysBuffer);\ | |
| 545 | clReleaseMemObject(valuesBuffer);\ | |
| 546 | return HASH_EXIT_CODE_NORMAL;\ | |
| 547 | }\ | |
| 548 | \ | |
| 549 | int NAME##MODIFIER##CLHash_BufferInsert(NAME##Hash_Table *table, size_t numEntries, cl_mem keysBuffer, cl_mem valuesBuffer){\ | |
| 550 | cl_int err;\ | |
| 551 | err = clSetKernelArg(table->insertSingleKernel, 0, sizeof(cl_mem), &table->tableDataBuffer);\ | |
| 552 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferInsert), "clSetKernelArg");\ | |
| 553 | err = clSetKernelArg(table->insertSingleKernel, 1, sizeof(unsigned int), &numEntries);\ | |
| 554 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferInsert), "clSetKernelArg");\ | |
| 555 | err = clSetKernelArg(table->insertSingleKernel, 2, sizeof(cl_mem), &keysBuffer);\ | |
| 556 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferInsert), "clSetKernelArg");\ | |
| 557 | err = clSetKernelArg(table->insertSingleKernel, 3, sizeof(cl_mem), &valuesBuffer);\ | |
| 558 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferInsert), "clSetKernelArg");\ | |
| 559 | const size_t groupWorkSize = roundUpToNearest(numEntries, table->localWorkSize);\ | |
| 560 | err = clEnqueueNDRangeKernel(table->queue, table->insertSingleKernel, 1, 0, &groupWorkSize, (const size_t*)&table->localWorkSize, 0, NULL, NULL);\ | |
| 561 | CLHash_Utilities_HandleError(err, NULL, "clEnqueueNDRangeKernel");\ | |
| 562 | return(0);\ | |
| 563 | }\ | |
| 564 | \ | |
| 565 | int NAME##MODIFIER##CLHash_InsertSingleNoOverwrite(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value){\ | |
| 566 | return NAME##MODIFIER##CLHash_InsertNoOverwrite(table, 1, &key, &value);\ | |
| 567 | }\ | |
| 568 | \ | |
| 569 | int NAME##MODIFIER##CLHash_InsertNoOverwrite(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values){\ | |
| 570 | cl_int err;\ | |
| 571 | cl_mem keysBuffer = clCreateBuffer(table->context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(KEY_TYPE) * numEntries, keys, &err);\ | |
| 572 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_InsertNoOverwrite), "clCreateBuffer");\ | |
| 573 | cl_mem valuesBuffer = clCreateBuffer(table->context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(VALUE_TYPE) * numEntries, values, &err);\ | |
| 574 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_InsertNoOverwrite), "clCreateBuffer");\ | |
| 575 | NAME##MODIFIER##CLHash_BufferInsertNoOverwrite(table, numEntries, keysBuffer, valuesBuffer);\ | |
| 576 | clReleaseMemObject(keysBuffer);\ | |
| 577 | clReleaseMemObject(valuesBuffer);\ | |
| 578 | return HASH_EXIT_CODE_NORMAL;\ | |
| 579 | }\ | |
| 580 | \ | |
| 581 | int NAME##MODIFIER##CLHash_BufferInsertNoOverwrite(NAME##Hash_Table *table, size_t numEntries, cl_mem keysBuffer, cl_mem valuesBuffer){\ | |
| 582 | cl_int err;\ | |
| 583 | err = clSetKernelArg(table->insertSingleNoOverwriteKernel, 0, sizeof(cl_mem), &table->tableDataBuffer);\ | |
| 584 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferInsertNoOverwrite), "clSetKernelArg");\ | |
| 585 | err = clSetKernelArg(table->insertSingleNoOverwriteKernel, 1, sizeof(unsigned int), &numEntries);\ | |
| 586 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferInsertNoOverwrite), "ClSetKernelArg");\ | |
| 587 | err = clSetKernelArg(table->insertSingleNoOverwriteKernel, 2, sizeof(cl_mem), &keysBuffer);\ | |
| 588 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferInsertNoOverwrite), "clSetKernelArg");\ | |
| 589 | err = clSetKernelArg(table->insertSingleNoOverwriteKernel, 3, sizeof(cl_mem), &valuesBuffer);\ | |
| 590 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferInsertNoOverwrite), "clSetKernelArg");\ | |
| 591 | const size_t groupWorkSize = roundUpToNearest(numEntries, table->localWorkSize);\ | |
| 592 | err = clEnqueueNDRangeKernel(table->queue, table->insertSingleNoOverwriteKernel, 1, 0, &groupWorkSize, (const size_t*)&table->localWorkSize, 0, NULL, NULL);\ | |
| 593 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferInsertNoOverwrite), "clEnqueueNDRangeKernel");\ | |
| 594 | return(0);\ | |
| 595 | }\ | |
| 596 | \ | |
| 597 |
| … | … | @@ -0,0 +1,82 @@ |
| 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 | #undef UNDEFINED | |
| 34 | #ifdef UNDEFINED | |
| 35 | /** | |
| 36 | * @file hash.hm | |
| 37 | * @author Peter Ahrens | |
| 38 | * @date Thu Jun 6 2013 | |
| 39 | */ | |
| 40 | #endif | |
| 41 | ||
| 42 | ||
| 43 | #define BASE_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 44 | \ | |
| 45 | int NAME##MODIFIER##Hash_CreateFactory(NAME##Hash_Factory *factory, int hashIndex);\ | |
| 46 | \ | |
| 47 | int NAME##MODIFIER##Hash_DestroyFactory(NAME##Hash_Factory *factory, int hashIndex);\ | |
| 48 | \ | |
| 49 | NAME##Hash_Table *NAME##MODIFIER##Hash_CreateTable(NAME##Hash_Factory* factory, int hashIndex, size_t keyRange, size_t numEntries, float loadFactor);\ | |
| 50 | \ | |
| 51 | int NAME##MODIFIER##Hash_InitTable(NAME##Hash_Table *table, va_list args);\ | |
| 52 | \ | |
| 53 | int NAME##MODIFIER##Hash_DestroyTable(NAME##Hash_Table *table);\ | |
| 54 | \ | |
| 55 | char *NAME##MODIFIER##Hash_Report(NAME##Hash_Table *table);\ | |
| 56 | \ | |
| 57 | int NAME##MODIFIER##Hash_EmptyTable(NAME##Hash_Table *table);\ | |
| 58 | \ | |
| 59 | int NAME##MODIFIER##Hash_Query(NAME##Hash_Table *table, size_t numKeys, KEY_TYPE *keys, VALUE_TYPE *valuesOutput);\ | |
| 60 | \ | |
| 61 | int NAME##MODIFIER##Hash_QuerySingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE *valueOutput);\ | |
| 62 | \ | |
| 63 | int NAME##MODIFIER##Hash_Insert(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values);\ | |
| 64 | \ | |
| 65 | int NAME##MODIFIER##Hash_InsertSingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value);\ | |
| 66 | \ | |
| 67 | int NAME##MODIFIER##Hash_InsertNoOverwrite(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values);\ | |
| 68 | \ | |
| 69 | int NAME##MODIFIER##Hash_InsertSingleNoOverwrite(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value);\ | |
| 70 | \ | |
| 71 | ||
| 72 | #define CL_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 73 | \ | |
| 74 | BASE_HASH_DECLARE(NAME, MODIFIER##CL, KEY_TYPE, VALUE_TYPE)\ | |
| 75 | \ | |
| 76 | int NAME##MODIFIER##CLHash_BufferQuery(NAME##Hash_Table *table, size_t numKeys, cl_mem keysBuffer, cl_mem valuesOutputBuffer);\ | |
| 77 | \ | |
| 78 | int NAME##MODIFIER##CLHash_BufferInsert(NAME##Hash_Table *table, size_t numEntries, cl_mem keysBuffer, cl_mem valuesBuffer);\ | |
| 79 | \ | |
| 80 | int NAME##MODIFIER##CLHash_BufferInsertNoOverwrite(NAME##Hash_Table *table, size_t numEntries, cl_mem keysBuffer, cl_mem valuesBuffer);\ | |
| 81 | \ | |
| 82 |
| … | … | @@ -0,0 +1,181 @@ |
| 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 | #undef UNDEFINED | |
| 34 | #ifdef UNDEFINED | |
| 35 | /** | |
| 36 | * @file compactHash.cm | |
| 37 | * @author Peter Ahrens | |
| 38 | * @date Thu Jun 6 2013 | |
| 39 | */ | |
| 40 | #endif | |
| 41 | #include "baseHash.cm" | |
| 42 | ||
| 43 | #define COMPACT_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP, SEARCH_EXP, ...)\ | |
| 44 | \ | |
| 45 | BASE_HASH_DEFINE(NAME, MODIFIER##Compact, HASH_ID, KEY_TYPE, VALUE_TYPE, KEY_VALUE_BASE_HASH_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA,,, INIT_EXP, SEARCH_EXP, KEY_VALUE_HASH_INNER_EMPTY_EXP, ##__VA_ARGS__)\ | |
| 46 | \ | |
| 47 | ||
| 48 | #define COMPACT_CL_HASH_KERN_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, SEARCH_EXP, ...)\ | |
| 49 | \ | |
| 50 | CL_HASH_KERN_DEFINE(NAME, MODIFIER##Compact, KEY_TYPE, VALUE_TYPE, KEY_VALUE_BASE_HASH_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, ATOMIC_CMPXCHG_HASH_READ_KEY_EXP, SEARCH_EXP, ##__VA_ARGS__)\ | |
| 51 | \ | |
| 52 | ||
| 53 | #define COMPACT_CL_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP)\ | |
| 54 | \ | |
| 55 | CL_BASE_HASH_DEFINE(NAME, MODIFIER##Compact, HASH_ID, KEY_TYPE, VALUE_TYPE, KEY_VALUE_BASE_HASH_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA,,, INIT_EXP, KEY_VALUE_CL_HASH_INNER_EMPTY_EXP)\ | |
| 56 | \ | |
| 57 | ||
| 58 | #define OPEN_COMPACT_HASH_INIT_EXP(NAME, MODIFIER, INIT_EXP) \ | |
| 59 | ((NAME##MODIFIER##Hash_TableData*)table->tableData)->numBuckets = (unsigned int)((double)numEntries / loadFactor);\ | |
| 60 | INIT_EXP\ | |
| 61 | \ | |
| 62 | ||
| 63 | #ifdef XXX | |
| 64 | unsigned int c = COMPRESS_FUNC(((CL_GLOBAL NAME##MODIFIER##Hash_TableData*)tableData)->compressFuncData, key);\ | |
| 65 | ||
| 66 | #endif | |
| 67 | ||
| 68 | #define OPEN_COMPACT_HASH_SEARCH_EXP(NAME, MODIFIER, COMPRESS_FUNC, COMPRESS_FUNC_DATA, READ_KEY_EXP, CL_GLOBAL, JUMP_EXP, CYCLE_EXP) \ | |
| 69 | GLOBAL NAME##MODIFIER##Hash_TableData* mytableData = (GLOBAL NAME##MODIFIER##Hash_TableData*)tableData;\ | |
| 70 | NAME##Hash_CompressLCGData compressFuncData = mytableData->compressFuncData;\ | |
| 71 | unsigned int c = COMPRESS_FUNC(compressFuncData, key);\ | |
| 72 | unsigned long int iteration = 0;\ | |
| 73 | for(;;){\ | |
| 74 | index = JUMP_EXP;\ | |
| 75 | if(READ_KEY_EXP == HASH_BUCKET_STATUS_EMPTY){\ | |
| 76 | exitCode = HASH_SEARCH_CODE_EMPTY;\ | |
| 77 | break;\ | |
| 78 | }else if(key == buckets[index].key){\ | |
| 79 | exitCode = HASH_SEARCH_CODE_MATCH;\ | |
| 80 | break;\ | |
| 81 | }else if(CYCLE_EXP){\ | |
| 82 | exitCode = HASH_EXIT_CODE_CYCLE;\ | |
| 83 | break;\ | |
| 84 | }\ | |
| 85 | iteration++;\ | |
| 86 | }\ | |
| 87 | \ | |
| 88 | ||
| 89 | #define OPEN_COMPACT_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP, ...)\ | |
| 90 | \ | |
| 91 | COMPACT_HASH_DEFINE(NAME, MODIFIER##Open, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, OPEN_COMPACT_HASH_INIT_EXP(NAME, MODIFIER##OpenCompact, INIT_EXP), OPEN_COMPACT_HASH_SEARCH_EXP, ##__VA_ARGS__)\ | |
| 92 | ||
| 93 | #define OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP, ...)\ | |
| 94 | \ | |
| 95 | COMPACT_CL_HASH_KERN_DEFINE(NAME, MODIFIER##Open, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, OPEN_COMPACT_HASH_SEARCH_EXP, ##__VA_ARGS__)\ | |
| 96 | \ | |
| 97 | ||
| 98 | #define OPEN_COMPACT_CL_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP)\ | |
| 99 | \ | |
| 100 | COMPACT_CL_HASH_DEFINE(NAME, MODIFIER##Open, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, OPEN_COMPACT_HASH_INIT_EXP(NAME, MODIFIER##OpenCompactCL, INIT_EXP))\ | |
| 101 | \ | |
| 102 | ||
| 103 | #define LINEAR_OPEN_COMPACT_HASH_JUMP_EXP(NAME, MODIFIER, B, CL_GLOBAL) ((B * iteration + c) % ((CL_GLOBAL NAME##MODIFIER##Hash_TableData*)tableData)->numBuckets) | |
| 104 | ||
| 105 | #define LINEAR_OPEN_COMPACT_HASH_CYCLE_EXP (index == c && iteration > 0) | |
| 106 | ||
| 107 | #define LINEAR_OPEN_COMPACT_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP, B)\ | |
| 108 | \ | |
| 109 | OPEN_COMPACT_HASH_DEFINE(NAME, MODIFIER##Linear, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP, LINEAR_OPEN_COMPACT_HASH_JUMP_EXP(NAME, MODIFIER##LinearOpenCompact, B,), LINEAR_OPEN_COMPACT_HASH_CYCLE_EXP)\ | |
| 110 | ||
| 111 | #define LINEAR_OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP, B)\ | |
| 112 | \ | |
| 113 | OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, MODIFIER##Linear, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP, LINEAR_OPEN_COMPACT_HASH_JUMP_EXP(NAME, MODIFIER##LinearOpenCompactCL, B, __global), LINEAR_OPEN_COMPACT_HASH_CYCLE_EXP)\ | |
| 114 | \ | |
| 115 | ||
| 116 | #define LINEAR_OPEN_COMPACT_CL_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP)\ | |
| 117 | \ | |
| 118 | OPEN_COMPACT_CL_HASH_DEFINE(NAME, MODIFIER##Linear, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP)\ | |
| 119 | \ | |
| 120 | ||
| 121 | #define QUADRATIC_OPEN_COMPACT_HASH_JUMP_EXP(NAME, MODIFIER, A, B, CL_GLOBAL) ((A * iteration * iteration + B * iteration + c) % ((CL_GLOBAL NAME##MODIFIER##Hash_TableData*)tableData)->numBuckets) | |
| 122 | ||
| 123 | #define QUADRATIC_OPEN_COMPACT_HASH_CYCLE_EXP(NAME, MODIFIER, CL_GLOBAL) (iteration > ((CL_GLOBAL NAME##MODIFIER##Hash_TableData*)tableData)->numBuckets) | |
| 124 | ||
| 125 | #define QUADRATIC_OPEN_COMPACT_HASH_INIT_EXP(NAME, MODIFIER, INIT_EXP)\ | |
| 126 | INIT_EXP\ | |
| 127 | ((NAME##MODIFIER##Hash_TableData*)table->tableData)->numBuckets = largestProthPrimeUnder(((NAME##MODIFIER##Hash_TableData*)table->tableData)->numBuckets);\ | |
| 128 | \ | |
| 129 | ||
| 130 | #define QUADRATIC_OPEN_COMPACT_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP, A, B)\ | |
| 131 | \ | |
| 132 | OPEN_COMPACT_HASH_DEFINE(NAME, MODIFIER##Quadratic, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, QUADRATIC_OPEN_COMPACT_HASH_INIT_EXP(NAME, MODIFIER##QuadraticOpenCompact, INIT_EXP), QUADRATIC_OPEN_COMPACT_HASH_JUMP_EXP(NAME, MODIFIER##QuadraticOpenCompact, A, B,), QUADRATIC_OPEN_COMPACT_HASH_CYCLE_EXP(NAME, MODIFIER##QuadraticOpenCompact,))\ | |
| 133 | \ | |
| 134 | ||
| 135 | #define QUADRATIC_OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP, A, B)\ | |
| 136 | \ | |
| 137 | OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, MODIFIER##Quadratic, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, QUADRATIC_OPEN_COMPACT_HASH_INIT_EXP(NAME, MODIFIER##QuadraticOpenCompactCL, INIT_EXP), QUADRATIC_OPEN_COMPACT_HASH_JUMP_EXP(NAME, MODIFIER##QuadraticOpenCompactCL, A, B, __global), QUADRATIC_OPEN_COMPACT_HASH_CYCLE_EXP(NAME, MODIFIER##QuadraticOpenCompactCL, __global))\ | |
| 138 | \ | |
| 139 | ||
| 140 | #define QUADRATIC_OPEN_COMPACT_CL_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP)\ | |
| 141 | \ | |
| 142 | OPEN_COMPACT_CL_HASH_DEFINE(NAME, MODIFIER##Quadratic, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, QUADRATIC_OPEN_COMPACT_HASH_INIT_EXP(NAME, MODIFIER##QuadraticOpenCompactCL, INIT_EXP)) | |
| 143 | \ | |
| 144 | ||
| 145 | #define LCG_OPEN_COMPACT_HASH_INIT_EXP(NAME, MODIFIER)\ | |
| 146 | ((NAME##MODIFIER##Hash_TableData*)table->tableData)->compressFuncData.a = HASH_LCG_A;\ | |
| 147 | ((NAME##MODIFIER##Hash_TableData*)table->tableData)->compressFuncData.c = HASH_LCG_C;\ | |
| 148 | ((NAME##MODIFIER##Hash_TableData*)table->tableData)->compressFuncData.m = HASH_LCG_M;\ | |
| 149 | ((NAME##MODIFIER##Hash_TableData*)table->tableData)->compressFuncData.n = ((NAME##MODIFIER##Hash_TableData*)table->tableData)->numBuckets;\ | |
| 150 | \ | |
| 151 | ||
| 152 | #define LCG_LINEAR_OPEN_COMPACT_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE, B)\ | |
| 153 | \ | |
| 154 | LINEAR_OPEN_COMPACT_HASH_DEFINE(NAME, LCG, LCG_LINEAR_OPEN_COMPACT_HASH_ID, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressLCG, NAME##Hash_CompressLCGData, LCG_OPEN_COMPACT_HASH_INIT_EXP(NAME, LCGLinearOpenCompact), B)\ | |
| 155 | \ | |
| 156 | ||
| 157 | #define LCG_LINEAR_OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, KEY_TYPE, VALUE_TYPE, B)\ | |
| 158 | \ | |
| 159 | LINEAR_OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, LCG, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressLCG, NAME##Hash_CompressLCGData, LCG_OPEN_COMPACT_HASH_INIT_EXP(NAME, LCGLinearOpenCompactCL), B)\ | |
| 160 | \ | |
| 161 | ||
| 162 | #define LCG_LINEAR_OPEN_COMPACT_CL_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 163 | \ | |
| 164 | LINEAR_OPEN_COMPACT_CL_HASH_DEFINE(NAME, LCG, LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressLCG, NAME##Hash_CompressLCGData, LCG_OPEN_COMPACT_HASH_INIT_EXP(NAME, LCGLinearOpenCompactCL))\ | |
| 165 | \ | |
| 166 | ||
| 167 | #define LCG_QUADRATIC_OPEN_COMPACT_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE, A, B)\ | |
| 168 | \ | |
| 169 | QUADRATIC_OPEN_COMPACT_HASH_DEFINE(NAME, LCG, LCG_QUADRATIC_OPEN_COMPACT_HASH_ID, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressLCG, NAME##Hash_CompressLCGData, LCG_OPEN_COMPACT_HASH_INIT_EXP(NAME, LCGQuadraticOpenCompact), A, B)\ | |
| 170 | \ | |
| 171 | ||
| 172 | #define LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, KEY_TYPE, VALUE_TYPE, A, B)\ | |
| 173 | \ | |
| 174 | QUADRATIC_OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, LCG, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressLCG, NAME##Hash_CompressLCGData, LCG_OPEN_COMPACT_HASH_INIT_EXP(NAME, LCGQuadraticOpenCompactCL), A, B)\ | |
| 175 | \ | |
| 176 | ||
| 177 | #define LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 178 | \ | |
| 179 | QUADRATIC_OPEN_COMPACT_CL_HASH_DEFINE(NAME, LCG, LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressLCG, NAME##Hash_CompressLCGData, LCG_OPEN_COMPACT_HASH_INIT_EXP(NAME, LCGQuadraticOpenCompactCL))\ | |
| 180 | \ | |
| 181 |
| … | … | @@ -0,0 +1,102 @@ |
| 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 | #undef UNDECLARED | |
| 34 | #ifdef UNDECLARED | |
| 35 | /** | |
| 36 | * @file compactHash.hm | |
| 37 | * @author Peter Ahrens | |
| 38 | * @date Thu Jun 6 2013 | |
| 39 | */ | |
| 40 | #endif | |
| 41 | #include "baseHash.hm" | |
| 42 | ||
| 43 | #define COMPACT_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 44 | \ | |
| 45 | BASE_HASH_DECLARE(NAME, MODIFIER##Compact, KEY_TYPE, VALUE_TYPE)\ | |
| 46 | \ | |
| 47 | ||
| 48 | #define OPEN_COMPACT_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 49 | \ | |
| 50 | COMPACT_HASH_DECLARE(NAME, MODIFIER##Open, KEY_TYPE, VALUE_TYPE)\ | |
| 51 | \ | |
| 52 | ||
| 53 | #define LINEAR_OPEN_COMPACT_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 54 | \ | |
| 55 | OPEN_COMPACT_HASH_DECLARE(NAME, MODIFIER##Linear, KEY_TYPE, VALUE_TYPE)\ | |
| 56 | \ | |
| 57 | ||
| 58 | #define LCG_LINEAR_OPEN_COMPACT_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 59 | \ | |
| 60 | LINEAR_OPEN_COMPACT_HASH_DECLARE(NAME, LCG, KEY_TYPE, VALUE_TYPE)\ | |
| 61 | \ | |
| 62 | ||
| 63 | #define QUADRATIC_OPEN_COMPACT_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 64 | \ | |
| 65 | OPEN_COMPACT_HASH_DECLARE(NAME, MODIFIER##Quadratic, KEY_TYPE, VALUE_TYPE)\ | |
| 66 | \ | |
| 67 | ||
| 68 | #define LCG_QUADRATIC_OPEN_COMPACT_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 69 | \ | |
| 70 | QUADRATIC_OPEN_COMPACT_HASH_DECLARE(NAME, LCG, KEY_TYPE, VALUE_TYPE)\ | |
| 71 | \ | |
| 72 | ||
| 73 | #define COMPACT_CL_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 74 | \ | |
| 75 | CL_HASH_DECLARE(NAME, MODIFIER##Compact, KEY_TYPE, VALUE_TYPE)\ | |
| 76 | \ | |
| 77 | ||
| 78 | #define OPEN_COMPACT_CL_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 79 | \ | |
| 80 | COMPACT_CL_HASH_DECLARE(NAME, MODIFIER##Open, KEY_TYPE, VALUE_TYPE)\ | |
| 81 | \ | |
| 82 | ||
| 83 | #define LINEAR_OPEN_COMPACT_CL_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 84 | \ | |
| 85 | OPEN_COMPACT_CL_HASH_DECLARE(NAME, MODIFIER##Linear, KEY_TYPE, VALUE_TYPE)\ | |
| 86 | \ | |
| 87 | ||
| 88 | #define LCG_LINEAR_OPEN_COMPACT_CL_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 89 | \ | |
| 90 | LINEAR_OPEN_COMPACT_CL_HASH_DECLARE(NAME, LCG, KEY_TYPE, VALUE_TYPE)\ | |
| 91 | \ | |
| 92 | ||
| 93 | #define QUADRATIC_OPEN_COMPACT_CL_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 94 | \ | |
| 95 | OPEN_COMPACT_CL_HASH_DECLARE(NAME, MODIFIER##Quadratic, KEY_TYPE, VALUE_TYPE)\ | |
| 96 | \ | |
| 97 | ||
| 98 | #define LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 99 | \ | |
| 100 | QUADRATIC_OPEN_COMPACT_CL_HASH_DECLARE(NAME, LCG, KEY_TYPE, VALUE_TYPE)\ | |
| 101 | \ | |
| 102 |
| … | … | @@ -0,0 +1,68 @@ |
| 1 | eval 'exec perl -w $0 ${1+"$@"}' | |
| 2 | if 0; | |
| 3 | ||
| 4 | # Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 5 | # under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 6 | # Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 7 | # for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 8 | # reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 9 | # ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 10 | # ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 11 | # to produce derivative works, such modified software should be clearly marked, | |
| 12 | # so as not to confuse it with the version available from LANL. | |
| 13 | # | |
| 14 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 15 | # use this file except in compliance with the License. You may obtain a copy | |
| 16 | # of the License at | |
| 17 | # | |
| 18 | # http://www.apache.org/licenses/LICENSE-2.0 | |
| 19 | # | |
| 20 | # Unless required by applicable law or agreed to in writing, software distributed | |
| 21 | # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 22 | # CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 23 | # specific language governing permissions and limitations under the License. | |
| 24 | # | |
| 25 | # Under this license, it is required to include a reference to this work. We | |
| 26 | # request that each derivative work contain a reference to LANL Copyright | |
| 27 | # Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 28 | # measured. In addition, it is requested that a modifier is included as in | |
| 29 | # the following example: | |
| 30 | # | |
| 31 | # //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 32 | # | |
| 33 | # This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 34 | ||
| 35 | use File::Basename; | |
| 36 | ||
| 37 | $ARGV_LAST = ""; | |
| 38 | ||
| 39 | ($file,,) = fileparse($ARGV[0], qr/\..*/); | |
| 40 | print "const char *",$file,"_source =\n"; | |
| 41 | ||
| 42 | while(<>) { | |
| 43 | if ($ARGV ne $ARGV_LAST){ | |
| 44 | # $comment = 0; | |
| 45 | $ARGV_LAST=$ARGV; | |
| 46 | } | |
| 47 | chop $_; | |
| 48 | ||
| 49 | s/"/""/g; | |
| 50 | ||
| 51 | # if (/^\/\*/){ | |
| 52 | # #print "Setting comment to 1\n"; | |
| 53 | # $comment = 1; | |
| 54 | # } | |
| 55 | # if (/\*\/$/){ | |
| 56 | # #print "Setting comment to 0\n"; | |
| 57 | # $comment = 0; | |
| 58 | # next; | |
| 59 | # } | |
| 60 | # if ($comment eq 1) { | |
| 61 | # #print "Skip line and goto next\n"; | |
| 62 | ## next; | |
| 63 | # } | |
| 64 | ||
| 65 | print '"',$_,'\n','"',"\n"; | |
| 66 | } | |
| 67 | ||
| 68 | print ";\n" |
| … | … | @@ -0,0 +1,106 @@ |
| 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 | /** | |
| 34 | * @file hashTest.c | |
| 35 | * @author Peter Ahrens | |
| 36 | * @date Fri Jun 7 2013 | |
| 37 | */ | |
| 38 | ||
| 39 | #include "testHelper.h" | |
| 40 | #include "HashFactory.h" | |
| 41 | ||
| 42 | void sanityTest(int hashType, TestData *metaTest, char* subTestName){ | |
| 43 | TestData *sanityTestData = Test_CreateTest(subTestName); | |
| 44 | int emptyValue = -1; | |
| 45 | intintHash_Factory *sanityFactory = intintHash_CreateFactory(hashType, &emptyValue, 128, NULL, NULL); | |
| 46 | intintHash_Table *sanityTable = intintHash_CreateTable(sanityFactory, hashType, 21, 7, 0.5); | |
| 47 | Test_IntEquality(sanityTestData, "Correct Hash Type Check", hashType, intintHash_GetTableType(sanityTable), NULL); | |
| 48 | intintHash_EmptyTable(sanityTable); | |
| 49 | int keys[] = {6, 6, 9, 12, 15, 18, 21}; | |
| 50 | int values[] = {101, 101, 102, 103, 104, 105, 106}; | |
| 51 | int keys1[] = {6, 9, 12, 15, 18, 21}; | |
| 52 | int values1[] = {101, 102, 103, 104, 105, 106}; | |
| 53 | int values2[] = {201, 202, 203, 204, 205, 206}; | |
| 54 | int valuesOut[6]; | |
| 55 | intintHash_Insert(sanityTable, 7, keys, values); | |
| 56 | int sanityInt; | |
| 57 | intintHash_QuerySingle(sanityTable, 6, &sanityInt); | |
| 58 | Test_IntEquality(sanityTestData, "QuerySingle after Insert Check 1", 101, sanityInt, NULL); | |
| 59 | intintHash_QuerySingle(sanityTable, 9, &sanityInt); | |
| 60 | Test_IntEquality(sanityTestData, "QuerySingle after Insert Check 2", 102, sanityInt, NULL); | |
| 61 | intintHash_QuerySingle(sanityTable, 12, &sanityInt); | |
| 62 | Test_IntEquality(sanityTestData, "QuerySingle after Insert Check 3", 103, sanityInt, NULL); | |
| 63 | intintHash_QuerySingle(sanityTable, 15, &sanityInt); | |
| 64 | Test_IntEquality(sanityTestData, "QuerySingle after Insert Check 4", 104, sanityInt, NULL); | |
| 65 | intintHash_QuerySingle(sanityTable, 18, &sanityInt); | |
| 66 | Test_IntEquality(sanityTestData, "QuerySingle after Insert Check 5", 105, sanityInt, NULL); | |
| 67 | intintHash_QuerySingle(sanityTable, 21, &sanityInt); | |
| 68 | Test_IntEquality(sanityTestData, "QuerySingle after Insert Check 6", 106, sanityInt, NULL); | |
| 69 | intintHash_InsertSingleNoOverwrite(sanityTable, 6, 201); | |
| 70 | intintHash_InsertSingleNoOverwrite(sanityTable, 9, 202); | |
| 71 | intintHash_InsertSingleNoOverwrite(sanityTable, 12, 203); | |
| 72 | intintHash_InsertSingleNoOverwrite(sanityTable, 15, 204); | |
| 73 | intintHash_InsertSingleNoOverwrite(sanityTable, 18, 205); | |
| 74 | intintHash_InsertSingleNoOverwrite(sanityTable, 21, 206); | |
| 75 | intintHash_Query(sanityTable, 6, keys1, &valuesOut[0]); | |
| 76 | Test_IntArrayEquality(sanityTestData, "Query after InsertSingleNoOverwrite Check", 6, values1, valuesOut, NULL); | |
| 77 | intintHash_InsertSingle(sanityTable, 6, 201); | |
| 78 | intintHash_InsertSingle(sanityTable, 9, 202); | |
| 79 | intintHash_InsertSingle(sanityTable, 12, 203); | |
| 80 | intintHash_InsertSingle(sanityTable, 15, 204); | |
| 81 | intintHash_InsertSingle(sanityTable, 18, 205); | |
| 82 | intintHash_InsertSingle(sanityTable, 21, 206); | |
| 83 | intintHash_Query(sanityTable, 6, keys1, valuesOut); | |
| 84 | Test_IntArrayEquality(sanityTestData, "Query after InsertSingle Check", 6, values2, valuesOut, NULL); | |
| 85 | intintHash_InsertNoOverwrite(sanityTable, 6, keys1, values1); | |
| 86 | intintHash_Query(sanityTable, 6, keys1, valuesOut); | |
| 87 | Test_IntArrayEquality(sanityTestData, "Query after InsertNoOverwrite Check", 6, values2, valuesOut, NULL); | |
| 88 | intintHash_DestroyTable(sanityTable); | |
| 89 | intintHash_DestroyFactory(sanityFactory); | |
| 90 | Test_FinishSubTest(metaTest, sanityTestData); | |
| 91 | } | |
| 92 | ||
| 93 | int main(int argc, char *argv[]){ | |
| 94 | CLHash_Init(argv[0]); | |
| 95 | TestData *allHashTestsData = Test_CreateTest("HashTest"); | |
| 96 | sanityTest(IDENTITY_PERFECT_HASH_ID, allHashTestsData, "intintIdentityPerfectHash Test"); | |
| 97 | sanityTest(IDENTITY_SENTINEL_PERFECT_HASH_ID, allHashTestsData, "intintIdentitySentinelPerfectHash Test"); | |
| 98 | sanityTest(LCG_LINEAR_OPEN_COMPACT_HASH_ID, allHashTestsData, "intintLCGLinearOpenCompactHash Test"); | |
| 99 | sanityTest(LCG_QUADRATIC_OPEN_COMPACT_HASH_ID, allHashTestsData, "intintLCGQuadraticOpenCompactHash Test"); | |
| 100 | sanityTest(IDENTITY_PERFECT_CL_HASH_ID, allHashTestsData, "intintIdentityPerfectCLHash Test"); | |
| 101 | sanityTest(IDENTITY_SENTINEL_PERFECT_CL_HASH_ID, allHashTestsData, "intintIdentitySentinelPerfectCLHash Test"); | |
| 102 | sanityTest(LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID, allHashTestsData, "intintLCGLinearOpenCompactCLHash Test"); | |
| 103 | sanityTest(LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID, allHashTestsData, "intintLCGQuadraticOpenCompactCLHash Test"); | |
| 104 | Test_FinishTest(allHashTestsData); | |
| 105 | return 0; | |
| 106 | } |
| … | … | @@ -0,0 +1,133 @@ |
| 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 | #undef UNDEFINED | |
| 34 | #ifdef UNDEFINED | |
| 35 | /** | |
| 36 | * @file perfectHash.cm | |
| 37 | * @author Peter Ahrens | |
| 38 | * @date Thu Jun 6 2013 | |
| 39 | */ | |
| 40 | #endif | |
| 41 | #include "baseHash.cm" | |
| 42 | ||
| 43 | #define PERFECT_HASH_SEARCH_EXP(NAME, MODIFIER, COMPRESS_FUNC, COMPRESS_FUNC_DATA, READ_KEY_EXP, CL_GLOBAL) \ | |
| 44 | index = COMPRESS_FUNC(((CL_GLOBAL NAME##MODIFIER##Hash_TableData*)tableData)->compressFuncData, key);\ | |
| 45 | if(READ_KEY_EXP != HASH_BUCKET_STATUS_EMPTY){\ | |
| 46 | if(key == buckets[index].key){\ | |
| 47 | exitCode = HASH_SEARCH_CODE_MATCH;\ | |
| 48 | }else{\ | |
| 49 | exitCode = HASH_SEARCH_CODE_MISMATCH;\ | |
| 50 | }\ | |
| 51 | }else{\ | |
| 52 | exitCode = HASH_SEARCH_CODE_EMPTY;\ | |
| 53 | }\ | |
| 54 | ||
| 55 | #define SENTINEL_PERFECT_HASH_SEARCH_EXP(NAME, MODIFIER, COMPRESS_FUNC, COMPRESS_FUNC_DATA, READ_KEY_EXP, CL_GLOBAL) \ | |
| 56 | index = COMPRESS_FUNC(((CL_GLOBAL NAME##MODIFIER##Hash_TableData*)tableData)->compressFuncData, key);\ | |
| 57 | if(buckets[index].value != ((CL_GLOBAL NAME##MODIFIER##Hash_TableData*)tableData)->emptyValue){\ | |
| 58 | exitCode = HASH_SEARCH_CODE_MATCH;\ | |
| 59 | }else{\ | |
| 60 | exitCode = HASH_SEARCH_CODE_EMPTY;\ | |
| 61 | }\ | |
| 62 | ||
| 63 | #define PERFECT_HASH_INIT_EXP(NAME, MODIFIER, INIT_EXP, COMPRESS_FUNC, COMPRESS_FUNC_DATA, KEY_TYPE) \ | |
| 64 | INIT_EXP\ | |
| 65 | ((NAME##MODIFIER##Hash_TableData*)table->tableData)->numBuckets = keyRange + 1;\ | |
| 66 | ||
| 67 | #define SENTINEL_PERFECT_HASH_INIT_EXP(NAME, MODIFIER, INIT_EXP, COMPRESS_FUNC, COMPRESS_FUNC_DATA, KEY_TYPE) \ | |
| 68 | \ | |
| 69 | ((NAME##MODIFIER##Hash_TableData*)table->tableData)->emptyValue = factory->emptyValue;\ | |
| 70 | \ | |
| 71 | PERFECT_HASH_INIT_EXP(NAME, MODIFIER, INIT_EXP, COMPRESS_FUNC, COMPRESS_FUNC_DATA, KEY_TYPE) \ | |
| 72 | \ | |
| 73 | ||
| 74 | #define PERFECT_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP)\ | |
| 75 | \ | |
| 76 | BASE_HASH_DEFINE(NAME, MODIFIER##Perfect, HASH_ID, KEY_TYPE, VALUE_TYPE, KEY_VALUE_BASE_HASH_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA,,, PERFECT_HASH_INIT_EXP(NAME, MODIFIER##Perfect, INIT_EXP, COMPRESS_FUNC, COMPRESS_FUNC_DATA, KEY_TYPE), PERFECT_HASH_SEARCH_EXP, KEY_VALUE_HASH_INNER_EMPTY_EXP)\ | |
| 77 | \ | |
| 78 | ||
| 79 | #define PERFECT_CL_HASH_KERN_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA)\ | |
| 80 | \ | |
| 81 | CL_HASH_KERN_DEFINE(NAME, MODIFIER##Perfect, KEY_TYPE, VALUE_TYPE, KEY_VALUE_BASE_HASH_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, CMPXCHG_HASH_READ_KEY_EXP, PERFECT_HASH_SEARCH_EXP)\ | |
| 82 | \ | |
| 83 | ||
| 84 | #define PERFECT_CL_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP)\ | |
| 85 | \ | |
| 86 | CL_BASE_HASH_DEFINE(NAME, MODIFIER##Perfect, HASH_ID, KEY_TYPE, VALUE_TYPE, KEY_VALUE_BASE_HASH_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA,,, PERFECT_HASH_INIT_EXP(NAME, MODIFIER##PerfectCL, INIT_EXP, COMPRESS_FUNC, COMPRESS_FUNC_DATA, KEY_TYPE), KEY_VALUE_CL_HASH_INNER_EMPTY_EXP)\ | |
| 87 | \ | |
| 88 | ||
| 89 | #define SENTINEL_PERFECT_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP)\ | |
| 90 | \ | |
| 91 | BASE_HASH_DEFINE(NAME, MODIFIER##SentinelPerfect, HASH_ID, KEY_TYPE, VALUE_TYPE, SENTINEL_VALUE_BASE_HASH_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA,,, SENTINEL_PERFECT_HASH_INIT_EXP(NAME, MODIFIER##SentinelPerfect, INIT_EXP, COMPRESS_FUNC, COMPRESS_FUNC_DATA, KEY_TYPE), SENTINEL_PERFECT_HASH_SEARCH_EXP, SENTINEL_VALUE_HASH_INNER_EMPTY_EXP(NAME, MODIFIER##SentinelPerfect))\ | |
| 92 | \ | |
| 93 | ||
| 94 | #define SENTINEL_PERFECT_CL_HASH_KERN_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA)\ | |
| 95 | \ | |
| 96 | CL_HASH_KERN_DEFINE(NAME, MODIFIER##SentinelPerfect, KEY_TYPE, VALUE_TYPE, SENTINEL_VALUE_BASE_HASH_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, CMPXCHG_HASH_READ_KEY_EXP, SENTINEL_PERFECT_HASH_SEARCH_EXP)\ | |
| 97 | \ | |
| 98 | ||
| 99 | #define SENTINEL_PERFECT_CL_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP)\ | |
| 100 | \ | |
| 101 | CL_BASE_HASH_DEFINE(NAME, MODIFIER##SentinelPerfect, HASH_ID, KEY_TYPE, VALUE_TYPE, SENTINEL_VALUE_BASE_HASH_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA,,, SENTINEL_PERFECT_HASH_INIT_EXP(NAME, MODIFIER##SentinelPerfectCL, INIT_EXP, COMPRESS_FUNC, COMPRESS_FUNC_DATA, KEY_TYPE), SENTINEL_VALUE_CL_HASH_INNER_EMPTY_EXP(NAME, MODIFIER##SentinelPerfectCL))\ | |
| 102 | \ | |
| 103 | ||
| 104 | #define IDENTITY_PERFECT_CL_HASH_KERN_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 105 | \ | |
| 106 | PERFECT_CL_HASH_KERN_DEFINE(NAME, Identity, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressIdentity, char)\ | |
| 107 | \ | |
| 108 | ||
| 109 | #define IDENTITY_PERFECT_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 110 | \ | |
| 111 | PERFECT_HASH_DEFINE(NAME, Identity, IDENTITY_PERFECT_HASH_ID, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressIdentity, char, )\ | |
| 112 | \ | |
| 113 | ||
| 114 | #define IDENTITY_PERFECT_CL_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 115 | \ | |
| 116 | PERFECT_CL_HASH_DEFINE(NAME, Identity, IDENTITY_PERFECT_CL_HASH_ID, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressIdentity, char, )\ | |
| 117 | \ | |
| 118 | ||
| 119 | #define IDENTITY_SENTINEL_PERFECT_CL_HASH_KERN_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 120 | \ | |
| 121 | SENTINEL_PERFECT_CL_HASH_KERN_DEFINE(NAME, Identity, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressIdentity, char)\ | |
| 122 | \ | |
| 123 | ||
| 124 | #define IDENTITY_SENTINEL_PERFECT_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 125 | \ | |
| 126 | SENTINEL_PERFECT_HASH_DEFINE(NAME, Identity, IDENTITY_SENTINEL_PERFECT_HASH_ID, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressIdentity, char, )\ | |
| 127 | \ | |
| 128 | ||
| 129 | #define IDENTITY_SENTINEL_PERFECT_CL_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 130 | \ | |
| 131 | SENTINEL_PERFECT_CL_HASH_DEFINE(NAME, Identity, IDENTITY_SENTINEL_PERFECT_CL_HASH_ID, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressIdentity, char, )\ | |
| 132 | \ | |
| 133 |
| … | … | @@ -0,0 +1,82 @@ |
| 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 | #undef UNDECLARED | |
| 34 | #ifdef UNDECLARED | |
| 35 | /** | |
| 36 | * @file perfectHash.hm | |
| 37 | * @author Peter Ahrens | |
| 38 | * @date Thu Jun 6 2013 | |
| 39 | */ | |
| 40 | #endif | |
| 41 | #include "baseHash.hm" | |
| 42 | ||
| 43 | #define PERFECT_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 44 | \ | |
| 45 | BASE_HASH_DECLARE(NAME, MODIFIER##Perfect, KEY_TYPE, VALUE_TYPE)\ | |
| 46 | \ | |
| 47 | ||
| 48 | #define IDENTITY_PERFECT_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 49 | \ | |
| 50 | PERFECT_HASH_DECLARE(NAME, Identity, KEY_TYPE, VALUE_TYPE)\ | |
| 51 | \ | |
| 52 | ||
| 53 | #define PERFECT_CL_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 54 | \ | |
| 55 | CL_HASH_DECLARE(NAME, MODIFIER##Perfect, KEY_TYPE, VALUE_TYPE)\ | |
| 56 | \ | |
| 57 | ||
| 58 | #define IDENTITY_PERFECT_CL_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 59 | \ | |
| 60 | PERFECT_CL_HASH_DECLARE(NAME, Identity, KEY_TYPE, VALUE_TYPE)\ | |
| 61 | \ | |
| 62 | ||
| 63 | #define SENTINEL_PERFECT_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 64 | \ | |
| 65 | BASE_HASH_DECLARE(NAME, MODIFIER##SentinelPerfect, KEY_TYPE, VALUE_TYPE)\ | |
| 66 | \ | |
| 67 | ||
| 68 | #define IDENTITY_SENTINEL_PERFECT_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 69 | \ | |
| 70 | SENTINEL_PERFECT_HASH_DECLARE(NAME, Identity, KEY_TYPE, VALUE_TYPE)\ | |
| 71 | \ | |
| 72 | ||
| 73 | #define SENTINEL_PERFECT_CL_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 74 | \ | |
| 75 | CL_HASH_DECLARE(NAME, MODIFIER##SentinelPerfect, KEY_TYPE, VALUE_TYPE)\ | |
| 76 | \ | |
| 77 | ||
| 78 | #define IDENTITY_SENTINEL_PERFECT_CL_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 79 | \ | |
| 80 | SENTINEL_PERFECT_CL_HASH_DECLARE(NAME, Identity, KEY_TYPE, VALUE_TYPE)\ | |
| 81 | \ | |
| 82 |
| … | … | @@ -0,0 +1,142 @@ |
| 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 <math.h> | |
| 34 | #include <stdio.h> | |
| 35 | #define LCG_A 2147483629 | |
| 36 | #define LCG_C 2147483587 | |
| 37 | #define LCG_M 2147483647 | |
| 38 | #define PRIME_NUM_CHECKS 20 | |
| 39 | ||
| 40 | int modularPow(int base, int exponent, int modulus){ | |
| 41 | int result = 1; | |
| 42 | while (exponent){ | |
| 43 | if (exponent & 1) | |
| 44 | result = ((long long int)result * base) % modulus; | |
| 45 | exponent >>= 1; | |
| 46 | base = ((long long int)base * base) % modulus; | |
| 47 | } | |
| 48 | return result; | |
| 49 | } | |
| 50 | ||
| 51 | int largestProthPrimeUnder(int N){ | |
| 52 | if(N < 4){ | |
| 53 | return N; | |
| 54 | } | |
| 55 | //determine the nearest proth number | |
| 56 | int n; | |
| 57 | int m; | |
| 58 | frexp((double)N, &n); | |
| 59 | n /= 2; | |
| 60 | int s = 1 << n; | |
| 61 | int p = s * ((N - 1) / s) + 1; | |
| 62 | int i; | |
| 63 | int a; | |
| 64 | srand(p); | |
| 65 | while(p > 3){ | |
| 66 | //check if a proth number is prime | |
| 67 | for(i = 0; i < PRIME_NUM_CHECKS; i++){ | |
| 68 | a = rand(); | |
| 69 | if(modularPow(a, (p - 1) / 2, p) == p - 1){ | |
| 70 | return p; | |
| 71 | } | |
| 72 | } | |
| 73 | //determine the next proth number | |
| 74 | if(p - 1 == s * s / 4){ | |
| 75 | s /= 2; | |
| 76 | } | |
| 77 | p -= s; | |
| 78 | } | |
| 79 | return 3; | |
| 80 | } | |
| 81 | ||
| 82 | int smallestProthPrimeAbove(int N){ | |
| 83 | if(N < 4){ | |
| 84 | return N; | |
| 85 | } | |
| 86 | //determine the nearest proth number | |
| 87 | int n; | |
| 88 | int m; | |
| 89 | frexp((double)N, &n); | |
| 90 | n /= 2; | |
| 91 | int s = 1 << n; | |
| 92 | int p = s * ((N - 1) / s) + 1; | |
| 93 | int i; | |
| 94 | int a; | |
| 95 | srand(p); | |
| 96 | while(1){ | |
| 97 | //determine the next proth number | |
| 98 | if(p - 1 == s * s){ | |
| 99 | s *= 2; | |
| 100 | } | |
| 101 | p += s; | |
| 102 | //check if a proth number is prime | |
| 103 | for(i = 0; i < PRIME_NUM_CHECKS; i++){ | |
| 104 | a = rand(); | |
| 105 | if(modularPow(a, (p - 1) / 2, p) == p - 1){ | |
| 106 | return p; | |
| 107 | } | |
| 108 | } | |
| 109 | } | |
| 110 | return 3; | |
| 111 | } | |
| 112 | ||
| 113 | int main(){ | |
| 114 | printf("%d\n", largestProthPrimeUnder(2)); | |
| 115 | printf("%d\n", smallestProthPrimeAbove(2)); | |
| 116 | printf("%d\n", largestProthPrimeUnder(3)); | |
| 117 | printf("%d\n", smallestProthPrimeAbove(3)); | |
| 118 | printf("%d\n", largestProthPrimeUnder(4)); | |
| 119 | printf("%d\n", smallestProthPrimeAbove(4)); | |
| 120 | printf("%d\n", largestProthPrimeUnder(5)); | |
| 121 | printf("%d\n", smallestProthPrimeAbove(5)); | |
| 122 | printf("%d\n", largestProthPrimeUnder(11)); | |
| 123 | printf("%d\n", smallestProthPrimeAbove(11)); | |
| 124 | printf("%d\n", largestProthPrimeUnder(13)); | |
| 125 | printf("%d\n", smallestProthPrimeAbove(13)); | |
| 126 | printf("%d\n", largestProthPrimeUnder(2000024)); | |
| 127 | printf("%d\n", smallestProthPrimeAbove(1993728)); | |
| 128 | int p = 3; | |
| 129 | int m = 2; | |
| 130 | int c = 1; | |
| 131 | int i; | |
| 132 | for(i = 0; i < 0; i++){ | |
| 133 | printf("%d %d\n", i, p); | |
| 134 | if(c == 0){ | |
| 135 | m *= 2; | |
| 136 | c = i + 2; | |
| 137 | } | |
| 138 | p += m; | |
| 139 | c--; | |
| 140 | } | |
| 141 | return 0; | |
| 142 | } |
| … | … | @@ -0,0 +1,186 @@ |
| 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 | /** | |
| 34 | * @file test.c | |
| 35 | * @author Peter Ahrens | |
| 36 | * @date Fri Jun 7 2013 | |
| 37 | */ | |
| 38 | ||
| 39 | #include "testHelper.h" | |
| 40 | ||
| 41 | void Test_StartTry(char *nameOfTest){ | |
| 42 | printf("TRYING %s: ", nameOfTest); | |
| 43 | fflush(stdout); | |
| 44 | } | |
| 45 | ||
| 46 | void Test_EndTry(TestData *currentTest){ | |
| 47 | printf("PASSED\n"); | |
| 48 | currentTest->numPassed++; | |
| 49 | } | |
| 50 | ||
| 51 | void Test_PointerEquality(TestData *currentTest, char *nameOfTest, void *expected, void *observed, char *failMessage){ | |
| 52 | if(expected == observed){ | |
| 53 | printf("%s: PASSED\n", nameOfTest); | |
| 54 | currentTest->numPassed++; | |
| 55 | }else{ | |
| 56 | printf("%s: FAILED\n", nameOfTest); | |
| 57 | printf(" POINTERS DO NOT MATCH"); | |
| 58 | if(failMessage != NULL){ | |
| 59 | printf(" ADDITIONAL INFO: %s\n", failMessage); | |
| 60 | } | |
| 61 | currentTest->numFailed++; | |
| 62 | printf("\n"); | |
| 63 | } | |
| 64 | } | |
| 65 | ||
| 66 | void Test_PointerInequality(TestData *currentTest, char *nameOfTest, void *notExpected, void *observed, char *failMessage){ | |
| 67 | if(notExpected != observed){ | |
| 68 | printf("%s: PASSED\n", nameOfTest); | |
| 69 | currentTest->numPassed++; | |
| 70 | }else{ | |
| 71 | printf("%s: FAILED\n", nameOfTest); | |
| 72 | printf(" POINTERS SHOULD NOT MATCH"); | |
| 73 | if(failMessage != NULL){ | |
| 74 | printf(" ADDITIONAL INFO: %s\n", failMessage); | |
| 75 | } | |
| 76 | currentTest->numFailed++; | |
| 77 | printf("\n"); | |
| 78 | } | |
| 79 | } | |
| 80 | ||
| 81 | void Test_IntEquality(TestData *currentTest, char *nameOfTest, int expected, int observed, char *failMessage){ | |
| 82 | if(expected == observed){ | |
| 83 | printf("%s: PASSED\n", nameOfTest); | |
| 84 | currentTest->numPassed++; | |
| 85 | }else{ | |
| 86 | printf("%s: FAILED\n", nameOfTest); | |
| 87 | printf(" EXPECTED: %d\n", expected); | |
| 88 | printf(" OBSERVED: %d\n", observed); | |
| 89 | if(failMessage != NULL){ | |
| 90 | printf(" ADDITIONAL INFO: %s\n", failMessage); | |
| 91 | } | |
| 92 | currentTest->numFailed++; | |
| 93 | printf("\n"); | |
| 94 | } | |
| 95 | } | |
| 96 | ||
| 97 | void Test_IntArrayEquality(TestData *currentTest, char *nameOfTest, unsigned int size, int *expected, int *observed, char *failMessage){ | |
| 98 | int result = 0; | |
| 99 | int i; | |
| 100 | for(i = 0; i < size; i++){ | |
| 101 | if(expected[i] != observed[i]){ | |
| 102 | result = 1; | |
| 103 | } | |
| 104 | } | |
| 105 | if(result == 0){ | |
| 106 | printf("%s: PASSED\n", nameOfTest); | |
| 107 | currentTest->numPassed++; | |
| 108 | }else{ | |
| 109 | printf("%s: FAILED\n", nameOfTest); | |
| 110 | printf(" EXPECTED: {"); | |
| 111 | for(i = 0; i < size; i++){ | |
| 112 | printf("%d, ", expected[i]); | |
| 113 | } | |
| 114 | printf("}\n"); | |
| 115 | printf(" OBSERVED: {"); | |
| 116 | for(i = 0; i < size; i++){ | |
| 117 | printf("%d, ", observed[i]); | |
| 118 | } | |
| 119 | printf("}\n"); | |
| 120 | if(failMessage != NULL){ | |
| 121 | printf(" ADDITIONAL INFO: %s\n", failMessage); | |
| 122 | } | |
| 123 | currentTest->numFailed++; | |
| 124 | printf("\n"); | |
| 125 | } | |
| 126 | } | |
| 127 | ||
| 128 | void Test_IntLessThan(TestData *currentTest, char *nameOfTest, int expectedAbove, int observed, char *failMessage){ | |
| 129 | if(expectedAbove > observed){ | |
| 130 | printf("%s: PASSED\n", nameOfTest); | |
| 131 | currentTest->numPassed++; | |
| 132 | }else{ | |
| 133 | printf("%s: FAILED\n", nameOfTest); | |
| 134 | printf(" EXPECTED OBSERVED VALUE TO BE LESS THAN: %d\n", expectedAbove); | |
| 135 | printf(" OBSERVED: %d\n", observed); | |
| 136 | if(failMessage != NULL){ | |
| 137 | printf(" ADDITIONAL INFO: %s\n", failMessage); | |
| 138 | } | |
| 139 | currentTest->numFailed++; | |
| 140 | printf("\n"); | |
| 141 | } | |
| 142 | } | |
| 143 | ||
| 144 | void Test_IntGreaterThan(TestData *currentTest, char *nameOfTest, int expectedBelow, int observed, char *failMessage){ | |
| 145 | if(expectedBelow < observed){ | |
| 146 | printf("%s: PASSED\n", nameOfTest); | |
| 147 | currentTest->numPassed++; | |
| 148 | }else{ | |
| 149 | printf("%s: FAILED\n", nameOfTest); | |
| 150 | printf(" EXPECTED OBSERVED VALUE TO BE GREATER THAN: %d\n", expectedBelow); | |
| 151 | printf(" OBSERVED: %d\n", observed); | |
| 152 | if(failMessage != NULL){ | |
| 153 | printf(" ADDITIONAL INFO: %s\n", failMessage); | |
| 154 | } | |
| 155 | currentTest->numFailed++; | |
| 156 | printf("\n"); | |
| 157 | } | |
| 158 | } | |
| 159 | ||
| 160 | void Test_FinishSubTest(TestData *currentTest, TestData *subTest){ | |
| 161 | if(subTest->numFailed == 0){ | |
| 162 | currentTest->numPassed++; | |
| 163 | }else{ | |
| 164 | currentTest->numFailed++; | |
| 165 | } | |
| 166 | Test_FinishTest(subTest); | |
| 167 | } | |
| 168 | ||
| 169 | ||
| 170 | TestData *Test_CreateTest(char *nameOfTestGroup){ | |
| 171 | TestData *newTest = (TestData*)malloc(sizeof(TestData)); | |
| 172 | newTest->nameOfTestGroup = nameOfTestGroup; | |
| 173 | newTest->numPassed = 0; | |
| 174 | newTest->numFailed = 0; | |
| 175 | printf("%s STARTED\n", nameOfTestGroup); | |
| 176 | return newTest; | |
| 177 | } | |
| 178 | ||
| 179 | void Test_FinishTest(TestData *currentTest){ | |
| 180 | printf("%s FINISHED\n", currentTest->nameOfTestGroup); | |
| 181 | printf("%d%% (%d/%d) TESTS PASSED\n\n", | |
| 182 | ((currentTest->numPassed * 100) / (currentTest->numPassed + currentTest->numFailed)), | |
| 183 | currentTest->numPassed, | |
| 184 | currentTest->numPassed + currentTest->numFailed); | |
| 185 | free(currentTest); | |
| 186 | } |
| … | … | @@ -0,0 +1,62 @@ |
| 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 | /** | |
| 34 | * @file test.h | |
| 35 | * @author Peter Ahrens | |
| 36 | * @date Fri Jun 7 2013 | |
| 37 | */ | |
| 38 | ||
| 39 | #include <stdio.h> | |
| 40 | #include <stdlib.h> | |
| 41 | #ifndef TEST_H | |
| 42 | #define TEST_H | |
| 43 | ||
| 44 | typedef struct TestData{ | |
| 45 | char* nameOfTestGroup; | |
| 46 | unsigned int numPassed; | |
| 47 | unsigned int numFailed; | |
| 48 | } TestData; | |
| 49 | ||
| 50 | void Test_StartTry(char *nameOfTest); | |
| 51 | void Test_EndTry(TestData *currentTest); | |
| 52 | void Test_PointerEquality(TestData *currentTest, char *nameOfTest, void *expected, void *observed, char *failMessage); | |
| 53 | void Test_PointerInequality(TestData *currentTest, char *nameOfTest, void *notExpected, void *observed, char *failMessage); | |
| 54 | void Test_IntGreaterThan(TestData *currentTest, char *nameOfTest, int expectedBelow, int observed, char *failMessage); | |
| 55 | void Test_IntLessThan(TestData *currentTest, char *nameOfTest, int expectedAbove, int observed, char *failMessage); | |
| 56 | void Test_IntEquality(TestData *currentTest, char *nameOfTest, int expected, int observed, char *failMessage); | |
| 57 | void Test_IntArrayEquality(TestData *currentTest, char *nameOfTest, unsigned int size, int *expected, int *observed, char *failMessage); | |
| 58 | void Test_FinishSubTest(TestData *currentTest, TestData *subTest); | |
| 59 | TestData *Test_CreateTest(char *nameOfTestGroup); | |
| 60 | void Test_FinishTest(TestData *currentTest); | |
| 61 | ||
| 62 | #endif |
| … | … | @@ -2,12 +2,12 @@ bin_PROGRAMS = neigh2d # neigh2d_memopts |
| 2 | 2 | |
| 3 | 3 | ACLOCAL_AMFLAGS = -I m4 |
| 4 | 4 | |
| 5 | SUBDIRS = kdtree hash simplehash timer | |
| 5 | SUBDIRS = kdtree HashFactory simplehash timer | |
| 6 | 6 | |
| 7 | 7 | neigh2d_C_SRCS = neigh2d.c gpu.c |
| 8 | 8 | neigh2d_H_SRCS = gpu.h |
| 9 | 9 | neigh2d_SOURCES = ${neigh2d_C_SRCS} ${neigh2d_H_SRCS} |
| 10 | neigh2d_LDADD = kdtree/libkdtree.la hash/libhash.la simplehash/libsimplehash.la timer/libtimer.la | |
| 10 | neigh2d_LDADD = kdtree/libkdtree.la HashFactory/libHashFactory.la simplehash/libsimplehash.la timer/libtimer.la | |
| 11 | 11 | |
| 12 | 12 | LDADD = -lm |
| 13 | 13 | |
| … | … | @@ -22,8 +22,8 @@ timer/libtimer.la: |
| 22 | 22 | cd timer |
| 23 | 23 | make |
| 24 | 24 | |
| 25 | hash/libhash.la: | |
| 26 | cd hash | |
| 25 | HashFactory/libHashFactory.la: | |
| 26 | cd HashFactory | |
| 27 | 27 | make |
| 28 | 28 | |
| 29 | 29 | simplehash/libsimplehash.la: |
| … | … | @@ -109,8 +109,9 @@ am__objects_1 = neigh2d.$(OBJEXT) gpu.$(OBJEXT) |
| 109 | 109 | am__objects_2 = |
| 110 | 110 | am_neigh2d_OBJECTS = $(am__objects_1) $(am__objects_2) |
| 111 | 111 | neigh2d_OBJECTS = $(am_neigh2d_OBJECTS) |
| 112 | neigh2d_DEPENDENCIES = kdtree/libkdtree.la hash/libhash.la \ | |
| 113 | simplehash/libsimplehash.la timer/libtimer.la | |
| 112 | neigh2d_DEPENDENCIES = kdtree/libkdtree.la \ | |
| 113 | HashFactory/libHashFactory.la simplehash/libsimplehash.la \ | |
| 114 | timer/libtimer.la | |
| 114 | 115 | AM_V_lt = $(am__v_lt_@AM_V@) |
| 115 | 116 | am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) |
| 116 | 117 | am__v_lt_0 = --silent |
| … | … | @@ -360,11 +361,11 @@ top_build_prefix = @top_build_prefix@ |
| 360 | 361 | top_builddir = @top_builddir@ |
| 361 | 362 | top_srcdir = @top_srcdir@ |
| 362 | 363 | ACLOCAL_AMFLAGS = -I m4 |
| 363 | SUBDIRS = kdtree hash simplehash timer | |
| 364 | SUBDIRS = kdtree HashFactory simplehash timer | |
| 364 | 365 | neigh2d_C_SRCS = neigh2d.c gpu.c |
| 365 | 366 | neigh2d_H_SRCS = gpu.h |
| 366 | 367 | neigh2d_SOURCES = ${neigh2d_C_SRCS} ${neigh2d_H_SRCS} |
| 367 | neigh2d_LDADD = kdtree/libkdtree.la hash/libhash.la simplehash/libsimplehash.la timer/libtimer.la | |
| 368 | neigh2d_LDADD = kdtree/libkdtree.la HashFactory/libHashFactory.la simplehash/libsimplehash.la timer/libtimer.la | |
| 368 | 369 | LDADD = -lm |
| 369 | 370 | EXTRA_DIST = neigh2d_kern.cl APACHE_LICENSE-2_0 AUTHORS README LICENSE \ |
| 370 | 371 | Papers.bib NOTICE README.md ReleaseAuthorization.pdf Todo libtool |
| … | … | @@ -929,8 +930,8 @@ timer/libtimer.la: |
| 929 | 930 | cd timer |
| 930 | 931 | make |
| 931 | 932 | |
| 932 | hash/libhash.la: | |
| 933 | cd hash | |
| 933 | HashFactory/libHashFactory.la: | |
| 934 | cd HashFactory | |
| 934 | 935 | make |
| 935 | 936 | |
| 936 | 937 | simplehash/libsimplehash.la: |
| … | … | @@ -16218,10 +16218,10 @@ $as_echo "$as_me: WARNING: to location of include directory and the OpenCL libra |
| 16218 | 16218 | $as_echo "$as_me: WARNING: or build without OpenCL with \"./configure --disable-opencl\"." >&2;} |
| 16219 | 16219 | { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: If you disable opencl" >&5 |
| 16220 | 16220 | $as_echo "$as_me: WARNING: If you disable opencl" >&2;} |
| 16221 | { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: and force the rebuild of hash.c and hash.h \"make hash.c hash.h\"." >&5 | |
| 16222 | $as_echo "$as_me: WARNING: and force the rebuild of hash.c and hash.h \"make hash.c hash.h\"." >&2;} | |
| 16223 | { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: You may need to remove the hash.c and hash.h files if make gets" >&5 | |
| 16224 | $as_echo "$as_me: WARNING: You may need to remove the hash.c and hash.h files if make gets" >&2;} | |
| 16221 | { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: and force the rebuild of HashFactory.c and HashFactory.h \"make HashFactory.c HashFactory.h\"." >&5 | |
| 16222 | $as_echo "$as_me: WARNING: and force the rebuild of HashFactory.c and HashFactory.h \"make HashFactory.c HashFactory.h\"." >&2;} | |
| 16223 | { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: You may need to remove the HashFactory.c and HashFactory.h files if make gets" >&5 | |
| 16224 | $as_echo "$as_me: WARNING: You may need to remove the HashFactory.c and HashFactory.h files if make gets" >&2;} | |
| 16225 | 16225 | { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: confused by timestamps" >&5 |
| 16226 | 16226 | $as_echo "$as_me: WARNING: confused by timestamps" >&2;} |
| 16227 | 16227 | { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: =================================================================" >&5 |
| … | … | @@ -16309,7 +16309,7 @@ ac_config_files="$ac_config_files Makefile" |
| 16309 | 16309 | |
| 16310 | 16310 | ac_config_files="$ac_config_files kdtree/Makefile" |
| 16311 | 16311 | |
| 16312 | ac_config_files="$ac_config_files hash/Makefile" | |
| 16312 | ac_config_files="$ac_config_files HashFactory/Makefile" | |
| 16313 | 16313 | |
| 16314 | 16314 | ac_config_files="$ac_config_files simplehash/Makefile" |
| 16315 | 16315 | |
| … | … | @@ -17356,7 +17356,7 @@ do |
| 17356 | 17356 | "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;; |
| 17357 | 17357 | "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; |
| 17358 | 17358 | "kdtree/Makefile") CONFIG_FILES="$CONFIG_FILES kdtree/Makefile" ;; |
| 17359 | "hash/Makefile") CONFIG_FILES="$CONFIG_FILES hash/Makefile" ;; | |
| 17359 | "HashFactory/Makefile") CONFIG_FILES="$CONFIG_FILES HashFactory/Makefile" ;; | |
| 17360 | 17360 | "simplehash/Makefile") CONFIG_FILES="$CONFIG_FILES simplehash/Makefile" ;; |
| 17361 | 17361 | "timer/Makefile") CONFIG_FILES="$CONFIG_FILES timer/Makefile" ;; |
| 17362 | 17362 |
| … | … | @@ -5,7 +5,7 @@ AC_CONFIG_AUX_DIR(./config) |
| 5 | 5 | AM_INIT_AUTOMAKE([foreign]) |
| 6 | 6 | |
| 7 | 7 | dnl AC_CONFIG_HEADERS([config.h]) |
| 8 | dnl AC_CONFIG_HEADERS([hash/config.h]) | |
| 8 | dnl AC_CONFIG_HEADERS([HashFactory/config.h]) | |
| 9 | 9 | |
| 10 | 10 | dnl |
| 11 | 11 | dnl Caching is usually WRONG for systems with cross-mounted file systems |
| … | … | @@ -314,9 +314,9 @@ if test "${enable_opencl}" != "no"; then |
| 314 | 314 | AC_MSG_WARN(If it fails, try setting OPENCL_INCLUDE and OPENCL_LIBS) |
| 315 | 315 | AC_MSG_WARN(to location of include directory and the OpenCL library) |
| 316 | 316 | AC_MSG_WARN(or build without OpenCL with "./configure --disable-opencl".) |
| 317 | AC_MSG_WARN(If you disable opencl, you may need to go into the hash directory) | |
| 318 | AC_MSG_WARN(and force the rebuild of hash.c and hash.h "make hash.c hash.h".) | |
| 319 | AC_MSG_WARN(You may need to remove the hash.c and hash.h files if make gets) | |
| 317 | AC_MSG_WARN(If you disable opencl, you may need to go into the HashFactory directory) | |
| 318 | AC_MSG_WARN(and force the rebuild of HashFactory.c and HashFactory.h "make HashFactory.c HashFactory.h".) | |
| 319 | AC_MSG_WARN(You may need to remove the HashFactory.c and HashFactory.h files if make gets) | |
| 320 | 320 | AC_MSG_WARN(confused by timestamps) |
| 321 | 321 | AC_MSG_WARN(=================================================================) |
| 322 | 322 | fi |
| … | … | @@ -375,7 +375,7 @@ AC_SUBST(CPREPROCESSOR) |
| 375 | 375 | |
| 376 | 376 | AC_CONFIG_FILES([Makefile]) |
| 377 | 377 | AC_CONFIG_FILES([kdtree/Makefile]) |
| 378 | AC_CONFIG_FILES([hash/Makefile]) | |
| 378 | AC_CONFIG_FILES([HashFactory/Makefile]) | |
| 379 | 379 | AC_CONFIG_FILES([simplehash/Makefile]) |
| 380 | 380 | AC_CONFIG_FILES([timer/Makefile]) |
| 381 | 381 |
| … | … | @@ -1,465 +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 | /** | |
| 34 | * @file CLHash_Utilities.c | |
| 35 | * @author Ahrens/Robey -- rewritten for distribution | |
| 36 | * @date Sun Aug 4 2013 | |
| 37 | */ | |
| 38 | ||
| 39 | #include <execinfo.h> | |
| 40 | #include <stdio.h> | |
| 41 | #include <string.h> | |
| 42 | #include <stdlib.h> | |
| 43 | #include "CLHash_Utilities.h" | |
| 44 | ||
| 45 | //#ifdef HAVE_CONFIG_H | |
| 46 | //#include "config.h" | |
| 47 | //#endif | |
| 48 | ||
| 49 | #ifdef HAVE_OPENCL | |
| 50 | #ifdef __APPLE_CC__ | |
| 51 | #include <OpenCL/OpenCL.h> | |
| 52 | #else | |
| 53 | #include <CL/cl.h> | |
| 54 | #endif | |
| 55 | ||
| 56 | #else | |
| 57 | int clGetPlatformIDs(uint nentries, int *platforms, uint *nplatforms) { return 0; } | |
| 58 | int clGetDeviceIDs(int platform, int device_type, uint nentries, int *devices, uint *ndevices) { return 0; } | |
| 59 | int clGetPlatformInfo(int platform, int param_name, size_t size, void *value, size_t *size_ret) { return 0; } | |
| 60 | int clGetDeviceInfo(int device, int param_name, size_t size, void *value, size_t *size_ret) { return 0; } | |
| 61 | int clCreateContext(int *properties, uint ndevices, const int *devices, void *notify, void *user_data, int *errcode_ret) { return 0; } | |
| 62 | int clCreateCommandQueue(int context, int device, int properties, int *errcode_ret) { return 0; } | |
| 63 | int clCreateProgramWithSource(int context, uint count, const char **strings, const size_t *lengths, int *errcode_ret) { return 0; } | |
| 64 | int clBuildProgram(int program, uint ndevices, const int *device_list, const char *options, void *notify, void *user_data) { return 0; } | |
| 65 | int clGetProgramBuildInfo(int program, int devices, int param_name, size_t size, void *value, size_t *size_ret) { return 0; } | |
| 66 | ||
| 67 | #define CL_SUCCESS 0 | |
| 68 | #define CL_PROGRAM_LOG 0 | |
| 69 | #define CL_PROGRAM_BUILD_LOG 0 | |
| 70 | #define CL_DEVICE_TYPE_GPU 0 | |
| 71 | #define CL_DEVICE_TYPE_CPU 0 | |
| 72 | #define CL_DEVICE_TYPE_ACCELERATOR 0 | |
| 73 | #define CL_DEVICE_NAME 0 | |
| 74 | #define CL_DEVICE_VENDOR 0 | |
| 75 | #define CL_PLATFORM_NAME 0 | |
| 76 | #define CL_PLATFORM_VENDOR 0 | |
| 77 | #define CL_PLATFORM_VERSION 0 | |
| 78 | #define CL_QUEUE_PROFILING_ENABLE 0 | |
| 79 | ||
| 80 | #define CL_DEVICE_NOT_FOUND -1 | |
| 81 | #define CL_DEVICE_NOT_AVAILABLE -2 | |
| 82 | #define CL_COMPILER_NOT_AVAILABLE -3 | |
| 83 | #define CL_MEM_OBJECT_ALLOCATION_FAILURE -4 | |
| 84 | #define CL_OUT_OF_RESOURCES -5 | |
| 85 | #define CL_OUT_OF_HOST_MEMORY -6 | |
| 86 | #define CL_PROFILING_INFO_NOT_AVAILABLE -7 | |
| 87 | #define CL_MEM_COPY_OVERLAP -8 | |
| 88 | #define CL_IMAGE_FORMAT_MISMATCH -9 | |
| 89 | #define CL_IMAGE_FORMAT_NOT_SUPPORTED -10 | |
| 90 | #define CL_BUILD_PROGRAM_FAILURE -11 | |
| 91 | #define CL_MAP_FAILURE -12 | |
| 92 | #define CL_INVALID_VALUE -30 | |
| 93 | #define CL_INVALID_DEVICE_TYPE -31 | |
| 94 | #define CL_INVALID_PLATFORM -32 | |
| 95 | #define CL_INVALID_DEVICE -33 | |
| 96 | #define CL_INVALID_CONTEXT -34 | |
| 97 | #define CL_INVALID_QUEUE_PROPERTIES -35 | |
| 98 | #define CL_INVALID_COMMAND_QUEUE -36 | |
| 99 | #define CL_INVALID_HOST_PTR -37 | |
| 100 | #define CL_INVALID_MEM_OBJECT -38 | |
| 101 | #define CL_INVALID_IMAGE_FORMAT_DESCRIPTOR -39 | |
| 102 | #define CL_INVALID_IMAGE_SIZE -40 | |
| 103 | #define CL_INVALID_SAMPLER -41 | |
| 104 | #define CL_INVALID_BINARY -42 | |
| 105 | #define CL_INVALID_BUILD_OPTIONS -43 | |
| 106 | #define CL_INVALID_PROGRAM -44 | |
| 107 | #define CL_INVALID_PROGRAM_EXECUTABLE -45 | |
| 108 | #define CL_INVALID_KERNEL_NAME -46 | |
| 109 | #define CL_INVALID_KERNEL_DEFINITION -47 | |
| 110 | #define CL_INVALID_KERNEL -48 | |
| 111 | #define CL_INVALID_ARG_INDEX -49 | |
| 112 | #define CL_INVALID_ARG_VALUE -50 | |
| 113 | #define CL_INVALID_ARG_SIZE -51 | |
| 114 | #define CL_INVALID_KERNEL_ARGS -52 | |
| 115 | #define CL_INVALID_WORK_DIMENSION -53 | |
| 116 | #define CL_INVALID_WORK_GROUP_SIZE -54 | |
| 117 | #define CL_INVALID_WORK_ITEM_SIZE -55 | |
| 118 | #define CL_INVALID_GLOBAL_OFFSET -56 | |
| 119 | #define CL_INVALID_EVENT_WAIT_LIST -57 | |
| 120 | #define CL_INVALID_EVENT -58 | |
| 121 | #define CL_INVALID_OPERATION -59 | |
| 122 | #define CL_INVALID_GL_OBJECT -60 | |
| 123 | #define CL_INVALID_BUFFER_SIZE -61 | |
| 124 | #define CL_INVALID_MIP_LEVEL -62 | |
| 125 | #endif | |
| 126 | ||
| 127 | #ifndef DEBUG | |
| 128 | #define DEBUG 0 | |
| 129 | #endif | |
| 130 | ||
| 131 | typedef unsigned int uint; | |
| 132 | ||
| 133 | char *program_name = NULL; | |
| 134 | ||
| 135 | void CLHash_Init(const char *program_name_in) | |
| 136 | { | |
| 137 | program_name = strdup(program_name_in); | |
| 138 | } | |
| 139 | ||
| 140 | /* Find a GPU or CPU associated with the first available platform */ | |
| 141 | void CLHash_Utilities_CreateContext_p(cl_context *context, cl_command_queue *command_queue, const char *file , int line) { | |
| 142 | ||
| 143 | uint num_platforms; | |
| 144 | cl_platform_id *platforms; | |
| 145 | cl_device_id device; | |
| 146 | int err; | |
| 147 | ||
| 148 | /* Get all available platforms */ | |
| 149 | err = clGetPlatformIDs(0, NULL, &num_platforms); | |
| 150 | CLHash_Utilities_HandleError(err, "CLHash_Utilities_CreateContext", "clGetPlatformIDs"); | |
| 151 | platforms = (cl_platform_id *)malloc(num_platforms*sizeof(cl_platform_id)); | |
| 152 | /* Identify a platform */ | |
| 153 | err = clGetPlatformIDs(num_platforms, platforms, NULL); | |
| 154 | CLHash_Utilities_HandleError(err, "CLHash_Utilities_CreateContext", "clGetPlatformIDs"); | |
| 155 | ||
| 156 | if (DEBUG == 1) { | |
| 157 | char info[1024]; | |
| 158 | for (int iplatform=0; iplatform<num_platforms; iplatform++){ | |
| 159 | printf(" Platform %d:\n",iplatform+1); | |
| 160 | ||
| 161 | //clGetPlatformInfo(platforms[iplatform],CL_PLATFORM_PROFILE, 1024L,info,0); | |
| 162 | //printf(" CL_PLATFORM_PROFILE : %s\n",info); | |
| 163 | ||
| 164 | clGetPlatformInfo(platforms[iplatform],CL_PLATFORM_VERSION, 1024L,info,0); | |
| 165 | printf(" CL_PLATFORM_VERSION : %s\n",info); | |
| 166 | ||
| 167 | clGetPlatformInfo(platforms[iplatform],CL_PLATFORM_NAME, 1024L,info,0); | |
| 168 | printf(" CL_PLATFORM_NAME : %s\n",info); | |
| 169 | ||
| 170 | clGetPlatformInfo(platforms[iplatform],CL_PLATFORM_VENDOR, 1024L,info,0); | |
| 171 | printf(" CL_PLATFORM_VENDOR : %s\n",info); | |
| 172 | ||
| 173 | //clGetPlatformInfo(platforms[iplatform],CL_PLATFORM_EXTENSIONS,1024L,info,0); | |
| 174 | // printf(" CL_PLATFORM_EXTENSIONS : %s\n",info); | |
| 175 | } | |
| 176 | } | |
| 177 | ||
| 178 | /* Access a device */ | |
| 179 | for (int iplatform=0; iplatform<num_platforms; iplatform++){ | |
| 180 | err = clGetDeviceIDs(platforms[iplatform], CL_DEVICE_TYPE_GPU, 1, &device, NULL); | |
| 181 | if(err != CL_DEVICE_NOT_FOUND){ | |
| 182 | break; | |
| 183 | } | |
| 184 | } | |
| 185 | if(err == CL_DEVICE_NOT_FOUND){ | |
| 186 | for (int iplatform=0; iplatform<num_platforms; iplatform++){ | |
| 187 | err = clGetDeviceIDs(platforms[iplatform], CL_DEVICE_TYPE_ACCELERATOR, 1, &device, NULL); | |
| 188 | if(err != CL_DEVICE_NOT_FOUND){ | |
| 189 | break; | |
| 190 | } | |
| 191 | } | |
| 192 | if(err == CL_DEVICE_NOT_FOUND){ | |
| 193 | for (int iplatform=0; iplatform<num_platforms; iplatform++){ | |
| 194 | err = clGetDeviceIDs(platforms[iplatform], CL_DEVICE_TYPE_CPU, 1, &device, NULL); | |
| 195 | if(err != CL_DEVICE_NOT_FOUND){ | |
| 196 | break; | |
| 197 | } | |
| 198 | } | |
| 199 | } | |
| 200 | } | |
| 201 | CLHash_Utilities_HandleError(err, "CLHash_Utilities_CreateContext", "clGetDeviceIDs"); | |
| 202 | ||
| 203 | if (DEBUG == 1) { | |
| 204 | char info[1024]; | |
| 205 | ||
| 206 | printf("\n\n"); | |
| 207 | printf(" Device:\n"); | |
| 208 | clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(info), info, NULL); | |
| 209 | printf(" CL_DEVICE_NAME : %s\n",info); | |
| 210 | ||
| 211 | clGetDeviceInfo(device, CL_DEVICE_VENDOR, sizeof(info), info, NULL); | |
| 212 | printf(" CL_DEVICE_VENDOR : %s\n",info); | |
| 213 | } | |
| 214 | ||
| 215 | *context = clCreateContext(NULL, 1, &device, NULL, NULL, &err); | |
| 216 | if(err != CL_SUCCESS) CLHash_Utilities_PrintError_p(err, "CLHash_Utilities_CreateContext", "clCreateContext", file, line); | |
| 217 | ||
| 218 | *command_queue = clCreateCommandQueue(*context, device, CL_QUEUE_PROFILING_ENABLE, &err); | |
| 219 | if(err != CL_SUCCESS) CLHash_Utilities_PrintError_p(err, "CLHash_Utilities_CreateContext", "clCreateCommandQueue", file, line); | |
| 220 | ||
| 221 | free(platforms); | |
| 222 | } | |
| 223 | ||
| 224 | cl_program CLHash_Utilities_BuildProgramString_p(cl_context ctx, cl_device_id device, const char *programString, const char *file , int line){ | |
| 225 | /* Create program from string */ | |
| 226 | cl_int err; | |
| 227 | size_t program_size, nReportSize; | |
| 228 | program_size = strlen(programString); | |
| 229 | cl_program program = clCreateProgramWithSource(ctx, 1, (const char **)&programString, &program_size, &err); | |
| 230 | if(err != CL_SUCCESS) CLHash_Utilities_PrintError(err, "CLHash_Utilities_CreateDevice", "clCreateProgram"); | |
| 231 | ||
| 232 | /* Build program */ | |
| 233 | char *BuildReport; | |
| 234 | err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL); | |
| 235 | if(err != CL_SUCCESS) { | |
| 236 | /* Find size of log and print to std output */ | |
| 237 | clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, 0, NULL, &nReportSize); | |
| 238 | ||
| 239 | if (err != CL_SUCCESS) { | |
| 240 | switch (err){ | |
| 241 | case CL_INVALID_DEVICE: | |
| 242 | printf("Invalid device in clProgramBuildInfo\n"); | |
| 243 | break; | |
| 244 | case CL_INVALID_VALUE: | |
| 245 | printf("Invalid value in clProgramBuildInfo\n"); | |
| 246 | break; | |
| 247 | case CL_INVALID_PROGRAM: | |
| 248 | printf("Invalid program in clProgramBuildInfo\n"); | |
| 249 | break; | |
| 250 | } | |
| 251 | } | |
| 252 | ||
| 253 | BuildReport = (char*) malloc(nReportSize + 1); | |
| 254 | BuildReport[nReportSize] = '\0'; | |
| 255 | clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, nReportSize + 1, BuildReport, NULL); | |
| 256 | printf("%s\n", BuildReport); | |
| 257 | free(BuildReport); | |
| 258 | exit(1); | |
| 259 | } | |
| 260 | ||
| 261 | return program; | |
| 262 | } | |
| 263 | ||
| 264 | /* Create program from a file and compile it */ | |
| 265 | cl_program CLHash_Utilities_BuildProgramFile_p(cl_context ctx, cl_device_id device, const char* fileName, const char *file , int line) { | |
| 266 | ||
| 267 | cl_program program; | |
| 268 | FILE *program_handle; | |
| 269 | char *program_buffer; | |
| 270 | size_t program_size; | |
| 271 | int err; | |
| 272 | ||
| 273 | /* Read program file and place content into buffer */ | |
| 274 | program_handle = fopen(fileName, "r"); | |
| 275 | if(program_handle == NULL) { | |
| 276 | perror("Couldn't find the program file"); | |
| 277 | exit(1); | |
| 278 | } | |
| 279 | fseek(program_handle, 0, SEEK_END); | |
| 280 | program_size = ftell(program_handle); | |
| 281 | rewind(program_handle); | |
| 282 | program_buffer = (char*)malloc(program_size + 1); | |
| 283 | program_buffer[program_size] = '\0'; | |
| 284 | fread(program_buffer, sizeof(char), program_size, program_handle); | |
| 285 | fclose(program_handle); | |
| 286 | program = CLHash_Utilities_BuildProgramString(ctx, device, program_buffer); | |
| 287 | free(program_buffer); | |
| 288 | return program; | |
| 289 | } | |
| 290 | ||
| 291 | void CLHash_Utilities_PrintError_p(cl_int err, const char *routine, const char *cl_routine, const char *file, int line){ | |
| 292 | switch(err){ | |
| 293 | case CL_DEVICE_NOT_FOUND: //#define CL_DEVICE_NOT_FOUND -1 | |
| 294 | printf("\nERROR: %s -- Device not found in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 295 | break; | |
| 296 | case CL_DEVICE_NOT_AVAILABLE: //#define CL_DEVICE_NOT_AVAILABLE -2 | |
| 297 | printf("\nERROR: %s -- Device not available in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 298 | break; | |
| 299 | case CL_COMPILER_NOT_AVAILABLE: //#define CL_COMPILER_NOT_AVAILABLE -3 | |
| 300 | printf("\nERROR: %s -- CL compiler not available failure in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 301 | break; | |
| 302 | case CL_MEM_OBJECT_ALLOCATION_FAILURE: //#define CL_MEM_OBJECT_ALLOCATION_FAILURE -4 | |
| 303 | printf("\nERROR: %s -- Mem object allocation failure in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 304 | break; | |
| 305 | case CL_OUT_OF_RESOURCES: //#define CL_OUT_OF_RESOURCES -5 | |
| 306 | printf("\nERROR: %s -- Out of resources in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 307 | break; | |
| 308 | case CL_OUT_OF_HOST_MEMORY: //#define CL_OUT_OF_HOST_MEMORY -6 | |
| 309 | printf("\nERROR: %s -- Out of host memory in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 310 | break; | |
| 311 | case CL_PROFILING_INFO_NOT_AVAILABLE: //#define CL_PROFILING_INFO_NOT_AVAILABLE -7 | |
| 312 | printf("\nERROR: %s -- Profiling info not available in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 313 | break; | |
| 314 | case CL_MEM_COPY_OVERLAP: //#define CL_MEM_COPY_OVERLAP -8 | |
| 315 | printf("\nERROR: %s -- Mem copy overlap in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 316 | break; | |
| 317 | case CL_IMAGE_FORMAT_MISMATCH: //#define CL_IMAGE_FORMAT_MISMATCH -9 | |
| 318 | printf("\nERROR: %s -- Image format mismatch in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 319 | break; | |
| 320 | case CL_IMAGE_FORMAT_NOT_SUPPORTED: //#define CL_IMAGE_FORMAT_NOT_SUPPORTED -10 | |
| 321 | printf("\nERROR: %s -- Image format not supported in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 322 | break; | |
| 323 | case CL_BUILD_PROGRAM_FAILURE: //#define CL_BUILD_PROGRAM_FAILURE -11 | |
| 324 | printf("\nERROR: %s -- Build program failure in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 325 | break; | |
| 326 | case CL_MAP_FAILURE: //#define CL_MAP_FAILURE -12 | |
| 327 | printf("\nERROR: %s -- Map failure in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 328 | break; | |
| 329 | case CL_INVALID_VALUE: //#define CL_INVALID_VALUE -30 | |
| 330 | printf("\nERROR: %s -- Invalid value in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 331 | break; | |
| 332 | case CL_INVALID_DEVICE_TYPE: //#define CL_INVALID_DEVICE_TYPE -31 | |
| 333 | printf("\nERROR: %s -- Invalid device type in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 334 | break; | |
| 335 | case CL_INVALID_PLATFORM: //#define CL_INVALID_PLATFORM -32 | |
| 336 | printf("\nERROR: %s -- Invalid platform in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 337 | break; | |
| 338 | case CL_INVALID_DEVICE: //#define CL_INVALID_DEVICE -33 | |
| 339 | printf("\nERROR: %s -- Invalid device in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 340 | break; | |
| 341 | case CL_INVALID_CONTEXT: //#define CL_INVALID_CONTEXT -34 | |
| 342 | printf("\nERROR: %s -- Invalid context in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 343 | break; | |
| 344 | case CL_INVALID_QUEUE_PROPERTIES: //#define CL_INVALID_QUEUE_PROPERTIES -35 | |
| 345 | printf("\nERROR: %s -- Invalid queue properties in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 346 | break; | |
| 347 | case CL_INVALID_COMMAND_QUEUE: //#define CL_INVALID_COMMAND_QUEUE -36 | |
| 348 | printf("\nERROR: %s -- Invalid command queue in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 349 | break; | |
| 350 | case CL_INVALID_HOST_PTR: //#define CL_INVALID_HOST_PTR -37 | |
| 351 | printf("\nERROR: %s -- Invalid host pointer in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 352 | break; | |
| 353 | case CL_INVALID_MEM_OBJECT: //#define CL_INVALID_MEM_OBJECT -38 | |
| 354 | printf("\nERROR: %s -- Invalid memory object in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 355 | break; | |
| 356 | case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: //#define CL_INVALID_IMAGE_FORMAT_DESCRIPTOR -39 | |
| 357 | printf("\nERROR: %s -- Invalid image format descriptor in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 358 | break; | |
| 359 | case CL_INVALID_IMAGE_SIZE: //#define CL_INVALID_IMAGE_SIZE -40 | |
| 360 | printf("\nERROR: %s -- Invalid image size in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 361 | break; | |
| 362 | case CL_INVALID_SAMPLER: //#define CL_INVALID_SAMPLER -41 | |
| 363 | printf("\nERROR: %s -- Invalid sampler in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 364 | break; | |
| 365 | case CL_INVALID_BINARY: //#define CL_INVALID_BINARY -42 | |
| 366 | printf("\nERROR: %s -- Invalid binary in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 367 | break; | |
| 368 | case CL_INVALID_BUILD_OPTIONS: //#define CL_INVALID_BUILD_OPTIONS -43 | |
| 369 | printf("\nERROR: %s -- Invalid build options in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 370 | break; | |
| 371 | case CL_INVALID_PROGRAM: //#define CL_INVALID_PROGRAM -44 | |
| 372 | printf("\nERROR: %s -- Invalid program in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 373 | break; | |
| 374 | case CL_INVALID_PROGRAM_EXECUTABLE: //#define CL_INVALID_PROGRAM_EXECUTABLE -45 | |
| 375 | printf("\nERROR: %s -- Invalid program executable in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 376 | break; | |
| 377 | case CL_INVALID_KERNEL_NAME: //#define CL_INVALID_KERNEL_NAME -46 | |
| 378 | printf("\nERROR: %s -- Invalid kernel name in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 379 | break; | |
| 380 | case CL_INVALID_KERNEL_DEFINITION: //#define CL_INVALID_KERNEL_DEFINITION -47 | |
| 381 | printf("\nERROR: %s -- Invalid kernel definition in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 382 | break; | |
| 383 | case CL_INVALID_KERNEL: //#define CL_INVALID_KERNEL -48 | |
| 384 | printf("\nERROR: %s -- Invalid kernel in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 385 | break; | |
| 386 | case CL_INVALID_ARG_INDEX: //#define CL_INVALID_ARG_INDEX -49 | |
| 387 | printf("\nERROR: %s -- Invalid arg index in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 388 | break; | |
| 389 | case CL_INVALID_ARG_VALUE: //#define CL_INVALID_ARG_VALUE -50 | |
| 390 | printf("\nERROR: %s -- Invalid arg value in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 391 | break; | |
| 392 | case CL_INVALID_ARG_SIZE: //#define CL_INVALID_ARG_SIZE -51 | |
| 393 | printf("\nERROR: %s -- Invalid arg size in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 394 | break; | |
| 395 | case CL_INVALID_KERNEL_ARGS: //#define CL_INVALID_KERNEL_ARGS -52 | |
| 396 | printf("\nERROR: %s -- Invalid kernel args in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 397 | break; | |
| 398 | case CL_INVALID_WORK_DIMENSION: //#define CL_INVALID_WORK_DIMENSION -53 | |
| 399 | printf("\nERROR: %s -- Invalid work dimension in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 400 | break; | |
| 401 | case CL_INVALID_WORK_GROUP_SIZE: //#define CL_INVALID_WORK_GROUP_SIZE -54 | |
| 402 | printf("\nERROR: %s -- Invalid work group size in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 403 | break; | |
| 404 | case CL_INVALID_WORK_ITEM_SIZE: //#define CL_INVALID_WORK_ITEM_SIZE -55 | |
| 405 | printf("\nERROR: %s -- Invalid work item size in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 406 | break; | |
| 407 | case CL_INVALID_GLOBAL_OFFSET: //#define CL_INVALID_GLOBAL_OFFSET -56 | |
| 408 | printf("\nERROR: %s -- Invalid global offset in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 409 | break; | |
| 410 | case CL_INVALID_EVENT_WAIT_LIST: //#define CL_INVALID_EVENT_WAIT_LIST -57 | |
| 411 | printf("\nERROR: %s -- Invalid event wait list in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 412 | break; | |
| 413 | case CL_INVALID_EVENT: //#define CL_INVALID_EVENT -58 | |
| 414 | printf("\nERROR: %s -- Invalid event in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 415 | break; | |
| 416 | case CL_INVALID_OPERATION: //#define CL_INVALID_OPERATION -59 | |
| 417 | printf("\nERROR: %s -- Invalid operation in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 418 | break; | |
| 419 | case CL_INVALID_GL_OBJECT: //#define CL_INVALID_GL_OBJECT -60 | |
| 420 | printf("\nERROR: %s -- Invalid GL object in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 421 | break; | |
| 422 | case CL_INVALID_BUFFER_SIZE: //#define CL_INVALID_BUFFER_SIZE -61 | |
| 423 | printf("\nERROR: %s -- Invalid buffer size in %s at line %d in file %s\n", routine, cl_routine, line, file); | |
| 424 | break; | |
| 425 | case CL_INVALID_MIP_LEVEL: //#define CL_INVALID_MIP_LEVEL -62 | |
| 426 | break; | |
| 427 | ||
| 428 | default: | |
| 429 | printf("\nERROR: %s -- %d in %s at line %d in file %s\n", routine, err, cl_routine, line, file); | |
| 430 | break; | |
| 431 | } | |
| 432 | void* callstack[128]; | |
| 433 | int frames = backtrace(callstack, 128); | |
| 434 | if (frames > 2) { | |
| 435 | #ifdef HAVE_ADDR2LINE | |
| 436 | char hex_address[21]; | |
| 437 | char command_string[80]; | |
| 438 | #endif | |
| 439 | char** strs = backtrace_symbols(callstack, frames); | |
| 440 | fprintf(stderr,"\n =============== Backtrace ===============\n"); | |
| 441 | for (int i = 1; i < frames-1; ++i) { | |
| 442 | fprintf(stderr," %s \t", strs[i]); | |
| 443 | #ifdef HAVE_ADDR2LINE | |
| 444 | if (program_name != NULL) { | |
| 445 | sscanf(strs[i],"%*s [%[^]]s]",hex_address); | |
| 446 | //printf("DEBUG addr2line -e clamr -f -s -i -p %s\n",hex_address); | |
| 447 | //sprintf(command_string,"addr2line -e %s -f -s -i %s | sed -e \'1,1s\?\\n\?\?' \n",program_name,hex_address); | |
| 448 | sprintf(command_string,"addr2line -e %s -f -s -i %s",program_name,hex_address); | |
| 449 | //printf("%s",command_string); | |
| 450 | system(command_string); | |
| 451 | } | |
| 452 | // on mac, need to install binutils using macports "port install binutils" | |
| 453 | #endif | |
| 454 | fprintf(stderr,"\n"); | |
| 455 | } | |
| 456 | fprintf(stderr," =============== Backtrace ===============\n\n"); | |
| 457 | free(strs); | |
| 458 | } | |
| 459 | exit(-1); | |
| 460 | } | |
| 461 | ||
| 462 | const char* CLHash_Utilities_HandleError_p(cl_int err, const char *routine, const char *cl_routine, const char *file, int line){ | |
| 463 | if(err != CL_SUCCESS) CLHash_Utilities_PrintError_p(err, routine, cl_routine, file, line); | |
| 464 | return(NULL); | |
| 465 | } |
| … | … | @@ -1,92 +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 | /** | |
| 34 | * @file CLHash_Utilities.h | |
| 35 | * @author Ahrens/Robey -- rewritten for distribution | |
| 36 | * @date Sun Aug 4 2013 | |
| 37 | */ | |
| 38 | #ifndef CLHASH_UTILITIES_H | |
| 39 | #define CLHASH_UTILITIES_H | |
| 40 | ||
| 41 | #ifdef HAVE_OPENCL | |
| 42 | #ifdef __APPLE_CC__ | |
| 43 | #include <OpenCL/OpenCL.h> | |
| 44 | #else | |
| 45 | #include <CL/cl.h> | |
| 46 | #endif | |
| 47 | #else | |
| 48 | typedef int cl_int; | |
| 49 | typedef int cl_context; | |
| 50 | typedef int cl_program; | |
| 51 | typedef int cl_command_queue; | |
| 52 | typedef int cl_device_id; | |
| 53 | typedef int cl_platform_id; | |
| 54 | ||
| 55 | int clGetPlatformIDs(uint nentries, int *platforms, uint *nplatforms); | |
| 56 | int clGetDeviceIDs(int platform, int device_type, uint nentries, int *devices, uint *ndevices); | |
| 57 | int clGetPlatformInfo(int platform, int param_name, size_t size, void *value, size_t *size_ret); | |
| 58 | int clGetDeviceInfo(int device, int param_name, size_t size, void *value, size_t *size_ret); | |
| 59 | int clCreateContext(int *properties, uint ndevices, const int *devices, void *notify, void *user_data, int *errcode_ret); | |
| 60 | int clCreateCommandQueue(int context, int device, int properties, int *errcode_ret); | |
| 61 | int clCreateProgramWithSource(int context, uint count, const char **strings, const size_t *lengths, int *errcode_ret); | |
| 62 | int clBuildProgram(int program, uint ndevices, const int *device_list, const char *options, void *notify, void *user_data); | |
| 63 | int clGetProgramBuildInfo(int program, int devices, int param_name, size_t size, void *value, size_t *size_ret); | |
| 64 | #endif | |
| 65 | ||
| 66 | #define CLHash_Utilities_CreateContext( context, command_queue) \ | |
| 67 | ( CLHash_Utilities_CreateContext_p( context, command_queue, __FILE__, __LINE__) ) | |
| 68 | #define CLHash_Utilities_BuildProgramString( context, device, programString) \ | |
| 69 | ( CLHash_Utilities_BuildProgramString_p( context, device, programString, __FILE__, __LINE__) ) | |
| 70 | #define CLHash_Utilities_BuildProgramFile( context, device, fileName) \ | |
| 71 | ( CLHash_Utilities_BuildProgramFile_p( context, device, fileName, __FILE__, __LINE__) ) | |
| 72 | ||
| 73 | #define CLHash_Utilities_HandleError( ierr, routine, cl_routine) \ | |
| 74 | ( CLHash_Utilities_HandleError_p( ierr, routine, cl_routine, __FILE__, __LINE__) ) | |
| 75 | #define CLHash_Utilities_PrintError( ierr, routine, cl_routine) \ | |
| 76 | ( CLHash_Utilities_PrintError_p( ierr, routine, cl_routine, __FILE__, __LINE__) ) | |
| 77 | ||
| 78 | /* Initialize Hash lib with program name for error reporting */ | |
| 79 | void CLHash_Init(const char *program_name_in); | |
| 80 | ||
| 81 | /* Hardware detection */ | |
| 82 | void CLHash_Utilities_CreateContext_p(cl_context *context, cl_command_queue *command_queue, const char *file, int line); | |
| 83 | ||
| 84 | /* Build Programs */ | |
| 85 | cl_program CLHash_Utilities_BuildProgramString_p(cl_context contex, cl_device_id device, const char *programString, const char *file, int line); | |
| 86 | cl_program CLHash_Utilities_BuildProgramFile_p(cl_context contex, cl_device_id device, const char* fileName, const char *file, int line); | |
| 87 | ||
| 88 | /* Error Handling */ | |
| 89 | const char* CLHash_Utilities_HandleError_p(cl_int err, const char *routine, const char *cl_routine, const char *file, int line); | |
| 90 | void CLHash_Utilities_PrintError_p(cl_int err, const char *routine, const char *cl_routine, const char *file, int line); | |
| 91 | ||
| 92 | #endif |
| … | … | @@ -1,35 +0,0 @@ |
| 1 | default: hash.c CLHash_Utilities.c hash.cl libhash.la | |
| 2 | all: hash.c CLHash_Utilities.c hash.cl libhash.la | |
| 3 | test: hashTest | |
| 4 | ||
| 5 | AM_MAKEFLAGS = -j 4 | |
| 6 | ||
| 7 | DEFAULT_INCLUDES=-I. -I.. | |
| 8 | ||
| 9 | lib_LTLIBRARIES = libhash.la | |
| 10 | include_HEADERS = hash.h | |
| 11 | bin_PROGRAMS = hashTest | |
| 12 | ||
| 13 | hashTest_CPPFLAGS = -DHAVE_OPENCL -DHAVE_CL_DOUBLE -I$(OPENCL_INCLUDE) | |
| 14 | ||
| 15 | H_SRCS = hash.h CLHash_Utilities.h | |
| 16 | ||
| 17 | C_SRCS = hash.c CLHash_Utilities.c | |
| 18 | ||
| 19 | libhash_la_SOURCES = ${C_SRCS} ${H_SRCS} | |
| 20 | hashTest_SOURCES = testHelper.c hashTest.c | |
| 21 | hashTest_LDADD = libhash.la | |
| 22 | ||
| 23 | hash.h: hash.hp hash.hm perfectHash.hm compactHash.hm | |
| 24 | ${CPREPROCESSOR} -CC -x c -imacros hash.hm hash.hp | ${INDENT} -linux -brf -o hash.h | |
| 25 | ||
| 26 | hash.c: hash.cp hash.cm hash.cl perfectHash.cm compactHash.cm | |
| 27 | ${CPREPROCESSOR} -CC -x c -imacros hash.cm hash.cp | ${INDENT} -linux -brf -o hash.c | |
| 28 | ./embed_source.pl hash.cl >> hash.c | |
| 29 | ||
| 30 | hash.cl: hash.clp hash.cm perfectHash.cm compactHash.cm | |
| 31 | ${CPREPROCESSOR} -CC -x c -imacros hash.cm hash.clp | ${INDENT} -linux -brf -o hash.cl | |
| 32 | ||
| 33 | EXTRA_DIST = perfectHash.cm perfectHash.hm primetest.c testHelper.h hash.hp \ | |
| 34 | hash.hm hash.cp hash.cm hash.h hash.c hash.cl hash.clp embed_source.pl \ | |
| 35 | compactHash.cm compactHash.hm baseHash.cm baseHash.hm |
| … | … | @@ -1,781 +0,0 @@ |
| 1 | # Makefile.in generated by automake 1.13.4 from Makefile.am. | |
| 2 | # @configure_input@ | |
| 3 | ||
| 4 | # Copyright (C) 1994-2013 Free Software Foundation, Inc. | |
| 5 | ||
| 6 | # This Makefile.in is free software; the Free Software Foundation | |
| 7 | # gives unlimited permission to copy and/or distribute it, | |
| 8 | # with or without modifications, as long as this notice is preserved. | |
| 9 | ||
| 10 | # This program is distributed in the hope that it will be useful, | |
| 11 | # but WITHOUT ANY WARRANTY, to the extent permitted by law; without | |
| 12 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A | |
| 13 | # PARTICULAR PURPOSE. | |
| 14 | ||
| 15 | @SET_MAKE@ | |
| 16 | ||
| 17 | ||
| 18 | ||
| 19 | VPATH = @srcdir@ | |
| 20 | am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' | |
| 21 | am__make_running_with_option = \ | |
| 22 | case $${target_option-} in \ | |
| 23 | ?) ;; \ | |
| 24 | *) echo "am__make_running_with_option: internal error: invalid" \ | |
| 25 | "target option '$${target_option-}' specified" >&2; \ | |
| 26 | exit 1;; \ | |
| 27 | esac; \ | |
| 28 | has_opt=no; \ | |
| 29 | sane_makeflags=$$MAKEFLAGS; \ | |
| 30 | if $(am__is_gnu_make); then \ | |
| 31 | sane_makeflags=$$MFLAGS; \ | |
| 32 | else \ | |
| 33 | case $$MAKEFLAGS in \ | |
| 34 | *\\[\ \ ]*) \ | |
| 35 | bs=\\; \ | |
| 36 | sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ | |
| 37 | | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ | |
| 38 | esac; \ | |
| 39 | fi; \ | |
| 40 | skip_next=no; \ | |
| 41 | strip_trailopt () \ | |
| 42 | { \ | |
| 43 | flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ | |
| 44 | }; \ | |
| 45 | for flg in $$sane_makeflags; do \ | |
| 46 | test $$skip_next = yes && { skip_next=no; continue; }; \ | |
| 47 | case $$flg in \ | |
| 48 | *=*|--*) continue;; \ | |
| 49 | -*I) strip_trailopt 'I'; skip_next=yes;; \ | |
| 50 | -*I?*) strip_trailopt 'I';; \ | |
| 51 | -*O) strip_trailopt 'O'; skip_next=yes;; \ | |
| 52 | -*O?*) strip_trailopt 'O';; \ | |
| 53 | -*l) strip_trailopt 'l'; skip_next=yes;; \ | |
| 54 | -*l?*) strip_trailopt 'l';; \ | |
| 55 | -[dEDm]) skip_next=yes;; \ | |
| 56 | -[JT]) skip_next=yes;; \ | |
| 57 | esac; \ | |
| 58 | case $$flg in \ | |
| 59 | *$$target_option*) has_opt=yes; break;; \ | |
| 60 | esac; \ | |
| 61 | done; \ | |
| 62 | test $$has_opt = yes | |
| 63 | am__make_dryrun = (target_option=n; $(am__make_running_with_option)) | |
| 64 | am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) | |
| 65 | pkgdatadir = $(datadir)/@PACKAGE@ | |
| 66 | pkgincludedir = $(includedir)/@PACKAGE@ | |
| 67 | pkglibdir = $(libdir)/@PACKAGE@ | |
| 68 | pkglibexecdir = $(libexecdir)/@PACKAGE@ | |
| 69 | am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd | |
| 70 | install_sh_DATA = $(install_sh) -c -m 644 | |
| 71 | install_sh_PROGRAM = $(install_sh) -c | |
| 72 | install_sh_SCRIPT = $(install_sh) -c | |
| 73 | INSTALL_HEADER = $(INSTALL_DATA) | |
| 74 | transform = $(program_transform_name) | |
| 75 | NORMAL_INSTALL = : | |
| 76 | PRE_INSTALL = : | |
| 77 | POST_INSTALL = : | |
| 78 | NORMAL_UNINSTALL = : | |
| 79 | PRE_UNINSTALL = : | |
| 80 | POST_UNINSTALL = : | |
| 81 | build_triplet = @build@ | |
| 82 | host_triplet = @host@ | |
| 83 | bin_PROGRAMS = hashTest$(EXEEXT) | |
| 84 | subdir = hash | |
| 85 | DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ | |
| 86 | $(top_srcdir)/./config/depcomp $(include_HEADERS) README | |
| 87 | ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 | |
| 88 | am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ | |
| 89 | $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ | |
| 90 | $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ | |
| 91 | $(top_srcdir)/configure.ac | |
| 92 | am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ | |
| 93 | $(ACLOCAL_M4) | |
| 94 | mkinstalldirs = $(install_sh) -d | |
| 95 | CONFIG_CLEAN_FILES = | |
| 96 | CONFIG_CLEAN_VPATH_FILES = | |
| 97 | am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; | |
| 98 | am__vpath_adj = case $$p in \ | |
| 99 | $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ | |
| 100 | *) f=$$p;; \ | |
| 101 | esac; | |
| 102 | am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; | |
| 103 | am__install_max = 40 | |
| 104 | am__nobase_strip_setup = \ | |
| 105 | srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` | |
| 106 | am__nobase_strip = \ | |
| 107 | for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" | |
| 108 | am__nobase_list = $(am__nobase_strip_setup); \ | |
| 109 | for p in $$list; do echo "$$p $$p"; done | \ | |
| 110 | sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ | |
| 111 | $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ | |
| 112 | if (++n[$$2] == $(am__install_max)) \ | |
| 113 | { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ | |
| 114 | END { for (dir in files) print dir, files[dir] }' | |
| 115 | am__base_list = \ | |
| 116 | sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ | |
| 117 | sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | |
| 118 | am__uninstall_files_from_dir = { \ | |
| 119 | test -z "$$files" \ | |
| 120 | || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ | |
| 121 | || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ | |
| 122 | $(am__cd) "$$dir" && rm -f $$files; }; \ | |
| 123 | } | |
| 124 | am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \ | |
| 125 | "$(DESTDIR)$(includedir)" | |
| 126 | LTLIBRARIES = $(lib_LTLIBRARIES) | |
| 127 | libhash_la_LIBADD = | |
| 128 | am__objects_1 = hash.lo CLHash_Utilities.lo | |
| 129 | am__objects_2 = | |
| 130 | am_libhash_la_OBJECTS = $(am__objects_1) $(am__objects_2) | |
| 131 | libhash_la_OBJECTS = $(am_libhash_la_OBJECTS) | |
| 132 | AM_V_lt = $(am__v_lt_@AM_V@) | |
| 133 | am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) | |
| 134 | am__v_lt_0 = --silent | |
| 135 | am__v_lt_1 = | |
| 136 | PROGRAMS = $(bin_PROGRAMS) | |
| 137 | am_hashTest_OBJECTS = hashTest-testHelper.$(OBJEXT) \ | |
| 138 | hashTest-hashTest.$(OBJEXT) | |
| 139 | hashTest_OBJECTS = $(am_hashTest_OBJECTS) | |
| 140 | hashTest_DEPENDENCIES = libhash.la | |
| 141 | AM_V_P = $(am__v_P_@AM_V@) | |
| 142 | am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) | |
| 143 | am__v_P_0 = false | |
| 144 | am__v_P_1 = : | |
| 145 | AM_V_GEN = $(am__v_GEN_@AM_V@) | |
| 146 | am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) | |
| 147 | am__v_GEN_0 = @echo " GEN " $@; | |
| 148 | am__v_GEN_1 = | |
| 149 | AM_V_at = $(am__v_at_@AM_V@) | |
| 150 | am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) | |
| 151 | am__v_at_0 = @ | |
| 152 | am__v_at_1 = | |
| 153 | depcomp = $(SHELL) $(top_srcdir)/./config/depcomp | |
| 154 | am__depfiles_maybe = depfiles | |
| 155 | am__mv = mv -f | |
| 156 | COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ | |
| 157 | $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) | |
| 158 | LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ | |
| 159 | $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ | |
| 160 | $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ | |
| 161 | $(AM_CFLAGS) $(CFLAGS) | |
| 162 | AM_V_CC = $(am__v_CC_@AM_V@) | |
| 163 | am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) | |
| 164 | am__v_CC_0 = @echo " CC " $@; | |
| 165 | am__v_CC_1 = | |
| 166 | CCLD = $(CC) | |
| 167 | LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ | |
| 168 | $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ | |
| 169 | $(AM_LDFLAGS) $(LDFLAGS) -o $@ | |
| 170 | AM_V_CCLD = $(am__v_CCLD_@AM_V@) | |
| 171 | am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) | |
| 172 | am__v_CCLD_0 = @echo " CCLD " $@; | |
| 173 | am__v_CCLD_1 = | |
| 174 | SOURCES = $(libhash_la_SOURCES) $(hashTest_SOURCES) | |
| 175 | DIST_SOURCES = $(libhash_la_SOURCES) $(hashTest_SOURCES) | |
| 176 | am__can_run_installinfo = \ | |
| 177 | case $$AM_UPDATE_INFO_DIR in \ | |
| 178 | n|no|NO) false;; \ | |
| 179 | *) (install-info --version) >/dev/null 2>&1;; \ | |
| 180 | esac | |
| 181 | HEADERS = $(include_HEADERS) | |
| 182 | am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) | |
| 183 | # Read a list of newline-separated strings from the standard input, | |
| 184 | # and print each of them once, without duplicates. Input order is | |
| 185 | # *not* preserved. | |
| 186 | am__uniquify_input = $(AWK) '\ | |
| 187 | BEGIN { nonempty = 0; } \ | |
| 188 | { items[$$0] = 1; nonempty = 1; } \ | |
| 189 | END { if (nonempty) { for (i in items) print i; }; } \ | |
| 190 | ' | |
| 191 | # Make sure the list of sources is unique. This is necessary because, | |
| 192 | # e.g., the same source file might be shared among _SOURCES variables | |
| 193 | # for different programs/libraries. | |
| 194 | am__define_uniq_tagged_files = \ | |
| 195 | list='$(am__tagged_files)'; \ | |
| 196 | unique=`for i in $$list; do \ | |
| 197 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ | |
| 198 | done | $(am__uniquify_input)` | |
| 199 | ETAGS = etags | |
| 200 | CTAGS = ctags | |
| 201 | DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) | |
| 202 | ACLOCAL = @ACLOCAL@ | |
| 203 | AMTAR = @AMTAR@ | |
| 204 | AM_CPPFLAGS = @AM_CPPFLAGS@ | |
| 205 | AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ | |
| 206 | AR = @AR@ | |
| 207 | AUTOCONF = @AUTOCONF@ | |
| 208 | AUTOHEADER = @AUTOHEADER@ | |
| 209 | AUTOMAKE = @AUTOMAKE@ | |
| 210 | AWK = @AWK@ | |
| 211 | CC = @CC@ | |
| 212 | CCDEPMODE = @CCDEPMODE@ | |
| 213 | CFLAGS = @CFLAGS@ | |
| 214 | CPP = @CPP@ | |
| 215 | CPPFLAGS = @CPPFLAGS@ | |
| 216 | CPREPROCESSOR = @CPREPROCESSOR@ | |
| 217 | CXX = @CXX@ | |
| 218 | CXXCPP = @CXXCPP@ | |
| 219 | CXXDEPMODE = @CXXDEPMODE@ | |
| 220 | CXXFLAGS = @CXXFLAGS@ | |
| 221 | CYGPATH_W = @CYGPATH_W@ | |
| 222 | DEFS = @DEFS@ | |
| 223 | DEPDIR = @DEPDIR@ | |
| 224 | DLLTOOL = @DLLTOOL@ | |
| 225 | DSYMUTIL = @DSYMUTIL@ | |
| 226 | DUMPBIN = @DUMPBIN@ | |
| 227 | ECHO_C = @ECHO_C@ | |
| 228 | ECHO_N = @ECHO_N@ | |
| 229 | ECHO_T = @ECHO_T@ | |
| 230 | EGREP = @EGREP@ | |
| 231 | EXEEXT = @EXEEXT@ | |
| 232 | FGREP = @FGREP@ | |
| 233 | GREP = @GREP@ | |
| 234 | HAVE_ADDR2LINE = @HAVE_ADDR2LINE@ | |
| 235 | INDENT = @INDENT@ | |
| 236 | INSTALL = @INSTALL@ | |
| 237 | INSTALL_DATA = @INSTALL_DATA@ | |
| 238 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ | |
| 239 | INSTALL_SCRIPT = @INSTALL_SCRIPT@ | |
| 240 | INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ | |
| 241 | LD = @LD@ | |
| 242 | LDFLAGS = @LDFLAGS@ | |
| 243 | LIBOBJS = @LIBOBJS@ | |
| 244 | LIBS = @LIBS@ | |
| 245 | LIBTOOL = @LIBTOOL@ | |
| 246 | LIPO = @LIPO@ | |
| 247 | LN_S = @LN_S@ | |
| 248 | LTLIBOBJS = @LTLIBOBJS@ | |
| 249 | MAKEINFO = @MAKEINFO@ | |
| 250 | MANIFEST_TOOL = @MANIFEST_TOOL@ | |
| 251 | MKDIR_P = @MKDIR_P@ | |
| 252 | NM = @NM@ | |
| 253 | NMEDIT = @NMEDIT@ | |
| 254 | OBJDUMP = @OBJDUMP@ | |
| 255 | OBJEXT = @OBJEXT@ | |
| 256 | OTOOL = @OTOOL@ | |
| 257 | OTOOL64 = @OTOOL64@ | |
| 258 | PACKAGE = @PACKAGE@ | |
| 259 | PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ | |
| 260 | PACKAGE_NAME = @PACKAGE_NAME@ | |
| 261 | PACKAGE_STRING = @PACKAGE_STRING@ | |
| 262 | PACKAGE_TARNAME = @PACKAGE_TARNAME@ | |
| 263 | PACKAGE_URL = @PACKAGE_URL@ | |
| 264 | PACKAGE_VERSION = @PACKAGE_VERSION@ | |
| 265 | PATH_SEPARATOR = @PATH_SEPARATOR@ | |
| 266 | RANLIB = @RANLIB@ | |
| 267 | SED = @SED@ | |
| 268 | SET_MAKE = @SET_MAKE@ | |
| 269 | SHELL = @SHELL@ | |
| 270 | STRIP = @STRIP@ | |
| 271 | VERSION = @VERSION@ | |
| 272 | abs_builddir = @abs_builddir@ | |
| 273 | abs_srcdir = @abs_srcdir@ | |
| 274 | abs_top_builddir = @abs_top_builddir@ | |
| 275 | abs_top_srcdir = @abs_top_srcdir@ | |
| 276 | ac_ct_AR = @ac_ct_AR@ | |
| 277 | ac_ct_CC = @ac_ct_CC@ | |
| 278 | ac_ct_CXX = @ac_ct_CXX@ | |
| 279 | ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ | |
| 280 | am__include = @am__include@ | |
| 281 | am__leading_dot = @am__leading_dot@ | |
| 282 | am__quote = @am__quote@ | |
| 283 | am__tar = @am__tar@ | |
| 284 | am__untar = @am__untar@ | |
| 285 | bindir = @bindir@ | |
| 286 | build = @build@ | |
| 287 | build_alias = @build_alias@ | |
| 288 | build_cpu = @build_cpu@ | |
| 289 | build_os = @build_os@ | |
| 290 | build_vendor = @build_vendor@ | |
| 291 | builddir = @builddir@ | |
| 292 | datadir = @datadir@ | |
| 293 | datarootdir = @datarootdir@ | |
| 294 | docdir = @docdir@ | |
| 295 | dvidir = @dvidir@ | |
| 296 | exec_prefix = @exec_prefix@ | |
| 297 | host = @host@ | |
| 298 | host_alias = @host_alias@ | |
| 299 | host_cpu = @host_cpu@ | |
| 300 | host_os = @host_os@ | |
| 301 | host_vendor = @host_vendor@ | |
| 302 | htmldir = @htmldir@ | |
| 303 | includedir = @includedir@ | |
| 304 | infodir = @infodir@ | |
| 305 | install_sh = @install_sh@ | |
| 306 | libdir = @libdir@ | |
| 307 | libexecdir = @libexecdir@ | |
| 308 | localedir = @localedir@ | |
| 309 | localstatedir = @localstatedir@ | |
| 310 | lspci_found = @lspci_found@ | |
| 311 | mandir = @mandir@ | |
| 312 | mkdir_p = @mkdir_p@ | |
| 313 | oldincludedir = @oldincludedir@ | |
| 314 | pdfdir = @pdfdir@ | |
| 315 | prefix = @prefix@ | |
| 316 | program_transform_name = @program_transform_name@ | |
| 317 | psdir = @psdir@ | |
| 318 | sbindir = @sbindir@ | |
| 319 | sharedstatedir = @sharedstatedir@ | |
| 320 | srcdir = @srcdir@ | |
| 321 | sysconfdir = @sysconfdir@ | |
| 322 | target_alias = @target_alias@ | |
| 323 | top_build_prefix = @top_build_prefix@ | |
| 324 | top_builddir = @top_builddir@ | |
| 325 | top_srcdir = @top_srcdir@ | |
| 326 | AM_MAKEFLAGS = -j 4 | |
| 327 | DEFAULT_INCLUDES = -I. -I.. | |
| 328 | lib_LTLIBRARIES = libhash.la | |
| 329 | include_HEADERS = hash.h | |
| 330 | hashTest_CPPFLAGS = -DHAVE_OPENCL -DHAVE_CL_DOUBLE -I$(OPENCL_INCLUDE) | |
| 331 | H_SRCS = hash.h CLHash_Utilities.h | |
| 332 | C_SRCS = hash.c CLHash_Utilities.c | |
| 333 | libhash_la_SOURCES = ${C_SRCS} ${H_SRCS} | |
| 334 | hashTest_SOURCES = testHelper.c hashTest.c | |
| 335 | hashTest_LDADD = libhash.la | |
| 336 | EXTRA_DIST = perfectHash.cm perfectHash.hm primetest.c testHelper.h hash.hp \ | |
| 337 | hash.hm hash.cp hash.cm hash.h hash.c hash.cl hash.clp embed_source.pl \ | |
| 338 | compactHash.cm compactHash.hm baseHash.cm baseHash.hm | |
| 339 | ||
| 340 | all: all-am | |
| 341 | ||
| 342 | .SUFFIXES: | |
| 343 | .SUFFIXES: .c .lo .o .obj | |
| 344 | $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) | |
| 345 | @for dep in $?; do \ | |
| 346 | case '$(am__configure_deps)' in \ | |
| 347 | *$$dep*) \ | |
| 348 | ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ | |
| 349 | && { if test -f $@; then exit 0; else break; fi; }; \ | |
| 350 | exit 1;; \ | |
| 351 | esac; \ | |
| 352 | done; \ | |
| 353 | echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign hash/Makefile'; \ | |
| 354 | $(am__cd) $(top_srcdir) && \ | |
| 355 | $(AUTOMAKE) --foreign hash/Makefile | |
| 356 | .PRECIOUS: Makefile | |
| 357 | Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status | |
| 358 | @case '$?' in \ | |
| 359 | *config.status*) \ | |
| 360 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ | |
| 361 | *) \ | |
| 362 | echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ | |
| 363 | cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ | |
| 364 | esac; | |
| 365 | ||
| 366 | $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) | |
| 367 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh | |
| 368 | ||
| 369 | $(top_srcdir)/configure: $(am__configure_deps) | |
| 370 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh | |
| 371 | $(ACLOCAL_M4): $(am__aclocal_m4_deps) | |
| 372 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh | |
| 373 | $(am__aclocal_m4_deps): | |
| 374 | ||
| 375 | install-libLTLIBRARIES: $(lib_LTLIBRARIES) | |
| 376 | @$(NORMAL_INSTALL) | |
| 377 | @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ | |
| 378 | list2=; for p in $$list; do \ | |
| 379 | if test -f $$p; then \ | |
| 380 | list2="$$list2 $$p"; \ | |
| 381 | else :; fi; \ | |
| 382 | done; \ | |
| 383 | test -z "$$list2" || { \ | |
| 384 | echo " $(MKDIR_P) '$(DESTDIR)$(libdir)'"; \ | |
| 385 | $(MKDIR_P) "$(DESTDIR)$(libdir)" || exit 1; \ | |
| 386 | echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ | |
| 387 | $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ | |
| 388 | } | |
| 389 | ||
| 390 | uninstall-libLTLIBRARIES: | |
| 391 | @$(NORMAL_UNINSTALL) | |
| 392 | @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ | |
| 393 | for p in $$list; do \ | |
| 394 | $(am__strip_dir) \ | |
| 395 | echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \ | |
| 396 | $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \ | |
| 397 | done | |
| 398 | ||
| 399 | clean-libLTLIBRARIES: | |
| 400 | -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) | |
| 401 | @list='$(lib_LTLIBRARIES)'; \ | |
| 402 | locs=`for p in $$list; do echo $$p; done | \ | |
| 403 | sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ | |
| 404 | sort -u`; \ | |
| 405 | test -z "$$locs" || { \ | |
| 406 | echo rm -f $${locs}; \ | |
| 407 | rm -f $${locs}; \ | |
| 408 | } | |
| 409 | ||
| 410 | libhash.la: $(libhash_la_OBJECTS) $(libhash_la_DEPENDENCIES) $(EXTRA_libhash_la_DEPENDENCIES) | |
| 411 | $(AM_V_CCLD)$(LINK) -rpath $(libdir) $(libhash_la_OBJECTS) $(libhash_la_LIBADD) $(LIBS) | |
| 412 | install-binPROGRAMS: $(bin_PROGRAMS) | |
| 413 | @$(NORMAL_INSTALL) | |
| 414 | @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ | |
| 415 | if test -n "$$list"; then \ | |
| 416 | echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \ | |
| 417 | $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \ | |
| 418 | fi; \ | |
| 419 | for p in $$list; do echo "$$p $$p"; done | \ | |
| 420 | sed 's/$(EXEEXT)$$//' | \ | |
| 421 | while read p p1; do if test -f $$p \ | |
| 422 | || test -f $$p1 \ | |
| 423 | ; then echo "$$p"; echo "$$p"; else :; fi; \ | |
| 424 | done | \ | |
| 425 | sed -e 'p;s,.*/,,;n;h' \ | |
| 426 | -e 's|.*|.|' \ | |
| 427 | -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ | |
| 428 | sed 'N;N;N;s,\n, ,g' | \ | |
| 429 | $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ | |
| 430 | { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ | |
| 431 | if ($$2 == $$4) files[d] = files[d] " " $$1; \ | |
| 432 | else { print "f", $$3 "/" $$4, $$1; } } \ | |
| 433 | END { for (d in files) print "f", d, files[d] }' | \ | |
| 434 | while read type dir files; do \ | |
| 435 | if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ | |
| 436 | test -z "$$files" || { \ | |
| 437 | echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ | |
| 438 | $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ | |
| 439 | } \ | |
| 440 | ; done | |
| 441 | ||
| 442 | uninstall-binPROGRAMS: | |
| 443 | @$(NORMAL_UNINSTALL) | |
| 444 | @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ | |
| 445 | files=`for p in $$list; do echo "$$p"; done | \ | |
| 446 | sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ | |
| 447 | -e 's/$$/$(EXEEXT)/' \ | |
| 448 | `; \ | |
| 449 | test -n "$$list" || exit 0; \ | |
| 450 | echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ | |
| 451 | cd "$(DESTDIR)$(bindir)" && rm -f $$files | |
| 452 | ||
| 453 | clean-binPROGRAMS: | |
| 454 | @list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \ | |
| 455 | echo " rm -f" $$list; \ | |
| 456 | rm -f $$list || exit $$?; \ | |
| 457 | test -n "$(EXEEXT)" || exit 0; \ | |
| 458 | list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ | |
| 459 | echo " rm -f" $$list; \ | |
| 460 | rm -f $$list | |
| 461 | ||
| 462 | hashTest$(EXEEXT): $(hashTest_OBJECTS) $(hashTest_DEPENDENCIES) $(EXTRA_hashTest_DEPENDENCIES) | |
| 463 | @rm -f hashTest$(EXEEXT) | |
| 464 | $(AM_V_CCLD)$(LINK) $(hashTest_OBJECTS) $(hashTest_LDADD) $(LIBS) | |
| 465 | ||
| 466 | mostlyclean-compile: | |
| 467 | -rm -f *.$(OBJEXT) | |
| 468 | ||
| 469 | distclean-compile: | |
| 470 | -rm -f *.tab.c | |
| 471 | ||
| 472 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CLHash_Utilities.Plo@am__quote@ | |
| 473 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hash.Plo@am__quote@ | |
| 474 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hashTest-hashTest.Po@am__quote@ | |
| 475 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hashTest-testHelper.Po@am__quote@ | |
| 476 | ||
| 477 | .c.o: | |
| 478 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< | |
| 479 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po | |
| 480 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ | |
| 481 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | |
| 482 | @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $< | |
| 483 | ||
| 484 | .c.obj: | |
| 485 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` | |
| 486 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po | |
| 487 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ | |
| 488 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | |
| 489 | @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'` | |
| 490 | ||
| 491 | .c.lo: | |
| 492 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< | |
| 493 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo | |
| 494 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ | |
| 495 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | |
| 496 | @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< | |
| 497 | ||
| 498 | hashTest-testHelper.o: testHelper.c | |
| 499 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hashTest_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hashTest-testHelper.o -MD -MP -MF $(DEPDIR)/hashTest-testHelper.Tpo -c -o hashTest-testHelper.o `test -f 'testHelper.c' || echo '$(srcdir)/'`testHelper.c | |
| 500 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hashTest-testHelper.Tpo $(DEPDIR)/hashTest-testHelper.Po | |
| 501 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='testHelper.c' object='hashTest-testHelper.o' libtool=no @AMDEPBACKSLASH@ | |
| 502 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | |
| 503 | @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hashTest_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hashTest-testHelper.o `test -f 'testHelper.c' || echo '$(srcdir)/'`testHelper.c | |
| 504 | ||
| 505 | hashTest-testHelper.obj: testHelper.c | |
| 506 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hashTest_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hashTest-testHelper.obj -MD -MP -MF $(DEPDIR)/hashTest-testHelper.Tpo -c -o hashTest-testHelper.obj `if test -f 'testHelper.c'; then $(CYGPATH_W) 'testHelper.c'; else $(CYGPATH_W) '$(srcdir)/testHelper.c'; fi` | |
| 507 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hashTest-testHelper.Tpo $(DEPDIR)/hashTest-testHelper.Po | |
| 508 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='testHelper.c' object='hashTest-testHelper.obj' libtool=no @AMDEPBACKSLASH@ | |
| 509 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | |
| 510 | @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hashTest_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hashTest-testHelper.obj `if test -f 'testHelper.c'; then $(CYGPATH_W) 'testHelper.c'; else $(CYGPATH_W) '$(srcdir)/testHelper.c'; fi` | |
| 511 | ||
| 512 | hashTest-hashTest.o: hashTest.c | |
| 513 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hashTest_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hashTest-hashTest.o -MD -MP -MF $(DEPDIR)/hashTest-hashTest.Tpo -c -o hashTest-hashTest.o `test -f 'hashTest.c' || echo '$(srcdir)/'`hashTest.c | |
| 514 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hashTest-hashTest.Tpo $(DEPDIR)/hashTest-hashTest.Po | |
| 515 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hashTest.c' object='hashTest-hashTest.o' libtool=no @AMDEPBACKSLASH@ | |
| 516 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | |
| 517 | @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hashTest_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hashTest-hashTest.o `test -f 'hashTest.c' || echo '$(srcdir)/'`hashTest.c | |
| 518 | ||
| 519 | hashTest-hashTest.obj: hashTest.c | |
| 520 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hashTest_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hashTest-hashTest.obj -MD -MP -MF $(DEPDIR)/hashTest-hashTest.Tpo -c -o hashTest-hashTest.obj `if test -f 'hashTest.c'; then $(CYGPATH_W) 'hashTest.c'; else $(CYGPATH_W) '$(srcdir)/hashTest.c'; fi` | |
| 521 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hashTest-hashTest.Tpo $(DEPDIR)/hashTest-hashTest.Po | |
| 522 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hashTest.c' object='hashTest-hashTest.obj' libtool=no @AMDEPBACKSLASH@ | |
| 523 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | |
| 524 | @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hashTest_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hashTest-hashTest.obj `if test -f 'hashTest.c'; then $(CYGPATH_W) 'hashTest.c'; else $(CYGPATH_W) '$(srcdir)/hashTest.c'; fi` | |
| 525 | ||
| 526 | mostlyclean-libtool: | |
| 527 | -rm -f *.lo | |
| 528 | ||
| 529 | clean-libtool: | |
| 530 | -rm -rf .libs _libs | |
| 531 | install-includeHEADERS: $(include_HEADERS) | |
| 532 | @$(NORMAL_INSTALL) | |
| 533 | @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \ | |
| 534 | if test -n "$$list"; then \ | |
| 535 | echo " $(MKDIR_P) '$(DESTDIR)$(includedir)'"; \ | |
| 536 | $(MKDIR_P) "$(DESTDIR)$(includedir)" || exit 1; \ | |
| 537 | fi; \ | |
| 538 | for p in $$list; do \ | |
| 539 | if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ | |
| 540 | echo "$$d$$p"; \ | |
| 541 | done | $(am__base_list) | \ | |
| 542 | while read files; do \ | |
| 543 | echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(includedir)'"; \ | |
| 544 | $(INSTALL_HEADER) $$files "$(DESTDIR)$(includedir)" || exit $$?; \ | |
| 545 | done | |
| 546 | ||
| 547 | uninstall-includeHEADERS: | |
| 548 | @$(NORMAL_UNINSTALL) | |
| 549 | @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \ | |
| 550 | files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ | |
| 551 | dir='$(DESTDIR)$(includedir)'; $(am__uninstall_files_from_dir) | |
| 552 | ||
| 553 | ID: $(am__tagged_files) | |
| 554 | $(am__define_uniq_tagged_files); mkid -fID $$unique | |
| 555 | tags: tags-am | |
| 556 | TAGS: tags | |
| 557 | ||
| 558 | tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) | |
| 559 | set x; \ | |
| 560 | here=`pwd`; \ | |
| 561 | $(am__define_uniq_tagged_files); \ | |
| 562 | shift; \ | |
| 563 | if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ | |
| 564 | test -n "$$unique" || unique=$$empty_fix; \ | |
| 565 | if test $$# -gt 0; then \ | |
| 566 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ | |
| 567 | "$$@" $$unique; \ | |
| 568 | else \ | |
| 569 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ | |
| 570 | $$unique; \ | |
| 571 | fi; \ | |
| 572 | fi | |
| 573 | ctags: ctags-am | |
| 574 | ||
| 575 | CTAGS: ctags | |
| 576 | ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) | |
| 577 | $(am__define_uniq_tagged_files); \ | |
| 578 | test -z "$(CTAGS_ARGS)$$unique" \ | |
| 579 | || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ | |
| 580 | $$unique | |
| 581 | ||
| 582 | GTAGS: | |
| 583 | here=`$(am__cd) $(top_builddir) && pwd` \ | |
| 584 | && $(am__cd) $(top_srcdir) \ | |
| 585 | && gtags -i $(GTAGS_ARGS) "$$here" | |
| 586 | cscopelist: cscopelist-am | |
| 587 | ||
| 588 | cscopelist-am: $(am__tagged_files) | |
| 589 | list='$(am__tagged_files)'; \ | |
| 590 | case "$(srcdir)" in \ | |
| 591 | [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ | |
| 592 | *) sdir=$(subdir)/$(srcdir) ;; \ | |
| 593 | esac; \ | |
| 594 | for i in $$list; do \ | |
| 595 | if test -f "$$i"; then \ | |
| 596 | echo "$(subdir)/$$i"; \ | |
| 597 | else \ | |
| 598 | echo "$$sdir/$$i"; \ | |
| 599 | fi; \ | |
| 600 | done >> $(top_builddir)/cscope.files | |
| 601 | ||
| 602 | distclean-tags: | |
| 603 | -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags | |
| 604 | ||
| 605 | distdir: $(DISTFILES) | |
| 606 | @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ | |
| 607 | topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ | |
| 608 | list='$(DISTFILES)'; \ | |
| 609 | dist_files=`for file in $$list; do echo $$file; done | \ | |
| 610 | sed -e "s|^$$srcdirstrip/||;t" \ | |
| 611 | -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ | |
| 612 | case $$dist_files in \ | |
| 613 | */*) $(MKDIR_P) `echo "$$dist_files" | \ | |
| 614 | sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ | |
| 615 | sort -u` ;; \ | |
| 616 | esac; \ | |
| 617 | for file in $$dist_files; do \ | |
| 618 | if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ | |
| 619 | if test -d $$d/$$file; then \ | |
| 620 | dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ | |
| 621 | if test -d "$(distdir)/$$file"; then \ | |
| 622 | find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ | |
| 623 | fi; \ | |
| 624 | if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ | |
| 625 | cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ | |
| 626 | find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ | |
| 627 | fi; \ | |
| 628 | cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ | |
| 629 | else \ | |
| 630 | test -f "$(distdir)/$$file" \ | |
| 631 | || cp -p $$d/$$file "$(distdir)/$$file" \ | |
| 632 | || exit 1; \ | |
| 633 | fi; \ | |
| 634 | done | |
| 635 | check-am: all-am | |
| 636 | check: check-am | |
| 637 | all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS) | |
| 638 | install-binPROGRAMS: install-libLTLIBRARIES | |
| 639 | ||
| 640 | installdirs: | |
| 641 | for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(includedir)"; do \ | |
| 642 | test -z "$$dir" || $(MKDIR_P) "$$dir"; \ | |
| 643 | done | |
| 644 | install: install-am | |
| 645 | install-exec: install-exec-am | |
| 646 | install-data: install-data-am | |
| 647 | uninstall: uninstall-am | |
| 648 | ||
| 649 | install-am: all-am | |
| 650 | @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am | |
| 651 | ||
| 652 | installcheck: installcheck-am | |
| 653 | install-strip: | |
| 654 | if test -z '$(STRIP)'; then \ | |
| 655 | $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ | |
| 656 | install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ | |
| 657 | install; \ | |
| 658 | else \ | |
| 659 | $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ | |
| 660 | install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ | |
| 661 | "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ | |
| 662 | fi | |
| 663 | mostlyclean-generic: | |
| 664 | ||
| 665 | clean-generic: | |
| 666 | ||
| 667 | distclean-generic: | |
| 668 | -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) | |
| 669 | -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) | |
| 670 | ||
| 671 | maintainer-clean-generic: | |
| 672 | @echo "This command is intended for maintainers to use" | |
| 673 | @echo "it deletes files that may require special tools to rebuild." | |
| 674 | clean: clean-am | |
| 675 | ||
| 676 | clean-am: clean-binPROGRAMS clean-generic clean-libLTLIBRARIES \ | |
| 677 | clean-libtool mostlyclean-am | |
| 678 | ||
| 679 | distclean: distclean-am | |
| 680 | -rm -rf ./$(DEPDIR) | |
| 681 | -rm -f Makefile | |
| 682 | distclean-am: clean-am distclean-compile distclean-generic \ | |
| 683 | distclean-tags | |
| 684 | ||
| 685 | dvi: dvi-am | |
| 686 | ||
| 687 | dvi-am: | |
| 688 | ||
| 689 | html: html-am | |
| 690 | ||
| 691 | html-am: | |
| 692 | ||
| 693 | info: info-am | |
| 694 | ||
| 695 | info-am: | |
| 696 | ||
| 697 | install-data-am: install-includeHEADERS | |
| 698 | ||
| 699 | install-dvi: install-dvi-am | |
| 700 | ||
| 701 | install-dvi-am: | |
| 702 | ||
| 703 | install-exec-am: install-binPROGRAMS install-libLTLIBRARIES | |
| 704 | ||
| 705 | install-html: install-html-am | |
| 706 | ||
| 707 | install-html-am: | |
| 708 | ||
| 709 | install-info: install-info-am | |
| 710 | ||
| 711 | install-info-am: | |
| 712 | ||
| 713 | install-man: | |
| 714 | ||
| 715 | install-pdf: install-pdf-am | |
| 716 | ||
| 717 | install-pdf-am: | |
| 718 | ||
| 719 | install-ps: install-ps-am | |
| 720 | ||
| 721 | install-ps-am: | |
| 722 | ||
| 723 | installcheck-am: | |
| 724 | ||
| 725 | maintainer-clean: maintainer-clean-am | |
| 726 | -rm -rf ./$(DEPDIR) | |
| 727 | -rm -f Makefile | |
| 728 | maintainer-clean-am: distclean-am maintainer-clean-generic | |
| 729 | ||
| 730 | mostlyclean: mostlyclean-am | |
| 731 | ||
| 732 | mostlyclean-am: mostlyclean-compile mostlyclean-generic \ | |
| 733 | mostlyclean-libtool | |
| 734 | ||
| 735 | pdf: pdf-am | |
| 736 | ||
| 737 | pdf-am: | |
| 738 | ||
| 739 | ps: ps-am | |
| 740 | ||
| 741 | ps-am: | |
| 742 | ||
| 743 | uninstall-am: uninstall-binPROGRAMS uninstall-includeHEADERS \ | |
| 744 | uninstall-libLTLIBRARIES | |
| 745 | ||
| 746 | .MAKE: install-am install-strip | |
| 747 | ||
| 748 | .PHONY: CTAGS GTAGS TAGS all all-am check check-am clean \ | |
| 749 | clean-binPROGRAMS clean-generic clean-libLTLIBRARIES \ | |
| 750 | clean-libtool cscopelist-am ctags ctags-am distclean \ | |
| 751 | distclean-compile distclean-generic distclean-libtool \ | |
| 752 | distclean-tags distdir dvi dvi-am html html-am info info-am \ | |
| 753 | install install-am install-binPROGRAMS install-data \ | |
| 754 | install-data-am install-dvi install-dvi-am install-exec \ | |
| 755 | install-exec-am install-html install-html-am \ | |
| 756 | install-includeHEADERS install-info install-info-am \ | |
| 757 | install-libLTLIBRARIES install-man install-pdf install-pdf-am \ | |
| 758 | install-ps install-ps-am install-strip installcheck \ | |
| 759 | installcheck-am installdirs maintainer-clean \ | |
| 760 | maintainer-clean-generic mostlyclean mostlyclean-compile \ | |
| 761 | mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ | |
| 762 | tags tags-am uninstall uninstall-am uninstall-binPROGRAMS \ | |
| 763 | uninstall-includeHEADERS uninstall-libLTLIBRARIES | |
| 764 | ||
| 765 | default: hash.c CLHash_Utilities.c hash.cl libhash.la | |
| 766 | all: hash.c CLHash_Utilities.c hash.cl libhash.la | |
| 767 | test: hashTest | |
| 768 | ||
| 769 | hash.h: hash.hp hash.hm perfectHash.hm compactHash.hm | |
| 770 | ${CPREPROCESSOR} -CC -x c -imacros hash.hm hash.hp | ${INDENT} -linux -brf -o hash.h | |
| 771 | ||
| 772 | hash.c: hash.cp hash.cm hash.cl perfectHash.cm compactHash.cm | |
| 773 | ${CPREPROCESSOR} -CC -x c -imacros hash.cm hash.cp | ${INDENT} -linux -brf -o hash.c | |
| 774 | ./embed_source.pl hash.cl >> hash.c | |
| 775 | ||
| 776 | hash.cl: hash.clp hash.cm perfectHash.cm compactHash.cm | |
| 777 | ${CPREPROCESSOR} -CC -x c -imacros hash.cm hash.clp | ${INDENT} -linux -brf -o hash.cl | |
| 778 | ||
| 779 | # Tell versions [3.59,3.63) of GNU make to not export all variables. | |
| 780 | # Otherwise a system limit (for SysV at least) may be exceeded. | |
| 781 | .NOEXPORT: |
| … | … | @@ -1,159 +0,0 @@ |
| 1 | This code uses autoconf/automake/libtool for builds. To build the code: | |
| 2 | ||
| 3 | ./configure | |
| 4 | make | |
| 5 | ||
| 6 | A statically-loaded library will be built: libhash.la | |
| 7 | If you specify the targets (all, test) an executable will be built: hashTest | |
| 8 | ||
| 9 | You can run hashTest like this: | |
| 10 | ||
| 11 | ./hashTest | |
| 12 | ||
| 13 | TESTING: | |
| 14 | The output should look like this: | |
| 15 | ||
| 16 | HashTest STARTED | |
| 17 | intintIdentityPerfectHash Test STARTED | |
| 18 | Correct Hash Type Check: PASSED | |
| 19 | QuerySingle after Insert Check 1: PASSED | |
| 20 | QuerySingle after Insert Check 2: PASSED | |
| 21 | QuerySingle after Insert Check 3: PASSED | |
| 22 | QuerySingle after Insert Check 4: PASSED | |
| 23 | QuerySingle after Insert Check 5: PASSED | |
| 24 | QuerySingle after Insert Check 6: PASSED | |
| 25 | Query after InsertSingleNoOverwrite Check: PASSED | |
| 26 | Query after InsertSingle Check: PASSED | |
| 27 | Query after InsertNoOverwrite Check: PASSED | |
| 28 | intintIdentityPerfectHash Test FINISHED | |
| 29 | 100% (10/10) TESTS PASSED | |
| 30 | ||
| 31 | intintIdentitySentinelPerfectHash Test STARTED | |
| 32 | Correct Hash Type Check: PASSED | |
| 33 | QuerySingle after Insert Check 1: PASSED | |
| 34 | QuerySingle after Insert Check 2: PASSED | |
| 35 | QuerySingle after Insert Check 3: PASSED | |
| 36 | QuerySingle after Insert Check 4: PASSED | |
| 37 | QuerySingle after Insert Check 5: PASSED | |
| 38 | QuerySingle after Insert Check 6: PASSED | |
| 39 | Query after InsertSingleNoOverwrite Check: PASSED | |
| 40 | Query after InsertSingle Check: PASSED | |
| 41 | Query after InsertNoOverwrite Check: PASSED | |
| 42 | intintIdentitySentinelPerfectHash Test FINISHED | |
| 43 | 100% (10/10) TESTS PASSED | |
| 44 | ||
| 45 | intintLCGLinearOpenCompactHash Test STARTED | |
| 46 | Correct Hash Type Check: PASSED | |
| 47 | QuerySingle after Insert Check 1: PASSED | |
| 48 | QuerySingle after Insert Check 2: PASSED | |
| 49 | QuerySingle after Insert Check 3: PASSED | |
| 50 | QuerySingle after Insert Check 4: PASSED | |
| 51 | QuerySingle after Insert Check 5: PASSED | |
| 52 | QuerySingle after Insert Check 6: PASSED | |
| 53 | Query after InsertSingleNoOverwrite Check: PASSED | |
| 54 | Query after InsertSingle Check: PASSED | |
| 55 | Query after InsertNoOverwrite Check: PASSED | |
| 56 | intintLCGLinearOpenCompactHash Test FINISHED | |
| 57 | 100% (10/10) TESTS PASSED | |
| 58 | ||
| 59 | intintLCGQuadraticOpenCompactHash Test STARTED | |
| 60 | Correct Hash Type Check: PASSED | |
| 61 | QuerySingle after Insert Check 1: PASSED | |
| 62 | QuerySingle after Insert Check 2: PASSED | |
| 63 | QuerySingle after Insert Check 3: PASSED | |
| 64 | QuerySingle after Insert Check 4: PASSED | |
| 65 | QuerySingle after Insert Check 5: PASSED | |
| 66 | QuerySingle after Insert Check 6: PASSED | |
| 67 | Query after InsertSingleNoOverwrite Check: PASSED | |
| 68 | Query after InsertSingle Check: PASSED | |
| 69 | Query after InsertNoOverwrite Check: PASSED | |
| 70 | intintLCGQuadraticOpenCompactHash Test FINISHED | |
| 71 | 100% (10/10) TESTS PASSED | |
| 72 | ||
| 73 | intintIdentityPerfectCLHash Test STARTED | |
| 74 | Correct Hash Type Check: PASSED | |
| 75 | QuerySingle after Insert Check 1: PASSED | |
| 76 | QuerySingle after Insert Check 2: PASSED | |
| 77 | QuerySingle after Insert Check 3: PASSED | |
| 78 | QuerySingle after Insert Check 4: PASSED | |
| 79 | QuerySingle after Insert Check 5: PASSED | |
| 80 | QuerySingle after Insert Check 6: PASSED | |
| 81 | Query after InsertSingleNoOverwrite Check: PASSED | |
| 82 | Query after InsertSingle Check: PASSED | |
| 83 | Query after InsertNoOverwrite Check: PASSED | |
| 84 | intintIdentityPerfectCLHash Test FINISHED | |
| 85 | 100% (10/10) TESTS PASSED | |
| 86 | ||
| 87 | intintIdentitySentinelPerfectCLHash Test STARTED | |
| 88 | Correct Hash Type Check: PASSED | |
| 89 | QuerySingle after Insert Check 1: PASSED | |
| 90 | QuerySingle after Insert Check 2: PASSED | |
| 91 | QuerySingle after Insert Check 3: PASSED | |
| 92 | QuerySingle after Insert Check 4: PASSED | |
| 93 | QuerySingle after Insert Check 5: PASSED | |
| 94 | QuerySingle after Insert Check 6: PASSED | |
| 95 | Query after InsertSingleNoOverwrite Check: PASSED | |
| 96 | Query after InsertSingle Check: PASSED | |
| 97 | Query after InsertNoOverwrite Check: PASSED | |
| 98 | intintIdentitySentinelPerfectCLHash Test FINISHED | |
| 99 | 100% (10/10) TESTS PASSED | |
| 100 | ||
| 101 | intintLCGLinearOpenCompactCLHash Test STARTED | |
| 102 | Correct Hash Type Check: PASSED | |
| 103 | QuerySingle after Insert Check 1: PASSED | |
| 104 | QuerySingle after Insert Check 2: PASSED | |
| 105 | QuerySingle after Insert Check 3: PASSED | |
| 106 | QuerySingle after Insert Check 4: PASSED | |
| 107 | QuerySingle after Insert Check 5: PASSED | |
| 108 | QuerySingle after Insert Check 6: PASSED | |
| 109 | Query after InsertSingleNoOverwrite Check: PASSED | |
| 110 | Query after InsertSingle Check: PASSED | |
| 111 | Query after InsertNoOverwrite Check: PASSED | |
| 112 | intintLCGLinearOpenCompactHash Test FINISHED | |
| 113 | 100% (10/10) TESTS PASSED | |
| 114 | ||
| 115 | intintLCGQuadraticOpenCompactCLHash Test STARTED | |
| 116 | Correct Hash Type Check: PASSED | |
| 117 | QuerySingle after Insert Check 1: PASSED | |
| 118 | QuerySingle after Insert Check 2: PASSED | |
| 119 | QuerySingle after Insert Check 3: PASSED | |
| 120 | QuerySingle after Insert Check 4: PASSED | |
| 121 | QuerySingle after Insert Check 5: PASSED | |
| 122 | QuerySingle after Insert Check 6: PASSED | |
| 123 | Query after InsertSingleNoOverwrite Check: PASSED | |
| 124 | Query after InsertSingle Check: PASSED | |
| 125 | Query after InsertNoOverwrite Check: PASSED | |
| 126 | intintLCGQuadraticOpenCompactHash Test FINISHED | |
| 127 | 100% (10/10) TESTS PASSED | |
| 128 | ||
| 129 | hashTest FINISHED | |
| 130 | 100% (8/8) TESTS PASSED | |
| 131 | ||
| 132 | If an error occurs, the expected and observed values will be printed. | |
| 133 | ||
| 134 | USAGE: | |
| 135 | There are many ways to use this library. | |
| 136 | ||
| 137 | Terms: | |
| 138 | Entry: A key-value pair to be inserted into the hash table | |
| 139 | Key: In this library, a 32-bit or 64-bit integer greater than or equal to 0 used to access some associated value | |
| 140 | Value: Any data type (except for a pointer) accessed by some associated key. | |
| 141 | ||
| 142 | Function Names: | |
| 143 | Function names in this library are preceeded by a name related to the types of data they can hash. The convention within the library is to use the type of keys followed by the type of values as the name. For example, if you wanted to insert an integer key and character value into the appropriate table, you would call intcharHash_InsertSingle. For the remainder of this document, the example name will be keyval. | |
| 144 | ||
| 145 | Key-Value Types Supported: | |
| 146 | int-int | |
| 147 | ||
| 148 | Factories: | |
| 149 | In order to avoid compiling code on OpenCL devices an unnecessary number of times, the program files and related info necessary to create a hash table on an OpenCL device are stored in a factory. The type of the factory is keyvalHash_Factory. | |
| 150 | To create a hash table, one must first create a factory. To create a factory, call keyvalHash_CreateFactory. For example: | |
| 151 | keyvalHash_Factory *factory = keyvalHash_CreateFactory(HASH_ALL_HASH_TYPES, NULL, 0, NULL, NULL); | |
| 152 | To destroy the factory, call keyvalHash_DestroyFactory. | |
| 153 | ||
| 154 | Hash Tables: | |
| 155 | When one creates a hash table, they must supply a factory to create it. Memory for the buckets is allocated during creation, so some arguments specifying the size of the table must also be supplied. The type of the hash tables is keyvalHash_Table. To create a hash table, call keyvalHash_CreateTable. For example: | |
| 156 | keyvalHash_Table *table = keyvalHash_CreateTable(factory, HASH_COMPACT_HASHES, 0, 4, 0.5); | |
| 157 | To destroy the hash table, call keyvalHash_DestroyTable. | |
| 158 | ||
| 159 |
| … | … | @@ -1,597 +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 | #undef UNDEFINED | |
| 34 | #ifdef UNDEFINED | |
| 35 | /** | |
| 36 | * @file hash.cm | |
| 37 | * @author Peter Ahrens | |
| 38 | * @date Thu Jun 6 2013 | |
| 39 | */ | |
| 40 | #endif | |
| 41 | ||
| 42 | #define HASH_COMPARE_HASH_INIT_EXP_WRAPPER(INIT_EXP) \ | |
| 43 | INIT_EXP\ | |
| 44 | table->compareFuncData = table->hashFuncData;\ | |
| 45 | \ | |
| 46 | ||
| 47 | #define KEY_VALUE_BASE_HASH_TYPES_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC_DATA)\ | |
| 48 | \ | |
| 49 | typedef struct NAME##MODIFIER##Hash_TableData{\ | |
| 50 | int hashID;\ | |
| 51 | unsigned int numBuckets;\ | |
| 52 | COMPRESS_FUNC_DATA compressFuncData;\ | |
| 53 | }NAME##MODIFIER##Hash_TableData;\ | |
| 54 | \ | |
| 55 | typedef struct NAME##MODIFIER##Hash_Bucket{\ | |
| 56 | KEY_TYPE key;\ | |
| 57 | VALUE_TYPE value;\ | |
| 58 | }NAME##MODIFIER##Hash_Bucket;\ | |
| 59 | \ | |
| 60 | ||
| 61 | #define SENTINEL_VALUE_BASE_HASH_TYPES_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC_DATA)\ | |
| 62 | \ | |
| 63 | typedef struct NAME##MODIFIER##Hash_TableData{\ | |
| 64 | int hashID;\ | |
| 65 | unsigned int numBuckets;\ | |
| 66 | COMPRESS_FUNC_DATA compressFuncData;\ | |
| 67 | VALUE_TYPE emptyValue;\ | |
| 68 | }NAME##MODIFIER##Hash_TableData;\ | |
| 69 | \ | |
| 70 | typedef struct NAME##MODIFIER##Hash_Bucket{\ | |
| 71 | VALUE_TYPE value;\ | |
| 72 | }NAME##MODIFIER##Hash_Bucket;\ | |
| 73 | \ | |
| 74 | ||
| 75 | #define BASE_HASH_UTIL(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, FACTORY_CREATE_EXP, FACTORY_DESTROY_EXP, CREATE_EXP, INIT_EXP, ALLOC_EXP, DESTROY_EXP, EMPTY_EXP)\ | |
| 76 | \ | |
| 77 | NAME##Hash_Table *NAME##MODIFIER##Hash_CreateTable(NAME##Hash_Factory* factory, int hashIndex, size_t keyRange, size_t numEntries, float loadFactor){\ | |
| 78 | NAME##Hash_Table* table = (NAME##Hash_Table*)malloc(sizeof(NAME##Hash_Table));\ | |
| 79 | table->destroyFunc= &NAME##MODIFIER##Hash_DestroyTable;\ | |
| 80 | table->emptyFunc = &NAME##MODIFIER##Hash_EmptyTable;\ | |
| 81 | table->queryFunc = &NAME##MODIFIER##Hash_Query;\ | |
| 82 | table->querySingleFunc = &NAME##MODIFIER##Hash_QuerySingle;\ | |
| 83 | table->insertFunc = &NAME##MODIFIER##Hash_Insert;\ | |
| 84 | table->insertSingleFunc = &NAME##MODIFIER##Hash_InsertSingle;\ | |
| 85 | table->insertNoOverwriteFunc = &NAME##MODIFIER##Hash_InsertNoOverwrite;\ | |
| 86 | table->insertSingleNoOverwriteFunc = &NAME##MODIFIER##Hash_InsertSingleNoOverwrite;\ | |
| 87 | table->tableData = (char*)malloc(sizeof(NAME##MODIFIER##Hash_TableData));\ | |
| 88 | ((NAME##MODIFIER##Hash_TableData*)table->tableData)->hashID = HASH_ID;\ | |
| 89 | CREATE_EXP\ | |
| 90 | INIT_EXP\ | |
| 91 | char* tempHashData = (char*)malloc(sizeof(NAME##MODIFIER##Hash_TableData) + ((NAME##MODIFIER##Hash_TableData*)table->tableData)->numBuckets * sizeof(NAME##MODIFIER##Hash_Bucket));\ | |
| 92 | memcpy(tempHashData, table->tableData, sizeof(NAME##MODIFIER##Hash_TableData));\ | |
| 93 | free(table->tableData);\ | |
| 94 | table->tableData = tempHashData;\ | |
| 95 | ALLOC_EXP\ | |
| 96 | return table;\ | |
| 97 | }\ | |
| 98 | \ | |
| 99 | int NAME##MODIFIER##Hash_CreateFactory(NAME##Hash_Factory *factory, int hashIndex){\ | |
| 100 | factory->createFunc[hashIndex] = &NAME##MODIFIER##Hash_CreateTable;\ | |
| 101 | factory->destroyFunc[hashIndex] = &NAME##MODIFIER##Hash_DestroyFactory;\ | |
| 102 | FACTORY_CREATE_EXP;\ | |
| 103 | return HASH_EXIT_CODE_NORMAL;\ | |
| 104 | }\ | |
| 105 | \ | |
| 106 | int NAME##MODIFIER##Hash_DestroyFactory(NAME##Hash_Factory* factory, int hashIndex){\ | |
| 107 | FACTORY_DESTROY_EXP;\ | |
| 108 | return HASH_EXIT_CODE_NORMAL;\ | |
| 109 | }\ | |
| 110 | \ | |
| 111 | int NAME##MODIFIER##Hash_DestroyTable(NAME##Hash_Table *table){\ | |
| 112 | int exitCode=0;\ | |
| 113 | DESTROY_EXP\ | |
| 114 | free(table->tableData);\ | |
| 115 | free(table);\ | |
| 116 | return exitCode;\ | |
| 117 | }\ | |
| 118 | \ | |
| 119 | int NAME##MODIFIER##Hash_EmptyTable(NAME##Hash_Table *table){\ | |
| 120 | int exitCode=0;\ | |
| 121 | EMPTY_EXP\ | |
| 122 | return exitCode;\ | |
| 123 | }\ | |
| 124 | \ | |
| 125 | ||
| 126 | #define HASH_READ_KEY_EXP (buckets[index].key) | |
| 127 | ||
| 128 | #define CMPXCHG_HASH_READ_KEY_EXP ((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ({buckets[index].key = key; HASH_BUCKET_STATUS_EMPTY;}) : buckets[index].key)\ | |
| 129 | ||
| 130 | #define BASE_HASH_METHODS(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, SEARCH_EXP, READ_KEY_EXP, CL_GLOBAL, ...) \ | |
| 131 | \ | |
| 132 | int NAME##MODIFIER##Hash_InnerQuerySingle(CL_GLOBAL char *tableData, KEY_TYPE key, CL_GLOBAL VALUE_TYPE *valueOutput){\ | |
| 133 | CL_GLOBAL NAME##MODIFIER##Hash_Bucket *buckets = (CL_GLOBAL NAME##MODIFIER##Hash_Bucket*)&tableData[sizeof(NAME##MODIFIER##Hash_TableData)];\ | |
| 134 | int index;\ | |
| 135 | int exitCode;\ | |
| 136 | SEARCH_EXP(NAME, MODIFIER, COMPRESS_FUNC, COMPRESS_FUNC_DATA, HASH_READ_KEY_EXP, CL_GLOBAL, ##__VA_ARGS__)\ | |
| 137 | switch(exitCode){\ | |
| 138 | case HASH_SEARCH_CODE_MATCH:\ | |
| 139 | *valueOutput = buckets[index].value;\ | |
| 140 | return HASH_EXIT_CODE_NORMAL;\ | |
| 141 | case HASH_SEARCH_CODE_MISMATCH:\ | |
| 142 | case HASH_SEARCH_CODE_EMPTY:\ | |
| 143 | return HASH_EXIT_CODE_KEY_DNE;\ | |
| 144 | default:\ | |
| 145 | return exitCode;\ | |
| 146 | }\ | |
| 147 | }\ | |
| 148 | \ | |
| 149 | int NAME##MODIFIER##Hash_InnerQuery(CL_GLOBAL char *tableData, unsigned int numKeys, CL_GLOBAL KEY_TYPE *keys, CL_GLOBAL VALUE_TYPE *valuesOutput){\ | |
| 150 | CL_GLOBAL NAME##MODIFIER##Hash_Bucket *buckets = (CL_GLOBAL NAME##MODIFIER##Hash_Bucket*)&tableData[sizeof(NAME##MODIFIER##Hash_TableData)];\ | |
| 151 | KEY_TYPE key;\ | |
| 152 | CL_GLOBAL VALUE_TYPE *valueOutput;\ | |
| 153 | int index;\ | |
| 154 | int exitCode;\ | |
| 155 | uint i;\ | |
| 156 | int resultExitCode = HASH_EXIT_CODE_NORMAL;\ | |
| 157 | for(i = 0; i < numKeys; i++){\ | |
| 158 | key = keys[i];\ | |
| 159 | valueOutput = &valuesOutput[i];\ | |
| 160 | SEARCH_EXP(NAME, MODIFIER, COMPRESS_FUNC, COMPRESS_FUNC_DATA, HASH_READ_KEY_EXP, CL_GLOBAL, ##__VA_ARGS__)\ | |
| 161 | switch(exitCode){\ | |
| 162 | case HASH_SEARCH_CODE_MATCH:\ | |
| 163 | *valueOutput = buckets[index].value;\ | |
| 164 | break;\ | |
| 165 | case HASH_SEARCH_CODE_MISMATCH:\ | |
| 166 | case HASH_SEARCH_CODE_EMPTY:\ | |
| 167 | resultExitCode = HASH_EXIT_CODE_KEY_DNE;\ | |
| 168 | break;\ | |
| 169 | default:\ | |
| 170 | return exitCode;\ | |
| 171 | }\ | |
| 172 | }\ | |
| 173 | return resultExitCode;\ | |
| 174 | }\ | |
| 175 | \ | |
| 176 | int NAME##MODIFIER##Hash_InnerInsertSingle(CL_GLOBAL char* tableData, KEY_TYPE key, VALUE_TYPE value){\ | |
| 177 | CL_GLOBAL NAME##MODIFIER##Hash_Bucket *buckets = (CL_GLOBAL NAME##MODIFIER##Hash_Bucket*)&tableData[sizeof(NAME##MODIFIER##Hash_TableData)];\ | |
| 178 | int index;\ | |
| 179 | int exitCode;\ | |
| 180 | SEARCH_EXP(NAME, MODIFIER, COMPRESS_FUNC, COMPRESS_FUNC_DATA, READ_KEY_EXP, CL_GLOBAL, ##__VA_ARGS__)\ | |
| 181 | switch(exitCode){\ | |
| 182 | case HASH_SEARCH_CODE_MATCH:\ | |
| 183 | case HASH_SEARCH_CODE_MISMATCH:\ | |
| 184 | buckets[index].value = value;\ | |
| 185 | return HASH_EXIT_CODE_OVERWRITE;\ | |
| 186 | case HASH_SEARCH_CODE_EMPTY:\ | |
| 187 | buckets[index].value = value;\ | |
| 188 | return HASH_EXIT_CODE_NORMAL;\ | |
| 189 | default:\ | |
| 190 | return exitCode;\ | |
| 191 | }\ | |
| 192 | }\ | |
| 193 | \ | |
| 194 | int NAME##MODIFIER##Hash_InnerInsert(CL_GLOBAL char *tableData, unsigned int numEntries, CL_GLOBAL KEY_TYPE *keys, CL_GLOBAL VALUE_TYPE *values){\ | |
| 195 | CL_GLOBAL NAME##MODIFIER##Hash_Bucket *buckets = (CL_GLOBAL NAME##MODIFIER##Hash_Bucket*)&tableData[sizeof(NAME##MODIFIER##Hash_TableData)];\ | |
| 196 | int resultExitCode = HASH_EXIT_CODE_NORMAL;\ | |
| 197 | KEY_TYPE key;\ | |
| 198 | VALUE_TYPE value;\ | |
| 199 | int index;\ | |
| 200 | int exitCode;\ | |
| 201 | uint i;\ | |
| 202 | for(i = 0; i < numEntries; i++){\ | |
| 203 | key = keys[i];\ | |
| 204 | SEARCH_EXP(NAME, MODIFIER, COMPRESS_FUNC, COMPRESS_FUNC_DATA, READ_KEY_EXP, CL_GLOBAL, ##__VA_ARGS__)\ | |
| 205 | switch(exitCode){\ | |
| 206 | case HASH_SEARCH_CODE_MATCH:\ | |
| 207 | case HASH_SEARCH_CODE_MISMATCH:\ | |
| 208 | resultExitCode = HASH_EXIT_CODE_OVERWRITE;\ | |
| 209 | case HASH_SEARCH_CODE_EMPTY:\ | |
| 210 | buckets[index].value = values[i];\ | |
| 211 | break;\ | |
| 212 | default:\ | |
| 213 | return exitCode;\ | |
| 214 | }\ | |
| 215 | }\ | |
| 216 | return resultExitCode;\ | |
| 217 | }\ | |
| 218 | \ | |
| 219 | int NAME##MODIFIER##Hash_InnerInsertSingleNoOverwrite(CL_GLOBAL char *tableData, KEY_TYPE key, VALUE_TYPE value){\ | |
| 220 | CL_GLOBAL NAME##MODIFIER##Hash_Bucket *buckets = (CL_GLOBAL NAME##MODIFIER##Hash_Bucket*)&tableData[sizeof(NAME##MODIFIER##Hash_TableData)];\ | |
| 221 | int index;\ | |
| 222 | int exitCode;\ | |
| 223 | SEARCH_EXP(NAME, MODIFIER, COMPRESS_FUNC, COMPRESS_FUNC_DATA, READ_KEY_EXP, CL_GLOBAL, ##__VA_ARGS__)\ | |
| 224 | switch(exitCode){\ | |
| 225 | case HASH_SEARCH_CODE_MATCH:\ | |
| 226 | case HASH_SEARCH_CODE_MISMATCH:\ | |
| 227 | return HASH_EXIT_CODE_OVERWRITE;\ | |
| 228 | case HASH_SEARCH_CODE_EMPTY:\ | |
| 229 | buckets[index].value = value;\ | |
| 230 | return HASH_EXIT_CODE_NORMAL;\ | |
| 231 | default:\ | |
| 232 | return exitCode;\ | |
| 233 | }\ | |
| 234 | }\ | |
| 235 | \ | |
| 236 | int NAME##MODIFIER##Hash_InnerInsertNoOverwrite(CL_GLOBAL char *tableData, unsigned int numEntries, CL_GLOBAL KEY_TYPE *keys, CL_GLOBAL VALUE_TYPE *values){\ | |
| 237 | CL_GLOBAL NAME##MODIFIER##Hash_Bucket *buckets = (CL_GLOBAL NAME##MODIFIER##Hash_Bucket*)&tableData[sizeof(NAME##MODIFIER##Hash_TableData)];\ | |
| 238 | int resultExitCode = HASH_EXIT_CODE_NORMAL;\ | |
| 239 | KEY_TYPE key;\ | |
| 240 | VALUE_TYPE value;\ | |
| 241 | int index;\ | |
| 242 | int exitCode;\ | |
| 243 | uint i;\ | |
| 244 | for(i = 0; i < numEntries; i++){\ | |
| 245 | key = keys[i];\ | |
| 246 | SEARCH_EXP(NAME, MODIFIER, COMPRESS_FUNC, COMPRESS_FUNC_DATA, READ_KEY_EXP, CL_GLOBAL, ##__VA_ARGS__)\ | |
| 247 | switch(exitCode){\ | |
| 248 | case HASH_SEARCH_CODE_MATCH:\ | |
| 249 | case HASH_SEARCH_CODE_MISMATCH:\ | |
| 250 | resultExitCode = HASH_EXIT_CODE_OVERWRITE;\ | |
| 251 | break;\ | |
| 252 | case HASH_SEARCH_CODE_EMPTY:\ | |
| 253 | buckets[index].value = values[i];\ | |
| 254 | break;\ | |
| 255 | default:\ | |
| 256 | return exitCode;\ | |
| 257 | }\ | |
| 258 | }\ | |
| 259 | return resultExitCode;\ | |
| 260 | }\ | |
| 261 | \ | |
| 262 | ||
| 263 | #define HASH_EMPTY_EXP(NAME, MODIFIER, INNER_EMPTY_EXP)\ | |
| 264 | NAME##MODIFIER##Hash_Bucket *buckets = (NAME##MODIFIER##Hash_Bucket*)&table->tableData[sizeof(NAME##MODIFIER##Hash_TableData)];\ | |
| 265 | int index;\ | |
| 266 | for(index = 0; index < ((NAME##MODIFIER##Hash_TableData*)table->tableData)->numBuckets; index++){\ | |
| 267 | INNER_EMPTY_EXP\ | |
| 268 | }\ | |
| 269 | exitCode = HASH_EXIT_CODE_NORMAL;\ | |
| 270 | \ | |
| 271 | ||
| 272 | #define KEY_VALUE_HASH_INNER_EMPTY_EXP buckets[index].key = HASH_BUCKET_STATUS_EMPTY; | |
| 273 | ||
| 274 | #define SENTINEL_VALUE_HASH_INNER_EMPTY_EXP(NAME, MODIFIER) buckets[index].value = ((NAME##MODIFIER##Hash_TableData*)table->tableData)->emptyValue; | |
| 275 | ||
| 276 | #define BASE_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, BASE_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, FACTORY_CREATE_EXP, CREATE_EXP, INIT_EXP, SEARCH_EXP, INNER_EMPTY_EXP, ...)\ | |
| 277 | \ | |
| 278 | BASE_TYPES_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC_DATA)\ | |
| 279 | \ | |
| 280 | BASE_HASH_UTIL(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, FACTORY_CREATE_EXP, , CREATE_EXP, INIT_EXP, , , HASH_EMPTY_EXP(NAME, MODIFIER, INNER_EMPTY_EXP))\ | |
| 281 | \ | |
| 282 | BASE_HASH_METHODS(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, SEARCH_EXP, CMPXCHG_HASH_READ_KEY_EXP, ,##__VA_ARGS__)\ | |
| 283 | \ | |
| 284 | int NAME##MODIFIER##Hash_QuerySingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE *valueOutput){\ | |
| 285 | return NAME##MODIFIER##Hash_InnerQuerySingle(table->tableData, key, valueOutput);\ | |
| 286 | }\ | |
| 287 | \ | |
| 288 | int NAME##MODIFIER##Hash_Query(NAME##Hash_Table *table, size_t numKeys, KEY_TYPE *keys, VALUE_TYPE *valuesOutput){\ | |
| 289 | return NAME##MODIFIER##Hash_InnerQuery(table->tableData, numKeys, keys, valuesOutput);\ | |
| 290 | }\ | |
| 291 | \ | |
| 292 | int NAME##MODIFIER##Hash_InsertSingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value){\ | |
| 293 | return NAME##MODIFIER##Hash_InnerInsertSingle(table->tableData, key, value);\ | |
| 294 | }\ | |
| 295 | \ | |
| 296 | int NAME##MODIFIER##Hash_Insert(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values){\ | |
| 297 | return NAME##MODIFIER##Hash_InnerInsert(table->tableData, numEntries, keys, values);\ | |
| 298 | }\ | |
| 299 | \ | |
| 300 | int NAME##MODIFIER##Hash_InsertSingleNoOverwrite(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value){\ | |
| 301 | return NAME##MODIFIER##Hash_InnerInsertSingleNoOverwrite(table->tableData, key, value);\ | |
| 302 | }\ | |
| 303 | \ | |
| 304 | int NAME##MODIFIER##Hash_InsertNoOverwrite(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values){\ | |
| 305 | return NAME##MODIFIER##Hash_InnerInsertNoOverwrite(table->tableData, numEntries, keys, values);\ | |
| 306 | }\ | |
| 307 | \ | |
| 308 | ||
| 309 | #define CL_FACTORY_CREATE_EXP(NAME, MODIFIER, FACTORY_CREATE_EXP, UTIL_PROGRAM_SOURCE)\ | |
| 310 | cl_int error;\ | |
| 311 | cl_device_id device;\ | |
| 312 | error = clGetContextInfo(factory->context, CL_CONTEXT_DEVICES, sizeof(device), &device, NULL);\ | |
| 313 | CLHash_Utilities_HandleError(error, STRINGIFY(NAME##Hash_CreateFactory), "clGetContextInfo");\ | |
| 314 | factory->querySingleKernel[hashIndex] = clCreateKernel(factory->program, STRINGIFY(NAME##MODIFIER##CLHash_RangeQuerySingle), &error);\ | |
| 315 | CLHash_Utilities_HandleError(error, STRINGIFY(NAME##MODIFIER##CLHash_CreateFactory), "clCreateKernel");\ | |
| 316 | factory->insertSingleKernel[hashIndex] = clCreateKernel(factory->program, STRINGIFY(NAME##MODIFIER##CLHash_RangeInsertSingle), &error);\ | |
| 317 | CLHash_Utilities_HandleError(error, STRINGIFY(NAME##MODIFIER##CLHash_CreateFactory), "clCreateKernel");\ | |
| 318 | factory->insertSingleNoOverwriteKernel[hashIndex] = clCreateKernel(factory->program, STRINGIFY(NAME##MODIFIER##CLHash_RangeInsertSingleNoOverwrite), &error);\ | |
| 319 | CLHash_Utilities_HandleError(error, STRINGIFY(NAME##MODIFIER##CLHash_CreateFactory), "clCreateKernel");\ | |
| 320 | factory->utilProgram[hashIndex] = CLHash_Utilities_BuildProgramString(factory->context, device, UTIL_PROGRAM_SOURCE);\ | |
| 321 | factory->emptyKernel[hashIndex] = clCreateKernel(factory->utilProgram[hashIndex], STRINGIFY(NAME##MODIFIER##CLHash_Empty), &error);\ | |
| 322 | CLHash_Utilities_HandleError(error, STRINGIFY(NAME##MODIFIER##CLHash_CreateFactory), "clCreateKernel");\ | |
| 323 | error = clGetKernelWorkGroupInfo(factory->emptyKernel[hashIndex], device, CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), &factory->emptyKernelLocalWorkSize[hashIndex], NULL);\ | |
| 324 | CLHash_Utilities_HandleError(error, STRINGIFY(NAME##MODIFIER##CLHash_CreateFactory), "clGetKernelWorkGroupInfo");\ | |
| 325 | FACTORY_CREATE_EXP;\ | |
| 326 | \ | |
| 327 | ||
| 328 | #define CL_FACTORY_DESTROY_EXP(NAME, MODIFIER, FACTORY_DESTROY_EXP)\ | |
| 329 | FACTORY_DESTROY_EXP;\ | |
| 330 | clReleaseKernel(factory->emptyKernel[hashIndex]);\ | |
| 331 | clReleaseProgram(factory->utilProgram[hashIndex]);\ | |
| 332 | clReleaseKernel(factory->querySingleKernel[hashIndex]);\ | |
| 333 | clReleaseKernel(factory->insertSingleKernel[hashIndex]);\ | |
| 334 | clReleaseKernel(factory->insertSingleNoOverwriteKernel[hashIndex]);\ | |
| 335 | \ | |
| 336 | ||
| 337 | #define CL_CREATE_EXP(NAME, MODIFIER, CREATE_EXP)\ | |
| 338 | table->context = factory->context;\ | |
| 339 | table->queue = factory->queue;\ | |
| 340 | table->program = factory->program;\ | |
| 341 | table->localWorkSize = factory->localWorkSize;\ | |
| 342 | table->utilProgram = factory->utilProgram[hashIndex];\ | |
| 343 | table->emptyKernel = factory->emptyKernel[hashIndex];\ | |
| 344 | table->emptyKernelLocalWorkSize = factory->emptyKernelLocalWorkSize[hashIndex];\ | |
| 345 | table->querySingleKernel = factory->querySingleKernel[hashIndex];\ | |
| 346 | table->insertSingleKernel = factory->insertSingleKernel[hashIndex];\ | |
| 347 | table->insertSingleNoOverwriteKernel = factory->insertSingleNoOverwriteKernel[hashIndex];\ | |
| 348 | clRetainContext(table->context);\ | |
| 349 | clRetainCommandQueue(table->queue);\ | |
| 350 | clRetainProgram(table->program);\ | |
| 351 | clRetainProgram(table->utilProgram);\ | |
| 352 | clRetainKernel(table->emptyKernel);\ | |
| 353 | clRetainKernel(table->querySingleKernel);\ | |
| 354 | clRetainKernel(table->insertSingleKernel);\ | |
| 355 | clRetainKernel(table->insertSingleNoOverwriteKernel);\ | |
| 356 | CREATE_EXP;\ | |
| 357 | \ | |
| 358 | ||
| 359 | #define CL_ALLOC_EXP(NAME, MODIFIER)\ | |
| 360 | cl_int err;\ | |
| 361 | table->tableDataBuffer = clCreateBuffer(table->context, CL_MEM_READ_WRITE, sizeof(NAME##MODIFIER##Hash_TableData) + ((NAME##MODIFIER##Hash_TableData*)table->tableData)->numBuckets * sizeof(NAME##MODIFIER##Hash_Bucket), NULL, &err);\ | |
| 362 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_InitTable), "clCreateBuffer");\ | |
| 363 | err = clEnqueueWriteBuffer(table->queue, table->tableDataBuffer, CL_TRUE, 0, sizeof(NAME##MODIFIER##Hash_TableData), table->tableData, 0, NULL, NULL);\ | |
| 364 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_InitTable), "clEnqueueWriteBuffer");\ | |
| 365 | \ | |
| 366 | ||
| 367 | #define CL_EMPTY_EXP(NAME, MODIFIER, EMPTY_EXP)\ | |
| 368 | cl_int err;\ | |
| 369 | err = clSetKernelArg(table->emptyKernel, 0, sizeof(cl_mem), &table->tableDataBuffer);\ | |
| 370 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_EmptyTable), "clSetKernelArg");\ | |
| 371 | const size_t groupWorkSize = roundUpToNearest(((NAME##MODIFIER##Hash_TableData*)table->tableData)->numBuckets, table->emptyKernelLocalWorkSize);\ | |
| 372 | err = clEnqueueNDRangeKernel(table->queue, table->emptyKernel, 1, 0, &groupWorkSize, (const size_t*)&table->emptyKernelLocalWorkSize, 0, NULL, NULL);\ | |
| 373 | \ | |
| 374 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_EmptyTable), "clEnqueueNDRangeKernel");\ | |
| 375 | exitCode = HASH_EXIT_CODE_NORMAL;\ | |
| 376 | EMPTY_EXP;\ | |
| 377 | \ | |
| 378 | ||
| 379 | #define CL_DESTROY_EXP(NAME)\ | |
| 380 | clReleaseMemObject(table->tableDataBuffer);\ | |
| 381 | clReleaseContext(table->context);\ | |
| 382 | clReleaseCommandQueue(table->queue);\ | |
| 383 | clReleaseProgram(table->utilProgram);\ | |
| 384 | clReleaseKernel(table->emptyKernel);\ | |
| 385 | clReleaseProgram(table->program);\ | |
| 386 | clReleaseKernel(table->querySingleKernel);\ | |
| 387 | clReleaseKernel(table->insertSingleKernel);\ | |
| 388 | clReleaseKernel(table->insertSingleNoOverwriteKernel);\ | |
| 389 | \ | |
| 390 | ||
| 391 | #define KEY_VALUE_CL_HASH_INNER_EMPTY_EXP buckets[index].key = -1;/*HASH_BUCKET_STATUS_EMPTY*/ | |
| 392 | ||
| 393 | #define SENTINEL_VALUE_CL_HASH_INNER_EMPTY_EXP(NAME, MODIFIER) buckets[index].value = ((__global NAME##MODIFIER##Hash_TableData*)tableData)->emptyValue; | |
| 394 | ||
| 395 | #define CL_UTIL_PROGRAM(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, BASE_TYPES_DEFINE, COMPRESS_FUNC_DATA, INNER_EMPTY_EXP)\ | |
| 396 | \ | |
| 397 | HASH_H_TYPES_DECLARE(NAME, KEY_TYPE)\ | |
| 398 | \ | |
| 399 | BASE_TYPES_DEFINE(NAME, MODIFIER##CL, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC_DATA)\ | |
| 400 | \ | |
| 401 | __kernel void NAME##MODIFIER##CLHash_Empty(__global char *tableData){\ | |
| 402 | int index = get_global_id(0);\ | |
| 403 | if(index >= ((__global NAME##MODIFIER##CLHash_TableData*)tableData)->numBuckets){\ | |
| 404 | return;\ | |
| 405 | }\ | |
| 406 | __global NAME##MODIFIER##CLHash_Bucket *buckets = (__global NAME##MODIFIER##CLHash_Bucket*)&tableData[sizeof(NAME##MODIFIER##CLHash_TableData)];\ | |
| 407 | INNER_EMPTY_EXP\ | |
| 408 | }\ | |
| 409 | \ | |
| 410 | ||
| 411 | #define ATOMIC_CMPXCHG_HASH_READ_KEY_EXP (atomic_cmpxchg(&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY, key))\ | |
| 412 | ||
| 413 | #define CL_HASH_KERN_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, BASE_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, READ_KEY_EXP, SEARCH_EXP, ...) \ | |
| 414 | \ | |
| 415 | BASE_TYPES_DEFINE(NAME, MODIFIER##CL, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC_DATA)\ | |
| 416 | \ | |
| 417 | BASE_HASH_METHODS(NAME, MODIFIER##CL, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, SEARCH_EXP, READ_KEY_EXP, __global, ##__VA_ARGS__) \ | |
| 418 | \ | |
| 419 | int NAME##MODIFIER##CLHash_QuerySingle(__global char *tableData, KEY_TYPE key, __global VALUE_TYPE *valueOutput){\ | |
| 420 | return NAME##MODIFIER##CLHash_InnerQuerySingle(tableData, key, valueOutput);\ | |
| 421 | }\ | |
| 422 | \ | |
| 423 | int NAME##MODIFIER##CLHash_Query(__global char *tableData, size_t numKeys, __global KEY_TYPE *keys, __global VALUE_TYPE *valuesOutput){\ | |
| 424 | return NAME##MODIFIER##CLHash_InnerQuery(tableData, numKeys, keys, valuesOutput);\ | |
| 425 | }\ | |
| 426 | \ | |
| 427 | int NAME##MODIFIER##CLHash_InsertSingle(__global char *tableData, KEY_TYPE key, VALUE_TYPE value){\ | |
| 428 | return NAME##MODIFIER##CLHash_InnerInsertSingle(tableData, key, value);\ | |
| 429 | }\ | |
| 430 | \ | |
| 431 | int NAME##MODIFIER##CLHash_Insert(__global char *tableData, size_t numEntries, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 432 | return NAME##MODIFIER##CLHash_InnerInsert(tableData, numEntries, keys, values);\ | |
| 433 | }\ | |
| 434 | \ | |
| 435 | int NAME##MODIFIER##CLHash_InsertSingleNoOverwrite(__global char *tableData, KEY_TYPE key, VALUE_TYPE value){\ | |
| 436 | return NAME##MODIFIER##CLHash_InnerInsertSingleNoOverwrite(tableData, key, value);\ | |
| 437 | }\ | |
| 438 | \ | |
| 439 | int NAME##MODIFIER##CLHash_InsertNoOverwrite(__global char *tableData, size_t numEntries, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 440 | return NAME##MODIFIER##CLHash_InnerInsertNoOverwrite(tableData, numEntries, keys, values);\ | |
| 441 | }\ | |
| 442 | \ | |
| 443 | __kernel void NAME##MODIFIER##CLHash_RangeQuerySingle(__global char *tableData, unsigned int numQueries, __global KEY_TYPE *keys, __global VALUE_TYPE *valuesOutput){\ | |
| 444 | uint i = get_global_id(0);\ | |
| 445 | if(i >= numQueries){\ | |
| 446 | return;\ | |
| 447 | }\ | |
| 448 | NAME##MODIFIER##CLHash_InnerQuerySingle(tableData, keys[i], valuesOutput + i);\ | |
| 449 | }\ | |
| 450 | \ | |
| 451 | __kernel void NAME##MODIFIER##CLHash_RangeQuery(__global char *tableData, unsigned int numQueries, unsigned int numKeys, __global KEY_TYPE *keys, __global VALUE_TYPE *valuesOutput){\ | |
| 452 | uint i = get_global_id(0);\ | |
| 453 | if(i >= numQueries){\ | |
| 454 | return;\ | |
| 455 | }\ | |
| 456 | NAME##MODIFIER##CLHash_InnerQuery(tableData, numKeys, keys + (i*numKeys), valuesOutput + (i*numKeys));\ | |
| 457 | }\ | |
| 458 | \ | |
| 459 | __kernel void NAME##MODIFIER##CLHash_RangeInsertSingle(__global char *tableData, unsigned int numInsertions, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 460 | uint i = get_global_id(0);\ | |
| 461 | if(i >= numInsertions){\ | |
| 462 | return;\ | |
| 463 | }\ | |
| 464 | NAME##MODIFIER##CLHash_InnerInsertSingle(tableData, keys[i], values[i]);\ | |
| 465 | }\ | |
| 466 | \ | |
| 467 | __kernel void NAME##MODIFIER##CLHash_RangeInsert(__global char *tableData, unsigned int numInsertions, unsigned int numEntries, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 468 | uint i = get_global_id(0);\ | |
| 469 | if(i >= numInsertions){\ | |
| 470 | return;\ | |
| 471 | }\ | |
| 472 | NAME##MODIFIER##CLHash_InnerInsert(tableData, numEntries, keys + (i*numEntries), values + (i*numEntries));\ | |
| 473 | }\ | |
| 474 | \ | |
| 475 | __kernel void NAME##MODIFIER##CLHash_RangeInsertSingleNoOverwrite(__global char* tableData, unsigned int numInsertions, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 476 | uint i = get_global_id(0);\ | |
| 477 | if(i >= numInsertions){\ | |
| 478 | return;\ | |
| 479 | }\ | |
| 480 | NAME##MODIFIER##CLHash_InnerInsertSingleNoOverwrite(tableData, keys[i], values[i]);\ | |
| 481 | }\ | |
| 482 | \ | |
| 483 | __kernel void NAME##MODIFIER##CLHash_RangeInsertNoOverwrite(__global char *tableData, unsigned int numInsertions, unsigned int numEntries, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 484 | uint i = get_global_id(0);\ | |
| 485 | if(i >= numInsertions){\ | |
| 486 | return;\ | |
| 487 | }\ | |
| 488 | NAME##MODIFIER##CLHash_InnerInsertNoOverwrite(tableData, numEntries, keys + (i*numEntries), values + (i*numEntries));\ | |
| 489 | }\ | |
| 490 | \ | |
| 491 | ||
| 492 | #define CL_BASE_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, BASE_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, FACTORY_CREATE_EXP, CREATE_EXP, INIT_EXP, INNER_EMPTY_EXP, ...)\ | |
| 493 | \ | |
| 494 | BASE_TYPES_DEFINE(NAME, MODIFIER##CL, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC_DATA)\ | |
| 495 | \ | |
| 496 | BASE_HASH_UTIL(NAME, MODIFIER##CL, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, CL_FACTORY_CREATE_EXP(NAME, MODIFIER, FACTORY_CREATE_EXP, STRINGIFY(CL_UTIL_PROGRAM(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, BASE_TYPES_DEFINE, COMPRESS_FUNC_DATA, INNER_EMPTY_EXP))), CL_FACTORY_DESTROY_EXP(NAME, MODIFIER, ), CL_CREATE_EXP(NAME, MODIFIER, CREATE_EXP), INIT_EXP, CL_ALLOC_EXP(NAME, MODIFIER), CL_DESTROY_EXP(NAME), CL_EMPTY_EXP(NAME, MODIFIER, ))\ | |
| 497 | \ | |
| 498 | int NAME##MODIFIER##CLHash_QuerySingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE *valueOutput){\ | |
| 499 | return NAME##MODIFIER##CLHash_Query(table, 1, &key, valueOutput);\ | |
| 500 | }\ | |
| 501 | \ | |
| 502 | int NAME##MODIFIER##CLHash_Query(NAME##Hash_Table *table, size_t numKeys, KEY_TYPE *keys, VALUE_TYPE *valuesOutput){\ | |
| 503 | cl_int err;\ | |
| 504 | cl_mem keysBuffer = clCreateBuffer(table->context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(KEY_TYPE) * numKeys, keys, &err);\ | |
| 505 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_Query), "clCreateBuffer");\ | |
| 506 | cl_mem valuesOutputBuffer = clCreateBuffer(table->context, CL_MEM_WRITE_ONLY, sizeof(VALUE_TYPE) * numKeys, NULL, &err);\ | |
| 507 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_Query), "clCreateBuffer");\ | |
| 508 | NAME##MODIFIER##CLHash_BufferQuery(table, numKeys, keysBuffer, valuesOutputBuffer);\ | |
| 509 | err = clEnqueueReadBuffer(table->queue, valuesOutputBuffer, CL_TRUE, 0, sizeof(VALUE_TYPE) * numKeys, valuesOutput, 0, NULL, NULL);\ | |
| 510 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_Query), "clEnqueueReadBuffer");\ | |
| 511 | clReleaseMemObject(keysBuffer);\ | |
| 512 | clReleaseMemObject(valuesOutputBuffer);\ | |
| 513 | return HASH_EXIT_CODE_NORMAL;\ | |
| 514 | }\ | |
| 515 | \ | |
| 516 | int NAME##MODIFIER##CLHash_BufferQuery(NAME##Hash_Table *table, size_t numKeys, cl_mem keysBuffer, cl_mem valuesOutputBuffer){\ | |
| 517 | cl_int err;\ | |
| 518 | err = clSetKernelArg(table->querySingleKernel, 0, sizeof(cl_mem), &table->tableDataBuffer);\ | |
| 519 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferQuery), "clSetKernelArg");\ | |
| 520 | err = clSetKernelArg(table->querySingleKernel, 1, sizeof(unsigned int), &numKeys);\ | |
| 521 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferQuery), "clSetKernelArg");\ | |
| 522 | err = clSetKernelArg(table->querySingleKernel, 2, sizeof(cl_mem), &keysBuffer);\ | |
| 523 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferQuery), "clSetKernelArg");\ | |
| 524 | err = clSetKernelArg(table->querySingleKernel, 3, sizeof(cl_mem), &valuesOutputBuffer);\ | |
| 525 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferQuery), "clSetKernelArg");\ | |
| 526 | const size_t groupWorkSize = roundUpToNearest(numKeys, table->localWorkSize);\ | |
| 527 | err = clEnqueueNDRangeKernel(table->queue, table->querySingleKernel, 1, 0, &groupWorkSize, (const size_t*)&table->localWorkSize, 0, NULL, NULL);\ | |
| 528 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferQuery), "clEnqueueNDRangeKernel");\ | |
| 529 | clFinish(table->queue);\ | |
| 530 | return HASH_EXIT_CODE_NORMAL;\ | |
| 531 | }\ | |
| 532 | \ | |
| 533 | int NAME##MODIFIER##CLHash_InsertSingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value){\ | |
| 534 | return NAME##MODIFIER##CLHash_Insert(table, 1, &key, &value);\ | |
| 535 | }\ | |
| 536 | \ | |
| 537 | int NAME##MODIFIER##CLHash_Insert(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values){\ | |
| 538 | cl_int err;\ | |
| 539 | cl_mem keysBuffer = clCreateBuffer(table->context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(KEY_TYPE) * numEntries, keys, &err);\ | |
| 540 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_Insert), "clCreateBuffer");\ | |
| 541 | cl_mem valuesBuffer = clCreateBuffer(table->context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(VALUE_TYPE) * numEntries, values, &err);\ | |
| 542 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_Insert), "clCreateBuffer");\ | |
| 543 | NAME##MODIFIER##CLHash_BufferInsert(table, numEntries, keysBuffer, valuesBuffer);\ | |
| 544 | clReleaseMemObject(keysBuffer);\ | |
| 545 | clReleaseMemObject(valuesBuffer);\ | |
| 546 | return HASH_EXIT_CODE_NORMAL;\ | |
| 547 | }\ | |
| 548 | \ | |
| 549 | int NAME##MODIFIER##CLHash_BufferInsert(NAME##Hash_Table *table, size_t numEntries, cl_mem keysBuffer, cl_mem valuesBuffer){\ | |
| 550 | cl_int err;\ | |
| 551 | err = clSetKernelArg(table->insertSingleKernel, 0, sizeof(cl_mem), &table->tableDataBuffer);\ | |
| 552 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferInsert), "clSetKernelArg");\ | |
| 553 | err = clSetKernelArg(table->insertSingleKernel, 1, sizeof(unsigned int), &numEntries);\ | |
| 554 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferInsert), "clSetKernelArg");\ | |
| 555 | err = clSetKernelArg(table->insertSingleKernel, 2, sizeof(cl_mem), &keysBuffer);\ | |
| 556 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferInsert), "clSetKernelArg");\ | |
| 557 | err = clSetKernelArg(table->insertSingleKernel, 3, sizeof(cl_mem), &valuesBuffer);\ | |
| 558 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferInsert), "clSetKernelArg");\ | |
| 559 | const size_t groupWorkSize = roundUpToNearest(numEntries, table->localWorkSize);\ | |
| 560 | err = clEnqueueNDRangeKernel(table->queue, table->insertSingleKernel, 1, 0, &groupWorkSize, (const size_t*)&table->localWorkSize, 0, NULL, NULL);\ | |
| 561 | CLHash_Utilities_HandleError(err, NULL, "clEnqueueNDRangeKernel");\ | |
| 562 | return(0);\ | |
| 563 | }\ | |
| 564 | \ | |
| 565 | int NAME##MODIFIER##CLHash_InsertSingleNoOverwrite(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value){\ | |
| 566 | return NAME##MODIFIER##CLHash_InsertNoOverwrite(table, 1, &key, &value);\ | |
| 567 | }\ | |
| 568 | \ | |
| 569 | int NAME##MODIFIER##CLHash_InsertNoOverwrite(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values){\ | |
| 570 | cl_int err;\ | |
| 571 | cl_mem keysBuffer = clCreateBuffer(table->context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(KEY_TYPE) * numEntries, keys, &err);\ | |
| 572 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_InsertNoOverwrite), "clCreateBuffer");\ | |
| 573 | cl_mem valuesBuffer = clCreateBuffer(table->context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(VALUE_TYPE) * numEntries, values, &err);\ | |
| 574 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_InsertNoOverwrite), "clCreateBuffer");\ | |
| 575 | NAME##MODIFIER##CLHash_BufferInsertNoOverwrite(table, numEntries, keysBuffer, valuesBuffer);\ | |
| 576 | clReleaseMemObject(keysBuffer);\ | |
| 577 | clReleaseMemObject(valuesBuffer);\ | |
| 578 | return HASH_EXIT_CODE_NORMAL;\ | |
| 579 | }\ | |
| 580 | \ | |
| 581 | int NAME##MODIFIER##CLHash_BufferInsertNoOverwrite(NAME##Hash_Table *table, size_t numEntries, cl_mem keysBuffer, cl_mem valuesBuffer){\ | |
| 582 | cl_int err;\ | |
| 583 | err = clSetKernelArg(table->insertSingleNoOverwriteKernel, 0, sizeof(cl_mem), &table->tableDataBuffer);\ | |
| 584 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferInsertNoOverwrite), "clSetKernelArg");\ | |
| 585 | err = clSetKernelArg(table->insertSingleNoOverwriteKernel, 1, sizeof(unsigned int), &numEntries);\ | |
| 586 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferInsertNoOverwrite), "ClSetKernelArg");\ | |
| 587 | err = clSetKernelArg(table->insertSingleNoOverwriteKernel, 2, sizeof(cl_mem), &keysBuffer);\ | |
| 588 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferInsertNoOverwrite), "clSetKernelArg");\ | |
| 589 | err = clSetKernelArg(table->insertSingleNoOverwriteKernel, 3, sizeof(cl_mem), &valuesBuffer);\ | |
| 590 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferInsertNoOverwrite), "clSetKernelArg");\ | |
| 591 | const size_t groupWorkSize = roundUpToNearest(numEntries, table->localWorkSize);\ | |
| 592 | err = clEnqueueNDRangeKernel(table->queue, table->insertSingleNoOverwriteKernel, 1, 0, &groupWorkSize, (const size_t*)&table->localWorkSize, 0, NULL, NULL);\ | |
| 593 | CLHash_Utilities_HandleError(err, STRINGIFY(NAME##MODIFIER##CLHash_BufferInsertNoOverwrite), "clEnqueueNDRangeKernel");\ | |
| 594 | return(0);\ | |
| 595 | }\ | |
| 596 | \ | |
| 597 |
| … | … | @@ -1,82 +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 | #undef UNDEFINED | |
| 34 | #ifdef UNDEFINED | |
| 35 | /** | |
| 36 | * @file hash.hm | |
| 37 | * @author Peter Ahrens | |
| 38 | * @date Thu Jun 6 2013 | |
| 39 | */ | |
| 40 | #endif | |
| 41 | ||
| 42 | ||
| 43 | #define BASE_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 44 | \ | |
| 45 | int NAME##MODIFIER##Hash_CreateFactory(NAME##Hash_Factory *factory, int hashIndex);\ | |
| 46 | \ | |
| 47 | int NAME##MODIFIER##Hash_DestroyFactory(NAME##Hash_Factory *factory, int hashIndex);\ | |
| 48 | \ | |
| 49 | NAME##Hash_Table *NAME##MODIFIER##Hash_CreateTable(NAME##Hash_Factory* factory, int hashIndex, size_t keyRange, size_t numEntries, float loadFactor);\ | |
| 50 | \ | |
| 51 | int NAME##MODIFIER##Hash_InitTable(NAME##Hash_Table *table, va_list args);\ | |
| 52 | \ | |
| 53 | int NAME##MODIFIER##Hash_DestroyTable(NAME##Hash_Table *table);\ | |
| 54 | \ | |
| 55 | char *NAME##MODIFIER##Hash_Report(NAME##Hash_Table *table);\ | |
| 56 | \ | |
| 57 | int NAME##MODIFIER##Hash_EmptyTable(NAME##Hash_Table *table);\ | |
| 58 | \ | |
| 59 | int NAME##MODIFIER##Hash_Query(NAME##Hash_Table *table, size_t numKeys, KEY_TYPE *keys, VALUE_TYPE *valuesOutput);\ | |
| 60 | \ | |
| 61 | int NAME##MODIFIER##Hash_QuerySingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE *valueOutput);\ | |
| 62 | \ | |
| 63 | int NAME##MODIFIER##Hash_Insert(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values);\ | |
| 64 | \ | |
| 65 | int NAME##MODIFIER##Hash_InsertSingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value);\ | |
| 66 | \ | |
| 67 | int NAME##MODIFIER##Hash_InsertNoOverwrite(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values);\ | |
| 68 | \ | |
| 69 | int NAME##MODIFIER##Hash_InsertSingleNoOverwrite(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value);\ | |
| 70 | \ | |
| 71 | ||
| 72 | #define CL_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 73 | \ | |
| 74 | BASE_HASH_DECLARE(NAME, MODIFIER##CL, KEY_TYPE, VALUE_TYPE)\ | |
| 75 | \ | |
| 76 | int NAME##MODIFIER##CLHash_BufferQuery(NAME##Hash_Table *table, size_t numKeys, cl_mem keysBuffer, cl_mem valuesOutputBuffer);\ | |
| 77 | \ | |
| 78 | int NAME##MODIFIER##CLHash_BufferInsert(NAME##Hash_Table *table, size_t numEntries, cl_mem keysBuffer, cl_mem valuesBuffer);\ | |
| 79 | \ | |
| 80 | int NAME##MODIFIER##CLHash_BufferInsertNoOverwrite(NAME##Hash_Table *table, size_t numEntries, cl_mem keysBuffer, cl_mem valuesBuffer);\ | |
| 81 | \ | |
| 82 |
| … | … | @@ -1,181 +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 | #undef UNDEFINED | |
| 34 | #ifdef UNDEFINED | |
| 35 | /** | |
| 36 | * @file compactHash.cm | |
| 37 | * @author Peter Ahrens | |
| 38 | * @date Thu Jun 6 2013 | |
| 39 | */ | |
| 40 | #endif | |
| 41 | #include "baseHash.cm" | |
| 42 | ||
| 43 | #define COMPACT_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP, SEARCH_EXP, ...)\ | |
| 44 | \ | |
| 45 | BASE_HASH_DEFINE(NAME, MODIFIER##Compact, HASH_ID, KEY_TYPE, VALUE_TYPE, KEY_VALUE_BASE_HASH_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA,,, INIT_EXP, SEARCH_EXP, KEY_VALUE_HASH_INNER_EMPTY_EXP, ##__VA_ARGS__)\ | |
| 46 | \ | |
| 47 | ||
| 48 | #define COMPACT_CL_HASH_KERN_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, SEARCH_EXP, ...)\ | |
| 49 | \ | |
| 50 | CL_HASH_KERN_DEFINE(NAME, MODIFIER##Compact, KEY_TYPE, VALUE_TYPE, KEY_VALUE_BASE_HASH_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, ATOMIC_CMPXCHG_HASH_READ_KEY_EXP, SEARCH_EXP, ##__VA_ARGS__)\ | |
| 51 | \ | |
| 52 | ||
| 53 | #define COMPACT_CL_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP)\ | |
| 54 | \ | |
| 55 | CL_BASE_HASH_DEFINE(NAME, MODIFIER##Compact, HASH_ID, KEY_TYPE, VALUE_TYPE, KEY_VALUE_BASE_HASH_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA,,, INIT_EXP, KEY_VALUE_CL_HASH_INNER_EMPTY_EXP)\ | |
| 56 | \ | |
| 57 | ||
| 58 | #define OPEN_COMPACT_HASH_INIT_EXP(NAME, MODIFIER, INIT_EXP) \ | |
| 59 | ((NAME##MODIFIER##Hash_TableData*)table->tableData)->numBuckets = (unsigned int)((double)numEntries / loadFactor);\ | |
| 60 | INIT_EXP\ | |
| 61 | \ | |
| 62 | ||
| 63 | #ifdef XXX | |
| 64 | unsigned int c = COMPRESS_FUNC(((CL_GLOBAL NAME##MODIFIER##Hash_TableData*)tableData)->compressFuncData, key);\ | |
| 65 | ||
| 66 | #endif | |
| 67 | ||
| 68 | #define OPEN_COMPACT_HASH_SEARCH_EXP(NAME, MODIFIER, COMPRESS_FUNC, COMPRESS_FUNC_DATA, READ_KEY_EXP, CL_GLOBAL, JUMP_EXP, CYCLE_EXP) \ | |
| 69 | GLOBAL NAME##MODIFIER##Hash_TableData* mytableData = (GLOBAL NAME##MODIFIER##Hash_TableData*)tableData;\ | |
| 70 | NAME##Hash_CompressLCGData compressFuncData = mytableData->compressFuncData;\ | |
| 71 | unsigned int c = COMPRESS_FUNC(compressFuncData, key);\ | |
| 72 | unsigned long int iteration = 0;\ | |
| 73 | for(;;){\ | |
| 74 | index = JUMP_EXP;\ | |
| 75 | if(READ_KEY_EXP == HASH_BUCKET_STATUS_EMPTY){\ | |
| 76 | exitCode = HASH_SEARCH_CODE_EMPTY;\ | |
| 77 | break;\ | |
| 78 | }else if(key == buckets[index].key){\ | |
| 79 | exitCode = HASH_SEARCH_CODE_MATCH;\ | |
| 80 | break;\ | |
| 81 | }else if(CYCLE_EXP){\ | |
| 82 | exitCode = HASH_EXIT_CODE_CYCLE;\ | |
| 83 | break;\ | |
| 84 | }\ | |
| 85 | iteration++;\ | |
| 86 | }\ | |
| 87 | \ | |
| 88 | ||
| 89 | #define OPEN_COMPACT_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP, ...)\ | |
| 90 | \ | |
| 91 | COMPACT_HASH_DEFINE(NAME, MODIFIER##Open, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, OPEN_COMPACT_HASH_INIT_EXP(NAME, MODIFIER##OpenCompact, INIT_EXP), OPEN_COMPACT_HASH_SEARCH_EXP, ##__VA_ARGS__)\ | |
| 92 | ||
| 93 | #define OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP, ...)\ | |
| 94 | \ | |
| 95 | COMPACT_CL_HASH_KERN_DEFINE(NAME, MODIFIER##Open, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, OPEN_COMPACT_HASH_SEARCH_EXP, ##__VA_ARGS__)\ | |
| 96 | \ | |
| 97 | ||
| 98 | #define OPEN_COMPACT_CL_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP)\ | |
| 99 | \ | |
| 100 | COMPACT_CL_HASH_DEFINE(NAME, MODIFIER##Open, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, OPEN_COMPACT_HASH_INIT_EXP(NAME, MODIFIER##OpenCompactCL, INIT_EXP))\ | |
| 101 | \ | |
| 102 | ||
| 103 | #define LINEAR_OPEN_COMPACT_HASH_JUMP_EXP(NAME, MODIFIER, B, CL_GLOBAL) ((B * iteration + c) % ((CL_GLOBAL NAME##MODIFIER##Hash_TableData*)tableData)->numBuckets) | |
| 104 | ||
| 105 | #define LINEAR_OPEN_COMPACT_HASH_CYCLE_EXP (index == c && iteration > 0) | |
| 106 | ||
| 107 | #define LINEAR_OPEN_COMPACT_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP, B)\ | |
| 108 | \ | |
| 109 | OPEN_COMPACT_HASH_DEFINE(NAME, MODIFIER##Linear, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP, LINEAR_OPEN_COMPACT_HASH_JUMP_EXP(NAME, MODIFIER##LinearOpenCompact, B,), LINEAR_OPEN_COMPACT_HASH_CYCLE_EXP)\ | |
| 110 | ||
| 111 | #define LINEAR_OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP, B)\ | |
| 112 | \ | |
| 113 | OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, MODIFIER##Linear, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP, LINEAR_OPEN_COMPACT_HASH_JUMP_EXP(NAME, MODIFIER##LinearOpenCompactCL, B, __global), LINEAR_OPEN_COMPACT_HASH_CYCLE_EXP)\ | |
| 114 | \ | |
| 115 | ||
| 116 | #define LINEAR_OPEN_COMPACT_CL_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP)\ | |
| 117 | \ | |
| 118 | OPEN_COMPACT_CL_HASH_DEFINE(NAME, MODIFIER##Linear, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP)\ | |
| 119 | \ | |
| 120 | ||
| 121 | #define QUADRATIC_OPEN_COMPACT_HASH_JUMP_EXP(NAME, MODIFIER, A, B, CL_GLOBAL) ((A * iteration * iteration + B * iteration + c) % ((CL_GLOBAL NAME##MODIFIER##Hash_TableData*)tableData)->numBuckets) | |
| 122 | ||
| 123 | #define QUADRATIC_OPEN_COMPACT_HASH_CYCLE_EXP(NAME, MODIFIER, CL_GLOBAL) (iteration > ((CL_GLOBAL NAME##MODIFIER##Hash_TableData*)tableData)->numBuckets) | |
| 124 | ||
| 125 | #define QUADRATIC_OPEN_COMPACT_HASH_INIT_EXP(NAME, MODIFIER, INIT_EXP)\ | |
| 126 | INIT_EXP\ | |
| 127 | ((NAME##MODIFIER##Hash_TableData*)table->tableData)->numBuckets = largestProthPrimeUnder(((NAME##MODIFIER##Hash_TableData*)table->tableData)->numBuckets);\ | |
| 128 | \ | |
| 129 | ||
| 130 | #define QUADRATIC_OPEN_COMPACT_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP, A, B)\ | |
| 131 | \ | |
| 132 | OPEN_COMPACT_HASH_DEFINE(NAME, MODIFIER##Quadratic, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, QUADRATIC_OPEN_COMPACT_HASH_INIT_EXP(NAME, MODIFIER##QuadraticOpenCompact, INIT_EXP), QUADRATIC_OPEN_COMPACT_HASH_JUMP_EXP(NAME, MODIFIER##QuadraticOpenCompact, A, B,), QUADRATIC_OPEN_COMPACT_HASH_CYCLE_EXP(NAME, MODIFIER##QuadraticOpenCompact,))\ | |
| 133 | \ | |
| 134 | ||
| 135 | #define QUADRATIC_OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP, A, B)\ | |
| 136 | \ | |
| 137 | OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, MODIFIER##Quadratic, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, QUADRATIC_OPEN_COMPACT_HASH_INIT_EXP(NAME, MODIFIER##QuadraticOpenCompactCL, INIT_EXP), QUADRATIC_OPEN_COMPACT_HASH_JUMP_EXP(NAME, MODIFIER##QuadraticOpenCompactCL, A, B, __global), QUADRATIC_OPEN_COMPACT_HASH_CYCLE_EXP(NAME, MODIFIER##QuadraticOpenCompactCL, __global))\ | |
| 138 | \ | |
| 139 | ||
| 140 | #define QUADRATIC_OPEN_COMPACT_CL_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP)\ | |
| 141 | \ | |
| 142 | OPEN_COMPACT_CL_HASH_DEFINE(NAME, MODIFIER##Quadratic, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, QUADRATIC_OPEN_COMPACT_HASH_INIT_EXP(NAME, MODIFIER##QuadraticOpenCompactCL, INIT_EXP)) | |
| 143 | \ | |
| 144 | ||
| 145 | #define LCG_OPEN_COMPACT_HASH_INIT_EXP(NAME, MODIFIER)\ | |
| 146 | ((NAME##MODIFIER##Hash_TableData*)table->tableData)->compressFuncData.a = HASH_LCG_A;\ | |
| 147 | ((NAME##MODIFIER##Hash_TableData*)table->tableData)->compressFuncData.c = HASH_LCG_C;\ | |
| 148 | ((NAME##MODIFIER##Hash_TableData*)table->tableData)->compressFuncData.m = HASH_LCG_M;\ | |
| 149 | ((NAME##MODIFIER##Hash_TableData*)table->tableData)->compressFuncData.n = ((NAME##MODIFIER##Hash_TableData*)table->tableData)->numBuckets;\ | |
| 150 | \ | |
| 151 | ||
| 152 | #define LCG_LINEAR_OPEN_COMPACT_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE, B)\ | |
| 153 | \ | |
| 154 | LINEAR_OPEN_COMPACT_HASH_DEFINE(NAME, LCG, LCG_LINEAR_OPEN_COMPACT_HASH_ID, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressLCG, NAME##Hash_CompressLCGData, LCG_OPEN_COMPACT_HASH_INIT_EXP(NAME, LCGLinearOpenCompact), B)\ | |
| 155 | \ | |
| 156 | ||
| 157 | #define LCG_LINEAR_OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, KEY_TYPE, VALUE_TYPE, B)\ | |
| 158 | \ | |
| 159 | LINEAR_OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, LCG, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressLCG, NAME##Hash_CompressLCGData, LCG_OPEN_COMPACT_HASH_INIT_EXP(NAME, LCGLinearOpenCompactCL), B)\ | |
| 160 | \ | |
| 161 | ||
| 162 | #define LCG_LINEAR_OPEN_COMPACT_CL_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 163 | \ | |
| 164 | LINEAR_OPEN_COMPACT_CL_HASH_DEFINE(NAME, LCG, LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressLCG, NAME##Hash_CompressLCGData, LCG_OPEN_COMPACT_HASH_INIT_EXP(NAME, LCGLinearOpenCompactCL))\ | |
| 165 | \ | |
| 166 | ||
| 167 | #define LCG_QUADRATIC_OPEN_COMPACT_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE, A, B)\ | |
| 168 | \ | |
| 169 | QUADRATIC_OPEN_COMPACT_HASH_DEFINE(NAME, LCG, LCG_QUADRATIC_OPEN_COMPACT_HASH_ID, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressLCG, NAME##Hash_CompressLCGData, LCG_OPEN_COMPACT_HASH_INIT_EXP(NAME, LCGQuadraticOpenCompact), A, B)\ | |
| 170 | \ | |
| 171 | ||
| 172 | #define LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, KEY_TYPE, VALUE_TYPE, A, B)\ | |
| 173 | \ | |
| 174 | QUADRATIC_OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, LCG, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressLCG, NAME##Hash_CompressLCGData, LCG_OPEN_COMPACT_HASH_INIT_EXP(NAME, LCGQuadraticOpenCompactCL), A, B)\ | |
| 175 | \ | |
| 176 | ||
| 177 | #define LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 178 | \ | |
| 179 | QUADRATIC_OPEN_COMPACT_CL_HASH_DEFINE(NAME, LCG, LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressLCG, NAME##Hash_CompressLCGData, LCG_OPEN_COMPACT_HASH_INIT_EXP(NAME, LCGQuadraticOpenCompactCL))\ | |
| 180 | \ | |
| 181 |
| … | … | @@ -1,102 +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 | #undef UNDECLARED | |
| 34 | #ifdef UNDECLARED | |
| 35 | /** | |
| 36 | * @file compactHash.hm | |
| 37 | * @author Peter Ahrens | |
| 38 | * @date Thu Jun 6 2013 | |
| 39 | */ | |
| 40 | #endif | |
| 41 | #include "baseHash.hm" | |
| 42 | ||
| 43 | #define COMPACT_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 44 | \ | |
| 45 | BASE_HASH_DECLARE(NAME, MODIFIER##Compact, KEY_TYPE, VALUE_TYPE)\ | |
| 46 | \ | |
| 47 | ||
| 48 | #define OPEN_COMPACT_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 49 | \ | |
| 50 | COMPACT_HASH_DECLARE(NAME, MODIFIER##Open, KEY_TYPE, VALUE_TYPE)\ | |
| 51 | \ | |
| 52 | ||
| 53 | #define LINEAR_OPEN_COMPACT_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 54 | \ | |
| 55 | OPEN_COMPACT_HASH_DECLARE(NAME, MODIFIER##Linear, KEY_TYPE, VALUE_TYPE)\ | |
| 56 | \ | |
| 57 | ||
| 58 | #define LCG_LINEAR_OPEN_COMPACT_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 59 | \ | |
| 60 | LINEAR_OPEN_COMPACT_HASH_DECLARE(NAME, LCG, KEY_TYPE, VALUE_TYPE)\ | |
| 61 | \ | |
| 62 | ||
| 63 | #define QUADRATIC_OPEN_COMPACT_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 64 | \ | |
| 65 | OPEN_COMPACT_HASH_DECLARE(NAME, MODIFIER##Quadratic, KEY_TYPE, VALUE_TYPE)\ | |
| 66 | \ | |
| 67 | ||
| 68 | #define LCG_QUADRATIC_OPEN_COMPACT_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 69 | \ | |
| 70 | QUADRATIC_OPEN_COMPACT_HASH_DECLARE(NAME, LCG, KEY_TYPE, VALUE_TYPE)\ | |
| 71 | \ | |
| 72 | ||
| 73 | #define COMPACT_CL_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 74 | \ | |
| 75 | CL_HASH_DECLARE(NAME, MODIFIER##Compact, KEY_TYPE, VALUE_TYPE)\ | |
| 76 | \ | |
| 77 | ||
| 78 | #define OPEN_COMPACT_CL_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 79 | \ | |
| 80 | COMPACT_CL_HASH_DECLARE(NAME, MODIFIER##Open, KEY_TYPE, VALUE_TYPE)\ | |
| 81 | \ | |
| 82 | ||
| 83 | #define LINEAR_OPEN_COMPACT_CL_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 84 | \ | |
| 85 | OPEN_COMPACT_CL_HASH_DECLARE(NAME, MODIFIER##Linear, KEY_TYPE, VALUE_TYPE)\ | |
| 86 | \ | |
| 87 | ||
| 88 | #define LCG_LINEAR_OPEN_COMPACT_CL_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 89 | \ | |
| 90 | LINEAR_OPEN_COMPACT_CL_HASH_DECLARE(NAME, LCG, KEY_TYPE, VALUE_TYPE)\ | |
| 91 | \ | |
| 92 | ||
| 93 | #define QUADRATIC_OPEN_COMPACT_CL_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 94 | \ | |
| 95 | OPEN_COMPACT_CL_HASH_DECLARE(NAME, MODIFIER##Quadratic, KEY_TYPE, VALUE_TYPE)\ | |
| 96 | \ | |
| 97 | ||
| 98 | #define LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 99 | \ | |
| 100 | QUADRATIC_OPEN_COMPACT_CL_HASH_DECLARE(NAME, LCG, KEY_TYPE, VALUE_TYPE)\ | |
| 101 | \ | |
| 102 |
| … | … | @@ -1,68 +0,0 @@ |
| 1 | eval 'exec perl -w $0 ${1+"$@"}' | |
| 2 | if 0; | |
| 3 | ||
| 4 | # Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 5 | # under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 6 | # Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 7 | # for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 8 | # reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 9 | # ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 10 | # ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 11 | # to produce derivative works, such modified software should be clearly marked, | |
| 12 | # so as not to confuse it with the version available from LANL. | |
| 13 | # | |
| 14 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 15 | # use this file except in compliance with the License. You may obtain a copy | |
| 16 | # of the License at | |
| 17 | # | |
| 18 | # http://www.apache.org/licenses/LICENSE-2.0 | |
| 19 | # | |
| 20 | # Unless required by applicable law or agreed to in writing, software distributed | |
| 21 | # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 22 | # CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 23 | # specific language governing permissions and limitations under the License. | |
| 24 | # | |
| 25 | # Under this license, it is required to include a reference to this work. We | |
| 26 | # request that each derivative work contain a reference to LANL Copyright | |
| 27 | # Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 28 | # measured. In addition, it is requested that a modifier is included as in | |
| 29 | # the following example: | |
| 30 | # | |
| 31 | # //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 32 | # | |
| 33 | # This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 34 | ||
| 35 | use File::Basename; | |
| 36 | ||
| 37 | $ARGV_LAST = ""; | |
| 38 | ||
| 39 | ($file,,) = fileparse($ARGV[0], qr/\..*/); | |
| 40 | print "const char *",$file,"_source =\n"; | |
| 41 | ||
| 42 | while(<>) { | |
| 43 | if ($ARGV ne $ARGV_LAST){ | |
| 44 | # $comment = 0; | |
| 45 | $ARGV_LAST=$ARGV; | |
| 46 | } | |
| 47 | chop $_; | |
| 48 | ||
| 49 | s/"/""/g; | |
| 50 | ||
| 51 | # if (/^\/\*/){ | |
| 52 | # #print "Setting comment to 1\n"; | |
| 53 | # $comment = 1; | |
| 54 | # } | |
| 55 | # if (/\*\/$/){ | |
| 56 | # #print "Setting comment to 0\n"; | |
| 57 | # $comment = 0; | |
| 58 | # next; | |
| 59 | # } | |
| 60 | # if ($comment eq 1) { | |
| 61 | # #print "Skip line and goto next\n"; | |
| 62 | ## next; | |
| 63 | # } | |
| 64 | ||
| 65 | print '"',$_,'\n','"',"\n"; | |
| 66 | } | |
| 67 | ||
| 68 | print ";\n" |
| … | … | @@ -1,6495 +0,0 @@ |
| 1 | ||
| 2 | /* Copyright (C) 1991-2012 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public | |
| 7 | License as published by the Free Software Foundation; either | |
| 8 | version 2.1 of the License, or (at your option) any later version. | |
| 9 | ||
| 10 | The GNU C Library is distributed in the hope that it will be useful, | |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | Lesser General Public License for more details. | |
| 14 | ||
| 15 | You should have received a copy of the GNU Lesser General Public | |
| 16 | License along with the GNU C Library; if not, see | |
| 17 | <http://www.gnu.org/licenses/>. */ | |
| 18 | /* This header is separate from features.h so that the compiler can | |
| 19 | include it implicitly at the start of every compilation. It must | |
| 20 | not itself include <features.h> or any other header that includes | |
| 21 | <features.h> because the implicit include comes before any feature | |
| 22 | test macros that may be defined in a source file before it first | |
| 23 | explicitly includes a system header. GCC knows the name of this | |
| 24 | header in order to preinclude it. */ | |
| 25 | /* We do support the IEC 559 math functionality, real and complex. */ | |
| 26 | /* wchar_t uses ISO/IEC 10646 (2nd ed., published 2011-03-15) / | |
| 27 | Unicode 6.0. */ | |
| 28 | /* We do not support C11 <threads.h>. */ | |
| 29 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 30 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 31 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 32 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 33 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 34 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 35 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 36 | * to produce derivative works, such modified software should be clearly marked, | |
| 37 | * so as not to confuse it with the version available from LANL. | |
| 38 | * | |
| 39 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 40 | * use this file except in compliance with the License. You may obtain a copy | |
| 41 | * of the License at | |
| 42 | * | |
| 43 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 44 | * | |
| 45 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 46 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 47 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 48 | * specific language governing permissions and limitations under the License. | |
| 49 | * | |
| 50 | * Under this license, it is required to include a reference to this work. We | |
| 51 | * request that each derivative work contain a reference to LANL Copyright | |
| 52 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 53 | * measured. In addition, it is requested that a modifier is included as in | |
| 54 | * the following example: | |
| 55 | * | |
| 56 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 57 | * | |
| 58 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 59 | */ | |
| 60 | /** | |
| 61 | * @file hash.c | |
| 62 | * @author Peter Ahrens | |
| 63 | * @date Thu Jun 6 2013 | |
| 64 | */ | |
| 65 | // | |
| 66 | #include "hash.h" | |
| 67 | #ifdef HAVE_OPENCL | |
| 68 | #ifdef __APPLE_CC__ | |
| 69 | #include <OpenCL/OpenCL.h> | |
| 70 | #else | |
| 71 | #include <CL/cl.h> | |
| 72 | #endif | |
| 73 | #else | |
| 74 | typedef int cl_kernel; | |
| 75 | #define CL_CONTEXT_DEVICES 0 | |
| 76 | #define CL_MEM_READ_WRITE 0 | |
| 77 | #define CL_TRUE 1 | |
| 78 | #define CL_MEM_READ_ONLY 0 | |
| 79 | #define CL_MEM_COPY_HOST_PTR 0 | |
| 80 | #define CL_MEM_WRITE_ONLY 0 | |
| 81 | #define CL_KERNEL_WORK_GROUP_SIZE 128 | |
| 82 | int clRetainContext(int context) { | |
| 83 | return context; | |
| 84 | } | |
| 85 | int clRetainCommandQueue(int command_queue) { | |
| 86 | return command_queue; | |
| 87 | } | |
| 88 | int clGetContextInfo(int context, int param, size_t size, void *value, | |
| 89 | size_t * size_ret) { | |
| 90 | return 0; | |
| 91 | } | |
| 92 | int clReleaseContext(int context) { | |
| 93 | return context; | |
| 94 | } | |
| 95 | int clReleaseCommandQueue(int command_queue) { | |
| 96 | return command_queue; | |
| 97 | } | |
| 98 | int clReleaseProgram(int program) { | |
| 99 | return program; | |
| 100 | } | |
| 101 | int clRetainKernel(int kernel) { | |
| 102 | return kernel; | |
| 103 | } | |
| 104 | int clRetainProgram(int program) { | |
| 105 | return program; | |
| 106 | } | |
| 107 | cl_mem clCreateBuffer(int context, int flags, size_t size, void *value, | |
| 108 | int *size_ret) { | |
| 109 | return 0; | |
| 110 | } | |
| 111 | int clEnqueueWriteBuffer(int command_queue, void *buffer, int blocking_write, | |
| 112 | size_t offset, size_t cb, const void *ptr, | |
| 113 | uint nevents, const int *wait_list, int *event) { | |
| 114 | return 0; | |
| 115 | } | |
| 116 | int clEnqueueReadBuffer(int command_queue, void *buffer, int blocking_write, | |
| 117 | size_t offset, size_t cb, const void *ptr, uint nevents, | |
| 118 | const int *wait_list, int *event) { | |
| 119 | return 0; | |
| 120 | } | |
| 121 | int clCreateKernel(int program, const char *kernel_name, int *errcode_ret) { | |
| 122 | return 0; | |
| 123 | } | |
| 124 | int clReleaseKernel(int kernel) { | |
| 125 | return kernel; | |
| 126 | } | |
| 127 | int clReleaseMemObject(void *memobj) { | |
| 128 | return 0; | |
| 129 | } | |
| 130 | int clSetKernelArg(int kernel, uint arg_index, size_t arg_size, | |
| 131 | const void *arg_value) { | |
| 132 | return 0; | |
| 133 | } | |
| 134 | int clGetKernelWorkGroupInfo(int kernel, int device, int param_name, | |
| 135 | size_t size, void *value, size_t * size_ret) { | |
| 136 | return 0; | |
| 137 | } | |
| 138 | int clEnqueueNDRangeKernel(int command_queue, int kernel, uint work_dim, | |
| 139 | const size_t * offset, const size_t * size, | |
| 140 | const size_t * local_size, uint nevents, | |
| 141 | const int *wait_list, int *event) { | |
| 142 | return 0; | |
| 143 | } | |
| 144 | int clFinish(int command_queue) { | |
| 145 | return 0; | |
| 146 | } | |
| 147 | #endif | |
| 148 | #define PRIME_NUM_CHECKS 20 | |
| 149 | typedef unsigned int uint; | |
| 150 | #include <math.h> | |
| 151 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 152 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 153 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 154 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 155 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 156 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 157 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 158 | * to produce derivative works, such modified software should be clearly marked, | |
| 159 | * so as not to confuse it with the version available from LANL. | |
| 160 | * | |
| 161 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 162 | * use this file except in compliance with the License. You may obtain a copy | |
| 163 | * of the License at | |
| 164 | * | |
| 165 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 166 | * | |
| 167 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 168 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 169 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 170 | * specific language governing permissions and limitations under the License. | |
| 171 | * | |
| 172 | * Under this license, it is required to include a reference to this work. We | |
| 173 | * request that each derivative work contain a reference to LANL Copyright | |
| 174 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 175 | * measured. In addition, it is requested that a modifier is included as in | |
| 176 | * the following example: | |
| 177 | * | |
| 178 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 179 | * | |
| 180 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 181 | */ | |
| 182 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 183 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 184 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 185 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 186 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 187 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 188 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 189 | * to produce derivative works, such modified software should be clearly marked, | |
| 190 | * so as not to confuse it with the version available from LANL. | |
| 191 | * | |
| 192 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 193 | * use this file except in compliance with the License. You may obtain a copy | |
| 194 | * of the License at | |
| 195 | * | |
| 196 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 197 | * | |
| 198 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 199 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 200 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 201 | * specific language governing permissions and limitations under the License. | |
| 202 | * | |
| 203 | * Under this license, it is required to include a reference to this work. We | |
| 204 | * request that each derivative work contain a reference to LANL Copyright | |
| 205 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 206 | * measured. In addition, it is requested that a modifier is included as in | |
| 207 | * the following example: | |
| 208 | * | |
| 209 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 210 | * | |
| 211 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 212 | */ | |
| 213 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 214 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 215 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 216 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 217 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 218 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 219 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 220 | * to produce derivative works, such modified software should be clearly marked, | |
| 221 | * so as not to confuse it with the version available from LANL. | |
| 222 | * | |
| 223 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 224 | * use this file except in compliance with the License. You may obtain a copy | |
| 225 | * of the License at | |
| 226 | * | |
| 227 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 228 | * | |
| 229 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 230 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 231 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 232 | * specific language governing permissions and limitations under the License. | |
| 233 | * | |
| 234 | * Under this license, it is required to include a reference to this work. We | |
| 235 | * request that each derivative work contain a reference to LANL Copyright | |
| 236 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 237 | * measured. In addition, it is requested that a modifier is included as in | |
| 238 | * the following example: | |
| 239 | * | |
| 240 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 241 | * | |
| 242 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 243 | */ | |
| 244 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 245 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 246 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 247 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 248 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 249 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 250 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 251 | * to produce derivative works, such modified software should be clearly marked, | |
| 252 | * so as not to confuse it with the version available from LANL. | |
| 253 | * | |
| 254 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 255 | * use this file except in compliance with the License. You may obtain a copy | |
| 256 | * of the License at | |
| 257 | * | |
| 258 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 259 | * | |
| 260 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 261 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 262 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 263 | * specific language governing permissions and limitations under the License. | |
| 264 | * | |
| 265 | * Under this license, it is required to include a reference to this work. We | |
| 266 | * request that each derivative work contain a reference to LANL Copyright | |
| 267 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 268 | * measured. In addition, it is requested that a modifier is included as in | |
| 269 | * the following example: | |
| 270 | * | |
| 271 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 272 | * | |
| 273 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 274 | */ | |
| 275 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 276 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 277 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 278 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 279 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 280 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 281 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 282 | * to produce derivative works, such modified software should be clearly marked, | |
| 283 | * so as not to confuse it with the version available from LANL. | |
| 284 | * | |
| 285 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 286 | * use this file except in compliance with the License. You may obtain a copy | |
| 287 | * of the License at | |
| 288 | * | |
| 289 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 290 | * | |
| 291 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 292 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 293 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 294 | * specific language governing permissions and limitations under the License. | |
| 295 | * | |
| 296 | * Under this license, it is required to include a reference to this work. We | |
| 297 | * request that each derivative work contain a reference to LANL Copyright | |
| 298 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 299 | * measured. In addition, it is requested that a modifier is included as in | |
| 300 | * the following example: | |
| 301 | * | |
| 302 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 303 | * | |
| 304 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 305 | */ | |
| 306 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 307 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 308 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 309 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 310 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 311 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 312 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 313 | * to produce derivative works, such modified software should be clearly marked, | |
| 314 | * so as not to confuse it with the version available from LANL. | |
| 315 | * | |
| 316 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 317 | * use this file except in compliance with the License. You may obtain a copy | |
| 318 | * of the License at | |
| 319 | * | |
| 320 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 321 | * | |
| 322 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 323 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 324 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 325 | * specific language governing permissions and limitations under the License. | |
| 326 | * | |
| 327 | * Under this license, it is required to include a reference to this work. We | |
| 328 | * request that each derivative work contain a reference to LANL Copyright | |
| 329 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 330 | * measured. In addition, it is requested that a modifier is included as in | |
| 331 | * the following example: | |
| 332 | * | |
| 333 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 334 | * | |
| 335 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 336 | */ | |
| 337 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 338 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 339 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 340 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 341 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 342 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 343 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 344 | * to produce derivative works, such modified software should be clearly marked, | |
| 345 | * so as not to confuse it with the version available from LANL. | |
| 346 | * | |
| 347 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 348 | * use this file except in compliance with the License. You may obtain a copy | |
| 349 | * of the License at | |
| 350 | * | |
| 351 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 352 | * | |
| 353 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 354 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 355 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 356 | * specific language governing permissions and limitations under the License. | |
| 357 | * | |
| 358 | * Under this license, it is required to include a reference to this work. We | |
| 359 | * request that each derivative work contain a reference to LANL Copyright | |
| 360 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 361 | * measured. In addition, it is requested that a modifier is included as in | |
| 362 | * the following example: | |
| 363 | * | |
| 364 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 365 | * | |
| 366 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 367 | */ | |
| 368 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 369 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 370 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 371 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 372 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 373 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 374 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 375 | * to produce derivative works, such modified software should be clearly marked, | |
| 376 | * so as not to confuse it with the version available from LANL. | |
| 377 | * | |
| 378 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 379 | * use this file except in compliance with the License. You may obtain a copy | |
| 380 | * of the License at | |
| 381 | * | |
| 382 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 383 | * | |
| 384 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 385 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 386 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 387 | * specific language governing permissions and limitations under the License. | |
| 388 | * | |
| 389 | * Under this license, it is required to include a reference to this work. We | |
| 390 | * request that each derivative work contain a reference to LANL Copyright | |
| 391 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 392 | * measured. In addition, it is requested that a modifier is included as in | |
| 393 | * the following example: | |
| 394 | * | |
| 395 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 396 | * | |
| 397 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 398 | */ | |
| 399 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 400 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 401 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 402 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 403 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 404 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 405 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 406 | * to produce derivative works, such modified software should be clearly marked, | |
| 407 | * so as not to confuse it with the version available from LANL. | |
| 408 | * | |
| 409 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 410 | * use this file except in compliance with the License. You may obtain a copy | |
| 411 | * of the License at | |
| 412 | * | |
| 413 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 414 | * | |
| 415 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 416 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 417 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 418 | * specific language governing permissions and limitations under the License. | |
| 419 | * | |
| 420 | * Under this license, it is required to include a reference to this work. We | |
| 421 | * request that each derivative work contain a reference to LANL Copyright | |
| 422 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 423 | * measured. In addition, it is requested that a modifier is included as in | |
| 424 | * the following example: | |
| 425 | * | |
| 426 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 427 | * | |
| 428 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 429 | */ | |
| 430 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 431 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 432 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 433 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 434 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 435 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 436 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 437 | * to produce derivative works, such modified software should be clearly marked, | |
| 438 | * so as not to confuse it with the version available from LANL. | |
| 439 | * | |
| 440 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 441 | * use this file except in compliance with the License. You may obtain a copy | |
| 442 | * of the License at | |
| 443 | * | |
| 444 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 445 | * | |
| 446 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 447 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 448 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 449 | * specific language governing permissions and limitations under the License. | |
| 450 | * | |
| 451 | * Under this license, it is required to include a reference to this work. We | |
| 452 | * request that each derivative work contain a reference to LANL Copyright | |
| 453 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 454 | * measured. In addition, it is requested that a modifier is included as in | |
| 455 | * the following example: | |
| 456 | * | |
| 457 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 458 | * | |
| 459 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 460 | */ | |
| 461 | static int reportLevel = 0; | |
| 462 | const char *hash_source; | |
| 463 | const char *Hash_GetKernelSourceString() { | |
| 464 | return hash_source; | |
| 465 | } | |
| 466 | size_t roundUpToNearest(size_t x, size_t r) { | |
| 467 | return (((x - 1) / r) + 1) * r; | |
| 468 | } | |
| 469 | int modularPow(int base, int exponent, int modulus) { | |
| 470 | int result = 1; | |
| 471 | while (exponent) { | |
| 472 | if (exponent & 1) | |
| 473 | result = ((long long int)result * base) % modulus; | |
| 474 | exponent >>= 1; | |
| 475 | base = ((long long int)base * base) % modulus; | |
| 476 | } | |
| 477 | return result; | |
| 478 | } | |
| 479 | int largestProthPrimeUnder(int N) { | |
| 480 | if (N < 4) { | |
| 481 | return N; | |
| 482 | } | |
| 483 | //determine the nearest proth number | |
| 484 | int n; | |
| 485 | int m; | |
| 486 | frexp((double)N, &n); | |
| 487 | n /= 2; | |
| 488 | int s = 1 << n; | |
| 489 | int p = s * ((N - 1) / s) + 1; | |
| 490 | int i; | |
| 491 | int a; | |
| 492 | srand(p); | |
| 493 | while (p > 3) { | |
| 494 | //check if a proth number is prime | |
| 495 | for (i = 0; i < PRIME_NUM_CHECKS; i++) { | |
| 496 | a = rand(); | |
| 497 | if (modularPow(a, (p - 1) / 2, p) == p - 1) { | |
| 498 | return p; | |
| 499 | } | |
| 500 | } | |
| 501 | //determine the next proth number | |
| 502 | if (p - 1 == s * s / 4) { | |
| 503 | s /= 2; | |
| 504 | } | |
| 505 | p -= s; | |
| 506 | } | |
| 507 | return 3; | |
| 508 | } | |
| 509 | int smallestProthPrimeAbove(int N) { | |
| 510 | if (N < 4) { | |
| 511 | return N; | |
| 512 | } | |
| 513 | //determine the nearest proth number | |
| 514 | int n; | |
| 515 | int m; | |
| 516 | frexp((double)N, &n); | |
| 517 | n /= 2; | |
| 518 | int s = 1 << n; | |
| 519 | int p = s * ((N - 1) / s) + 1; | |
| 520 | int i; | |
| 521 | int a; | |
| 522 | srand(p); | |
| 523 | while (1) { | |
| 524 | //determine the next proth number | |
| 525 | if (p - 1 == s * s) { | |
| 526 | s *= 2; | |
| 527 | } | |
| 528 | p += s; | |
| 529 | //check if a proth number is prime | |
| 530 | for (i = 0; i < PRIME_NUM_CHECKS; i++) { | |
| 531 | a = rand(); | |
| 532 | if (modularPow(a, (p - 1) / 2, p) == p - 1) { | |
| 533 | return p; | |
| 534 | } | |
| 535 | } | |
| 536 | } | |
| 537 | return 3; | |
| 538 | } | |
| 539 | int intLog2(int n) { | |
| 540 | int result = 0; | |
| 541 | while (n >>= 1) { | |
| 542 | result++; | |
| 543 | } | |
| 544 | return result; | |
| 545 | } | |
| 546 | void Hash_SetReportLevel(int level) { | |
| 547 | reportLevel = level; | |
| 548 | } | |
| 549 | int Hash_GetReportLevel() { | |
| 550 | return reportLevel; | |
| 551 | } | |
| 552 | char *Hash_ExitCodeString(int exitCode) { | |
| 553 | switch (exitCode) { | |
| 554 | case HASH_EXIT_CODE_NORMAL: | |
| 555 | return "Normal"; | |
| 556 | case HASH_EXIT_CODE_ERROR: | |
| 557 | return "Error"; | |
| 558 | case HASH_EXIT_CODE_OVERWRITE: | |
| 559 | return "Overwrite"; | |
| 560 | case HASH_EXIT_CODE_KEY_DNE: | |
| 561 | return "Key Does Not Exist"; | |
| 562 | case HASH_EXIT_CODE_CYCLE: | |
| 563 | return "Cycle"; | |
| 564 | case HASH_EXIT_CODE_MAX_ENTRIES_EXCEEDED: | |
| 565 | return "Maximum Number Of Entries Exceeded"; | |
| 566 | default: | |
| 567 | return "Unknown"; | |
| 568 | } | |
| 569 | } | |
| 570 | void Hash_ExitCodeDebug(int exitCode) { | |
| 571 | if (exitCode != HASH_EXIT_CODE_NORMAL) { | |
| 572 | printf("HashExitCode: %s\n", Hash_ExitCodeString(exitCode)); | |
| 573 | } | |
| 574 | } | |
| 575 | ||
| 576 | struct intintHash_Table_ { | |
| 577 | char *tableData; | |
| 578 | cl_mem tableDataBuffer; | |
| 579 | int (*destroyFunc) (intintHash_Table *); | |
| 580 | int (*emptyFunc) (intintHash_Table *); | |
| 581 | int (*queryFunc) (intintHash_Table *, size_t, int *, int *); | |
| 582 | int (*querySingleFunc) (intintHash_Table *, int, int *); | |
| 583 | int (*insertFunc) (intintHash_Table *, size_t, int *, int *); | |
| 584 | int (*insertSingleFunc) (intintHash_Table *, int, int); | |
| 585 | int (*insertNoOverwriteFunc) (intintHash_Table *, size_t, int *, int *); | |
| 586 | int (*insertSingleNoOverwriteFunc) (intintHash_Table *, int, int); | |
| 587 | int (*bufferQueryFunc) (intintHash_Table *, size_t, cl_mem, cl_mem); | |
| 588 | int (*bufferInsertFunc) (intintHash_Table *, size_t, cl_mem, cl_mem); | |
| 589 | int (*bufferInsertNoOverwriteFunc) (intintHash_Table *, size_t, cl_mem, | |
| 590 | cl_mem); | |
| 591 | cl_context context; | |
| 592 | cl_command_queue queue; | |
| 593 | cl_program utilProgram; | |
| 594 | cl_kernel emptyKernel; | |
| 595 | size_t emptyKernelLocalWorkSize; | |
| 596 | cl_program program; | |
| 597 | cl_kernel querySingleKernel; | |
| 598 | cl_kernel insertSingleKernel; | |
| 599 | cl_kernel insertSingleNoOverwriteKernel; | |
| 600 | size_t localWorkSize; | |
| 601 | }; | |
| 602 | struct intintHash_Factory_ { | |
| 603 | cl_context context; | |
| 604 | cl_program program; | |
| 605 | cl_command_queue queue; | |
| 606 | int hashTypesAvailable; | |
| 607 | cl_program utilProgram[HASH_NUM_CL_HASHES]; | |
| 608 | cl_kernel emptyKernel[HASH_NUM_CL_HASHES]; | |
| 609 | size_t emptyKernelLocalWorkSize[HASH_NUM_CL_HASHES]; | |
| 610 | cl_kernel querySingleKernel[HASH_NUM_CL_HASHES]; | |
| 611 | cl_kernel insertSingleKernel[HASH_NUM_CL_HASHES]; | |
| 612 | cl_kernel insertSingleNoOverwriteKernel[HASH_NUM_CL_HASHES]; | |
| 613 | int emptyValue; | |
| 614 | size_t localWorkSize; | |
| 615 | intintHash_Table *(*createFunc[HASH_NUM_HASHES]) (intintHash_Factory *, | |
| 616 | int hashIndex, | |
| 617 | size_t keyRange, | |
| 618 | size_t numEntries, | |
| 619 | float loadFactor); | |
| 620 | int (*destroyFunc[HASH_NUM_HASHES]) (intintHash_Factory *, | |
| 621 | int hashIndex); | |
| 622 | }; | |
| 623 | intintHash_Factory *intintHash_CreateFactory(int hashTypes, int *emptyValue, | |
| 624 | size_t localWorkSize, | |
| 625 | cl_context * context, | |
| 626 | cl_command_queue * queue) { | |
| 627 | if (hashTypes == 0) { | |
| 628 | hashTypes = HASH_ALL_C_HASHES; | |
| 629 | } | |
| 630 | if (!(hashTypes & HASH_ALL_HASHES)) { | |
| 631 | printf("Please specify a valid hash type to create.\n"); | |
| 632 | exit(1); | |
| 633 | } | |
| 634 | hashTypes &= HASH_ALL_HASHES; | |
| 635 | if ((hashTypes & HASH_SENTINEL_PERFECT_HASHES) == hashTypes | |
| 636 | && emptyValue == NULL) { | |
| 637 | printf | |
| 638 | ("emptyValue must be valid if a sentinel perfect hash is the only option available.\n"); | |
| 639 | exit(1); | |
| 640 | } | |
| 641 | intintHash_Factory *factory = | |
| 642 | (intintHash_Factory *) malloc(sizeof(intintHash_Factory)); | |
| 643 | if (emptyValue == NULL) { | |
| 644 | hashTypes &= !HASH_SENTINEL_PERFECT_HASHES; | |
| 645 | } else { | |
| 646 | factory->emptyValue = *emptyValue; | |
| 647 | } | |
| 648 | factory->hashTypesAvailable = hashTypes; | |
| 649 | if (hashTypes & HASH_ALL_CL_HASHES) { | |
| 650 | if (localWorkSize == 0) { | |
| 651 | factory->localWorkSize = HASH_DEFAULT_LOCAL_WORK_SIZE; | |
| 652 | } else { | |
| 653 | factory->localWorkSize = 1 << intLog2(localWorkSize); | |
| 654 | } | |
| 655 | if (context == NULL) { | |
| 656 | CLHash_Utilities_CreateContext(&factory->context, | |
| 657 | &factory->queue); | |
| 658 | } else { | |
| 659 | factory->context = *context; | |
| 660 | clRetainContext(*context); | |
| 661 | if (queue == NULL) { | |
| 662 | printf | |
| 663 | ("Please specify a command queue for your context.\n"); | |
| 664 | exit(-1); | |
| 665 | } | |
| 666 | factory->queue = *queue; | |
| 667 | clRetainCommandQueue(*queue); | |
| 668 | } | |
| 669 | cl_int error; | |
| 670 | cl_device_id device; | |
| 671 | error = | |
| 672 | clGetContextInfo(factory->context, CL_CONTEXT_DEVICES, | |
| 673 | sizeof(device), &device, NULL); | |
| 674 | CLHash_Utilities_HandleError(error, "intintHash_CreateFactory", | |
| 675 | "clGetContextInfo"); | |
| 676 | factory->program = | |
| 677 | CLHash_Utilities_BuildProgramString(factory->context, | |
| 678 | device, | |
| 679 | Hash_GetKernelSourceString | |
| 680 | ()); | |
| 681 | } | |
| 682 | int hashType = 1; | |
| 683 | for (int hashIndex = 0; hashIndex < HASH_NUM_HASHES; hashIndex++) { | |
| 684 | hashType = 1 << hashIndex; | |
| 685 | switch (hashType & hashTypes) { | |
| 686 | case IDENTITY_PERFECT_HASH_ID: | |
| 687 | intintIdentityPerfectHash_CreateFactory(factory, | |
| 688 | hashIndex); | |
| 689 | break; | |
| 690 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 691 | intintIdentityPerfectCLHash_CreateFactory(factory, | |
| 692 | hashIndex); | |
| 693 | break; | |
| 694 | case IDENTITY_SENTINEL_PERFECT_HASH_ID: | |
| 695 | intintIdentitySentinelPerfectHash_CreateFactory(factory, | |
| 696 | hashIndex); | |
| 697 | break; | |
| 698 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 699 | intintIdentitySentinelPerfectCLHash_CreateFactory | |
| 700 | (factory, hashIndex); | |
| 701 | break; | |
| 702 | case LCG_LINEAR_OPEN_COMPACT_HASH_ID: | |
| 703 | intintLCGLinearOpenCompactHash_CreateFactory(factory, | |
| 704 | hashIndex); | |
| 705 | break; | |
| 706 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 707 | intintLCGLinearOpenCompactCLHash_CreateFactory(factory, | |
| 708 | hashIndex); | |
| 709 | break; | |
| 710 | case LCG_QUADRATIC_OPEN_COMPACT_HASH_ID: | |
| 711 | intintLCGQuadraticOpenCompactHash_CreateFactory(factory, | |
| 712 | hashIndex); | |
| 713 | break; | |
| 714 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 715 | intintLCGQuadraticOpenCompactCLHash_CreateFactory | |
| 716 | (factory, hashIndex); | |
| 717 | break; | |
| 718 | } | |
| 719 | } | |
| 720 | return factory; | |
| 721 | } | |
| 722 | int intintHash_DestroyFactory(intintHash_Factory * factory) { | |
| 723 | int hashType; | |
| 724 | for (int hashIndex = 0; hashIndex < HASH_NUM_HASHES; | |
| 725 | hashType = 1 << hashIndex) { | |
| 726 | switch (hashType & factory->hashTypesAvailable) { | |
| 727 | case IDENTITY_PERFECT_HASH_ID: | |
| 728 | intintIdentityPerfectHash_DestroyFactory(factory, | |
| 729 | hashIndex); | |
| 730 | break; | |
| 731 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 732 | intintIdentityPerfectCLHash_DestroyFactory(factory, | |
| 733 | hashIndex); | |
| 734 | break; | |
| 735 | case IDENTITY_SENTINEL_PERFECT_HASH_ID: | |
| 736 | intintIdentitySentinelPerfectHash_DestroyFactory | |
| 737 | (factory, hashIndex); | |
| 738 | break; | |
| 739 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 740 | intintIdentitySentinelPerfectCLHash_DestroyFactory | |
| 741 | (factory, hashIndex); | |
| 742 | break; | |
| 743 | case LCG_LINEAR_OPEN_COMPACT_HASH_ID: | |
| 744 | intintLCGLinearOpenCompactHash_DestroyFactory(factory, | |
| 745 | hashIndex); | |
| 746 | break; | |
| 747 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 748 | intintLCGLinearOpenCompactCLHash_DestroyFactory(factory, | |
| 749 | hashIndex); | |
| 750 | break; | |
| 751 | case LCG_QUADRATIC_OPEN_COMPACT_HASH_ID: | |
| 752 | intintLCGQuadraticOpenCompactHash_DestroyFactory | |
| 753 | (factory, hashIndex); | |
| 754 | break; | |
| 755 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 756 | intintLCGQuadraticOpenCompactCLHash_DestroyFactory | |
| 757 | (factory, hashIndex); | |
| 758 | break; | |
| 759 | } | |
| 760 | hashIndex++; | |
| 761 | } | |
| 762 | if (factory->hashTypesAvailable & HASH_ALL_CL_HASHES) { | |
| 763 | clReleaseContext(factory->context); | |
| 764 | clReleaseCommandQueue(factory->queue); | |
| 765 | clReleaseProgram(factory->program); | |
| 766 | } | |
| 767 | free(factory); | |
| 768 | return (0); | |
| 769 | } | |
| 770 | intintHash_Table *intintHash_CreateTable(intintHash_Factory * factory, | |
| 771 | int hashTypes, size_t keyRange, | |
| 772 | size_t numEntries, float loadFactor) { | |
| 773 | if (loadFactor > 1.0 || loadFactor < HASH_MIN_LOAD_FACTOR) { | |
| 774 | loadFactor = HASH_DEFAULT_LOAD_FACTOR; | |
| 775 | } | |
| 776 | if (hashTypes == 0) { | |
| 777 | hashTypes = factory->hashTypesAvailable; | |
| 778 | if ((hashTypes & HASH_ALL_CL_HASHES) | |
| 779 | && (hashTypes & HASH_ALL_C_HASHES)) { | |
| 780 | hashTypes &= HASH_ALL_C_HASHES; | |
| 781 | } | |
| 782 | } | |
| 783 | if (!(hashTypes & factory->hashTypesAvailable)) { | |
| 784 | printf | |
| 785 | ("None of the selected hash types are supported by this factory.\n"); | |
| 786 | exit(1); | |
| 787 | } | |
| 788 | hashTypes &= factory->hashTypesAvailable; | |
| 789 | if ((hashTypes & HASH_ALL_CL_HASHES) && (hashTypes & HASH_ALL_C_HASHES)) { | |
| 790 | printf("Please decide between OpenCL or C hash.\n"); | |
| 791 | exit(1); | |
| 792 | } | |
| 793 | if ((hashTypes & HASH_PERFECT_HASHES) == hashTypes && keyRange == 0) { | |
| 794 | printf | |
| 795 | ("keyRange must be set if a perfect hash is the only option available.\n"); | |
| 796 | exit(1); | |
| 797 | } | |
| 798 | if ((hashTypes & HASH_COMPACT_HASHES) == hashTypes && numEntries == 0) { | |
| 799 | printf | |
| 800 | ("numEntries must be set if a compact hash is the only option available.\n"); | |
| 801 | exit(1); | |
| 802 | } | |
| 803 | if (numEntries == 0 && keyRange == 0) { | |
| 804 | printf("either numEntries or keyRange must be set.\n"); | |
| 805 | exit(1); | |
| 806 | } | |
| 807 | size_t perfectNumBuckets = keyRange; | |
| 808 | size_t compactNumBuckets = (size_t) (numEntries / loadFactor); | |
| 809 | int hashIndex; | |
| 810 | if ((hashTypes & HASH_SENTINEL_PERFECT_HASHES) | |
| 811 | && ((hashTypes == (hashTypes & HASH_SENTINEL_PERFECT_HASHES)) | |
| 812 | || (compactNumBuckets == 0 | |
| 813 | || (perfectNumBuckets / compactNumBuckets < | |
| 814 | HASH_PERFECT_COMPACT_SWITCH_FACTOR)))) { | |
| 815 | hashIndex = intLog2(hashTypes & HASH_SENTINEL_PERFECT_HASHES); | |
| 816 | } else if ((hashTypes & HASH_NOSENTINEL_PERFECT_HASHES) | |
| 817 | && ((hashTypes == (hashTypes & HASH_PERFECT_HASHES)) | |
| 818 | || (compactNumBuckets == 0 | |
| 819 | || (perfectNumBuckets / compactNumBuckets < | |
| 820 | HASH_PERFECT_COMPACT_SWITCH_FACTOR)))) { | |
| 821 | hashIndex = intLog2(hashTypes & HASH_NOSENTINEL_PERFECT_HASHES); | |
| 822 | } else if ((hashTypes & HASH_LINEAR_COMPACT_HASHES) | |
| 823 | && | |
| 824 | ((hashTypes == | |
| 825 | (hashTypes & | |
| 826 | (HASH_PERFECT_HASHES | HASH_LINEAR_COMPACT_HASHES))) | |
| 827 | || | |
| 828 | ((hashTypes & HASH_COMPACT_HASHES & | |
| 829 | HASH_LINEAR_COMPACT_HASHES) == | |
| 830 | (hashTypes & HASH_COMPACT_HASHES) || loadFactor > 0.5))) { | |
| 831 | hashIndex = intLog2(hashTypes & HASH_LINEAR_COMPACT_HASHES); | |
| 832 | } else { | |
| 833 | hashIndex = intLog2(hashTypes & HASH_QUADRATIC_COMPACT_HASHES); | |
| 834 | } | |
| 835 | intintHash_Table *table = | |
| 836 | factory->createFunc[hashIndex] (factory, hashIndex, keyRange, | |
| 837 | numEntries, loadFactor); | |
| 838 | return table; | |
| 839 | } | |
| 840 | int intintHash_EmptyTable(intintHash_Table * table) { | |
| 841 | table->emptyFunc(table); | |
| 842 | return (0); | |
| 843 | } | |
| 844 | int intintHash_DestroyTable(intintHash_Table * table) { | |
| 845 | table->destroyFunc(table); | |
| 846 | return (0); | |
| 847 | } | |
| 848 | cl_mem intintHash_GetTableDataBuffer(intintHash_Table * table) { | |
| 849 | return table->tableDataBuffer; | |
| 850 | } | |
| 851 | cl_mem *intintHash_GetTableDataBufferPtr(intintHash_Table * table) { | |
| 852 | return &table->tableDataBuffer; | |
| 853 | } | |
| 854 | int intintHash_GetTableType(intintHash_Table * table) { | |
| 855 | return ((int *)table->tableData)[0]; | |
| 856 | } int intintHash_Query(intintHash_Table * table, size_t numKeys, int *keys, | |
| 857 | int *valuesOutput) { | |
| 858 | table->queryFunc(table, numKeys, keys, valuesOutput); | |
| 859 | return (0); | |
| 860 | } | |
| 861 | int intintHash_QuerySingle(intintHash_Table * table, int key, int *valueOutput) { | |
| 862 | table->querySingleFunc(table, key, valueOutput); | |
| 863 | return (0); | |
| 864 | } | |
| 865 | int intintHash_Insert(intintHash_Table * table, size_t numEntries, int *keys, | |
| 866 | int *values) { | |
| 867 | table->insertFunc(table, numEntries, keys, values); | |
| 868 | return (0); | |
| 869 | } | |
| 870 | int intintHash_InsertSingle(intintHash_Table * table, int key, int value) { | |
| 871 | table->insertSingleFunc(table, key, value); | |
| 872 | return (0); | |
| 873 | } | |
| 874 | int intintHash_InsertNoOverwrite(intintHash_Table * table, size_t numEntries, | |
| 875 | int *keys, int *values) { | |
| 876 | table->insertNoOverwriteFunc(table, numEntries, keys, values); | |
| 877 | return (0); | |
| 878 | } | |
| 879 | int intintHash_InsertSingleNoOverwrite(intintHash_Table * table, int key, | |
| 880 | int value) { | |
| 881 | table->insertSingleNoOverwriteFunc(table, key, value); | |
| 882 | return (0); | |
| 883 | } | |
| 884 | int intintHash_BufferQuery(intintHash_Table * table, size_t numKeys, | |
| 885 | cl_mem keys, cl_mem valuesOutput) { | |
| 886 | table->bufferQueryFunc(table, numKeys, keys, valuesOutput); | |
| 887 | return (0); | |
| 888 | } | |
| 889 | int intintHash_BufferInsert(intintHash_Table * table, size_t numEntries, | |
| 890 | cl_mem keys, cl_mem values) { | |
| 891 | table->bufferInsertFunc(table, numEntries, keys, values); | |
| 892 | return (0); | |
| 893 | } | |
| 894 | int intintHash_BufferInsertNoOverwrite(intintHash_Table * table, | |
| 895 | size_t numEntries, cl_mem keys, | |
| 896 | cl_mem values) { | |
| 897 | table->bufferInsertNoOverwriteFunc(table, numEntries, keys, values); | |
| 898 | return (0); | |
| 899 | } | |
| 900 | ||
| 901 | typedef struct intintIdentityPerfectHash_TableData { | |
| 902 | int hashID; | |
| 903 | unsigned int numBuckets; | |
| 904 | char compressFuncData; | |
| 905 | } intintIdentityPerfectHash_TableData; | |
| 906 | typedef struct intintIdentityPerfectHash_Bucket { | |
| 907 | int key; | |
| 908 | int value; | |
| 909 | } intintIdentityPerfectHash_Bucket; | |
| 910 | intintHash_Table *intintIdentityPerfectHash_CreateTable(intintHash_Factory * | |
| 911 | factory, int hashIndex, | |
| 912 | size_t keyRange, | |
| 913 | size_t numEntries, | |
| 914 | float loadFactor) { | |
| 915 | intintHash_Table *table = | |
| 916 | (intintHash_Table *) malloc(sizeof(intintHash_Table)); | |
| 917 | table->destroyFunc = &intintIdentityPerfectHash_DestroyTable; | |
| 918 | table->emptyFunc = &intintIdentityPerfectHash_EmptyTable; | |
| 919 | table->queryFunc = &intintIdentityPerfectHash_Query; | |
| 920 | table->querySingleFunc = &intintIdentityPerfectHash_QuerySingle; | |
| 921 | table->insertFunc = &intintIdentityPerfectHash_Insert; | |
| 922 | table->insertSingleFunc = &intintIdentityPerfectHash_InsertSingle; | |
| 923 | table->insertNoOverwriteFunc = | |
| 924 | &intintIdentityPerfectHash_InsertNoOverwrite; | |
| 925 | table->insertSingleNoOverwriteFunc = | |
| 926 | &intintIdentityPerfectHash_InsertSingleNoOverwrite; | |
| 927 | table->tableData = | |
| 928 | (char *)malloc(sizeof(intintIdentityPerfectHash_TableData)); | |
| 929 | ((intintIdentityPerfectHash_TableData *) table->tableData)->hashID = | |
| 930 | IDENTITY_PERFECT_HASH_ID; | |
| 931 | ((intintIdentityPerfectHash_TableData *) table->tableData)->numBuckets = | |
| 932 | keyRange + 1; | |
| 933 | char *tempHashData = | |
| 934 | (char *)malloc(sizeof(intintIdentityPerfectHash_TableData) + | |
| 935 | ((intintIdentityPerfectHash_TableData *) table-> | |
| 936 | tableData)->numBuckets * | |
| 937 | sizeof(intintIdentityPerfectHash_Bucket)); | |
| 938 | memcpy(tempHashData, table->tableData, | |
| 939 | sizeof(intintIdentityPerfectHash_TableData)); | |
| 940 | free(table->tableData); | |
| 941 | table->tableData = tempHashData; | |
| 942 | return table; | |
| 943 | } | |
| 944 | int intintIdentityPerfectHash_CreateFactory(intintHash_Factory * factory, | |
| 945 | int hashIndex) { | |
| 946 | factory->createFunc[hashIndex] = &intintIdentityPerfectHash_CreateTable; | |
| 947 | factory->destroyFunc[hashIndex] = | |
| 948 | &intintIdentityPerfectHash_DestroyFactory;; | |
| 949 | return HASH_EXIT_CODE_NORMAL; | |
| 950 | } | |
| 951 | int intintIdentityPerfectHash_DestroyFactory(intintHash_Factory * factory, | |
| 952 | int hashIndex) {; | |
| 953 | return HASH_EXIT_CODE_NORMAL; | |
| 954 | } | |
| 955 | int intintIdentityPerfectHash_DestroyTable(intintHash_Table * table) { | |
| 956 | int exitCode = 0; | |
| 957 | free(table->tableData); | |
| 958 | free(table); | |
| 959 | return exitCode; | |
| 960 | } | |
| 961 | int intintIdentityPerfectHash_EmptyTable(intintHash_Table * table) { | |
| 962 | int exitCode = 0; | |
| 963 | intintIdentityPerfectHash_Bucket *buckets = | |
| 964 | (intintIdentityPerfectHash_Bucket *) & table-> | |
| 965 | tableData[sizeof(intintIdentityPerfectHash_TableData)]; | |
| 966 | int index; | |
| 967 | for (index = 0; | |
| 968 | index < | |
| 969 | ((intintIdentityPerfectHash_TableData *) table->tableData)-> | |
| 970 | numBuckets; index++) { | |
| 971 | buckets[index].key = HASH_BUCKET_STATUS_EMPTY; | |
| 972 | } | |
| 973 | exitCode = HASH_EXIT_CODE_NORMAL; | |
| 974 | return exitCode; | |
| 975 | } | |
| 976 | int intintIdentityPerfectHash_InnerQuerySingle(char *tableData, int key, | |
| 977 | int *valueOutput) { | |
| 978 | intintIdentityPerfectHash_Bucket *buckets = | |
| 979 | (intintIdentityPerfectHash_Bucket *) & | |
| 980 | tableData[sizeof(intintIdentityPerfectHash_TableData)]; | |
| 981 | int index; | |
| 982 | int exitCode; | |
| 983 | index = | |
| 984 | intintHash_CompressIdentity(((intintIdentityPerfectHash_TableData *) | |
| 985 | tableData)->compressFuncData, key); | |
| 986 | if ((buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 987 | if (key == buckets[index].key) { | |
| 988 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 989 | } else { | |
| 990 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 991 | } | |
| 992 | } else { | |
| 993 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 994 | } | |
| 995 | switch (exitCode) { | |
| 996 | case HASH_SEARCH_CODE_MATCH: | |
| 997 | *valueOutput = buckets[index].value; | |
| 998 | return HASH_EXIT_CODE_NORMAL; | |
| 999 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1000 | case HASH_SEARCH_CODE_EMPTY: | |
| 1001 | return HASH_EXIT_CODE_KEY_DNE; | |
| 1002 | default: | |
| 1003 | return exitCode; | |
| 1004 | } | |
| 1005 | } | |
| 1006 | int intintIdentityPerfectHash_InnerQuery(char *tableData, unsigned int numKeys, | |
| 1007 | int *keys, int *valuesOutput) { | |
| 1008 | intintIdentityPerfectHash_Bucket *buckets = | |
| 1009 | (intintIdentityPerfectHash_Bucket *) & | |
| 1010 | tableData[sizeof(intintIdentityPerfectHash_TableData)]; | |
| 1011 | int key; | |
| 1012 | int *valueOutput; | |
| 1013 | int index; | |
| 1014 | int exitCode; | |
| 1015 | uint i; | |
| 1016 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1017 | for (i = 0; i < numKeys; i++) { | |
| 1018 | key = keys[i]; | |
| 1019 | valueOutput = &valuesOutput[i]; | |
| 1020 | index = | |
| 1021 | intintHash_CompressIdentity(((intintIdentityPerfectHash_TableData *) tableData)->compressFuncData, key); | |
| 1022 | if ((buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 1023 | if (key == buckets[index].key) { | |
| 1024 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1025 | } else { | |
| 1026 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 1027 | } | |
| 1028 | } else { | |
| 1029 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1030 | } | |
| 1031 | switch (exitCode) { | |
| 1032 | case HASH_SEARCH_CODE_MATCH: | |
| 1033 | *valueOutput = buckets[index].value; | |
| 1034 | break; | |
| 1035 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1036 | case HASH_SEARCH_CODE_EMPTY: | |
| 1037 | resultExitCode = HASH_EXIT_CODE_KEY_DNE; | |
| 1038 | break; | |
| 1039 | default: | |
| 1040 | return exitCode; | |
| 1041 | } | |
| 1042 | } | |
| 1043 | return resultExitCode; | |
| 1044 | } | |
| 1045 | int intintIdentityPerfectHash_InnerInsertSingle(char *tableData, int key, | |
| 1046 | int value) { | |
| 1047 | intintIdentityPerfectHash_Bucket *buckets = | |
| 1048 | (intintIdentityPerfectHash_Bucket *) & | |
| 1049 | tableData[sizeof(intintIdentityPerfectHash_TableData)]; | |
| 1050 | int index; | |
| 1051 | int exitCode; | |
| 1052 | index = | |
| 1053 | intintHash_CompressIdentity(((intintIdentityPerfectHash_TableData *) | |
| 1054 | tableData)->compressFuncData, key); | |
| 1055 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 1056 | buckets[index]. | |
| 1057 | key = key; | |
| 1058 | HASH_BUCKET_STATUS_EMPTY;} | |
| 1059 | ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 1060 | if (key == buckets[index].key) { | |
| 1061 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1062 | } else { | |
| 1063 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 1064 | } | |
| 1065 | } else { | |
| 1066 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1067 | } | |
| 1068 | switch (exitCode) { | |
| 1069 | case HASH_SEARCH_CODE_MATCH: | |
| 1070 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1071 | buckets[index].value = value; | |
| 1072 | return HASH_EXIT_CODE_OVERWRITE; | |
| 1073 | case HASH_SEARCH_CODE_EMPTY: | |
| 1074 | buckets[index].value = value; | |
| 1075 | return HASH_EXIT_CODE_NORMAL; | |
| 1076 | default: | |
| 1077 | return exitCode; | |
| 1078 | } | |
| 1079 | } | |
| 1080 | int intintIdentityPerfectHash_InnerInsert(char *tableData, | |
| 1081 | unsigned int numEntries, int *keys, | |
| 1082 | int *values) { | |
| 1083 | intintIdentityPerfectHash_Bucket *buckets = | |
| 1084 | (intintIdentityPerfectHash_Bucket *) & | |
| 1085 | tableData[sizeof(intintIdentityPerfectHash_TableData)]; | |
| 1086 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1087 | int key; | |
| 1088 | int value; | |
| 1089 | int index; | |
| 1090 | int exitCode; | |
| 1091 | uint i; | |
| 1092 | for (i = 0; i < numEntries; i++) { | |
| 1093 | key = keys[i]; | |
| 1094 | index = | |
| 1095 | intintHash_CompressIdentity(((intintIdentityPerfectHash_TableData *) tableData)->compressFuncData, key); | |
| 1096 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 1097 | buckets | |
| 1098 | [index]. | |
| 1099 | key = | |
| 1100 | key; | |
| 1101 | HASH_BUCKET_STATUS_EMPTY;} | |
| 1102 | ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 1103 | if (key == buckets[index].key) { | |
| 1104 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1105 | } else { | |
| 1106 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 1107 | } | |
| 1108 | } else { | |
| 1109 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1110 | } | |
| 1111 | switch (exitCode) { | |
| 1112 | case HASH_SEARCH_CODE_MATCH: | |
| 1113 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1114 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 1115 | case HASH_SEARCH_CODE_EMPTY: | |
| 1116 | buckets[index].value = values[i]; | |
| 1117 | break; | |
| 1118 | default: | |
| 1119 | return exitCode; | |
| 1120 | } | |
| 1121 | } | |
| 1122 | return resultExitCode; | |
| 1123 | } | |
| 1124 | int intintIdentityPerfectHash_InnerInsertSingleNoOverwrite(char *tableData, | |
| 1125 | int key, int value) { | |
| 1126 | intintIdentityPerfectHash_Bucket *buckets = | |
| 1127 | (intintIdentityPerfectHash_Bucket *) & | |
| 1128 | tableData[sizeof(intintIdentityPerfectHash_TableData)]; | |
| 1129 | int index; | |
| 1130 | int exitCode; | |
| 1131 | index = | |
| 1132 | intintHash_CompressIdentity(((intintIdentityPerfectHash_TableData *) | |
| 1133 | tableData)->compressFuncData, key); | |
| 1134 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 1135 | buckets[index]. | |
| 1136 | key = key; | |
| 1137 | HASH_BUCKET_STATUS_EMPTY;} | |
| 1138 | ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 1139 | if (key == buckets[index].key) { | |
| 1140 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1141 | } else { | |
| 1142 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 1143 | } | |
| 1144 | } else { | |
| 1145 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1146 | } | |
| 1147 | switch (exitCode) { | |
| 1148 | case HASH_SEARCH_CODE_MATCH: | |
| 1149 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1150 | return HASH_EXIT_CODE_OVERWRITE; | |
| 1151 | case HASH_SEARCH_CODE_EMPTY: | |
| 1152 | buckets[index].value = value; | |
| 1153 | return HASH_EXIT_CODE_NORMAL; | |
| 1154 | default: | |
| 1155 | return exitCode; | |
| 1156 | } | |
| 1157 | } | |
| 1158 | int intintIdentityPerfectHash_InnerInsertNoOverwrite(char *tableData, | |
| 1159 | unsigned int numEntries, | |
| 1160 | int *keys, int *values) { | |
| 1161 | intintIdentityPerfectHash_Bucket *buckets = | |
| 1162 | (intintIdentityPerfectHash_Bucket *) & | |
| 1163 | tableData[sizeof(intintIdentityPerfectHash_TableData)]; | |
| 1164 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1165 | int key; | |
| 1166 | int value; | |
| 1167 | int index; | |
| 1168 | int exitCode; | |
| 1169 | uint i; | |
| 1170 | for (i = 0; i < numEntries; i++) { | |
| 1171 | key = keys[i]; | |
| 1172 | index = | |
| 1173 | intintHash_CompressIdentity(((intintIdentityPerfectHash_TableData *) tableData)->compressFuncData, key); | |
| 1174 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 1175 | buckets | |
| 1176 | [index]. | |
| 1177 | key = | |
| 1178 | key; | |
| 1179 | HASH_BUCKET_STATUS_EMPTY;} | |
| 1180 | ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 1181 | if (key == buckets[index].key) { | |
| 1182 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1183 | } else { | |
| 1184 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 1185 | } | |
| 1186 | } else { | |
| 1187 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1188 | } | |
| 1189 | switch (exitCode) { | |
| 1190 | case HASH_SEARCH_CODE_MATCH: | |
| 1191 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1192 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 1193 | break; | |
| 1194 | case HASH_SEARCH_CODE_EMPTY: | |
| 1195 | buckets[index].value = values[i]; | |
| 1196 | break; | |
| 1197 | default: | |
| 1198 | return exitCode; | |
| 1199 | } | |
| 1200 | } | |
| 1201 | return resultExitCode; | |
| 1202 | } | |
| 1203 | int intintIdentityPerfectHash_QuerySingle(intintHash_Table * table, int key, | |
| 1204 | int *valueOutput) { | |
| 1205 | return intintIdentityPerfectHash_InnerQuerySingle(table->tableData, key, | |
| 1206 | valueOutput); | |
| 1207 | } | |
| 1208 | int intintIdentityPerfectHash_Query(intintHash_Table * table, size_t numKeys, | |
| 1209 | int *keys, int *valuesOutput) { | |
| 1210 | return intintIdentityPerfectHash_InnerQuery(table->tableData, numKeys, | |
| 1211 | keys, valuesOutput); | |
| 1212 | } | |
| 1213 | int intintIdentityPerfectHash_InsertSingle(intintHash_Table * table, int key, | |
| 1214 | int value) { | |
| 1215 | return intintIdentityPerfectHash_InnerInsertSingle(table->tableData, | |
| 1216 | key, value); | |
| 1217 | } | |
| 1218 | int intintIdentityPerfectHash_Insert(intintHash_Table * table, | |
| 1219 | size_t numEntries, int *keys, | |
| 1220 | int *values) { | |
| 1221 | return intintIdentityPerfectHash_InnerInsert(table->tableData, | |
| 1222 | numEntries, keys, values); | |
| 1223 | } | |
| 1224 | int intintIdentityPerfectHash_InsertSingleNoOverwrite(intintHash_Table * table, | |
| 1225 | int key, int value) { | |
| 1226 | return intintIdentityPerfectHash_InnerInsertSingleNoOverwrite(table-> | |
| 1227 | tableData, | |
| 1228 | key, | |
| 1229 | value); | |
| 1230 | } | |
| 1231 | int intintIdentityPerfectHash_InsertNoOverwrite(intintHash_Table * table, | |
| 1232 | size_t numEntries, int *keys, | |
| 1233 | int *values) { | |
| 1234 | return intintIdentityPerfectHash_InnerInsertNoOverwrite(table-> | |
| 1235 | tableData, | |
| 1236 | numEntries, | |
| 1237 | keys, values); | |
| 1238 | } | |
| 1239 | ||
| 1240 | typedef struct intintIdentityPerfectCLHash_TableData { | |
| 1241 | int hashID; | |
| 1242 | unsigned int numBuckets; | |
| 1243 | char compressFuncData; | |
| 1244 | } intintIdentityPerfectCLHash_TableData; | |
| 1245 | typedef struct intintIdentityPerfectCLHash_Bucket { | |
| 1246 | int key; | |
| 1247 | int value; | |
| 1248 | } intintIdentityPerfectCLHash_Bucket; | |
| 1249 | intintHash_Table *intintIdentityPerfectCLHash_CreateTable(intintHash_Factory * | |
| 1250 | factory, | |
| 1251 | int hashIndex, | |
| 1252 | size_t keyRange, | |
| 1253 | size_t numEntries, | |
| 1254 | float loadFactor) { | |
| 1255 | intintHash_Table *table = | |
| 1256 | (intintHash_Table *) malloc(sizeof(intintHash_Table)); | |
| 1257 | table->destroyFunc = &intintIdentityPerfectCLHash_DestroyTable; | |
| 1258 | table->emptyFunc = &intintIdentityPerfectCLHash_EmptyTable; | |
| 1259 | table->queryFunc = &intintIdentityPerfectCLHash_Query; | |
| 1260 | table->querySingleFunc = &intintIdentityPerfectCLHash_QuerySingle; | |
| 1261 | table->insertFunc = &intintIdentityPerfectCLHash_Insert; | |
| 1262 | table->insertSingleFunc = &intintIdentityPerfectCLHash_InsertSingle; | |
| 1263 | table->insertNoOverwriteFunc = | |
| 1264 | &intintIdentityPerfectCLHash_InsertNoOverwrite; | |
| 1265 | table->insertSingleNoOverwriteFunc = | |
| 1266 | &intintIdentityPerfectCLHash_InsertSingleNoOverwrite; | |
| 1267 | table->tableData = | |
| 1268 | (char *)malloc(sizeof(intintIdentityPerfectCLHash_TableData)); | |
| 1269 | ((intintIdentityPerfectCLHash_TableData *) table->tableData)->hashID = | |
| 1270 | IDENTITY_PERFECT_CL_HASH_ID; | |
| 1271 | table->context = factory->context; | |
| 1272 | table->queue = factory->queue; | |
| 1273 | table->program = factory->program; | |
| 1274 | table->localWorkSize = factory->localWorkSize; | |
| 1275 | table->utilProgram = factory->utilProgram[hashIndex]; | |
| 1276 | table->emptyKernel = factory->emptyKernel[hashIndex]; | |
| 1277 | table->emptyKernelLocalWorkSize = | |
| 1278 | factory->emptyKernelLocalWorkSize[hashIndex]; | |
| 1279 | table->querySingleKernel = factory->querySingleKernel[hashIndex]; | |
| 1280 | table->insertSingleKernel = factory->insertSingleKernel[hashIndex]; | |
| 1281 | table->insertSingleNoOverwriteKernel = | |
| 1282 | factory->insertSingleNoOverwriteKernel[hashIndex]; | |
| 1283 | clRetainContext(table->context); | |
| 1284 | clRetainCommandQueue(table->queue); | |
| 1285 | clRetainProgram(table->program); | |
| 1286 | clRetainProgram(table->utilProgram); | |
| 1287 | clRetainKernel(table->emptyKernel); | |
| 1288 | clRetainKernel(table->querySingleKernel); | |
| 1289 | clRetainKernel(table->insertSingleKernel); | |
| 1290 | clRetainKernel(table->insertSingleNoOverwriteKernel);; | |
| 1291 | ((intintIdentityPerfectCLHash_TableData *) table->tableData)-> | |
| 1292 | numBuckets = keyRange + 1; | |
| 1293 | char *tempHashData = | |
| 1294 | (char *)malloc(sizeof(intintIdentityPerfectCLHash_TableData) + | |
| 1295 | ((intintIdentityPerfectCLHash_TableData *) table-> | |
| 1296 | tableData)->numBuckets * | |
| 1297 | sizeof(intintIdentityPerfectCLHash_Bucket)); | |
| 1298 | memcpy(tempHashData, table->tableData, | |
| 1299 | sizeof(intintIdentityPerfectCLHash_TableData)); | |
| 1300 | free(table->tableData); | |
| 1301 | table->tableData = tempHashData; | |
| 1302 | cl_int err; | |
| 1303 | table->tableDataBuffer = | |
| 1304 | clCreateBuffer(table->context, CL_MEM_READ_WRITE, | |
| 1305 | sizeof(intintIdentityPerfectHash_TableData) + | |
| 1306 | ((intintIdentityPerfectHash_TableData *) table-> | |
| 1307 | tableData)->numBuckets * | |
| 1308 | sizeof(intintIdentityPerfectHash_Bucket), NULL, | |
| 1309 | &err); | |
| 1310 | CLHash_Utilities_HandleError(err, | |
| 1311 | "intintIdentityPerfectCLHash_InitTable", | |
| 1312 | "clCreateBuffer"); | |
| 1313 | err = | |
| 1314 | clEnqueueWriteBuffer(table->queue, table->tableDataBuffer, CL_TRUE, | |
| 1315 | 0, sizeof(intintIdentityPerfectHash_TableData), | |
| 1316 | table->tableData, 0, NULL, NULL); | |
| 1317 | CLHash_Utilities_HandleError(err, | |
| 1318 | "intintIdentityPerfectCLHash_InitTable", | |
| 1319 | "clEnqueueWriteBuffer"); | |
| 1320 | return table; | |
| 1321 | } | |
| 1322 | int intintIdentityPerfectCLHash_CreateFactory(intintHash_Factory * factory, | |
| 1323 | int hashIndex) { | |
| 1324 | factory->createFunc[hashIndex] = | |
| 1325 | &intintIdentityPerfectCLHash_CreateTable; | |
| 1326 | factory->destroyFunc[hashIndex] = | |
| 1327 | &intintIdentityPerfectCLHash_DestroyFactory; | |
| 1328 | cl_int error; | |
| 1329 | cl_device_id device; | |
| 1330 | error = | |
| 1331 | clGetContextInfo(factory->context, CL_CONTEXT_DEVICES, | |
| 1332 | sizeof(device), &device, NULL); | |
| 1333 | CLHash_Utilities_HandleError(error, "intintHash_CreateFactory", | |
| 1334 | "clGetContextInfo"); | |
| 1335 | factory->querySingleKernel[hashIndex] = | |
| 1336 | clCreateKernel(factory->program, | |
| 1337 | "intintIdentityPerfectCLHash_RangeQuerySingle", | |
| 1338 | &error); | |
| 1339 | CLHash_Utilities_HandleError(error, | |
| 1340 | "intintIdentityPerfectCLHash_CreateFactory", | |
| 1341 | "clCreateKernel"); | |
| 1342 | factory->insertSingleKernel[hashIndex] = | |
| 1343 | clCreateKernel(factory->program, | |
| 1344 | "intintIdentityPerfectCLHash_RangeInsertSingle", | |
| 1345 | &error); | |
| 1346 | CLHash_Utilities_HandleError(error, | |
| 1347 | "intintIdentityPerfectCLHash_CreateFactory", | |
| 1348 | "clCreateKernel"); | |
| 1349 | factory->insertSingleNoOverwriteKernel[hashIndex] = | |
| 1350 | clCreateKernel(factory->program, | |
| 1351 | "intintIdentityPerfectCLHash_RangeInsertSingleNoOverwrite", | |
| 1352 | &error); | |
| 1353 | CLHash_Utilities_HandleError(error, | |
| 1354 | "intintIdentityPerfectCLHash_CreateFactory", | |
| 1355 | "clCreateKernel"); | |
| 1356 | factory->utilProgram[hashIndex] = | |
| 1357 | CLHash_Utilities_BuildProgramString(factory->context, device, | |
| 1358 | "static inline unsigned int intintHash_CompressIdentity(char data, int hashCode){ return hashCode; } typedef struct intintHash_CompressLCGData{ long unsigned int a; long unsigned int c; unsigned int m; unsigned int n; }intintHash_CompressLCGData; static inline unsigned int intintHash_CompressLCG(intintHash_CompressLCGData compressLCGData, int hashCode){ return ((compressLCGData.a * hashCode + compressLCGData.c) % compressLCGData.m) % compressLCGData.n; } typedef struct intintIdentityPerfectCLHash_TableData{ int hashID; unsigned int numBuckets; char compressFuncData; }intintIdentityPerfectCLHash_TableData; typedef struct intintIdentityPerfectCLHash_Bucket{ int key; int value; }intintIdentityPerfectCLHash_Bucket; __kernel void intintIdentityPerfectCLHash_Empty(__global char *tableData){ int index = get_global_id(0); if(index >= ((__global intintIdentityPerfectCLHash_TableData*)tableData)->numBuckets){ return; } __global intintIdentityPerfectCLHash_Bucket *buckets = (__global intintIdentityPerfectCLHash_Bucket*)&tableData[sizeof(intintIdentityPerfectCLHash_TableData)]; buckets[index].key = -1;/*HASH_BUCKET_STATUS_EMPTY*/ }"); | |
| 1359 | factory->emptyKernel[hashIndex] = | |
| 1360 | clCreateKernel(factory->utilProgram[hashIndex], | |
| 1361 | "intintIdentityPerfectCLHash_Empty", &error); | |
| 1362 | CLHash_Utilities_HandleError(error, | |
| 1363 | "intintIdentityPerfectCLHash_CreateFactory", | |
| 1364 | "clCreateKernel"); | |
| 1365 | error = | |
| 1366 | clGetKernelWorkGroupInfo(factory->emptyKernel[hashIndex], device, | |
| 1367 | CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), | |
| 1368 | &factory-> | |
| 1369 | emptyKernelLocalWorkSize[hashIndex], NULL); | |
| 1370 | CLHash_Utilities_HandleError(error, | |
| 1371 | "intintIdentityPerfectCLHash_CreateFactory", | |
| 1372 | "clGetKernelWorkGroupInfo");;; | |
| 1373 | return HASH_EXIT_CODE_NORMAL; | |
| 1374 | } | |
| 1375 | int intintIdentityPerfectCLHash_DestroyFactory(intintHash_Factory * factory, | |
| 1376 | int hashIndex) {; | |
| 1377 | clReleaseKernel(factory->emptyKernel[hashIndex]); | |
| 1378 | clReleaseProgram(factory->utilProgram[hashIndex]); | |
| 1379 | clReleaseKernel(factory->querySingleKernel[hashIndex]); | |
| 1380 | clReleaseKernel(factory->insertSingleKernel[hashIndex]); | |
| 1381 | clReleaseKernel(factory->insertSingleNoOverwriteKernel[hashIndex]);; | |
| 1382 | return HASH_EXIT_CODE_NORMAL; | |
| 1383 | } | |
| 1384 | int intintIdentityPerfectCLHash_DestroyTable(intintHash_Table * table) { | |
| 1385 | int exitCode = 0; | |
| 1386 | clReleaseMemObject(table->tableDataBuffer); | |
| 1387 | clReleaseContext(table->context); | |
| 1388 | clReleaseCommandQueue(table->queue); | |
| 1389 | clReleaseProgram(table->utilProgram); | |
| 1390 | clReleaseKernel(table->emptyKernel); | |
| 1391 | clReleaseProgram(table->program); | |
| 1392 | clReleaseKernel(table->querySingleKernel); | |
| 1393 | clReleaseKernel(table->insertSingleKernel); | |
| 1394 | clReleaseKernel(table->insertSingleNoOverwriteKernel); | |
| 1395 | free(table->tableData); | |
| 1396 | free(table); | |
| 1397 | return exitCode; | |
| 1398 | } | |
| 1399 | int intintIdentityPerfectCLHash_EmptyTable(intintHash_Table * table) { | |
| 1400 | int exitCode = 0; | |
| 1401 | cl_int err; | |
| 1402 | err = | |
| 1403 | clSetKernelArg(table->emptyKernel, 0, sizeof(cl_mem), | |
| 1404 | &table->tableDataBuffer); | |
| 1405 | CLHash_Utilities_HandleError(err, | |
| 1406 | "intintIdentityPerfectCLHash_EmptyTable", | |
| 1407 | "clSetKernelArg"); | |
| 1408 | const size_t groupWorkSize = | |
| 1409 | roundUpToNearest(((intintIdentityPerfectHash_TableData *) table-> | |
| 1410 | tableData)->numBuckets, | |
| 1411 | table->emptyKernelLocalWorkSize); | |
| 1412 | err = | |
| 1413 | clEnqueueNDRangeKernel(table->queue, table->emptyKernel, 1, 0, | |
| 1414 | &groupWorkSize, | |
| 1415 | (const size_t *)&table-> | |
| 1416 | emptyKernelLocalWorkSize, 0, NULL, NULL); | |
| 1417 | CLHash_Utilities_HandleError(err, | |
| 1418 | "intintIdentityPerfectCLHash_EmptyTable", | |
| 1419 | "clEnqueueNDRangeKernel"); | |
| 1420 | exitCode = HASH_EXIT_CODE_NORMAL;; | |
| 1421 | return exitCode; | |
| 1422 | } | |
| 1423 | int intintIdentityPerfectCLHash_QuerySingle(intintHash_Table * table, int key, | |
| 1424 | int *valueOutput) { | |
| 1425 | return intintIdentityPerfectCLHash_Query(table, 1, &key, valueOutput); | |
| 1426 | } | |
| 1427 | int intintIdentityPerfectCLHash_Query(intintHash_Table * table, size_t numKeys, | |
| 1428 | int *keys, int *valuesOutput) { | |
| 1429 | cl_int err; | |
| 1430 | cl_mem keysBuffer = | |
| 1431 | clCreateBuffer(table->context, | |
| 1432 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 1433 | sizeof(int) * numKeys, keys, &err); | |
| 1434 | CLHash_Utilities_HandleError(err, "intintIdentityPerfectCLHash_Query", | |
| 1435 | "clCreateBuffer"); | |
| 1436 | cl_mem valuesOutputBuffer = | |
| 1437 | clCreateBuffer(table->context, CL_MEM_WRITE_ONLY, | |
| 1438 | sizeof(int) * numKeys, NULL, &err); | |
| 1439 | CLHash_Utilities_HandleError(err, "intintIdentityPerfectCLHash_Query", | |
| 1440 | "clCreateBuffer"); | |
| 1441 | intintIdentityPerfectCLHash_BufferQuery(table, numKeys, keysBuffer, | |
| 1442 | valuesOutputBuffer); | |
| 1443 | err = | |
| 1444 | clEnqueueReadBuffer(table->queue, valuesOutputBuffer, CL_TRUE, 0, | |
| 1445 | sizeof(int) * numKeys, valuesOutput, 0, NULL, | |
| 1446 | NULL); | |
| 1447 | CLHash_Utilities_HandleError(err, "intintIdentityPerfectCLHash_Query", | |
| 1448 | "clEnqueueReadBuffer"); | |
| 1449 | clReleaseMemObject(keysBuffer); | |
| 1450 | clReleaseMemObject(valuesOutputBuffer); | |
| 1451 | return HASH_EXIT_CODE_NORMAL; | |
| 1452 | } | |
| 1453 | int intintIdentityPerfectCLHash_BufferQuery(intintHash_Table * table, | |
| 1454 | size_t numKeys, cl_mem keysBuffer, | |
| 1455 | cl_mem valuesOutputBuffer) { | |
| 1456 | cl_int err; | |
| 1457 | err = | |
| 1458 | clSetKernelArg(table->querySingleKernel, 0, sizeof(cl_mem), | |
| 1459 | &table->tableDataBuffer); | |
| 1460 | CLHash_Utilities_HandleError(err, | |
| 1461 | "intintIdentityPerfectCLHash_BufferQuery", | |
| 1462 | "clSetKernelArg"); | |
| 1463 | err = | |
| 1464 | clSetKernelArg(table->querySingleKernel, 1, sizeof(unsigned int), | |
| 1465 | &numKeys); | |
| 1466 | CLHash_Utilities_HandleError(err, | |
| 1467 | "intintIdentityPerfectCLHash_BufferQuery", | |
| 1468 | "clSetKernelArg"); | |
| 1469 | err = | |
| 1470 | clSetKernelArg(table->querySingleKernel, 2, sizeof(cl_mem), | |
| 1471 | &keysBuffer); | |
| 1472 | CLHash_Utilities_HandleError(err, | |
| 1473 | "intintIdentityPerfectCLHash_BufferQuery", | |
| 1474 | "clSetKernelArg"); | |
| 1475 | err = | |
| 1476 | clSetKernelArg(table->querySingleKernel, 3, sizeof(cl_mem), | |
| 1477 | &valuesOutputBuffer); | |
| 1478 | CLHash_Utilities_HandleError(err, | |
| 1479 | "intintIdentityPerfectCLHash_BufferQuery", | |
| 1480 | "clSetKernelArg"); | |
| 1481 | const size_t groupWorkSize = | |
| 1482 | roundUpToNearest(numKeys, table->localWorkSize); | |
| 1483 | err = | |
| 1484 | clEnqueueNDRangeKernel(table->queue, table->querySingleKernel, 1, 0, | |
| 1485 | &groupWorkSize, | |
| 1486 | (const size_t *)&table->localWorkSize, 0, | |
| 1487 | NULL, NULL); | |
| 1488 | CLHash_Utilities_HandleError(err, | |
| 1489 | "intintIdentityPerfectCLHash_BufferQuery", | |
| 1490 | "clEnqueueNDRangeKernel"); | |
| 1491 | clFinish(table->queue); | |
| 1492 | return HASH_EXIT_CODE_NORMAL; | |
| 1493 | } | |
| 1494 | int intintIdentityPerfectCLHash_InsertSingle(intintHash_Table * table, int key, | |
| 1495 | int value) { | |
| 1496 | return intintIdentityPerfectCLHash_Insert(table, 1, &key, &value); | |
| 1497 | } | |
| 1498 | int intintIdentityPerfectCLHash_Insert(intintHash_Table * table, | |
| 1499 | size_t numEntries, int *keys, | |
| 1500 | int *values) { | |
| 1501 | cl_int err; | |
| 1502 | cl_mem keysBuffer = | |
| 1503 | clCreateBuffer(table->context, | |
| 1504 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 1505 | sizeof(int) * numEntries, keys, &err); | |
| 1506 | CLHash_Utilities_HandleError(err, "intintIdentityPerfectCLHash_Insert", | |
| 1507 | "clCreateBuffer"); | |
| 1508 | cl_mem valuesBuffer = | |
| 1509 | clCreateBuffer(table->context, | |
| 1510 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 1511 | sizeof(int) * numEntries, values, &err); | |
| 1512 | CLHash_Utilities_HandleError(err, "intintIdentityPerfectCLHash_Insert", | |
| 1513 | "clCreateBuffer"); | |
| 1514 | intintIdentityPerfectCLHash_BufferInsert(table, numEntries, keysBuffer, | |
| 1515 | valuesBuffer); | |
| 1516 | clReleaseMemObject(keysBuffer); | |
| 1517 | clReleaseMemObject(valuesBuffer); | |
| 1518 | return HASH_EXIT_CODE_NORMAL; | |
| 1519 | } | |
| 1520 | int intintIdentityPerfectCLHash_BufferInsert(intintHash_Table * table, | |
| 1521 | size_t numEntries, | |
| 1522 | cl_mem keysBuffer, | |
| 1523 | cl_mem valuesBuffer) { | |
| 1524 | cl_int err; | |
| 1525 | err = | |
| 1526 | clSetKernelArg(table->insertSingleKernel, 0, sizeof(cl_mem), | |
| 1527 | &table->tableDataBuffer); | |
| 1528 | CLHash_Utilities_HandleError(err, | |
| 1529 | "intintIdentityPerfectCLHash_BufferInsert", | |
| 1530 | "clSetKernelArg"); | |
| 1531 | err = | |
| 1532 | clSetKernelArg(table->insertSingleKernel, 1, sizeof(unsigned int), | |
| 1533 | &numEntries); | |
| 1534 | CLHash_Utilities_HandleError(err, | |
| 1535 | "intintIdentityPerfectCLHash_BufferInsert", | |
| 1536 | "clSetKernelArg"); | |
| 1537 | err = | |
| 1538 | clSetKernelArg(table->insertSingleKernel, 2, sizeof(cl_mem), | |
| 1539 | &keysBuffer); | |
| 1540 | CLHash_Utilities_HandleError(err, | |
| 1541 | "intintIdentityPerfectCLHash_BufferInsert", | |
| 1542 | "clSetKernelArg"); | |
| 1543 | err = | |
| 1544 | clSetKernelArg(table->insertSingleKernel, 3, sizeof(cl_mem), | |
| 1545 | &valuesBuffer); | |
| 1546 | CLHash_Utilities_HandleError(err, | |
| 1547 | "intintIdentityPerfectCLHash_BufferInsert", | |
| 1548 | "clSetKernelArg"); | |
| 1549 | const size_t groupWorkSize = | |
| 1550 | roundUpToNearest(numEntries, table->localWorkSize); | |
| 1551 | err = | |
| 1552 | clEnqueueNDRangeKernel(table->queue, table->insertSingleKernel, 1, | |
| 1553 | 0, &groupWorkSize, | |
| 1554 | (const size_t *)&table->localWorkSize, 0, | |
| 1555 | NULL, NULL); | |
| 1556 | CLHash_Utilities_HandleError(err, NULL, "clEnqueueNDRangeKernel"); | |
| 1557 | return (0); | |
| 1558 | } | |
| 1559 | int intintIdentityPerfectCLHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 1560 | table, int key, | |
| 1561 | int value) { | |
| 1562 | return intintIdentityPerfectCLHash_InsertNoOverwrite(table, 1, &key, | |
| 1563 | &value); | |
| 1564 | } | |
| 1565 | int intintIdentityPerfectCLHash_InsertNoOverwrite(intintHash_Table * table, | |
| 1566 | size_t numEntries, int *keys, | |
| 1567 | int *values) { | |
| 1568 | cl_int err; | |
| 1569 | cl_mem keysBuffer = | |
| 1570 | clCreateBuffer(table->context, | |
| 1571 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 1572 | sizeof(int) * numEntries, keys, &err); | |
| 1573 | CLHash_Utilities_HandleError(err, | |
| 1574 | "intintIdentityPerfectCLHash_InsertNoOverwrite", | |
| 1575 | "clCreateBuffer"); | |
| 1576 | cl_mem valuesBuffer = | |
| 1577 | clCreateBuffer(table->context, | |
| 1578 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 1579 | sizeof(int) * numEntries, values, &err); | |
| 1580 | CLHash_Utilities_HandleError(err, | |
| 1581 | "intintIdentityPerfectCLHash_InsertNoOverwrite", | |
| 1582 | "clCreateBuffer"); | |
| 1583 | intintIdentityPerfectCLHash_BufferInsertNoOverwrite(table, numEntries, | |
| 1584 | keysBuffer, | |
| 1585 | valuesBuffer); | |
| 1586 | clReleaseMemObject(keysBuffer); | |
| 1587 | clReleaseMemObject(valuesBuffer); | |
| 1588 | return HASH_EXIT_CODE_NORMAL; | |
| 1589 | } | |
| 1590 | int intintIdentityPerfectCLHash_BufferInsertNoOverwrite(intintHash_Table * | |
| 1591 | table, | |
| 1592 | size_t numEntries, | |
| 1593 | cl_mem keysBuffer, | |
| 1594 | cl_mem valuesBuffer) { | |
| 1595 | cl_int err; | |
| 1596 | err = | |
| 1597 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 0, | |
| 1598 | sizeof(cl_mem), &table->tableDataBuffer); | |
| 1599 | CLHash_Utilities_HandleError(err, | |
| 1600 | "intintIdentityPerfectCLHash_BufferInsertNoOverwrite", | |
| 1601 | "clSetKernelArg"); | |
| 1602 | err = | |
| 1603 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 1, | |
| 1604 | sizeof(unsigned int), &numEntries); | |
| 1605 | CLHash_Utilities_HandleError(err, | |
| 1606 | "intintIdentityPerfectCLHash_BufferInsertNoOverwrite", | |
| 1607 | "ClSetKernelArg"); | |
| 1608 | err = | |
| 1609 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 2, | |
| 1610 | sizeof(cl_mem), &keysBuffer); | |
| 1611 | CLHash_Utilities_HandleError(err, | |
| 1612 | "intintIdentityPerfectCLHash_BufferInsertNoOverwrite", | |
| 1613 | "clSetKernelArg"); | |
| 1614 | err = | |
| 1615 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 3, | |
| 1616 | sizeof(cl_mem), &valuesBuffer); | |
| 1617 | CLHash_Utilities_HandleError(err, | |
| 1618 | "intintIdentityPerfectCLHash_BufferInsertNoOverwrite", | |
| 1619 | "clSetKernelArg"); | |
| 1620 | const size_t groupWorkSize = | |
| 1621 | roundUpToNearest(numEntries, table->localWorkSize); | |
| 1622 | err = | |
| 1623 | clEnqueueNDRangeKernel(table->queue, | |
| 1624 | table->insertSingleNoOverwriteKernel, 1, 0, | |
| 1625 | &groupWorkSize, | |
| 1626 | (const size_t *)&table->localWorkSize, 0, | |
| 1627 | NULL, NULL); | |
| 1628 | CLHash_Utilities_HandleError(err, | |
| 1629 | "intintIdentityPerfectCLHash_BufferInsertNoOverwrite", | |
| 1630 | "clEnqueueNDRangeKernel"); | |
| 1631 | return (0); | |
| 1632 | } | |
| 1633 | ||
| 1634 | typedef struct intintIdentitySentinelPerfectHash_TableData { | |
| 1635 | int hashID; | |
| 1636 | unsigned int numBuckets; | |
| 1637 | char compressFuncData; | |
| 1638 | int emptyValue; | |
| 1639 | } intintIdentitySentinelPerfectHash_TableData; | |
| 1640 | typedef struct intintIdentitySentinelPerfectHash_Bucket { | |
| 1641 | int value; | |
| 1642 | } intintIdentitySentinelPerfectHash_Bucket; | |
| 1643 | intintHash_Table | |
| 1644 | *intintIdentitySentinelPerfectHash_CreateTable(intintHash_Factory * factory, | |
| 1645 | int hashIndex, | |
| 1646 | size_t keyRange, | |
| 1647 | size_t numEntries, | |
| 1648 | float loadFactor) { | |
| 1649 | intintHash_Table *table = | |
| 1650 | (intintHash_Table *) malloc(sizeof(intintHash_Table)); | |
| 1651 | table->destroyFunc = &intintIdentitySentinelPerfectHash_DestroyTable; | |
| 1652 | table->emptyFunc = &intintIdentitySentinelPerfectHash_EmptyTable; | |
| 1653 | table->queryFunc = &intintIdentitySentinelPerfectHash_Query; | |
| 1654 | table->querySingleFunc = &intintIdentitySentinelPerfectHash_QuerySingle; | |
| 1655 | table->insertFunc = &intintIdentitySentinelPerfectHash_Insert; | |
| 1656 | table->insertSingleFunc = | |
| 1657 | &intintIdentitySentinelPerfectHash_InsertSingle; | |
| 1658 | table->insertNoOverwriteFunc = | |
| 1659 | &intintIdentitySentinelPerfectHash_InsertNoOverwrite; | |
| 1660 | table->insertSingleNoOverwriteFunc = | |
| 1661 | &intintIdentitySentinelPerfectHash_InsertSingleNoOverwrite; | |
| 1662 | table->tableData = | |
| 1663 | (char *)malloc(sizeof(intintIdentitySentinelPerfectHash_TableData)); | |
| 1664 | ((intintIdentitySentinelPerfectHash_TableData *) table->tableData)-> | |
| 1665 | hashID = IDENTITY_SENTINEL_PERFECT_HASH_ID; | |
| 1666 | ((intintIdentitySentinelPerfectHash_TableData *) table->tableData)-> | |
| 1667 | emptyValue = factory->emptyValue; | |
| 1668 | ((intintIdentitySentinelPerfectHash_TableData *) table->tableData)-> | |
| 1669 | numBuckets = keyRange + 1; | |
| 1670 | char *tempHashData = | |
| 1671 | (char *)malloc(sizeof(intintIdentitySentinelPerfectHash_TableData) + | |
| 1672 | ((intintIdentitySentinelPerfectHash_TableData *) | |
| 1673 | table->tableData)->numBuckets * | |
| 1674 | sizeof(intintIdentitySentinelPerfectHash_Bucket)); | |
| 1675 | memcpy(tempHashData, table->tableData, | |
| 1676 | sizeof(intintIdentitySentinelPerfectHash_TableData)); | |
| 1677 | free(table->tableData); | |
| 1678 | table->tableData = tempHashData; | |
| 1679 | return table; | |
| 1680 | } | |
| 1681 | int intintIdentitySentinelPerfectHash_CreateFactory(intintHash_Factory * | |
| 1682 | factory, int hashIndex) { | |
| 1683 | factory->createFunc[hashIndex] = | |
| 1684 | &intintIdentitySentinelPerfectHash_CreateTable; | |
| 1685 | factory->destroyFunc[hashIndex] = | |
| 1686 | &intintIdentitySentinelPerfectHash_DestroyFactory;; | |
| 1687 | return HASH_EXIT_CODE_NORMAL; | |
| 1688 | } | |
| 1689 | int intintIdentitySentinelPerfectHash_DestroyFactory(intintHash_Factory * | |
| 1690 | factory, int hashIndex) {; | |
| 1691 | return HASH_EXIT_CODE_NORMAL; | |
| 1692 | } | |
| 1693 | int intintIdentitySentinelPerfectHash_DestroyTable(intintHash_Table * table) { | |
| 1694 | int exitCode = 0; | |
| 1695 | free(table->tableData); | |
| 1696 | free(table); | |
| 1697 | return exitCode; | |
| 1698 | } | |
| 1699 | int intintIdentitySentinelPerfectHash_EmptyTable(intintHash_Table * table) { | |
| 1700 | int exitCode = 0; | |
| 1701 | intintIdentitySentinelPerfectHash_Bucket *buckets = | |
| 1702 | (intintIdentitySentinelPerfectHash_Bucket *) & table-> | |
| 1703 | tableData[sizeof(intintIdentitySentinelPerfectHash_TableData)]; | |
| 1704 | int index; | |
| 1705 | for (index = 0; | |
| 1706 | index < | |
| 1707 | ((intintIdentitySentinelPerfectHash_TableData *) table-> | |
| 1708 | tableData)->numBuckets; index++) { | |
| 1709 | buckets[index].value = | |
| 1710 | ((intintIdentitySentinelPerfectHash_TableData *) table-> | |
| 1711 | tableData)->emptyValue; | |
| 1712 | } | |
| 1713 | exitCode = HASH_EXIT_CODE_NORMAL; | |
| 1714 | return exitCode; | |
| 1715 | } | |
| 1716 | int intintIdentitySentinelPerfectHash_InnerQuerySingle(char *tableData, int key, | |
| 1717 | int *valueOutput) { | |
| 1718 | intintIdentitySentinelPerfectHash_Bucket *buckets = | |
| 1719 | (intintIdentitySentinelPerfectHash_Bucket *) & | |
| 1720 | tableData[sizeof(intintIdentitySentinelPerfectHash_TableData)]; | |
| 1721 | int index; | |
| 1722 | int exitCode; | |
| 1723 | index = | |
| 1724 | intintHash_CompressIdentity(((intintIdentitySentinelPerfectHash_TableData *) tableData)->compressFuncData, key); | |
| 1725 | if (buckets[index].value != | |
| 1726 | ((intintIdentitySentinelPerfectHash_TableData *) tableData)-> | |
| 1727 | emptyValue) { | |
| 1728 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1729 | } else { | |
| 1730 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1731 | } | |
| 1732 | switch (exitCode) { | |
| 1733 | case HASH_SEARCH_CODE_MATCH: | |
| 1734 | *valueOutput = buckets[index].value; | |
| 1735 | return HASH_EXIT_CODE_NORMAL; | |
| 1736 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1737 | case HASH_SEARCH_CODE_EMPTY: | |
| 1738 | return HASH_EXIT_CODE_KEY_DNE; | |
| 1739 | default: | |
| 1740 | return exitCode; | |
| 1741 | } | |
| 1742 | } | |
| 1743 | int intintIdentitySentinelPerfectHash_InnerQuery(char *tableData, | |
| 1744 | unsigned int numKeys, | |
| 1745 | int *keys, int *valuesOutput) { | |
| 1746 | intintIdentitySentinelPerfectHash_Bucket *buckets = | |
| 1747 | (intintIdentitySentinelPerfectHash_Bucket *) & | |
| 1748 | tableData[sizeof(intintIdentitySentinelPerfectHash_TableData)]; | |
| 1749 | int key; | |
| 1750 | int *valueOutput; | |
| 1751 | int index; | |
| 1752 | int exitCode; | |
| 1753 | uint i; | |
| 1754 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1755 | for (i = 0; i < numKeys; i++) { | |
| 1756 | key = keys[i]; | |
| 1757 | valueOutput = &valuesOutput[i]; | |
| 1758 | index = | |
| 1759 | intintHash_CompressIdentity(((intintIdentitySentinelPerfectHash_TableData *) tableData)->compressFuncData, key); | |
| 1760 | if (buckets[index].value != | |
| 1761 | ((intintIdentitySentinelPerfectHash_TableData *) | |
| 1762 | tableData)->emptyValue) { | |
| 1763 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1764 | } else { | |
| 1765 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1766 | } | |
| 1767 | switch (exitCode) { | |
| 1768 | case HASH_SEARCH_CODE_MATCH: | |
| 1769 | *valueOutput = buckets[index].value; | |
| 1770 | break; | |
| 1771 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1772 | case HASH_SEARCH_CODE_EMPTY: | |
| 1773 | resultExitCode = HASH_EXIT_CODE_KEY_DNE; | |
| 1774 | break; | |
| 1775 | default: | |
| 1776 | return exitCode; | |
| 1777 | } | |
| 1778 | } | |
| 1779 | return resultExitCode; | |
| 1780 | } | |
| 1781 | int intintIdentitySentinelPerfectHash_InnerInsertSingle(char *tableData, | |
| 1782 | int key, int value) { | |
| 1783 | intintIdentitySentinelPerfectHash_Bucket *buckets = | |
| 1784 | (intintIdentitySentinelPerfectHash_Bucket *) & | |
| 1785 | tableData[sizeof(intintIdentitySentinelPerfectHash_TableData)]; | |
| 1786 | int index; | |
| 1787 | int exitCode; | |
| 1788 | index = | |
| 1789 | intintHash_CompressIdentity(((intintIdentitySentinelPerfectHash_TableData *) tableData)->compressFuncData, key); | |
| 1790 | if (buckets[index].value != | |
| 1791 | ((intintIdentitySentinelPerfectHash_TableData *) tableData)-> | |
| 1792 | emptyValue) { | |
| 1793 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1794 | } else { | |
| 1795 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1796 | } | |
| 1797 | switch (exitCode) { | |
| 1798 | case HASH_SEARCH_CODE_MATCH: | |
| 1799 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1800 | buckets[index].value = value; | |
| 1801 | return HASH_EXIT_CODE_OVERWRITE; | |
| 1802 | case HASH_SEARCH_CODE_EMPTY: | |
| 1803 | buckets[index].value = value; | |
| 1804 | return HASH_EXIT_CODE_NORMAL; | |
| 1805 | default: | |
| 1806 | return exitCode; | |
| 1807 | } | |
| 1808 | } | |
| 1809 | int intintIdentitySentinelPerfectHash_InnerInsert(char *tableData, | |
| 1810 | unsigned int numEntries, | |
| 1811 | int *keys, int *values) { | |
| 1812 | intintIdentitySentinelPerfectHash_Bucket *buckets = | |
| 1813 | (intintIdentitySentinelPerfectHash_Bucket *) & | |
| 1814 | tableData[sizeof(intintIdentitySentinelPerfectHash_TableData)]; | |
| 1815 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1816 | int key; | |
| 1817 | int value; | |
| 1818 | int index; | |
| 1819 | int exitCode; | |
| 1820 | uint i; | |
| 1821 | for (i = 0; i < numEntries; i++) { | |
| 1822 | key = keys[i]; | |
| 1823 | index = | |
| 1824 | intintHash_CompressIdentity(((intintIdentitySentinelPerfectHash_TableData *) tableData)->compressFuncData, key); | |
| 1825 | if (buckets[index].value != | |
| 1826 | ((intintIdentitySentinelPerfectHash_TableData *) | |
| 1827 | tableData)->emptyValue) { | |
| 1828 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1829 | } else { | |
| 1830 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1831 | } | |
| 1832 | switch (exitCode) { | |
| 1833 | case HASH_SEARCH_CODE_MATCH: | |
| 1834 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1835 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 1836 | case HASH_SEARCH_CODE_EMPTY: | |
| 1837 | buckets[index].value = values[i]; | |
| 1838 | break; | |
| 1839 | default: | |
| 1840 | return exitCode; | |
| 1841 | } | |
| 1842 | } | |
| 1843 | return resultExitCode; | |
| 1844 | } | |
| 1845 | int intintIdentitySentinelPerfectHash_InnerInsertSingleNoOverwrite(char | |
| 1846 | *tableData, | |
| 1847 | int key, | |
| 1848 | int value) { | |
| 1849 | intintIdentitySentinelPerfectHash_Bucket *buckets = | |
| 1850 | (intintIdentitySentinelPerfectHash_Bucket *) & | |
| 1851 | tableData[sizeof(intintIdentitySentinelPerfectHash_TableData)]; | |
| 1852 | int index; | |
| 1853 | int exitCode; | |
| 1854 | index = | |
| 1855 | intintHash_CompressIdentity(((intintIdentitySentinelPerfectHash_TableData *) tableData)->compressFuncData, key); | |
| 1856 | if (buckets[index].value != | |
| 1857 | ((intintIdentitySentinelPerfectHash_TableData *) tableData)-> | |
| 1858 | emptyValue) { | |
| 1859 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1860 | } else { | |
| 1861 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1862 | } | |
| 1863 | switch (exitCode) { | |
| 1864 | case HASH_SEARCH_CODE_MATCH: | |
| 1865 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1866 | return HASH_EXIT_CODE_OVERWRITE; | |
| 1867 | case HASH_SEARCH_CODE_EMPTY: | |
| 1868 | buckets[index].value = value; | |
| 1869 | return HASH_EXIT_CODE_NORMAL; | |
| 1870 | default: | |
| 1871 | return exitCode; | |
| 1872 | } | |
| 1873 | } | |
| 1874 | int intintIdentitySentinelPerfectHash_InnerInsertNoOverwrite(char *tableData, | |
| 1875 | unsigned int | |
| 1876 | numEntries, | |
| 1877 | int *keys, | |
| 1878 | int *values) { | |
| 1879 | intintIdentitySentinelPerfectHash_Bucket *buckets = | |
| 1880 | (intintIdentitySentinelPerfectHash_Bucket *) & | |
| 1881 | tableData[sizeof(intintIdentitySentinelPerfectHash_TableData)]; | |
| 1882 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1883 | int key; | |
| 1884 | int value; | |
| 1885 | int index; | |
| 1886 | int exitCode; | |
| 1887 | uint i; | |
| 1888 | for (i = 0; i < numEntries; i++) { | |
| 1889 | key = keys[i]; | |
| 1890 | index = | |
| 1891 | intintHash_CompressIdentity(((intintIdentitySentinelPerfectHash_TableData *) tableData)->compressFuncData, key); | |
| 1892 | if (buckets[index].value != | |
| 1893 | ((intintIdentitySentinelPerfectHash_TableData *) | |
| 1894 | tableData)->emptyValue) { | |
| 1895 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1896 | } else { | |
| 1897 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1898 | } | |
| 1899 | switch (exitCode) { | |
| 1900 | case HASH_SEARCH_CODE_MATCH: | |
| 1901 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1902 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 1903 | break; | |
| 1904 | case HASH_SEARCH_CODE_EMPTY: | |
| 1905 | buckets[index].value = values[i]; | |
| 1906 | break; | |
| 1907 | default: | |
| 1908 | return exitCode; | |
| 1909 | } | |
| 1910 | } | |
| 1911 | return resultExitCode; | |
| 1912 | } | |
| 1913 | int intintIdentitySentinelPerfectHash_QuerySingle(intintHash_Table * table, | |
| 1914 | int key, int *valueOutput) { | |
| 1915 | return intintIdentitySentinelPerfectHash_InnerQuerySingle(table-> | |
| 1916 | tableData, | |
| 1917 | key, | |
| 1918 | valueOutput); | |
| 1919 | } | |
| 1920 | int intintIdentitySentinelPerfectHash_Query(intintHash_Table * table, | |
| 1921 | size_t numKeys, int *keys, | |
| 1922 | int *valuesOutput) { | |
| 1923 | return intintIdentitySentinelPerfectHash_InnerQuery(table->tableData, | |
| 1924 | numKeys, keys, | |
| 1925 | valuesOutput); | |
| 1926 | } | |
| 1927 | int intintIdentitySentinelPerfectHash_InsertSingle(intintHash_Table * table, | |
| 1928 | int key, int value) { | |
| 1929 | return intintIdentitySentinelPerfectHash_InnerInsertSingle(table-> | |
| 1930 | tableData, | |
| 1931 | key, value); | |
| 1932 | } | |
| 1933 | int intintIdentitySentinelPerfectHash_Insert(intintHash_Table * table, | |
| 1934 | size_t numEntries, int *keys, | |
| 1935 | int *values) { | |
| 1936 | return intintIdentitySentinelPerfectHash_InnerInsert(table->tableData, | |
| 1937 | numEntries, keys, | |
| 1938 | values); | |
| 1939 | } | |
| 1940 | int intintIdentitySentinelPerfectHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 1941 | table, int key, | |
| 1942 | int value) { | |
| 1943 | return | |
| 1944 | intintIdentitySentinelPerfectHash_InnerInsertSingleNoOverwrite | |
| 1945 | (table->tableData, key, value); | |
| 1946 | } | |
| 1947 | int intintIdentitySentinelPerfectHash_InsertNoOverwrite(intintHash_Table * | |
| 1948 | table, | |
| 1949 | size_t numEntries, | |
| 1950 | int *keys, | |
| 1951 | int *values) { | |
| 1952 | return intintIdentitySentinelPerfectHash_InnerInsertNoOverwrite(table-> | |
| 1953 | tableData, | |
| 1954 | numEntries, | |
| 1955 | keys, | |
| 1956 | values); | |
| 1957 | } | |
| 1958 | ||
| 1959 | typedef struct intintIdentitySentinelPerfectCLHash_TableData { | |
| 1960 | int hashID; | |
| 1961 | unsigned int numBuckets; | |
| 1962 | char compressFuncData; | |
| 1963 | int emptyValue; | |
| 1964 | } intintIdentitySentinelPerfectCLHash_TableData; | |
| 1965 | typedef struct intintIdentitySentinelPerfectCLHash_Bucket { | |
| 1966 | int value; | |
| 1967 | } intintIdentitySentinelPerfectCLHash_Bucket; | |
| 1968 | intintHash_Table | |
| 1969 | *intintIdentitySentinelPerfectCLHash_CreateTable(intintHash_Factory * | |
| 1970 | factory, int hashIndex, | |
| 1971 | size_t keyRange, | |
| 1972 | size_t numEntries, | |
| 1973 | float loadFactor) { | |
| 1974 | intintHash_Table *table = | |
| 1975 | (intintHash_Table *) malloc(sizeof(intintHash_Table)); | |
| 1976 | table->destroyFunc = &intintIdentitySentinelPerfectCLHash_DestroyTable; | |
| 1977 | table->emptyFunc = &intintIdentitySentinelPerfectCLHash_EmptyTable; | |
| 1978 | table->queryFunc = &intintIdentitySentinelPerfectCLHash_Query; | |
| 1979 | table->querySingleFunc = | |
| 1980 | &intintIdentitySentinelPerfectCLHash_QuerySingle; | |
| 1981 | table->insertFunc = &intintIdentitySentinelPerfectCLHash_Insert; | |
| 1982 | table->insertSingleFunc = | |
| 1983 | &intintIdentitySentinelPerfectCLHash_InsertSingle; | |
| 1984 | table->insertNoOverwriteFunc = | |
| 1985 | &intintIdentitySentinelPerfectCLHash_InsertNoOverwrite; | |
| 1986 | table->insertSingleNoOverwriteFunc = | |
| 1987 | &intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite; | |
| 1988 | table->tableData = | |
| 1989 | (char *) | |
| 1990 | malloc(sizeof(intintIdentitySentinelPerfectCLHash_TableData)); | |
| 1991 | ((intintIdentitySentinelPerfectCLHash_TableData *) table->tableData)-> | |
| 1992 | hashID = IDENTITY_SENTINEL_PERFECT_CL_HASH_ID; | |
| 1993 | table->context = factory->context; | |
| 1994 | table->queue = factory->queue; | |
| 1995 | table->program = factory->program; | |
| 1996 | table->localWorkSize = factory->localWorkSize; | |
| 1997 | table->utilProgram = factory->utilProgram[hashIndex]; | |
| 1998 | table->emptyKernel = factory->emptyKernel[hashIndex]; | |
| 1999 | table->emptyKernelLocalWorkSize = | |
| 2000 | factory->emptyKernelLocalWorkSize[hashIndex]; | |
| 2001 | table->querySingleKernel = factory->querySingleKernel[hashIndex]; | |
| 2002 | table->insertSingleKernel = factory->insertSingleKernel[hashIndex]; | |
| 2003 | table->insertSingleNoOverwriteKernel = | |
| 2004 | factory->insertSingleNoOverwriteKernel[hashIndex]; | |
| 2005 | clRetainContext(table->context); | |
| 2006 | clRetainCommandQueue(table->queue); | |
| 2007 | clRetainProgram(table->program); | |
| 2008 | clRetainProgram(table->utilProgram); | |
| 2009 | clRetainKernel(table->emptyKernel); | |
| 2010 | clRetainKernel(table->querySingleKernel); | |
| 2011 | clRetainKernel(table->insertSingleKernel); | |
| 2012 | clRetainKernel(table->insertSingleNoOverwriteKernel);; | |
| 2013 | ((intintIdentitySentinelPerfectCLHash_TableData *) table->tableData)-> | |
| 2014 | emptyValue = factory->emptyValue; | |
| 2015 | ((intintIdentitySentinelPerfectCLHash_TableData *) table->tableData)-> | |
| 2016 | numBuckets = keyRange + 1; | |
| 2017 | char *tempHashData = | |
| 2018 | (char *)malloc(sizeof(intintIdentitySentinelPerfectCLHash_TableData) | |
| 2019 | + | |
| 2020 | ((intintIdentitySentinelPerfectCLHash_TableData *) | |
| 2021 | table->tableData)->numBuckets * | |
| 2022 | sizeof(intintIdentitySentinelPerfectCLHash_Bucket)); | |
| 2023 | memcpy(tempHashData, table->tableData, | |
| 2024 | sizeof(intintIdentitySentinelPerfectCLHash_TableData)); | |
| 2025 | free(table->tableData); | |
| 2026 | table->tableData = tempHashData; | |
| 2027 | cl_int err; | |
| 2028 | table->tableDataBuffer = | |
| 2029 | clCreateBuffer(table->context, CL_MEM_READ_WRITE, | |
| 2030 | sizeof(intintIdentitySentinelPerfectHash_TableData) + | |
| 2031 | ((intintIdentitySentinelPerfectHash_TableData *) | |
| 2032 | table->tableData)->numBuckets * | |
| 2033 | sizeof(intintIdentitySentinelPerfectHash_Bucket), | |
| 2034 | NULL, &err); | |
| 2035 | CLHash_Utilities_HandleError(err, | |
| 2036 | "intintIdentitySentinelPerfectCLHash_InitTable", | |
| 2037 | "clCreateBuffer"); | |
| 2038 | err = | |
| 2039 | clEnqueueWriteBuffer(table->queue, table->tableDataBuffer, CL_TRUE, | |
| 2040 | 0, | |
| 2041 | sizeof | |
| 2042 | (intintIdentitySentinelPerfectHash_TableData), | |
| 2043 | table->tableData, 0, NULL, NULL); | |
| 2044 | CLHash_Utilities_HandleError(err, | |
| 2045 | "intintIdentitySentinelPerfectCLHash_InitTable", | |
| 2046 | "clEnqueueWriteBuffer"); | |
| 2047 | return table; | |
| 2048 | } | |
| 2049 | int intintIdentitySentinelPerfectCLHash_CreateFactory(intintHash_Factory * | |
| 2050 | factory, int hashIndex) { | |
| 2051 | factory->createFunc[hashIndex] = | |
| 2052 | &intintIdentitySentinelPerfectCLHash_CreateTable; | |
| 2053 | factory->destroyFunc[hashIndex] = | |
| 2054 | &intintIdentitySentinelPerfectCLHash_DestroyFactory; | |
| 2055 | cl_int error; | |
| 2056 | cl_device_id device; | |
| 2057 | error = | |
| 2058 | clGetContextInfo(factory->context, CL_CONTEXT_DEVICES, | |
| 2059 | sizeof(device), &device, NULL); | |
| 2060 | CLHash_Utilities_HandleError(error, "intintHash_CreateFactory", | |
| 2061 | "clGetContextInfo"); | |
| 2062 | factory->querySingleKernel[hashIndex] = | |
| 2063 | clCreateKernel(factory->program, | |
| 2064 | "intintIdentitySentinelPerfectCLHash_RangeQuerySingle", | |
| 2065 | &error); | |
| 2066 | CLHash_Utilities_HandleError(error, | |
| 2067 | "intintIdentitySentinelPerfectCLHash_CreateFactory", | |
| 2068 | "clCreateKernel"); | |
| 2069 | factory->insertSingleKernel[hashIndex] = | |
| 2070 | clCreateKernel(factory->program, | |
| 2071 | "intintIdentitySentinelPerfectCLHash_RangeInsertSingle", | |
| 2072 | &error); | |
| 2073 | CLHash_Utilities_HandleError(error, | |
| 2074 | "intintIdentitySentinelPerfectCLHash_CreateFactory", | |
| 2075 | "clCreateKernel"); | |
| 2076 | factory->insertSingleNoOverwriteKernel[hashIndex] = | |
| 2077 | clCreateKernel(factory->program, | |
| 2078 | "intintIdentitySentinelPerfectCLHash_RangeInsertSingleNoOverwrite", | |
| 2079 | &error); | |
| 2080 | CLHash_Utilities_HandleError(error, | |
| 2081 | "intintIdentitySentinelPerfectCLHash_CreateFactory", | |
| 2082 | "clCreateKernel"); | |
| 2083 | factory->utilProgram[hashIndex] = | |
| 2084 | CLHash_Utilities_BuildProgramString(factory->context, device, | |
| 2085 | "static inline unsigned int intintHash_CompressIdentity(char data, int hashCode){ return hashCode; } typedef struct intintHash_CompressLCGData{ long unsigned int a; long unsigned int c; unsigned int m; unsigned int n; }intintHash_CompressLCGData; static inline unsigned int intintHash_CompressLCG(intintHash_CompressLCGData compressLCGData, int hashCode){ return ((compressLCGData.a * hashCode + compressLCGData.c) % compressLCGData.m) % compressLCGData.n; } typedef struct intintIdentitySentinelPerfectCLHash_TableData{ int hashID; unsigned int numBuckets; char compressFuncData; int emptyValue; }intintIdentitySentinelPerfectCLHash_TableData; typedef struct intintIdentitySentinelPerfectCLHash_Bucket{ int value; }intintIdentitySentinelPerfectCLHash_Bucket; __kernel void intintIdentitySentinelPerfectCLHash_Empty(__global char *tableData){ int index = get_global_id(0); if(index >= ((__global intintIdentitySentinelPerfectCLHash_TableData*)tableData)->numBuckets){ return; } __global intintIdentitySentinelPerfectCLHash_Bucket *buckets = (__global intintIdentitySentinelPerfectCLHash_Bucket*)&tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)]; buckets[index].value = ((__global intintIdentitySentinelPerfectCLHash_TableData*)tableData)->emptyValue; }"); | |
| 2086 | factory->emptyKernel[hashIndex] = | |
| 2087 | clCreateKernel(factory->utilProgram[hashIndex], | |
| 2088 | "intintIdentitySentinelPerfectCLHash_Empty", &error); | |
| 2089 | CLHash_Utilities_HandleError(error, | |
| 2090 | "intintIdentitySentinelPerfectCLHash_CreateFactory", | |
| 2091 | "clCreateKernel"); | |
| 2092 | error = | |
| 2093 | clGetKernelWorkGroupInfo(factory->emptyKernel[hashIndex], device, | |
| 2094 | CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), | |
| 2095 | &factory-> | |
| 2096 | emptyKernelLocalWorkSize[hashIndex], NULL); | |
| 2097 | CLHash_Utilities_HandleError(error, | |
| 2098 | "intintIdentitySentinelPerfectCLHash_CreateFactory", | |
| 2099 | "clGetKernelWorkGroupInfo");;; | |
| 2100 | return HASH_EXIT_CODE_NORMAL; | |
| 2101 | } | |
| 2102 | int intintIdentitySentinelPerfectCLHash_DestroyFactory(intintHash_Factory * | |
| 2103 | factory, | |
| 2104 | int hashIndex) {; | |
| 2105 | clReleaseKernel(factory->emptyKernel[hashIndex]); | |
| 2106 | clReleaseProgram(factory->utilProgram[hashIndex]); | |
| 2107 | clReleaseKernel(factory->querySingleKernel[hashIndex]); | |
| 2108 | clReleaseKernel(factory->insertSingleKernel[hashIndex]); | |
| 2109 | clReleaseKernel(factory->insertSingleNoOverwriteKernel[hashIndex]);; | |
| 2110 | return HASH_EXIT_CODE_NORMAL; | |
| 2111 | } | |
| 2112 | int intintIdentitySentinelPerfectCLHash_DestroyTable(intintHash_Table * table) { | |
| 2113 | int exitCode = 0; | |
| 2114 | clReleaseMemObject(table->tableDataBuffer); | |
| 2115 | clReleaseContext(table->context); | |
| 2116 | clReleaseCommandQueue(table->queue); | |
| 2117 | clReleaseProgram(table->utilProgram); | |
| 2118 | clReleaseKernel(table->emptyKernel); | |
| 2119 | clReleaseProgram(table->program); | |
| 2120 | clReleaseKernel(table->querySingleKernel); | |
| 2121 | clReleaseKernel(table->insertSingleKernel); | |
| 2122 | clReleaseKernel(table->insertSingleNoOverwriteKernel); | |
| 2123 | free(table->tableData); | |
| 2124 | free(table); | |
| 2125 | return exitCode; | |
| 2126 | } | |
| 2127 | int intintIdentitySentinelPerfectCLHash_EmptyTable(intintHash_Table * table) { | |
| 2128 | int exitCode = 0; | |
| 2129 | cl_int err; | |
| 2130 | err = | |
| 2131 | clSetKernelArg(table->emptyKernel, 0, sizeof(cl_mem), | |
| 2132 | &table->tableDataBuffer); | |
| 2133 | CLHash_Utilities_HandleError(err, | |
| 2134 | "intintIdentitySentinelPerfectCLHash_EmptyTable", | |
| 2135 | "clSetKernelArg"); | |
| 2136 | const size_t groupWorkSize = | |
| 2137 | roundUpToNearest(((intintIdentitySentinelPerfectHash_TableData *) | |
| 2138 | table->tableData)->numBuckets, | |
| 2139 | table->emptyKernelLocalWorkSize); | |
| 2140 | err = | |
| 2141 | clEnqueueNDRangeKernel(table->queue, table->emptyKernel, 1, 0, | |
| 2142 | &groupWorkSize, | |
| 2143 | (const size_t *)&table-> | |
| 2144 | emptyKernelLocalWorkSize, 0, NULL, NULL); | |
| 2145 | CLHash_Utilities_HandleError(err, | |
| 2146 | "intintIdentitySentinelPerfectCLHash_EmptyTable", | |
| 2147 | "clEnqueueNDRangeKernel"); | |
| 2148 | exitCode = HASH_EXIT_CODE_NORMAL;; | |
| 2149 | return exitCode; | |
| 2150 | } | |
| 2151 | int intintIdentitySentinelPerfectCLHash_QuerySingle(intintHash_Table * table, | |
| 2152 | int key, int *valueOutput) { | |
| 2153 | return intintIdentitySentinelPerfectCLHash_Query(table, 1, &key, | |
| 2154 | valueOutput); | |
| 2155 | } | |
| 2156 | int intintIdentitySentinelPerfectCLHash_Query(intintHash_Table * table, | |
| 2157 | size_t numKeys, int *keys, | |
| 2158 | int *valuesOutput) { | |
| 2159 | cl_int err; | |
| 2160 | cl_mem keysBuffer = | |
| 2161 | clCreateBuffer(table->context, | |
| 2162 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 2163 | sizeof(int) * numKeys, keys, &err); | |
| 2164 | CLHash_Utilities_HandleError(err, | |
| 2165 | "intintIdentitySentinelPerfectCLHash_Query", | |
| 2166 | "clCreateBuffer"); | |
| 2167 | cl_mem valuesOutputBuffer = | |
| 2168 | clCreateBuffer(table->context, CL_MEM_WRITE_ONLY, | |
| 2169 | sizeof(int) * numKeys, NULL, &err); | |
| 2170 | CLHash_Utilities_HandleError(err, | |
| 2171 | "intintIdentitySentinelPerfectCLHash_Query", | |
| 2172 | "clCreateBuffer"); | |
| 2173 | intintIdentitySentinelPerfectCLHash_BufferQuery(table, numKeys, | |
| 2174 | keysBuffer, | |
| 2175 | valuesOutputBuffer); | |
| 2176 | err = | |
| 2177 | clEnqueueReadBuffer(table->queue, valuesOutputBuffer, CL_TRUE, 0, | |
| 2178 | sizeof(int) * numKeys, valuesOutput, 0, NULL, | |
| 2179 | NULL); | |
| 2180 | CLHash_Utilities_HandleError(err, | |
| 2181 | "intintIdentitySentinelPerfectCLHash_Query", | |
| 2182 | "clEnqueueReadBuffer"); | |
| 2183 | clReleaseMemObject(keysBuffer); | |
| 2184 | clReleaseMemObject(valuesOutputBuffer); | |
| 2185 | return HASH_EXIT_CODE_NORMAL; | |
| 2186 | } | |
| 2187 | int intintIdentitySentinelPerfectCLHash_BufferQuery(intintHash_Table * table, | |
| 2188 | size_t numKeys, | |
| 2189 | cl_mem keysBuffer, | |
| 2190 | cl_mem valuesOutputBuffer) { | |
| 2191 | cl_int err; | |
| 2192 | err = | |
| 2193 | clSetKernelArg(table->querySingleKernel, 0, sizeof(cl_mem), | |
| 2194 | &table->tableDataBuffer); | |
| 2195 | CLHash_Utilities_HandleError(err, | |
| 2196 | "intintIdentitySentinelPerfectCLHash_BufferQuery", | |
| 2197 | "clSetKernelArg"); | |
| 2198 | err = | |
| 2199 | clSetKernelArg(table->querySingleKernel, 1, sizeof(unsigned int), | |
| 2200 | &numKeys); | |
| 2201 | CLHash_Utilities_HandleError(err, | |
| 2202 | "intintIdentitySentinelPerfectCLHash_BufferQuery", | |
| 2203 | "clSetKernelArg"); | |
| 2204 | err = | |
| 2205 | clSetKernelArg(table->querySingleKernel, 2, sizeof(cl_mem), | |
| 2206 | &keysBuffer); | |
| 2207 | CLHash_Utilities_HandleError(err, | |
| 2208 | "intintIdentitySentinelPerfectCLHash_BufferQuery", | |
| 2209 | "clSetKernelArg"); | |
| 2210 | err = | |
| 2211 | clSetKernelArg(table->querySingleKernel, 3, sizeof(cl_mem), | |
| 2212 | &valuesOutputBuffer); | |
| 2213 | CLHash_Utilities_HandleError(err, | |
| 2214 | "intintIdentitySentinelPerfectCLHash_BufferQuery", | |
| 2215 | "clSetKernelArg"); | |
| 2216 | const size_t groupWorkSize = | |
| 2217 | roundUpToNearest(numKeys, table->localWorkSize); | |
| 2218 | err = | |
| 2219 | clEnqueueNDRangeKernel(table->queue, table->querySingleKernel, 1, 0, | |
| 2220 | &groupWorkSize, | |
| 2221 | (const size_t *)&table->localWorkSize, 0, | |
| 2222 | NULL, NULL); | |
| 2223 | CLHash_Utilities_HandleError(err, | |
| 2224 | "intintIdentitySentinelPerfectCLHash_BufferQuery", | |
| 2225 | "clEnqueueNDRangeKernel"); | |
| 2226 | clFinish(table->queue); | |
| 2227 | return HASH_EXIT_CODE_NORMAL; | |
| 2228 | } | |
| 2229 | int intintIdentitySentinelPerfectCLHash_InsertSingle(intintHash_Table * table, | |
| 2230 | int key, int value) { | |
| 2231 | return intintIdentitySentinelPerfectCLHash_Insert(table, 1, &key, | |
| 2232 | &value); | |
| 2233 | } | |
| 2234 | int intintIdentitySentinelPerfectCLHash_Insert(intintHash_Table * table, | |
| 2235 | size_t numEntries, int *keys, | |
| 2236 | int *values) { | |
| 2237 | cl_int err; | |
| 2238 | cl_mem keysBuffer = | |
| 2239 | clCreateBuffer(table->context, | |
| 2240 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 2241 | sizeof(int) * numEntries, keys, &err); | |
| 2242 | CLHash_Utilities_HandleError(err, | |
| 2243 | "intintIdentitySentinelPerfectCLHash_Insert", | |
| 2244 | "clCreateBuffer"); | |
| 2245 | cl_mem valuesBuffer = | |
| 2246 | clCreateBuffer(table->context, | |
| 2247 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 2248 | sizeof(int) * numEntries, values, &err); | |
| 2249 | CLHash_Utilities_HandleError(err, | |
| 2250 | "intintIdentitySentinelPerfectCLHash_Insert", | |
| 2251 | "clCreateBuffer"); | |
| 2252 | intintIdentitySentinelPerfectCLHash_BufferInsert(table, numEntries, | |
| 2253 | keysBuffer, | |
| 2254 | valuesBuffer); | |
| 2255 | clReleaseMemObject(keysBuffer); | |
| 2256 | clReleaseMemObject(valuesBuffer); | |
| 2257 | return HASH_EXIT_CODE_NORMAL; | |
| 2258 | } | |
| 2259 | int intintIdentitySentinelPerfectCLHash_BufferInsert(intintHash_Table * table, | |
| 2260 | size_t numEntries, | |
| 2261 | cl_mem keysBuffer, | |
| 2262 | cl_mem valuesBuffer) { | |
| 2263 | cl_int err; | |
| 2264 | err = | |
| 2265 | clSetKernelArg(table->insertSingleKernel, 0, sizeof(cl_mem), | |
| 2266 | &table->tableDataBuffer); | |
| 2267 | CLHash_Utilities_HandleError(err, | |
| 2268 | "intintIdentitySentinelPerfectCLHash_BufferInsert", | |
| 2269 | "clSetKernelArg"); | |
| 2270 | err = | |
| 2271 | clSetKernelArg(table->insertSingleKernel, 1, sizeof(unsigned int), | |
| 2272 | &numEntries); | |
| 2273 | CLHash_Utilities_HandleError(err, | |
| 2274 | "intintIdentitySentinelPerfectCLHash_BufferInsert", | |
| 2275 | "clSetKernelArg"); | |
| 2276 | err = | |
| 2277 | clSetKernelArg(table->insertSingleKernel, 2, sizeof(cl_mem), | |
| 2278 | &keysBuffer); | |
| 2279 | CLHash_Utilities_HandleError(err, | |
| 2280 | "intintIdentitySentinelPerfectCLHash_BufferInsert", | |
| 2281 | "clSetKernelArg"); | |
| 2282 | err = | |
| 2283 | clSetKernelArg(table->insertSingleKernel, 3, sizeof(cl_mem), | |
| 2284 | &valuesBuffer); | |
| 2285 | CLHash_Utilities_HandleError(err, | |
| 2286 | "intintIdentitySentinelPerfectCLHash_BufferInsert", | |
| 2287 | "clSetKernelArg"); | |
| 2288 | const size_t groupWorkSize = | |
| 2289 | roundUpToNearest(numEntries, table->localWorkSize); | |
| 2290 | err = | |
| 2291 | clEnqueueNDRangeKernel(table->queue, table->insertSingleKernel, 1, | |
| 2292 | 0, &groupWorkSize, | |
| 2293 | (const size_t *)&table->localWorkSize, 0, | |
| 2294 | NULL, NULL); | |
| 2295 | CLHash_Utilities_HandleError(err, NULL, "clEnqueueNDRangeKernel"); | |
| 2296 | return (0); | |
| 2297 | } | |
| 2298 | int intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite(intintHash_Table | |
| 2299 | * table, | |
| 2300 | int key, | |
| 2301 | int value) { | |
| 2302 | return intintIdentitySentinelPerfectCLHash_InsertNoOverwrite(table, 1, | |
| 2303 | &key, | |
| 2304 | &value); | |
| 2305 | } | |
| 2306 | int intintIdentitySentinelPerfectCLHash_InsertNoOverwrite(intintHash_Table * | |
| 2307 | table, | |
| 2308 | size_t numEntries, | |
| 2309 | int *keys, | |
| 2310 | int *values) { | |
| 2311 | cl_int err; | |
| 2312 | cl_mem keysBuffer = | |
| 2313 | clCreateBuffer(table->context, | |
| 2314 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 2315 | sizeof(int) * numEntries, keys, &err); | |
| 2316 | CLHash_Utilities_HandleError(err, | |
| 2317 | "intintIdentitySentinelPerfectCLHash_InsertNoOverwrite", | |
| 2318 | "clCreateBuffer"); | |
| 2319 | cl_mem valuesBuffer = | |
| 2320 | clCreateBuffer(table->context, | |
| 2321 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 2322 | sizeof(int) * numEntries, values, &err); | |
| 2323 | CLHash_Utilities_HandleError(err, | |
| 2324 | "intintIdentitySentinelPerfectCLHash_InsertNoOverwrite", | |
| 2325 | "clCreateBuffer"); | |
| 2326 | intintIdentitySentinelPerfectCLHash_BufferInsertNoOverwrite(table, | |
| 2327 | numEntries, | |
| 2328 | keysBuffer, | |
| 2329 | valuesBuffer); | |
| 2330 | clReleaseMemObject(keysBuffer); | |
| 2331 | clReleaseMemObject(valuesBuffer); | |
| 2332 | return HASH_EXIT_CODE_NORMAL; | |
| 2333 | } | |
| 2334 | int intintIdentitySentinelPerfectCLHash_BufferInsertNoOverwrite(intintHash_Table | |
| 2335 | * table, | |
| 2336 | size_t | |
| 2337 | numEntries, | |
| 2338 | cl_mem | |
| 2339 | keysBuffer, | |
| 2340 | cl_mem | |
| 2341 | valuesBuffer) { | |
| 2342 | cl_int err; | |
| 2343 | err = | |
| 2344 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 0, | |
| 2345 | sizeof(cl_mem), &table->tableDataBuffer); | |
| 2346 | CLHash_Utilities_HandleError(err, | |
| 2347 | "intintIdentitySentinelPerfectCLHash_BufferInsertNoOverwrite", | |
| 2348 | "clSetKernelArg"); | |
| 2349 | err = | |
| 2350 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 1, | |
| 2351 | sizeof(unsigned int), &numEntries); | |
| 2352 | CLHash_Utilities_HandleError(err, | |
| 2353 | "intintIdentitySentinelPerfectCLHash_BufferInsertNoOverwrite", | |
| 2354 | "ClSetKernelArg"); | |
| 2355 | err = | |
| 2356 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 2, | |
| 2357 | sizeof(cl_mem), &keysBuffer); | |
| 2358 | CLHash_Utilities_HandleError(err, | |
| 2359 | "intintIdentitySentinelPerfectCLHash_BufferInsertNoOverwrite", | |
| 2360 | "clSetKernelArg"); | |
| 2361 | err = | |
| 2362 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 3, | |
| 2363 | sizeof(cl_mem), &valuesBuffer); | |
| 2364 | CLHash_Utilities_HandleError(err, | |
| 2365 | "intintIdentitySentinelPerfectCLHash_BufferInsertNoOverwrite", | |
| 2366 | "clSetKernelArg"); | |
| 2367 | const size_t groupWorkSize = | |
| 2368 | roundUpToNearest(numEntries, table->localWorkSize); | |
| 2369 | err = | |
| 2370 | clEnqueueNDRangeKernel(table->queue, | |
| 2371 | table->insertSingleNoOverwriteKernel, 1, 0, | |
| 2372 | &groupWorkSize, | |
| 2373 | (const size_t *)&table->localWorkSize, 0, | |
| 2374 | NULL, NULL); | |
| 2375 | CLHash_Utilities_HandleError(err, | |
| 2376 | "intintIdentitySentinelPerfectCLHash_BufferInsertNoOverwrite", | |
| 2377 | "clEnqueueNDRangeKernel"); | |
| 2378 | return (0); | |
| 2379 | } | |
| 2380 | ||
| 2381 | typedef struct intintLCGLinearOpenCompactHash_TableData { | |
| 2382 | int hashID; | |
| 2383 | unsigned int numBuckets; | |
| 2384 | intintHash_CompressLCGData compressFuncData; | |
| 2385 | } intintLCGLinearOpenCompactHash_TableData; | |
| 2386 | typedef struct intintLCGLinearOpenCompactHash_Bucket { | |
| 2387 | int key; | |
| 2388 | int value; | |
| 2389 | } intintLCGLinearOpenCompactHash_Bucket; | |
| 2390 | intintHash_Table *intintLCGLinearOpenCompactHash_CreateTable(intintHash_Factory | |
| 2391 | * factory, | |
| 2392 | int hashIndex, | |
| 2393 | size_t keyRange, | |
| 2394 | size_t numEntries, | |
| 2395 | float loadFactor) { | |
| 2396 | intintHash_Table *table = | |
| 2397 | (intintHash_Table *) malloc(sizeof(intintHash_Table)); | |
| 2398 | table->destroyFunc = &intintLCGLinearOpenCompactHash_DestroyTable; | |
| 2399 | table->emptyFunc = &intintLCGLinearOpenCompactHash_EmptyTable; | |
| 2400 | table->queryFunc = &intintLCGLinearOpenCompactHash_Query; | |
| 2401 | table->querySingleFunc = &intintLCGLinearOpenCompactHash_QuerySingle; | |
| 2402 | table->insertFunc = &intintLCGLinearOpenCompactHash_Insert; | |
| 2403 | table->insertSingleFunc = &intintLCGLinearOpenCompactHash_InsertSingle; | |
| 2404 | table->insertNoOverwriteFunc = | |
| 2405 | &intintLCGLinearOpenCompactHash_InsertNoOverwrite; | |
| 2406 | table->insertSingleNoOverwriteFunc = | |
| 2407 | &intintLCGLinearOpenCompactHash_InsertSingleNoOverwrite; | |
| 2408 | table->tableData = | |
| 2409 | (char *)malloc(sizeof(intintLCGLinearOpenCompactHash_TableData)); | |
| 2410 | ((intintLCGLinearOpenCompactHash_TableData *) table->tableData)-> | |
| 2411 | hashID = LCG_LINEAR_OPEN_COMPACT_HASH_ID; | |
| 2412 | ((intintLCGLinearOpenCompactHash_TableData *) table->tableData)-> | |
| 2413 | numBuckets = (unsigned int)((double)numEntries / loadFactor); | |
| 2414 | ((intintLCGLinearOpenCompactHash_TableData *) table->tableData)-> | |
| 2415 | compressFuncData.a = HASH_LCG_A; | |
| 2416 | ((intintLCGLinearOpenCompactHash_TableData *) table->tableData)-> | |
| 2417 | compressFuncData.c = HASH_LCG_C; | |
| 2418 | ((intintLCGLinearOpenCompactHash_TableData *) table->tableData)-> | |
| 2419 | compressFuncData.m = HASH_LCG_M; | |
| 2420 | ((intintLCGLinearOpenCompactHash_TableData *) table->tableData)-> | |
| 2421 | compressFuncData.n = | |
| 2422 | ((intintLCGLinearOpenCompactHash_TableData *) table->tableData)-> | |
| 2423 | numBuckets; | |
| 2424 | char *tempHashData = | |
| 2425 | (char *)malloc(sizeof(intintLCGLinearOpenCompactHash_TableData) + | |
| 2426 | ((intintLCGLinearOpenCompactHash_TableData *) table-> | |
| 2427 | tableData)->numBuckets * | |
| 2428 | sizeof(intintLCGLinearOpenCompactHash_Bucket)); | |
| 2429 | memcpy(tempHashData, table->tableData, | |
| 2430 | sizeof(intintLCGLinearOpenCompactHash_TableData)); | |
| 2431 | free(table->tableData); | |
| 2432 | table->tableData = tempHashData; | |
| 2433 | return table; | |
| 2434 | } | |
| 2435 | int intintLCGLinearOpenCompactHash_CreateFactory(intintHash_Factory * factory, | |
| 2436 | int hashIndex) { | |
| 2437 | factory->createFunc[hashIndex] = | |
| 2438 | &intintLCGLinearOpenCompactHash_CreateTable; | |
| 2439 | factory->destroyFunc[hashIndex] = | |
| 2440 | &intintLCGLinearOpenCompactHash_DestroyFactory;; | |
| 2441 | return HASH_EXIT_CODE_NORMAL; | |
| 2442 | } | |
| 2443 | int intintLCGLinearOpenCompactHash_DestroyFactory(intintHash_Factory * factory, | |
| 2444 | int hashIndex) {; | |
| 2445 | return HASH_EXIT_CODE_NORMAL; | |
| 2446 | } | |
| 2447 | int intintLCGLinearOpenCompactHash_DestroyTable(intintHash_Table * table) { | |
| 2448 | int exitCode = 0; | |
| 2449 | free(table->tableData); | |
| 2450 | free(table); | |
| 2451 | return exitCode; | |
| 2452 | } | |
| 2453 | int intintLCGLinearOpenCompactHash_EmptyTable(intintHash_Table * table) { | |
| 2454 | int exitCode = 0; | |
| 2455 | intintLCGLinearOpenCompactHash_Bucket *buckets = | |
| 2456 | (intintLCGLinearOpenCompactHash_Bucket *) & table-> | |
| 2457 | tableData[sizeof(intintLCGLinearOpenCompactHash_TableData)]; | |
| 2458 | int index; | |
| 2459 | for (index = 0; | |
| 2460 | index < | |
| 2461 | ((intintLCGLinearOpenCompactHash_TableData *) table->tableData)-> | |
| 2462 | numBuckets; index++) { | |
| 2463 | buckets[index].key = HASH_BUCKET_STATUS_EMPTY; | |
| 2464 | } | |
| 2465 | exitCode = HASH_EXIT_CODE_NORMAL; | |
| 2466 | return exitCode; | |
| 2467 | } | |
| 2468 | int intintLCGLinearOpenCompactHash_InnerQuerySingle(char *tableData, int key, | |
| 2469 | int *valueOutput) { | |
| 2470 | intintLCGLinearOpenCompactHash_Bucket *buckets = | |
| 2471 | (intintLCGLinearOpenCompactHash_Bucket *) & | |
| 2472 | tableData[sizeof(intintLCGLinearOpenCompactHash_TableData)]; | |
| 2473 | int index; | |
| 2474 | int exitCode; | |
| 2475 | intintLCGLinearOpenCompactHash_TableData *mytableData = | |
| 2476 | (intintLCGLinearOpenCompactHash_TableData *) tableData; | |
| 2477 | intintHash_CompressLCGData compressFuncData = | |
| 2478 | mytableData->compressFuncData; | |
| 2479 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 2480 | unsigned long int iteration = 0; | |
| 2481 | for (;;) { | |
| 2482 | index = | |
| 2483 | ((1 * iteration + | |
| 2484 | c) % | |
| 2485 | ((intintLCGLinearOpenCompactHash_TableData *) tableData)-> | |
| 2486 | numBuckets); | |
| 2487 | if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 2488 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 2489 | break; | |
| 2490 | } else if (key == buckets[index].key) { | |
| 2491 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 2492 | break; | |
| 2493 | } else if ((index == c && iteration > 0)) { | |
| 2494 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 2495 | break; | |
| 2496 | } | |
| 2497 | iteration++; | |
| 2498 | } | |
| 2499 | switch (exitCode) { | |
| 2500 | case HASH_SEARCH_CODE_MATCH: | |
| 2501 | *valueOutput = buckets[index].value; | |
| 2502 | return HASH_EXIT_CODE_NORMAL; | |
| 2503 | case HASH_SEARCH_CODE_MISMATCH: | |
| 2504 | case HASH_SEARCH_CODE_EMPTY: | |
| 2505 | return HASH_EXIT_CODE_KEY_DNE; | |
| 2506 | default: | |
| 2507 | return exitCode; | |
| 2508 | } | |
| 2509 | } | |
| 2510 | int intintLCGLinearOpenCompactHash_InnerQuery(char *tableData, | |
| 2511 | unsigned int numKeys, int *keys, | |
| 2512 | int *valuesOutput) { | |
| 2513 | intintLCGLinearOpenCompactHash_Bucket *buckets = | |
| 2514 | (intintLCGLinearOpenCompactHash_Bucket *) & | |
| 2515 | tableData[sizeof(intintLCGLinearOpenCompactHash_TableData)]; | |
| 2516 | int key; | |
| 2517 | int *valueOutput; | |
| 2518 | int index; | |
| 2519 | int exitCode; | |
| 2520 | uint i; | |
| 2521 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 2522 | for (i = 0; i < numKeys; i++) { | |
| 2523 | key = keys[i]; | |
| 2524 | valueOutput = &valuesOutput[i]; | |
| 2525 | intintLCGLinearOpenCompactHash_TableData *mytableData = | |
| 2526 | (intintLCGLinearOpenCompactHash_TableData *) tableData; | |
| 2527 | intintHash_CompressLCGData compressFuncData = | |
| 2528 | mytableData->compressFuncData; | |
| 2529 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 2530 | unsigned long int iteration = 0; | |
| 2531 | for (;;) { | |
| 2532 | index = | |
| 2533 | ((1 * iteration + | |
| 2534 | c) % | |
| 2535 | ((intintLCGLinearOpenCompactHash_TableData *) | |
| 2536 | tableData)->numBuckets); | |
| 2537 | if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 2538 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 2539 | break; | |
| 2540 | } else if (key == buckets[index].key) { | |
| 2541 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 2542 | break; | |
| 2543 | } else if ((index == c && iteration > 0)) { | |
| 2544 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 2545 | break; | |
| 2546 | } | |
| 2547 | iteration++; | |
| 2548 | } | |
| 2549 | switch (exitCode) { | |
| 2550 | case HASH_SEARCH_CODE_MATCH: | |
| 2551 | *valueOutput = buckets[index].value; | |
| 2552 | break; | |
| 2553 | case HASH_SEARCH_CODE_MISMATCH: | |
| 2554 | case HASH_SEARCH_CODE_EMPTY: | |
| 2555 | resultExitCode = HASH_EXIT_CODE_KEY_DNE; | |
| 2556 | break; | |
| 2557 | default: | |
| 2558 | return exitCode; | |
| 2559 | } | |
| 2560 | } | |
| 2561 | return resultExitCode; | |
| 2562 | } | |
| 2563 | int intintLCGLinearOpenCompactHash_InnerInsertSingle(char *tableData, int key, | |
| 2564 | int value) { | |
| 2565 | intintLCGLinearOpenCompactHash_Bucket *buckets = | |
| 2566 | (intintLCGLinearOpenCompactHash_Bucket *) & | |
| 2567 | tableData[sizeof(intintLCGLinearOpenCompactHash_TableData)]; | |
| 2568 | int index; | |
| 2569 | int exitCode; | |
| 2570 | intintLCGLinearOpenCompactHash_TableData *mytableData = | |
| 2571 | (intintLCGLinearOpenCompactHash_TableData *) tableData; | |
| 2572 | intintHash_CompressLCGData compressFuncData = | |
| 2573 | mytableData->compressFuncData; | |
| 2574 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 2575 | unsigned long int iteration = 0; | |
| 2576 | for (;;) { | |
| 2577 | index = | |
| 2578 | ((1 * iteration + | |
| 2579 | c) % | |
| 2580 | ((intintLCGLinearOpenCompactHash_TableData *) tableData)-> | |
| 2581 | numBuckets); | |
| 2582 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 2583 | buckets | |
| 2584 | [index]. | |
| 2585 | key = | |
| 2586 | key; | |
| 2587 | HASH_BUCKET_STATUS_EMPTY;} | |
| 2588 | ): buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 2589 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 2590 | break; | |
| 2591 | } else if (key == buckets[index].key) { | |
| 2592 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 2593 | break; | |
| 2594 | } else if ((index == c && iteration > 0)) { | |
| 2595 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 2596 | break; | |
| 2597 | } | |
| 2598 | iteration++; | |
| 2599 | } | |
| 2600 | switch (exitCode) { | |
| 2601 | case HASH_SEARCH_CODE_MATCH: | |
| 2602 | case HASH_SEARCH_CODE_MISMATCH: | |
| 2603 | buckets[index].value = value; | |
| 2604 | return HASH_EXIT_CODE_OVERWRITE; | |
| 2605 | case HASH_SEARCH_CODE_EMPTY: | |
| 2606 | buckets[index].value = value; | |
| 2607 | return HASH_EXIT_CODE_NORMAL; | |
| 2608 | default: | |
| 2609 | return exitCode; | |
| 2610 | } | |
| 2611 | } | |
| 2612 | int intintLCGLinearOpenCompactHash_InnerInsert(char *tableData, | |
| 2613 | unsigned int numEntries, | |
| 2614 | int *keys, int *values) { | |
| 2615 | intintLCGLinearOpenCompactHash_Bucket *buckets = | |
| 2616 | (intintLCGLinearOpenCompactHash_Bucket *) & | |
| 2617 | tableData[sizeof(intintLCGLinearOpenCompactHash_TableData)]; | |
| 2618 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 2619 | int key; | |
| 2620 | int value; | |
| 2621 | int index; | |
| 2622 | int exitCode; | |
| 2623 | uint i; | |
| 2624 | for (i = 0; i < numEntries; i++) { | |
| 2625 | key = keys[i]; | |
| 2626 | intintLCGLinearOpenCompactHash_TableData *mytableData = | |
| 2627 | (intintLCGLinearOpenCompactHash_TableData *) tableData; | |
| 2628 | intintHash_CompressLCGData compressFuncData = | |
| 2629 | mytableData->compressFuncData; | |
| 2630 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 2631 | unsigned long int iteration = 0; | |
| 2632 | for (;;) { | |
| 2633 | index = | |
| 2634 | ((1 * iteration + | |
| 2635 | c) % | |
| 2636 | ((intintLCGLinearOpenCompactHash_TableData *) | |
| 2637 | tableData)->numBuckets); | |
| 2638 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 2639 | buckets | |
| 2640 | [index]. | |
| 2641 | key | |
| 2642 | = | |
| 2643 | key; | |
| 2644 | HASH_BUCKET_STATUS_EMPTY;} | |
| 2645 | ): buckets[index].key) == | |
| 2646 | HASH_BUCKET_STATUS_EMPTY) { | |
| 2647 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 2648 | break; | |
| 2649 | } else if (key == buckets[index].key) { | |
| 2650 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 2651 | break; | |
| 2652 | } else if ((index == c && iteration > 0)) { | |
| 2653 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 2654 | break; | |
| 2655 | } | |
| 2656 | iteration++; | |
| 2657 | } | |
| 2658 | switch (exitCode) { | |
| 2659 | case HASH_SEARCH_CODE_MATCH: | |
| 2660 | case HASH_SEARCH_CODE_MISMATCH: | |
| 2661 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 2662 | case HASH_SEARCH_CODE_EMPTY: | |
| 2663 | buckets[index].value = values[i]; | |
| 2664 | break; | |
| 2665 | default: | |
| 2666 | return exitCode; | |
| 2667 | } | |
| 2668 | } | |
| 2669 | return resultExitCode; | |
| 2670 | } | |
| 2671 | int intintLCGLinearOpenCompactHash_InnerInsertSingleNoOverwrite(char *tableData, | |
| 2672 | int key, | |
| 2673 | int value) { | |
| 2674 | intintLCGLinearOpenCompactHash_Bucket *buckets = | |
| 2675 | (intintLCGLinearOpenCompactHash_Bucket *) & | |
| 2676 | tableData[sizeof(intintLCGLinearOpenCompactHash_TableData)]; | |
| 2677 | int index; | |
| 2678 | int exitCode; | |
| 2679 | intintLCGLinearOpenCompactHash_TableData *mytableData = | |
| 2680 | (intintLCGLinearOpenCompactHash_TableData *) tableData; | |
| 2681 | intintHash_CompressLCGData compressFuncData = | |
| 2682 | mytableData->compressFuncData; | |
| 2683 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 2684 | unsigned long int iteration = 0; | |
| 2685 | for (;;) { | |
| 2686 | index = | |
| 2687 | ((1 * iteration + | |
| 2688 | c) % | |
| 2689 | ((intintLCGLinearOpenCompactHash_TableData *) tableData)-> | |
| 2690 | numBuckets); | |
| 2691 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 2692 | buckets | |
| 2693 | [index]. | |
| 2694 | key = | |
| 2695 | key; | |
| 2696 | HASH_BUCKET_STATUS_EMPTY;} | |
| 2697 | ): buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 2698 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 2699 | break; | |
| 2700 | } else if (key == buckets[index].key) { | |
| 2701 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 2702 | break; | |
| 2703 | } else if ((index == c && iteration > 0)) { | |
| 2704 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 2705 | break; | |
| 2706 | } | |
| 2707 | iteration++; | |
| 2708 | } | |
| 2709 | switch (exitCode) { | |
| 2710 | case HASH_SEARCH_CODE_MATCH: | |
| 2711 | case HASH_SEARCH_CODE_MISMATCH: | |
| 2712 | return HASH_EXIT_CODE_OVERWRITE; | |
| 2713 | case HASH_SEARCH_CODE_EMPTY: | |
| 2714 | buckets[index].value = value; | |
| 2715 | return HASH_EXIT_CODE_NORMAL; | |
| 2716 | default: | |
| 2717 | return exitCode; | |
| 2718 | } | |
| 2719 | } | |
| 2720 | int intintLCGLinearOpenCompactHash_InnerInsertNoOverwrite(char *tableData, | |
| 2721 | unsigned int | |
| 2722 | numEntries, int *keys, | |
| 2723 | int *values) { | |
| 2724 | intintLCGLinearOpenCompactHash_Bucket *buckets = | |
| 2725 | (intintLCGLinearOpenCompactHash_Bucket *) & | |
| 2726 | tableData[sizeof(intintLCGLinearOpenCompactHash_TableData)]; | |
| 2727 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 2728 | int key; | |
| 2729 | int value; | |
| 2730 | int index; | |
| 2731 | int exitCode; | |
| 2732 | uint i; | |
| 2733 | for (i = 0; i < numEntries; i++) { | |
| 2734 | key = keys[i]; | |
| 2735 | intintLCGLinearOpenCompactHash_TableData *mytableData = | |
| 2736 | (intintLCGLinearOpenCompactHash_TableData *) tableData; | |
| 2737 | intintHash_CompressLCGData compressFuncData = | |
| 2738 | mytableData->compressFuncData; | |
| 2739 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 2740 | unsigned long int iteration = 0; | |
| 2741 | for (;;) { | |
| 2742 | index = | |
| 2743 | ((1 * iteration + | |
| 2744 | c) % | |
| 2745 | ((intintLCGLinearOpenCompactHash_TableData *) | |
| 2746 | tableData)->numBuckets); | |
| 2747 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 2748 | buckets | |
| 2749 | [index]. | |
| 2750 | key | |
| 2751 | = | |
| 2752 | key; | |
| 2753 | HASH_BUCKET_STATUS_EMPTY;} | |
| 2754 | ): buckets[index].key) == | |
| 2755 | HASH_BUCKET_STATUS_EMPTY) { | |
| 2756 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 2757 | break; | |
| 2758 | } else if (key == buckets[index].key) { | |
| 2759 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 2760 | break; | |
| 2761 | } else if ((index == c && iteration > 0)) { | |
| 2762 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 2763 | break; | |
| 2764 | } | |
| 2765 | iteration++; | |
| 2766 | } | |
| 2767 | switch (exitCode) { | |
| 2768 | case HASH_SEARCH_CODE_MATCH: | |
| 2769 | case HASH_SEARCH_CODE_MISMATCH: | |
| 2770 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 2771 | break; | |
| 2772 | case HASH_SEARCH_CODE_EMPTY: | |
| 2773 | buckets[index].value = values[i]; | |
| 2774 | break; | |
| 2775 | default: | |
| 2776 | return exitCode; | |
| 2777 | } | |
| 2778 | } | |
| 2779 | return resultExitCode; | |
| 2780 | } | |
| 2781 | int intintLCGLinearOpenCompactHash_QuerySingle(intintHash_Table * table, | |
| 2782 | int key, int *valueOutput) { | |
| 2783 | return intintLCGLinearOpenCompactHash_InnerQuerySingle(table->tableData, | |
| 2784 | key, | |
| 2785 | valueOutput); | |
| 2786 | } | |
| 2787 | int intintLCGLinearOpenCompactHash_Query(intintHash_Table * table, | |
| 2788 | size_t numKeys, int *keys, | |
| 2789 | int *valuesOutput) { | |
| 2790 | return intintLCGLinearOpenCompactHash_InnerQuery(table->tableData, | |
| 2791 | numKeys, keys, | |
| 2792 | valuesOutput); | |
| 2793 | } | |
| 2794 | int intintLCGLinearOpenCompactHash_InsertSingle(intintHash_Table * table, | |
| 2795 | int key, int value) { | |
| 2796 | return intintLCGLinearOpenCompactHash_InnerInsertSingle(table-> | |
| 2797 | tableData, key, | |
| 2798 | value); | |
| 2799 | } | |
| 2800 | int intintLCGLinearOpenCompactHash_Insert(intintHash_Table * table, | |
| 2801 | size_t numEntries, int *keys, | |
| 2802 | int *values) { | |
| 2803 | return intintLCGLinearOpenCompactHash_InnerInsert(table->tableData, | |
| 2804 | numEntries, keys, | |
| 2805 | values); | |
| 2806 | } | |
| 2807 | int intintLCGLinearOpenCompactHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 2808 | table, int key, | |
| 2809 | int value) { | |
| 2810 | return | |
| 2811 | intintLCGLinearOpenCompactHash_InnerInsertSingleNoOverwrite(table-> | |
| 2812 | tableData, | |
| 2813 | key, | |
| 2814 | value); | |
| 2815 | } | |
| 2816 | int intintLCGLinearOpenCompactHash_InsertNoOverwrite(intintHash_Table * table, | |
| 2817 | size_t numEntries, | |
| 2818 | int *keys, int *values) { | |
| 2819 | return intintLCGLinearOpenCompactHash_InnerInsertNoOverwrite(table-> | |
| 2820 | tableData, | |
| 2821 | numEntries, | |
| 2822 | keys, | |
| 2823 | values); | |
| 2824 | } | |
| 2825 | ||
| 2826 | typedef struct intintLCGLinearOpenCompactCLHash_TableData { | |
| 2827 | int hashID; | |
| 2828 | unsigned int numBuckets; | |
| 2829 | intintHash_CompressLCGData compressFuncData; | |
| 2830 | } intintLCGLinearOpenCompactCLHash_TableData; | |
| 2831 | typedef struct intintLCGLinearOpenCompactCLHash_Bucket { | |
| 2832 | int key; | |
| 2833 | int value; | |
| 2834 | } intintLCGLinearOpenCompactCLHash_Bucket; | |
| 2835 | intintHash_Table | |
| 2836 | *intintLCGLinearOpenCompactCLHash_CreateTable(intintHash_Factory * factory, | |
| 2837 | int hashIndex, | |
| 2838 | size_t keyRange, | |
| 2839 | size_t numEntries, | |
| 2840 | float loadFactor) { | |
| 2841 | intintHash_Table *table = | |
| 2842 | (intintHash_Table *) malloc(sizeof(intintHash_Table)); | |
| 2843 | table->destroyFunc = &intintLCGLinearOpenCompactCLHash_DestroyTable; | |
| 2844 | table->emptyFunc = &intintLCGLinearOpenCompactCLHash_EmptyTable; | |
| 2845 | table->queryFunc = &intintLCGLinearOpenCompactCLHash_Query; | |
| 2846 | table->querySingleFunc = &intintLCGLinearOpenCompactCLHash_QuerySingle; | |
| 2847 | table->insertFunc = &intintLCGLinearOpenCompactCLHash_Insert; | |
| 2848 | table->insertSingleFunc = | |
| 2849 | &intintLCGLinearOpenCompactCLHash_InsertSingle; | |
| 2850 | table->insertNoOverwriteFunc = | |
| 2851 | &intintLCGLinearOpenCompactCLHash_InsertNoOverwrite; | |
| 2852 | table->insertSingleNoOverwriteFunc = | |
| 2853 | &intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite; | |
| 2854 | table->tableData = | |
| 2855 | (char *)malloc(sizeof(intintLCGLinearOpenCompactCLHash_TableData)); | |
| 2856 | ((intintLCGLinearOpenCompactCLHash_TableData *) table->tableData)-> | |
| 2857 | hashID = LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID; | |
| 2858 | table->context = factory->context; | |
| 2859 | table->queue = factory->queue; | |
| 2860 | table->program = factory->program; | |
| 2861 | table->localWorkSize = factory->localWorkSize; | |
| 2862 | table->utilProgram = factory->utilProgram[hashIndex]; | |
| 2863 | table->emptyKernel = factory->emptyKernel[hashIndex]; | |
| 2864 | table->emptyKernelLocalWorkSize = | |
| 2865 | factory->emptyKernelLocalWorkSize[hashIndex]; | |
| 2866 | table->querySingleKernel = factory->querySingleKernel[hashIndex]; | |
| 2867 | table->insertSingleKernel = factory->insertSingleKernel[hashIndex]; | |
| 2868 | table->insertSingleNoOverwriteKernel = | |
| 2869 | factory->insertSingleNoOverwriteKernel[hashIndex]; | |
| 2870 | clRetainContext(table->context); | |
| 2871 | clRetainCommandQueue(table->queue); | |
| 2872 | clRetainProgram(table->program); | |
| 2873 | clRetainProgram(table->utilProgram); | |
| 2874 | clRetainKernel(table->emptyKernel); | |
| 2875 | clRetainKernel(table->querySingleKernel); | |
| 2876 | clRetainKernel(table->insertSingleKernel); | |
| 2877 | clRetainKernel(table->insertSingleNoOverwriteKernel);; | |
| 2878 | ((intintLCGLinearOpenCompactCLHash_TableData *) table->tableData)-> | |
| 2879 | numBuckets = (unsigned int)((double)numEntries / loadFactor); | |
| 2880 | ((intintLCGLinearOpenCompactCLHash_TableData *) table->tableData)-> | |
| 2881 | compressFuncData.a = HASH_LCG_A; | |
| 2882 | ((intintLCGLinearOpenCompactCLHash_TableData *) table->tableData)-> | |
| 2883 | compressFuncData.c = HASH_LCG_C; | |
| 2884 | ((intintLCGLinearOpenCompactCLHash_TableData *) table->tableData)-> | |
| 2885 | compressFuncData.m = HASH_LCG_M; | |
| 2886 | ((intintLCGLinearOpenCompactCLHash_TableData *) table->tableData)-> | |
| 2887 | compressFuncData.n = | |
| 2888 | ((intintLCGLinearOpenCompactCLHash_TableData *) table->tableData)-> | |
| 2889 | numBuckets; | |
| 2890 | char *tempHashData = | |
| 2891 | (char *)malloc(sizeof(intintLCGLinearOpenCompactCLHash_TableData) + | |
| 2892 | ((intintLCGLinearOpenCompactCLHash_TableData *) | |
| 2893 | table->tableData)->numBuckets * | |
| 2894 | sizeof(intintLCGLinearOpenCompactCLHash_Bucket)); | |
| 2895 | memcpy(tempHashData, table->tableData, | |
| 2896 | sizeof(intintLCGLinearOpenCompactCLHash_TableData)); | |
| 2897 | free(table->tableData); | |
| 2898 | table->tableData = tempHashData; | |
| 2899 | cl_int err; | |
| 2900 | table->tableDataBuffer = | |
| 2901 | clCreateBuffer(table->context, CL_MEM_READ_WRITE, | |
| 2902 | sizeof(intintLCGLinearOpenCompactHash_TableData) + | |
| 2903 | ((intintLCGLinearOpenCompactHash_TableData *) table-> | |
| 2904 | tableData)->numBuckets * | |
| 2905 | sizeof(intintLCGLinearOpenCompactHash_Bucket), NULL, | |
| 2906 | &err); | |
| 2907 | CLHash_Utilities_HandleError(err, | |
| 2908 | "intintLCGLinearOpenCompactCLHash_InitTable", | |
| 2909 | "clCreateBuffer"); | |
| 2910 | err = | |
| 2911 | clEnqueueWriteBuffer(table->queue, table->tableDataBuffer, CL_TRUE, | |
| 2912 | 0, | |
| 2913 | sizeof | |
| 2914 | (intintLCGLinearOpenCompactHash_TableData), | |
| 2915 | table->tableData, 0, NULL, NULL); | |
| 2916 | CLHash_Utilities_HandleError(err, | |
| 2917 | "intintLCGLinearOpenCompactCLHash_InitTable", | |
| 2918 | "clEnqueueWriteBuffer"); | |
| 2919 | return table; | |
| 2920 | } | |
| 2921 | int intintLCGLinearOpenCompactCLHash_CreateFactory(intintHash_Factory * factory, | |
| 2922 | int hashIndex) { | |
| 2923 | factory->createFunc[hashIndex] = | |
| 2924 | &intintLCGLinearOpenCompactCLHash_CreateTable; | |
| 2925 | factory->destroyFunc[hashIndex] = | |
| 2926 | &intintLCGLinearOpenCompactCLHash_DestroyFactory; | |
| 2927 | cl_int error; | |
| 2928 | cl_device_id device; | |
| 2929 | error = | |
| 2930 | clGetContextInfo(factory->context, CL_CONTEXT_DEVICES, | |
| 2931 | sizeof(device), &device, NULL); | |
| 2932 | CLHash_Utilities_HandleError(error, "intintHash_CreateFactory", | |
| 2933 | "clGetContextInfo"); | |
| 2934 | factory->querySingleKernel[hashIndex] = | |
| 2935 | clCreateKernel(factory->program, | |
| 2936 | "intintLCGLinearOpenCompactCLHash_RangeQuerySingle", | |
| 2937 | &error); | |
| 2938 | CLHash_Utilities_HandleError(error, | |
| 2939 | "intintLCGLinearOpenCompactCLHash_CreateFactory", | |
| 2940 | "clCreateKernel"); | |
| 2941 | factory->insertSingleKernel[hashIndex] = | |
| 2942 | clCreateKernel(factory->program, | |
| 2943 | "intintLCGLinearOpenCompactCLHash_RangeInsertSingle", | |
| 2944 | &error); | |
| 2945 | CLHash_Utilities_HandleError(error, | |
| 2946 | "intintLCGLinearOpenCompactCLHash_CreateFactory", | |
| 2947 | "clCreateKernel"); | |
| 2948 | factory->insertSingleNoOverwriteKernel[hashIndex] = | |
| 2949 | clCreateKernel(factory->program, | |
| 2950 | "intintLCGLinearOpenCompactCLHash_RangeInsertSingleNoOverwrite", | |
| 2951 | &error); | |
| 2952 | CLHash_Utilities_HandleError(error, | |
| 2953 | "intintLCGLinearOpenCompactCLHash_CreateFactory", | |
| 2954 | "clCreateKernel"); | |
| 2955 | factory->utilProgram[hashIndex] = | |
| 2956 | CLHash_Utilities_BuildProgramString(factory->context, device, | |
| 2957 | "static inline unsigned int intintHash_CompressIdentity(char data, int hashCode){ return hashCode; } typedef struct intintHash_CompressLCGData{ long unsigned int a; long unsigned int c; unsigned int m; unsigned int n; }intintHash_CompressLCGData; static inline unsigned int intintHash_CompressLCG(intintHash_CompressLCGData compressLCGData, int hashCode){ return ((compressLCGData.a * hashCode + compressLCGData.c) % compressLCGData.m) % compressLCGData.n; } typedef struct intintLCGLinearOpenCompactCLHash_TableData{ int hashID; unsigned int numBuckets; intintHash_CompressLCGData compressFuncData; }intintLCGLinearOpenCompactCLHash_TableData; typedef struct intintLCGLinearOpenCompactCLHash_Bucket{ int key; int value; }intintLCGLinearOpenCompactCLHash_Bucket; __kernel void intintLCGLinearOpenCompactCLHash_Empty(__global char *tableData){ int index = get_global_id(0); if(index >= ((__global intintLCGLinearOpenCompactCLHash_TableData*)tableData)->numBuckets){ return; } __global intintLCGLinearOpenCompactCLHash_Bucket *buckets = (__global intintLCGLinearOpenCompactCLHash_Bucket*)&tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)]; buckets[index].key = -1;/*HASH_BUCKET_STATUS_EMPTY*/ }"); | |
| 2958 | factory->emptyKernel[hashIndex] = | |
| 2959 | clCreateKernel(factory->utilProgram[hashIndex], | |
| 2960 | "intintLCGLinearOpenCompactCLHash_Empty", &error); | |
| 2961 | CLHash_Utilities_HandleError(error, | |
| 2962 | "intintLCGLinearOpenCompactCLHash_CreateFactory", | |
| 2963 | "clCreateKernel"); | |
| 2964 | error = | |
| 2965 | clGetKernelWorkGroupInfo(factory->emptyKernel[hashIndex], device, | |
| 2966 | CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), | |
| 2967 | &factory-> | |
| 2968 | emptyKernelLocalWorkSize[hashIndex], NULL); | |
| 2969 | CLHash_Utilities_HandleError(error, | |
| 2970 | "intintLCGLinearOpenCompactCLHash_CreateFactory", | |
| 2971 | "clGetKernelWorkGroupInfo");;; | |
| 2972 | return HASH_EXIT_CODE_NORMAL; | |
| 2973 | } | |
| 2974 | int intintLCGLinearOpenCompactCLHash_DestroyFactory(intintHash_Factory * | |
| 2975 | factory, int hashIndex) {; | |
| 2976 | clReleaseKernel(factory->emptyKernel[hashIndex]); | |
| 2977 | clReleaseProgram(factory->utilProgram[hashIndex]); | |
| 2978 | clReleaseKernel(factory->querySingleKernel[hashIndex]); | |
| 2979 | clReleaseKernel(factory->insertSingleKernel[hashIndex]); | |
| 2980 | clReleaseKernel(factory->insertSingleNoOverwriteKernel[hashIndex]);; | |
| 2981 | return HASH_EXIT_CODE_NORMAL; | |
| 2982 | } | |
| 2983 | int intintLCGLinearOpenCompactCLHash_DestroyTable(intintHash_Table * table) { | |
| 2984 | int exitCode = 0; | |
| 2985 | clReleaseMemObject(table->tableDataBuffer); | |
| 2986 | clReleaseContext(table->context); | |
| 2987 | clReleaseCommandQueue(table->queue); | |
| 2988 | clReleaseProgram(table->utilProgram); | |
| 2989 | clReleaseKernel(table->emptyKernel); | |
| 2990 | clReleaseProgram(table->program); | |
| 2991 | clReleaseKernel(table->querySingleKernel); | |
| 2992 | clReleaseKernel(table->insertSingleKernel); | |
| 2993 | clReleaseKernel(table->insertSingleNoOverwriteKernel); | |
| 2994 | free(table->tableData); | |
| 2995 | free(table); | |
| 2996 | return exitCode; | |
| 2997 | } | |
| 2998 | int intintLCGLinearOpenCompactCLHash_EmptyTable(intintHash_Table * table) { | |
| 2999 | int exitCode = 0; | |
| 3000 | cl_int err; | |
| 3001 | err = | |
| 3002 | clSetKernelArg(table->emptyKernel, 0, sizeof(cl_mem), | |
| 3003 | &table->tableDataBuffer); | |
| 3004 | CLHash_Utilities_HandleError(err, | |
| 3005 | "intintLCGLinearOpenCompactCLHash_EmptyTable", | |
| 3006 | "clSetKernelArg"); | |
| 3007 | const size_t groupWorkSize = | |
| 3008 | roundUpToNearest(((intintLCGLinearOpenCompactHash_TableData *) | |
| 3009 | table->tableData)->numBuckets, | |
| 3010 | table->emptyKernelLocalWorkSize); | |
| 3011 | err = | |
| 3012 | clEnqueueNDRangeKernel(table->queue, table->emptyKernel, 1, 0, | |
| 3013 | &groupWorkSize, | |
| 3014 | (const size_t *)&table-> | |
| 3015 | emptyKernelLocalWorkSize, 0, NULL, NULL); | |
| 3016 | CLHash_Utilities_HandleError(err, | |
| 3017 | "intintLCGLinearOpenCompactCLHash_EmptyTable", | |
| 3018 | "clEnqueueNDRangeKernel"); | |
| 3019 | exitCode = HASH_EXIT_CODE_NORMAL;; | |
| 3020 | return exitCode; | |
| 3021 | } | |
| 3022 | int intintLCGLinearOpenCompactCLHash_QuerySingle(intintHash_Table * table, | |
| 3023 | int key, int *valueOutput) { | |
| 3024 | return intintLCGLinearOpenCompactCLHash_Query(table, 1, &key, | |
| 3025 | valueOutput); | |
| 3026 | } | |
| 3027 | int intintLCGLinearOpenCompactCLHash_Query(intintHash_Table * table, | |
| 3028 | size_t numKeys, int *keys, | |
| 3029 | int *valuesOutput) { | |
| 3030 | cl_int err; | |
| 3031 | cl_mem keysBuffer = | |
| 3032 | clCreateBuffer(table->context, | |
| 3033 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 3034 | sizeof(int) * numKeys, keys, &err); | |
| 3035 | CLHash_Utilities_HandleError(err, | |
| 3036 | "intintLCGLinearOpenCompactCLHash_Query", | |
| 3037 | "clCreateBuffer"); | |
| 3038 | cl_mem valuesOutputBuffer = | |
| 3039 | clCreateBuffer(table->context, CL_MEM_WRITE_ONLY, | |
| 3040 | sizeof(int) * numKeys, NULL, &err); | |
| 3041 | CLHash_Utilities_HandleError(err, | |
| 3042 | "intintLCGLinearOpenCompactCLHash_Query", | |
| 3043 | "clCreateBuffer"); | |
| 3044 | intintLCGLinearOpenCompactCLHash_BufferQuery(table, numKeys, keysBuffer, | |
| 3045 | valuesOutputBuffer); | |
| 3046 | err = | |
| 3047 | clEnqueueReadBuffer(table->queue, valuesOutputBuffer, CL_TRUE, 0, | |
| 3048 | sizeof(int) * numKeys, valuesOutput, 0, NULL, | |
| 3049 | NULL); | |
| 3050 | CLHash_Utilities_HandleError(err, | |
| 3051 | "intintLCGLinearOpenCompactCLHash_Query", | |
| 3052 | "clEnqueueReadBuffer"); | |
| 3053 | clReleaseMemObject(keysBuffer); | |
| 3054 | clReleaseMemObject(valuesOutputBuffer); | |
| 3055 | return HASH_EXIT_CODE_NORMAL; | |
| 3056 | } | |
| 3057 | int intintLCGLinearOpenCompactCLHash_BufferQuery(intintHash_Table * table, | |
| 3058 | size_t numKeys, | |
| 3059 | cl_mem keysBuffer, | |
| 3060 | cl_mem valuesOutputBuffer) { | |
| 3061 | cl_int err; | |
| 3062 | err = | |
| 3063 | clSetKernelArg(table->querySingleKernel, 0, sizeof(cl_mem), | |
| 3064 | &table->tableDataBuffer); | |
| 3065 | CLHash_Utilities_HandleError(err, | |
| 3066 | "intintLCGLinearOpenCompactCLHash_BufferQuery", | |
| 3067 | "clSetKernelArg"); | |
| 3068 | err = | |
| 3069 | clSetKernelArg(table->querySingleKernel, 1, sizeof(unsigned int), | |
| 3070 | &numKeys); | |
| 3071 | CLHash_Utilities_HandleError(err, | |
| 3072 | "intintLCGLinearOpenCompactCLHash_BufferQuery", | |
| 3073 | "clSetKernelArg"); | |
| 3074 | err = | |
| 3075 | clSetKernelArg(table->querySingleKernel, 2, sizeof(cl_mem), | |
| 3076 | &keysBuffer); | |
| 3077 | CLHash_Utilities_HandleError(err, | |
| 3078 | "intintLCGLinearOpenCompactCLHash_BufferQuery", | |
| 3079 | "clSetKernelArg"); | |
| 3080 | err = | |
| 3081 | clSetKernelArg(table->querySingleKernel, 3, sizeof(cl_mem), | |
| 3082 | &valuesOutputBuffer); | |
| 3083 | CLHash_Utilities_HandleError(err, | |
| 3084 | "intintLCGLinearOpenCompactCLHash_BufferQuery", | |
| 3085 | "clSetKernelArg"); | |
| 3086 | const size_t groupWorkSize = | |
| 3087 | roundUpToNearest(numKeys, table->localWorkSize); | |
| 3088 | err = | |
| 3089 | clEnqueueNDRangeKernel(table->queue, table->querySingleKernel, 1, 0, | |
| 3090 | &groupWorkSize, | |
| 3091 | (const size_t *)&table->localWorkSize, 0, | |
| 3092 | NULL, NULL); | |
| 3093 | CLHash_Utilities_HandleError(err, | |
| 3094 | "intintLCGLinearOpenCompactCLHash_BufferQuery", | |
| 3095 | "clEnqueueNDRangeKernel"); | |
| 3096 | clFinish(table->queue); | |
| 3097 | return HASH_EXIT_CODE_NORMAL; | |
| 3098 | } | |
| 3099 | int intintLCGLinearOpenCompactCLHash_InsertSingle(intintHash_Table * table, | |
| 3100 | int key, int value) { | |
| 3101 | return intintLCGLinearOpenCompactCLHash_Insert(table, 1, &key, &value); | |
| 3102 | } | |
| 3103 | int intintLCGLinearOpenCompactCLHash_Insert(intintHash_Table * table, | |
| 3104 | size_t numEntries, int *keys, | |
| 3105 | int *values) { | |
| 3106 | cl_int err; | |
| 3107 | cl_mem keysBuffer = | |
| 3108 | clCreateBuffer(table->context, | |
| 3109 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 3110 | sizeof(int) * numEntries, keys, &err); | |
| 3111 | CLHash_Utilities_HandleError(err, | |
| 3112 | "intintLCGLinearOpenCompactCLHash_Insert", | |
| 3113 | "clCreateBuffer"); | |
| 3114 | cl_mem valuesBuffer = | |
| 3115 | clCreateBuffer(table->context, | |
| 3116 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 3117 | sizeof(int) * numEntries, values, &err); | |
| 3118 | CLHash_Utilities_HandleError(err, | |
| 3119 | "intintLCGLinearOpenCompactCLHash_Insert", | |
| 3120 | "clCreateBuffer"); | |
| 3121 | intintLCGLinearOpenCompactCLHash_BufferInsert(table, numEntries, | |
| 3122 | keysBuffer, valuesBuffer); | |
| 3123 | clReleaseMemObject(keysBuffer); | |
| 3124 | clReleaseMemObject(valuesBuffer); | |
| 3125 | return HASH_EXIT_CODE_NORMAL; | |
| 3126 | } | |
| 3127 | int intintLCGLinearOpenCompactCLHash_BufferInsert(intintHash_Table * table, | |
| 3128 | size_t numEntries, | |
| 3129 | cl_mem keysBuffer, | |
| 3130 | cl_mem valuesBuffer) { | |
| 3131 | cl_int err; | |
| 3132 | err = | |
| 3133 | clSetKernelArg(table->insertSingleKernel, 0, sizeof(cl_mem), | |
| 3134 | &table->tableDataBuffer); | |
| 3135 | CLHash_Utilities_HandleError(err, | |
| 3136 | "intintLCGLinearOpenCompactCLHash_BufferInsert", | |
| 3137 | "clSetKernelArg"); | |
| 3138 | err = | |
| 3139 | clSetKernelArg(table->insertSingleKernel, 1, sizeof(unsigned int), | |
| 3140 | &numEntries); | |
| 3141 | CLHash_Utilities_HandleError(err, | |
| 3142 | "intintLCGLinearOpenCompactCLHash_BufferInsert", | |
| 3143 | "clSetKernelArg"); | |
| 3144 | err = | |
| 3145 | clSetKernelArg(table->insertSingleKernel, 2, sizeof(cl_mem), | |
| 3146 | &keysBuffer); | |
| 3147 | CLHash_Utilities_HandleError(err, | |
| 3148 | "intintLCGLinearOpenCompactCLHash_BufferInsert", | |
| 3149 | "clSetKernelArg"); | |
| 3150 | err = | |
| 3151 | clSetKernelArg(table->insertSingleKernel, 3, sizeof(cl_mem), | |
| 3152 | &valuesBuffer); | |
| 3153 | CLHash_Utilities_HandleError(err, | |
| 3154 | "intintLCGLinearOpenCompactCLHash_BufferInsert", | |
| 3155 | "clSetKernelArg"); | |
| 3156 | const size_t groupWorkSize = | |
| 3157 | roundUpToNearest(numEntries, table->localWorkSize); | |
| 3158 | err = | |
| 3159 | clEnqueueNDRangeKernel(table->queue, table->insertSingleKernel, 1, | |
| 3160 | 0, &groupWorkSize, | |
| 3161 | (const size_t *)&table->localWorkSize, 0, | |
| 3162 | NULL, NULL); | |
| 3163 | CLHash_Utilities_HandleError(err, NULL, "clEnqueueNDRangeKernel"); | |
| 3164 | return (0); | |
| 3165 | } | |
| 3166 | int intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 3167 | table, int key, | |
| 3168 | int value) { | |
| 3169 | return intintLCGLinearOpenCompactCLHash_InsertNoOverwrite(table, 1, | |
| 3170 | &key, &value); | |
| 3171 | } | |
| 3172 | int intintLCGLinearOpenCompactCLHash_InsertNoOverwrite(intintHash_Table * table, | |
| 3173 | size_t numEntries, | |
| 3174 | int *keys, int *values) { | |
| 3175 | cl_int err; | |
| 3176 | cl_mem keysBuffer = | |
| 3177 | clCreateBuffer(table->context, | |
| 3178 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 3179 | sizeof(int) * numEntries, keys, &err); | |
| 3180 | CLHash_Utilities_HandleError(err, | |
| 3181 | "intintLCGLinearOpenCompactCLHash_InsertNoOverwrite", | |
| 3182 | "clCreateBuffer"); | |
| 3183 | cl_mem valuesBuffer = | |
| 3184 | clCreateBuffer(table->context, | |
| 3185 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 3186 | sizeof(int) * numEntries, values, &err); | |
| 3187 | CLHash_Utilities_HandleError(err, | |
| 3188 | "intintLCGLinearOpenCompactCLHash_InsertNoOverwrite", | |
| 3189 | "clCreateBuffer"); | |
| 3190 | intintLCGLinearOpenCompactCLHash_BufferInsertNoOverwrite(table, | |
| 3191 | numEntries, | |
| 3192 | keysBuffer, | |
| 3193 | valuesBuffer); | |
| 3194 | clReleaseMemObject(keysBuffer); | |
| 3195 | clReleaseMemObject(valuesBuffer); | |
| 3196 | return HASH_EXIT_CODE_NORMAL; | |
| 3197 | } | |
| 3198 | int intintLCGLinearOpenCompactCLHash_BufferInsertNoOverwrite(intintHash_Table * | |
| 3199 | table, | |
| 3200 | size_t numEntries, | |
| 3201 | cl_mem keysBuffer, | |
| 3202 | cl_mem | |
| 3203 | valuesBuffer) { | |
| 3204 | cl_int err; | |
| 3205 | err = | |
| 3206 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 0, | |
| 3207 | sizeof(cl_mem), &table->tableDataBuffer); | |
| 3208 | CLHash_Utilities_HandleError(err, | |
| 3209 | "intintLCGLinearOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 3210 | "clSetKernelArg"); | |
| 3211 | err = | |
| 3212 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 1, | |
| 3213 | sizeof(unsigned int), &numEntries); | |
| 3214 | CLHash_Utilities_HandleError(err, | |
| 3215 | "intintLCGLinearOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 3216 | "ClSetKernelArg"); | |
| 3217 | err = | |
| 3218 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 2, | |
| 3219 | sizeof(cl_mem), &keysBuffer); | |
| 3220 | CLHash_Utilities_HandleError(err, | |
| 3221 | "intintLCGLinearOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 3222 | "clSetKernelArg"); | |
| 3223 | err = | |
| 3224 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 3, | |
| 3225 | sizeof(cl_mem), &valuesBuffer); | |
| 3226 | CLHash_Utilities_HandleError(err, | |
| 3227 | "intintLCGLinearOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 3228 | "clSetKernelArg"); | |
| 3229 | const size_t groupWorkSize = | |
| 3230 | roundUpToNearest(numEntries, table->localWorkSize); | |
| 3231 | err = | |
| 3232 | clEnqueueNDRangeKernel(table->queue, | |
| 3233 | table->insertSingleNoOverwriteKernel, 1, 0, | |
| 3234 | &groupWorkSize, | |
| 3235 | (const size_t *)&table->localWorkSize, 0, | |
| 3236 | NULL, NULL); | |
| 3237 | CLHash_Utilities_HandleError(err, | |
| 3238 | "intintLCGLinearOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 3239 | "clEnqueueNDRangeKernel"); | |
| 3240 | return (0); | |
| 3241 | } | |
| 3242 | ||
| 3243 | typedef struct intintLCGQuadraticOpenCompactHash_TableData { | |
| 3244 | int hashID; | |
| 3245 | unsigned int numBuckets; | |
| 3246 | intintHash_CompressLCGData compressFuncData; | |
| 3247 | } intintLCGQuadraticOpenCompactHash_TableData; | |
| 3248 | typedef struct intintLCGQuadraticOpenCompactHash_Bucket { | |
| 3249 | int key; | |
| 3250 | int value; | |
| 3251 | } intintLCGQuadraticOpenCompactHash_Bucket; | |
| 3252 | intintHash_Table | |
| 3253 | *intintLCGQuadraticOpenCompactHash_CreateTable(intintHash_Factory * factory, | |
| 3254 | int hashIndex, | |
| 3255 | size_t keyRange, | |
| 3256 | size_t numEntries, | |
| 3257 | float loadFactor) { | |
| 3258 | intintHash_Table *table = | |
| 3259 | (intintHash_Table *) malloc(sizeof(intintHash_Table)); | |
| 3260 | table->destroyFunc = &intintLCGQuadraticOpenCompactHash_DestroyTable; | |
| 3261 | table->emptyFunc = &intintLCGQuadraticOpenCompactHash_EmptyTable; | |
| 3262 | table->queryFunc = &intintLCGQuadraticOpenCompactHash_Query; | |
| 3263 | table->querySingleFunc = &intintLCGQuadraticOpenCompactHash_QuerySingle; | |
| 3264 | table->insertFunc = &intintLCGQuadraticOpenCompactHash_Insert; | |
| 3265 | table->insertSingleFunc = | |
| 3266 | &intintLCGQuadraticOpenCompactHash_InsertSingle; | |
| 3267 | table->insertNoOverwriteFunc = | |
| 3268 | &intintLCGQuadraticOpenCompactHash_InsertNoOverwrite; | |
| 3269 | table->insertSingleNoOverwriteFunc = | |
| 3270 | &intintLCGQuadraticOpenCompactHash_InsertSingleNoOverwrite; | |
| 3271 | table->tableData = | |
| 3272 | (char *)malloc(sizeof(intintLCGQuadraticOpenCompactHash_TableData)); | |
| 3273 | ((intintLCGQuadraticOpenCompactHash_TableData *) table->tableData)-> | |
| 3274 | hashID = LCG_QUADRATIC_OPEN_COMPACT_HASH_ID; | |
| 3275 | ((intintLCGQuadraticOpenCompactHash_TableData *) table->tableData)-> | |
| 3276 | numBuckets = (unsigned int)((double)numEntries / loadFactor); | |
| 3277 | ((intintLCGQuadraticOpenCompactHash_TableData *) table->tableData)-> | |
| 3278 | compressFuncData.a = HASH_LCG_A; | |
| 3279 | ((intintLCGQuadraticOpenCompactHash_TableData *) table->tableData)-> | |
| 3280 | compressFuncData.c = HASH_LCG_C; | |
| 3281 | ((intintLCGQuadraticOpenCompactHash_TableData *) table->tableData)-> | |
| 3282 | compressFuncData.m = HASH_LCG_M; | |
| 3283 | ((intintLCGQuadraticOpenCompactHash_TableData *) table->tableData)-> | |
| 3284 | compressFuncData.n = | |
| 3285 | ((intintLCGQuadraticOpenCompactHash_TableData *) table->tableData)-> | |
| 3286 | numBuckets; | |
| 3287 | ((intintLCGQuadraticOpenCompactHash_TableData *) table->tableData)-> | |
| 3288 | numBuckets = | |
| 3289 | largestProthPrimeUnder(((intintLCGQuadraticOpenCompactHash_TableData | |
| 3290 | *) table->tableData)->numBuckets); | |
| 3291 | char *tempHashData = | |
| 3292 | (char *)malloc(sizeof(intintLCGQuadraticOpenCompactHash_TableData) + | |
| 3293 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3294 | table->tableData)->numBuckets * | |
| 3295 | sizeof(intintLCGQuadraticOpenCompactHash_Bucket)); | |
| 3296 | memcpy(tempHashData, table->tableData, | |
| 3297 | sizeof(intintLCGQuadraticOpenCompactHash_TableData)); | |
| 3298 | free(table->tableData); | |
| 3299 | table->tableData = tempHashData; | |
| 3300 | return table; | |
| 3301 | } | |
| 3302 | int intintLCGQuadraticOpenCompactHash_CreateFactory(intintHash_Factory * | |
| 3303 | factory, int hashIndex) { | |
| 3304 | factory->createFunc[hashIndex] = | |
| 3305 | &intintLCGQuadraticOpenCompactHash_CreateTable; | |
| 3306 | factory->destroyFunc[hashIndex] = | |
| 3307 | &intintLCGQuadraticOpenCompactHash_DestroyFactory;; | |
| 3308 | return HASH_EXIT_CODE_NORMAL; | |
| 3309 | } | |
| 3310 | int intintLCGQuadraticOpenCompactHash_DestroyFactory(intintHash_Factory * | |
| 3311 | factory, int hashIndex) {; | |
| 3312 | return HASH_EXIT_CODE_NORMAL; | |
| 3313 | } | |
| 3314 | int intintLCGQuadraticOpenCompactHash_DestroyTable(intintHash_Table * table) { | |
| 3315 | int exitCode = 0; | |
| 3316 | free(table->tableData); | |
| 3317 | free(table); | |
| 3318 | return exitCode; | |
| 3319 | } | |
| 3320 | int intintLCGQuadraticOpenCompactHash_EmptyTable(intintHash_Table * table) { | |
| 3321 | int exitCode = 0; | |
| 3322 | intintLCGQuadraticOpenCompactHash_Bucket *buckets = | |
| 3323 | (intintLCGQuadraticOpenCompactHash_Bucket *) & table-> | |
| 3324 | tableData[sizeof(intintLCGQuadraticOpenCompactHash_TableData)]; | |
| 3325 | int index; | |
| 3326 | for (index = 0; | |
| 3327 | index < | |
| 3328 | ((intintLCGQuadraticOpenCompactHash_TableData *) table-> | |
| 3329 | tableData)->numBuckets; index++) { | |
| 3330 | buckets[index].key = HASH_BUCKET_STATUS_EMPTY; | |
| 3331 | } | |
| 3332 | exitCode = HASH_EXIT_CODE_NORMAL; | |
| 3333 | return exitCode; | |
| 3334 | } | |
| 3335 | int intintLCGQuadraticOpenCompactHash_InnerQuerySingle(char *tableData, int key, | |
| 3336 | int *valueOutput) { | |
| 3337 | intintLCGQuadraticOpenCompactHash_Bucket *buckets = | |
| 3338 | (intintLCGQuadraticOpenCompactHash_Bucket *) & | |
| 3339 | tableData[sizeof(intintLCGQuadraticOpenCompactHash_TableData)]; | |
| 3340 | int index; | |
| 3341 | int exitCode; | |
| 3342 | intintLCGQuadraticOpenCompactHash_TableData *mytableData = | |
| 3343 | (intintLCGQuadraticOpenCompactHash_TableData *) tableData; | |
| 3344 | intintHash_CompressLCGData compressFuncData = | |
| 3345 | mytableData->compressFuncData; | |
| 3346 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 3347 | unsigned long int iteration = 0; | |
| 3348 | for (;;) { | |
| 3349 | index = | |
| 3350 | ((1 * iteration * iteration + 0 * iteration + | |
| 3351 | c) % | |
| 3352 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3353 | tableData)->numBuckets); | |
| 3354 | if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 3355 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 3356 | break; | |
| 3357 | } else if (key == buckets[index].key) { | |
| 3358 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 3359 | break; | |
| 3360 | } else | |
| 3361 | if ((iteration > | |
| 3362 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3363 | tableData)->numBuckets)) { | |
| 3364 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 3365 | break; | |
| 3366 | } | |
| 3367 | iteration++; | |
| 3368 | } | |
| 3369 | switch (exitCode) { | |
| 3370 | case HASH_SEARCH_CODE_MATCH: | |
| 3371 | *valueOutput = buckets[index].value; | |
| 3372 | return HASH_EXIT_CODE_NORMAL; | |
| 3373 | case HASH_SEARCH_CODE_MISMATCH: | |
| 3374 | case HASH_SEARCH_CODE_EMPTY: | |
| 3375 | return HASH_EXIT_CODE_KEY_DNE; | |
| 3376 | default: | |
| 3377 | return exitCode; | |
| 3378 | } | |
| 3379 | } | |
| 3380 | int intintLCGQuadraticOpenCompactHash_InnerQuery(char *tableData, | |
| 3381 | unsigned int numKeys, | |
| 3382 | int *keys, int *valuesOutput) { | |
| 3383 | intintLCGQuadraticOpenCompactHash_Bucket *buckets = | |
| 3384 | (intintLCGQuadraticOpenCompactHash_Bucket *) & | |
| 3385 | tableData[sizeof(intintLCGQuadraticOpenCompactHash_TableData)]; | |
| 3386 | int key; | |
| 3387 | int *valueOutput; | |
| 3388 | int index; | |
| 3389 | int exitCode; | |
| 3390 | uint i; | |
| 3391 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 3392 | for (i = 0; i < numKeys; i++) { | |
| 3393 | key = keys[i]; | |
| 3394 | valueOutput = &valuesOutput[i]; | |
| 3395 | intintLCGQuadraticOpenCompactHash_TableData *mytableData = | |
| 3396 | (intintLCGQuadraticOpenCompactHash_TableData *) tableData; | |
| 3397 | intintHash_CompressLCGData compressFuncData = | |
| 3398 | mytableData->compressFuncData; | |
| 3399 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 3400 | unsigned long int iteration = 0; | |
| 3401 | for (;;) { | |
| 3402 | index = | |
| 3403 | ((1 * iteration * iteration + 0 * iteration + | |
| 3404 | c) % | |
| 3405 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3406 | tableData)->numBuckets); | |
| 3407 | if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 3408 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 3409 | break; | |
| 3410 | } else if (key == buckets[index].key) { | |
| 3411 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 3412 | break; | |
| 3413 | } else | |
| 3414 | if ((iteration > | |
| 3415 | ((intintLCGQuadraticOpenCompactHash_TableData | |
| 3416 | *) tableData)->numBuckets)) { | |
| 3417 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 3418 | break; | |
| 3419 | } | |
| 3420 | iteration++; | |
| 3421 | } | |
| 3422 | switch (exitCode) { | |
| 3423 | case HASH_SEARCH_CODE_MATCH: | |
| 3424 | *valueOutput = buckets[index].value; | |
| 3425 | break; | |
| 3426 | case HASH_SEARCH_CODE_MISMATCH: | |
| 3427 | case HASH_SEARCH_CODE_EMPTY: | |
| 3428 | resultExitCode = HASH_EXIT_CODE_KEY_DNE; | |
| 3429 | break; | |
| 3430 | default: | |
| 3431 | return exitCode; | |
| 3432 | } | |
| 3433 | } | |
| 3434 | return resultExitCode; | |
| 3435 | } | |
| 3436 | int intintLCGQuadraticOpenCompactHash_InnerInsertSingle(char *tableData, | |
| 3437 | int key, int value) { | |
| 3438 | intintLCGQuadraticOpenCompactHash_Bucket *buckets = | |
| 3439 | (intintLCGQuadraticOpenCompactHash_Bucket *) & | |
| 3440 | tableData[sizeof(intintLCGQuadraticOpenCompactHash_TableData)]; | |
| 3441 | int index; | |
| 3442 | int exitCode; | |
| 3443 | intintLCGQuadraticOpenCompactHash_TableData *mytableData = | |
| 3444 | (intintLCGQuadraticOpenCompactHash_TableData *) tableData; | |
| 3445 | intintHash_CompressLCGData compressFuncData = | |
| 3446 | mytableData->compressFuncData; | |
| 3447 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 3448 | unsigned long int iteration = 0; | |
| 3449 | for (;;) { | |
| 3450 | index = | |
| 3451 | ((1 * iteration * iteration + 0 * iteration + | |
| 3452 | c) % | |
| 3453 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3454 | tableData)->numBuckets); | |
| 3455 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 3456 | buckets | |
| 3457 | [index]. | |
| 3458 | key = | |
| 3459 | key; | |
| 3460 | HASH_BUCKET_STATUS_EMPTY;} | |
| 3461 | ): buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 3462 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 3463 | break; | |
| 3464 | } else if (key == buckets[index].key) { | |
| 3465 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 3466 | break; | |
| 3467 | } else | |
| 3468 | if ((iteration > | |
| 3469 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3470 | tableData)->numBuckets)) { | |
| 3471 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 3472 | break; | |
| 3473 | } | |
| 3474 | iteration++; | |
| 3475 | } | |
| 3476 | switch (exitCode) { | |
| 3477 | case HASH_SEARCH_CODE_MATCH: | |
| 3478 | case HASH_SEARCH_CODE_MISMATCH: | |
| 3479 | buckets[index].value = value; | |
| 3480 | return HASH_EXIT_CODE_OVERWRITE; | |
| 3481 | case HASH_SEARCH_CODE_EMPTY: | |
| 3482 | buckets[index].value = value; | |
| 3483 | return HASH_EXIT_CODE_NORMAL; | |
| 3484 | default: | |
| 3485 | return exitCode; | |
| 3486 | } | |
| 3487 | } | |
| 3488 | int intintLCGQuadraticOpenCompactHash_InnerInsert(char *tableData, | |
| 3489 | unsigned int numEntries, | |
| 3490 | int *keys, int *values) { | |
| 3491 | intintLCGQuadraticOpenCompactHash_Bucket *buckets = | |
| 3492 | (intintLCGQuadraticOpenCompactHash_Bucket *) & | |
| 3493 | tableData[sizeof(intintLCGQuadraticOpenCompactHash_TableData)]; | |
| 3494 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 3495 | int key; | |
| 3496 | int value; | |
| 3497 | int index; | |
| 3498 | int exitCode; | |
| 3499 | uint i; | |
| 3500 | for (i = 0; i < numEntries; i++) { | |
| 3501 | key = keys[i]; | |
| 3502 | intintLCGQuadraticOpenCompactHash_TableData *mytableData = | |
| 3503 | (intintLCGQuadraticOpenCompactHash_TableData *) tableData; | |
| 3504 | intintHash_CompressLCGData compressFuncData = | |
| 3505 | mytableData->compressFuncData; | |
| 3506 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 3507 | unsigned long int iteration = 0; | |
| 3508 | for (;;) { | |
| 3509 | index = | |
| 3510 | ((1 * iteration * iteration + 0 * iteration + | |
| 3511 | c) % | |
| 3512 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3513 | tableData)->numBuckets); | |
| 3514 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 3515 | buckets | |
| 3516 | [index]. | |
| 3517 | key | |
| 3518 | = | |
| 3519 | key; | |
| 3520 | HASH_BUCKET_STATUS_EMPTY;} | |
| 3521 | ): buckets[index].key) == | |
| 3522 | HASH_BUCKET_STATUS_EMPTY) { | |
| 3523 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 3524 | break; | |
| 3525 | } else if (key == buckets[index].key) { | |
| 3526 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 3527 | break; | |
| 3528 | } else | |
| 3529 | if ((iteration > | |
| 3530 | ((intintLCGQuadraticOpenCompactHash_TableData | |
| 3531 | *) tableData)->numBuckets)) { | |
| 3532 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 3533 | break; | |
| 3534 | } | |
| 3535 | iteration++; | |
| 3536 | } | |
| 3537 | switch (exitCode) { | |
| 3538 | case HASH_SEARCH_CODE_MATCH: | |
| 3539 | case HASH_SEARCH_CODE_MISMATCH: | |
| 3540 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 3541 | case HASH_SEARCH_CODE_EMPTY: | |
| 3542 | buckets[index].value = values[i]; | |
| 3543 | break; | |
| 3544 | default: | |
| 3545 | return exitCode; | |
| 3546 | } | |
| 3547 | } | |
| 3548 | return resultExitCode; | |
| 3549 | } | |
| 3550 | int intintLCGQuadraticOpenCompactHash_InnerInsertSingleNoOverwrite(char | |
| 3551 | *tableData, | |
| 3552 | int key, | |
| 3553 | int value) { | |
| 3554 | intintLCGQuadraticOpenCompactHash_Bucket *buckets = | |
| 3555 | (intintLCGQuadraticOpenCompactHash_Bucket *) & | |
| 3556 | tableData[sizeof(intintLCGQuadraticOpenCompactHash_TableData)]; | |
| 3557 | int index; | |
| 3558 | int exitCode; | |
| 3559 | intintLCGQuadraticOpenCompactHash_TableData *mytableData = | |
| 3560 | (intintLCGQuadraticOpenCompactHash_TableData *) tableData; | |
| 3561 | intintHash_CompressLCGData compressFuncData = | |
| 3562 | mytableData->compressFuncData; | |
| 3563 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 3564 | unsigned long int iteration = 0; | |
| 3565 | for (;;) { | |
| 3566 | index = | |
| 3567 | ((1 * iteration * iteration + 0 * iteration + | |
| 3568 | c) % | |
| 3569 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3570 | tableData)->numBuckets); | |
| 3571 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 3572 | buckets | |
| 3573 | [index]. | |
| 3574 | key = | |
| 3575 | key; | |
| 3576 | HASH_BUCKET_STATUS_EMPTY;} | |
| 3577 | ): buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 3578 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 3579 | break; | |
| 3580 | } else if (key == buckets[index].key) { | |
| 3581 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 3582 | break; | |
| 3583 | } else | |
| 3584 | if ((iteration > | |
| 3585 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3586 | tableData)->numBuckets)) { | |
| 3587 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 3588 | break; | |
| 3589 | } | |
| 3590 | iteration++; | |
| 3591 | } | |
| 3592 | switch (exitCode) { | |
| 3593 | case HASH_SEARCH_CODE_MATCH: | |
| 3594 | case HASH_SEARCH_CODE_MISMATCH: | |
| 3595 | return HASH_EXIT_CODE_OVERWRITE; | |
| 3596 | case HASH_SEARCH_CODE_EMPTY: | |
| 3597 | buckets[index].value = value; | |
| 3598 | return HASH_EXIT_CODE_NORMAL; | |
| 3599 | default: | |
| 3600 | return exitCode; | |
| 3601 | } | |
| 3602 | } | |
| 3603 | int intintLCGQuadraticOpenCompactHash_InnerInsertNoOverwrite(char *tableData, | |
| 3604 | unsigned int | |
| 3605 | numEntries, | |
| 3606 | int *keys, | |
| 3607 | int *values) { | |
| 3608 | intintLCGQuadraticOpenCompactHash_Bucket *buckets = | |
| 3609 | (intintLCGQuadraticOpenCompactHash_Bucket *) & | |
| 3610 | tableData[sizeof(intintLCGQuadraticOpenCompactHash_TableData)]; | |
| 3611 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 3612 | int key; | |
| 3613 | int value; | |
| 3614 | int index; | |
| 3615 | int exitCode; | |
| 3616 | uint i; | |
| 3617 | for (i = 0; i < numEntries; i++) { | |
| 3618 | key = keys[i]; | |
| 3619 | intintLCGQuadraticOpenCompactHash_TableData *mytableData = | |
| 3620 | (intintLCGQuadraticOpenCompactHash_TableData *) tableData; | |
| 3621 | intintHash_CompressLCGData compressFuncData = | |
| 3622 | mytableData->compressFuncData; | |
| 3623 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 3624 | unsigned long int iteration = 0; | |
| 3625 | for (;;) { | |
| 3626 | index = | |
| 3627 | ((1 * iteration * iteration + 0 * iteration + | |
| 3628 | c) % | |
| 3629 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3630 | tableData)->numBuckets); | |
| 3631 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 3632 | buckets | |
| 3633 | [index]. | |
| 3634 | key | |
| 3635 | = | |
| 3636 | key; | |
| 3637 | HASH_BUCKET_STATUS_EMPTY;} | |
| 3638 | ): buckets[index].key) == | |
| 3639 | HASH_BUCKET_STATUS_EMPTY) { | |
| 3640 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 3641 | break; | |
| 3642 | } else if (key == buckets[index].key) { | |
| 3643 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 3644 | break; | |
| 3645 | } else | |
| 3646 | if ((iteration > | |
| 3647 | ((intintLCGQuadraticOpenCompactHash_TableData | |
| 3648 | *) tableData)->numBuckets)) { | |
| 3649 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 3650 | break; | |
| 3651 | } | |
| 3652 | iteration++; | |
| 3653 | } | |
| 3654 | switch (exitCode) { | |
| 3655 | case HASH_SEARCH_CODE_MATCH: | |
| 3656 | case HASH_SEARCH_CODE_MISMATCH: | |
| 3657 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 3658 | break; | |
| 3659 | case HASH_SEARCH_CODE_EMPTY: | |
| 3660 | buckets[index].value = values[i]; | |
| 3661 | break; | |
| 3662 | default: | |
| 3663 | return exitCode; | |
| 3664 | } | |
| 3665 | } | |
| 3666 | return resultExitCode; | |
| 3667 | } | |
| 3668 | int intintLCGQuadraticOpenCompactHash_QuerySingle(intintHash_Table * table, | |
| 3669 | int key, int *valueOutput) { | |
| 3670 | return intintLCGQuadraticOpenCompactHash_InnerQuerySingle(table-> | |
| 3671 | tableData, | |
| 3672 | key, | |
| 3673 | valueOutput); | |
| 3674 | } | |
| 3675 | int intintLCGQuadraticOpenCompactHash_Query(intintHash_Table * table, | |
| 3676 | size_t numKeys, int *keys, | |
| 3677 | int *valuesOutput) { | |
| 3678 | return intintLCGQuadraticOpenCompactHash_InnerQuery(table->tableData, | |
| 3679 | numKeys, keys, | |
| 3680 | valuesOutput); | |
| 3681 | } | |
| 3682 | int intintLCGQuadraticOpenCompactHash_InsertSingle(intintHash_Table * table, | |
| 3683 | int key, int value) { | |
| 3684 | return intintLCGQuadraticOpenCompactHash_InnerInsertSingle(table-> | |
| 3685 | tableData, | |
| 3686 | key, value); | |
| 3687 | } | |
| 3688 | int intintLCGQuadraticOpenCompactHash_Insert(intintHash_Table * table, | |
| 3689 | size_t numEntries, int *keys, | |
| 3690 | int *values) { | |
| 3691 | return intintLCGQuadraticOpenCompactHash_InnerInsert(table->tableData, | |
| 3692 | numEntries, keys, | |
| 3693 | values); | |
| 3694 | } | |
| 3695 | int intintLCGQuadraticOpenCompactHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 3696 | table, int key, | |
| 3697 | int value) { | |
| 3698 | return | |
| 3699 | intintLCGQuadraticOpenCompactHash_InnerInsertSingleNoOverwrite | |
| 3700 | (table->tableData, key, value); | |
| 3701 | } | |
| 3702 | int intintLCGQuadraticOpenCompactHash_InsertNoOverwrite(intintHash_Table * | |
| 3703 | table, | |
| 3704 | size_t numEntries, | |
| 3705 | int *keys, | |
| 3706 | int *values) { | |
| 3707 | return intintLCGQuadraticOpenCompactHash_InnerInsertNoOverwrite(table-> | |
| 3708 | tableData, | |
| 3709 | numEntries, | |
| 3710 | keys, | |
| 3711 | values); | |
| 3712 | } | |
| 3713 | ||
| 3714 | typedef struct intintLCGQuadraticOpenCompactCLHash_TableData { | |
| 3715 | int hashID; | |
| 3716 | unsigned int numBuckets; | |
| 3717 | intintHash_CompressLCGData compressFuncData; | |
| 3718 | } intintLCGQuadraticOpenCompactCLHash_TableData; | |
| 3719 | typedef struct intintLCGQuadraticOpenCompactCLHash_Bucket { | |
| 3720 | int key; | |
| 3721 | int value; | |
| 3722 | } intintLCGQuadraticOpenCompactCLHash_Bucket; | |
| 3723 | intintHash_Table | |
| 3724 | *intintLCGQuadraticOpenCompactCLHash_CreateTable(intintHash_Factory * | |
| 3725 | factory, int hashIndex, | |
| 3726 | size_t keyRange, | |
| 3727 | size_t numEntries, | |
| 3728 | float loadFactor) { | |
| 3729 | intintHash_Table *table = | |
| 3730 | (intintHash_Table *) malloc(sizeof(intintHash_Table)); | |
| 3731 | table->destroyFunc = &intintLCGQuadraticOpenCompactCLHash_DestroyTable; | |
| 3732 | table->emptyFunc = &intintLCGQuadraticOpenCompactCLHash_EmptyTable; | |
| 3733 | table->queryFunc = &intintLCGQuadraticOpenCompactCLHash_Query; | |
| 3734 | table->querySingleFunc = | |
| 3735 | &intintLCGQuadraticOpenCompactCLHash_QuerySingle; | |
| 3736 | table->insertFunc = &intintLCGQuadraticOpenCompactCLHash_Insert; | |
| 3737 | table->insertSingleFunc = | |
| 3738 | &intintLCGQuadraticOpenCompactCLHash_InsertSingle; | |
| 3739 | table->insertNoOverwriteFunc = | |
| 3740 | &intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite; | |
| 3741 | table->insertSingleNoOverwriteFunc = | |
| 3742 | &intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite; | |
| 3743 | table->tableData = | |
| 3744 | (char *) | |
| 3745 | malloc(sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)); | |
| 3746 | ((intintLCGQuadraticOpenCompactCLHash_TableData *) table->tableData)-> | |
| 3747 | hashID = LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID; | |
| 3748 | table->context = factory->context; | |
| 3749 | table->queue = factory->queue; | |
| 3750 | table->program = factory->program; | |
| 3751 | table->localWorkSize = factory->localWorkSize; | |
| 3752 | table->utilProgram = factory->utilProgram[hashIndex]; | |
| 3753 | table->emptyKernel = factory->emptyKernel[hashIndex]; | |
| 3754 | table->emptyKernelLocalWorkSize = | |
| 3755 | factory->emptyKernelLocalWorkSize[hashIndex]; | |
| 3756 | table->querySingleKernel = factory->querySingleKernel[hashIndex]; | |
| 3757 | table->insertSingleKernel = factory->insertSingleKernel[hashIndex]; | |
| 3758 | table->insertSingleNoOverwriteKernel = | |
| 3759 | factory->insertSingleNoOverwriteKernel[hashIndex]; | |
| 3760 | clRetainContext(table->context); | |
| 3761 | clRetainCommandQueue(table->queue); | |
| 3762 | clRetainProgram(table->program); | |
| 3763 | clRetainProgram(table->utilProgram); | |
| 3764 | clRetainKernel(table->emptyKernel); | |
| 3765 | clRetainKernel(table->querySingleKernel); | |
| 3766 | clRetainKernel(table->insertSingleKernel); | |
| 3767 | clRetainKernel(table->insertSingleNoOverwriteKernel);; | |
| 3768 | ((intintLCGQuadraticOpenCompactCLHash_TableData *) table->tableData)-> | |
| 3769 | numBuckets = (unsigned int)((double)numEntries / loadFactor); | |
| 3770 | ((intintLCGQuadraticOpenCompactCLHash_TableData *) table->tableData)-> | |
| 3771 | compressFuncData.a = HASH_LCG_A; | |
| 3772 | ((intintLCGQuadraticOpenCompactCLHash_TableData *) table->tableData)-> | |
| 3773 | compressFuncData.c = HASH_LCG_C; | |
| 3774 | ((intintLCGQuadraticOpenCompactCLHash_TableData *) table->tableData)-> | |
| 3775 | compressFuncData.m = HASH_LCG_M; | |
| 3776 | ((intintLCGQuadraticOpenCompactCLHash_TableData *) table->tableData)-> | |
| 3777 | compressFuncData.n = | |
| 3778 | ((intintLCGQuadraticOpenCompactCLHash_TableData *) table-> | |
| 3779 | tableData)->numBuckets; | |
| 3780 | ((intintLCGQuadraticOpenCompactCLHash_TableData *) table->tableData)-> | |
| 3781 | numBuckets = | |
| 3782 | largestProthPrimeUnder(((intintLCGQuadraticOpenCompactCLHash_TableData *) table->tableData)->numBuckets); | |
| 3783 | char *tempHashData = | |
| 3784 | (char *)malloc(sizeof(intintLCGQuadraticOpenCompactCLHash_TableData) | |
| 3785 | + | |
| 3786 | ((intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 3787 | table->tableData)->numBuckets * | |
| 3788 | sizeof(intintLCGQuadraticOpenCompactCLHash_Bucket)); | |
| 3789 | memcpy(tempHashData, table->tableData, | |
| 3790 | sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)); | |
| 3791 | free(table->tableData); | |
| 3792 | table->tableData = tempHashData; | |
| 3793 | cl_int err; | |
| 3794 | table->tableDataBuffer = | |
| 3795 | clCreateBuffer(table->context, CL_MEM_READ_WRITE, | |
| 3796 | sizeof(intintLCGQuadraticOpenCompactHash_TableData) + | |
| 3797 | ((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3798 | table->tableData)->numBuckets * | |
| 3799 | sizeof(intintLCGQuadraticOpenCompactHash_Bucket), | |
| 3800 | NULL, &err); | |
| 3801 | CLHash_Utilities_HandleError(err, | |
| 3802 | "intintLCGQuadraticOpenCompactCLHash_InitTable", | |
| 3803 | "clCreateBuffer"); | |
| 3804 | err = | |
| 3805 | clEnqueueWriteBuffer(table->queue, table->tableDataBuffer, CL_TRUE, | |
| 3806 | 0, | |
| 3807 | sizeof | |
| 3808 | (intintLCGQuadraticOpenCompactHash_TableData), | |
| 3809 | table->tableData, 0, NULL, NULL); | |
| 3810 | CLHash_Utilities_HandleError(err, | |
| 3811 | "intintLCGQuadraticOpenCompactCLHash_InitTable", | |
| 3812 | "clEnqueueWriteBuffer"); | |
| 3813 | return table; | |
| 3814 | } | |
| 3815 | int intintLCGQuadraticOpenCompactCLHash_CreateFactory(intintHash_Factory * | |
| 3816 | factory, int hashIndex) { | |
| 3817 | factory->createFunc[hashIndex] = | |
| 3818 | &intintLCGQuadraticOpenCompactCLHash_CreateTable; | |
| 3819 | factory->destroyFunc[hashIndex] = | |
| 3820 | &intintLCGQuadraticOpenCompactCLHash_DestroyFactory; | |
| 3821 | cl_int error; | |
| 3822 | cl_device_id device; | |
| 3823 | error = | |
| 3824 | clGetContextInfo(factory->context, CL_CONTEXT_DEVICES, | |
| 3825 | sizeof(device), &device, NULL); | |
| 3826 | CLHash_Utilities_HandleError(error, "intintHash_CreateFactory", | |
| 3827 | "clGetContextInfo"); | |
| 3828 | factory->querySingleKernel[hashIndex] = | |
| 3829 | clCreateKernel(factory->program, | |
| 3830 | "intintLCGQuadraticOpenCompactCLHash_RangeQuerySingle", | |
| 3831 | &error); | |
| 3832 | CLHash_Utilities_HandleError(error, | |
| 3833 | "intintLCGQuadraticOpenCompactCLHash_CreateFactory", | |
| 3834 | "clCreateKernel"); | |
| 3835 | factory->insertSingleKernel[hashIndex] = | |
| 3836 | clCreateKernel(factory->program, | |
| 3837 | "intintLCGQuadraticOpenCompactCLHash_RangeInsertSingle", | |
| 3838 | &error); | |
| 3839 | CLHash_Utilities_HandleError(error, | |
| 3840 | "intintLCGQuadraticOpenCompactCLHash_CreateFactory", | |
| 3841 | "clCreateKernel"); | |
| 3842 | factory->insertSingleNoOverwriteKernel[hashIndex] = | |
| 3843 | clCreateKernel(factory->program, | |
| 3844 | "intintLCGQuadraticOpenCompactCLHash_RangeInsertSingleNoOverwrite", | |
| 3845 | &error); | |
| 3846 | CLHash_Utilities_HandleError(error, | |
| 3847 | "intintLCGQuadraticOpenCompactCLHash_CreateFactory", | |
| 3848 | "clCreateKernel"); | |
| 3849 | factory->utilProgram[hashIndex] = | |
| 3850 | CLHash_Utilities_BuildProgramString(factory->context, device, | |
| 3851 | "static inline unsigned int intintHash_CompressIdentity(char data, int hashCode){ return hashCode; } typedef struct intintHash_CompressLCGData{ long unsigned int a; long unsigned int c; unsigned int m; unsigned int n; }intintHash_CompressLCGData; static inline unsigned int intintHash_CompressLCG(intintHash_CompressLCGData compressLCGData, int hashCode){ return ((compressLCGData.a * hashCode + compressLCGData.c) % compressLCGData.m) % compressLCGData.n; } typedef struct intintLCGQuadraticOpenCompactCLHash_TableData{ int hashID; unsigned int numBuckets; intintHash_CompressLCGData compressFuncData; }intintLCGQuadraticOpenCompactCLHash_TableData; typedef struct intintLCGQuadraticOpenCompactCLHash_Bucket{ int key; int value; }intintLCGQuadraticOpenCompactCLHash_Bucket; __kernel void intintLCGQuadraticOpenCompactCLHash_Empty(__global char *tableData){ int index = get_global_id(0); if(index >= ((__global intintLCGQuadraticOpenCompactCLHash_TableData*)tableData)->numBuckets){ return; } __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets = (__global intintLCGQuadraticOpenCompactCLHash_Bucket*)&tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)]; buckets[index].key = -1;/*HASH_BUCKET_STATUS_EMPTY*/ }"); | |
| 3852 | factory->emptyKernel[hashIndex] = | |
| 3853 | clCreateKernel(factory->utilProgram[hashIndex], | |
| 3854 | "intintLCGQuadraticOpenCompactCLHash_Empty", &error); | |
| 3855 | CLHash_Utilities_HandleError(error, | |
| 3856 | "intintLCGQuadraticOpenCompactCLHash_CreateFactory", | |
| 3857 | "clCreateKernel"); | |
| 3858 | error = | |
| 3859 | clGetKernelWorkGroupInfo(factory->emptyKernel[hashIndex], device, | |
| 3860 | CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), | |
| 3861 | &factory-> | |
| 3862 | emptyKernelLocalWorkSize[hashIndex], NULL); | |
| 3863 | CLHash_Utilities_HandleError(error, | |
| 3864 | "intintLCGQuadraticOpenCompactCLHash_CreateFactory", | |
| 3865 | "clGetKernelWorkGroupInfo");;; | |
| 3866 | return HASH_EXIT_CODE_NORMAL; | |
| 3867 | } | |
| 3868 | int intintLCGQuadraticOpenCompactCLHash_DestroyFactory(intintHash_Factory * | |
| 3869 | factory, | |
| 3870 | int hashIndex) {; | |
| 3871 | clReleaseKernel(factory->emptyKernel[hashIndex]); | |
| 3872 | clReleaseProgram(factory->utilProgram[hashIndex]); | |
| 3873 | clReleaseKernel(factory->querySingleKernel[hashIndex]); | |
| 3874 | clReleaseKernel(factory->insertSingleKernel[hashIndex]); | |
| 3875 | clReleaseKernel(factory->insertSingleNoOverwriteKernel[hashIndex]);; | |
| 3876 | return HASH_EXIT_CODE_NORMAL; | |
| 3877 | } | |
| 3878 | int intintLCGQuadraticOpenCompactCLHash_DestroyTable(intintHash_Table * table) { | |
| 3879 | int exitCode = 0; | |
| 3880 | clReleaseMemObject(table->tableDataBuffer); | |
| 3881 | clReleaseContext(table->context); | |
| 3882 | clReleaseCommandQueue(table->queue); | |
| 3883 | clReleaseProgram(table->utilProgram); | |
| 3884 | clReleaseKernel(table->emptyKernel); | |
| 3885 | clReleaseProgram(table->program); | |
| 3886 | clReleaseKernel(table->querySingleKernel); | |
| 3887 | clReleaseKernel(table->insertSingleKernel); | |
| 3888 | clReleaseKernel(table->insertSingleNoOverwriteKernel); | |
| 3889 | free(table->tableData); | |
| 3890 | free(table); | |
| 3891 | return exitCode; | |
| 3892 | } | |
| 3893 | int intintLCGQuadraticOpenCompactCLHash_EmptyTable(intintHash_Table * table) { | |
| 3894 | int exitCode = 0; | |
| 3895 | cl_int err; | |
| 3896 | err = | |
| 3897 | clSetKernelArg(table->emptyKernel, 0, sizeof(cl_mem), | |
| 3898 | &table->tableDataBuffer); | |
| 3899 | CLHash_Utilities_HandleError(err, | |
| 3900 | "intintLCGQuadraticOpenCompactCLHash_EmptyTable", | |
| 3901 | "clSetKernelArg"); | |
| 3902 | const size_t groupWorkSize = | |
| 3903 | roundUpToNearest(((intintLCGQuadraticOpenCompactHash_TableData *) | |
| 3904 | table->tableData)->numBuckets, | |
| 3905 | table->emptyKernelLocalWorkSize); | |
| 3906 | err = | |
| 3907 | clEnqueueNDRangeKernel(table->queue, table->emptyKernel, 1, 0, | |
| 3908 | &groupWorkSize, | |
| 3909 | (const size_t *)&table-> | |
| 3910 | emptyKernelLocalWorkSize, 0, NULL, NULL); | |
| 3911 | CLHash_Utilities_HandleError(err, | |
| 3912 | "intintLCGQuadraticOpenCompactCLHash_EmptyTable", | |
| 3913 | "clEnqueueNDRangeKernel"); | |
| 3914 | exitCode = HASH_EXIT_CODE_NORMAL;; | |
| 3915 | return exitCode; | |
| 3916 | } | |
| 3917 | int intintLCGQuadraticOpenCompactCLHash_QuerySingle(intintHash_Table * table, | |
| 3918 | int key, int *valueOutput) { | |
| 3919 | return intintLCGQuadraticOpenCompactCLHash_Query(table, 1, &key, | |
| 3920 | valueOutput); | |
| 3921 | } | |
| 3922 | int intintLCGQuadraticOpenCompactCLHash_Query(intintHash_Table * table, | |
| 3923 | size_t numKeys, int *keys, | |
| 3924 | int *valuesOutput) { | |
| 3925 | cl_int err; | |
| 3926 | cl_mem keysBuffer = | |
| 3927 | clCreateBuffer(table->context, | |
| 3928 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 3929 | sizeof(int) * numKeys, keys, &err); | |
| 3930 | CLHash_Utilities_HandleError(err, | |
| 3931 | "intintLCGQuadraticOpenCompactCLHash_Query", | |
| 3932 | "clCreateBuffer"); | |
| 3933 | cl_mem valuesOutputBuffer = | |
| 3934 | clCreateBuffer(table->context, CL_MEM_WRITE_ONLY, | |
| 3935 | sizeof(int) * numKeys, NULL, &err); | |
| 3936 | CLHash_Utilities_HandleError(err, | |
| 3937 | "intintLCGQuadraticOpenCompactCLHash_Query", | |
| 3938 | "clCreateBuffer"); | |
| 3939 | intintLCGQuadraticOpenCompactCLHash_BufferQuery(table, numKeys, | |
| 3940 | keysBuffer, | |
| 3941 | valuesOutputBuffer); | |
| 3942 | err = | |
| 3943 | clEnqueueReadBuffer(table->queue, valuesOutputBuffer, CL_TRUE, 0, | |
| 3944 | sizeof(int) * numKeys, valuesOutput, 0, NULL, | |
| 3945 | NULL); | |
| 3946 | CLHash_Utilities_HandleError(err, | |
| 3947 | "intintLCGQuadraticOpenCompactCLHash_Query", | |
| 3948 | "clEnqueueReadBuffer"); | |
| 3949 | clReleaseMemObject(keysBuffer); | |
| 3950 | clReleaseMemObject(valuesOutputBuffer); | |
| 3951 | return HASH_EXIT_CODE_NORMAL; | |
| 3952 | } | |
| 3953 | int intintLCGQuadraticOpenCompactCLHash_BufferQuery(intintHash_Table * table, | |
| 3954 | size_t numKeys, | |
| 3955 | cl_mem keysBuffer, | |
| 3956 | cl_mem valuesOutputBuffer) { | |
| 3957 | cl_int err; | |
| 3958 | err = | |
| 3959 | clSetKernelArg(table->querySingleKernel, 0, sizeof(cl_mem), | |
| 3960 | &table->tableDataBuffer); | |
| 3961 | CLHash_Utilities_HandleError(err, | |
| 3962 | "intintLCGQuadraticOpenCompactCLHash_BufferQuery", | |
| 3963 | "clSetKernelArg"); | |
| 3964 | err = | |
| 3965 | clSetKernelArg(table->querySingleKernel, 1, sizeof(unsigned int), | |
| 3966 | &numKeys); | |
| 3967 | CLHash_Utilities_HandleError(err, | |
| 3968 | "intintLCGQuadraticOpenCompactCLHash_BufferQuery", | |
| 3969 | "clSetKernelArg"); | |
| 3970 | err = | |
| 3971 | clSetKernelArg(table->querySingleKernel, 2, sizeof(cl_mem), | |
| 3972 | &keysBuffer); | |
| 3973 | CLHash_Utilities_HandleError(err, | |
| 3974 | "intintLCGQuadraticOpenCompactCLHash_BufferQuery", | |
| 3975 | "clSetKernelArg"); | |
| 3976 | err = | |
| 3977 | clSetKernelArg(table->querySingleKernel, 3, sizeof(cl_mem), | |
| 3978 | &valuesOutputBuffer); | |
| 3979 | CLHash_Utilities_HandleError(err, | |
| 3980 | "intintLCGQuadraticOpenCompactCLHash_BufferQuery", | |
| 3981 | "clSetKernelArg"); | |
| 3982 | const size_t groupWorkSize = | |
| 3983 | roundUpToNearest(numKeys, table->localWorkSize); | |
| 3984 | err = | |
| 3985 | clEnqueueNDRangeKernel(table->queue, table->querySingleKernel, 1, 0, | |
| 3986 | &groupWorkSize, | |
| 3987 | (const size_t *)&table->localWorkSize, 0, | |
| 3988 | NULL, NULL); | |
| 3989 | CLHash_Utilities_HandleError(err, | |
| 3990 | "intintLCGQuadraticOpenCompactCLHash_BufferQuery", | |
| 3991 | "clEnqueueNDRangeKernel"); | |
| 3992 | clFinish(table->queue); | |
| 3993 | return HASH_EXIT_CODE_NORMAL; | |
| 3994 | } | |
| 3995 | int intintLCGQuadraticOpenCompactCLHash_InsertSingle(intintHash_Table * table, | |
| 3996 | int key, int value) { | |
| 3997 | return intintLCGQuadraticOpenCompactCLHash_Insert(table, 1, &key, | |
| 3998 | &value); | |
| 3999 | } | |
| 4000 | int intintLCGQuadraticOpenCompactCLHash_Insert(intintHash_Table * table, | |
| 4001 | size_t numEntries, int *keys, | |
| 4002 | int *values) { | |
| 4003 | cl_int err; | |
| 4004 | cl_mem keysBuffer = | |
| 4005 | clCreateBuffer(table->context, | |
| 4006 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 4007 | sizeof(int) * numEntries, keys, &err); | |
| 4008 | CLHash_Utilities_HandleError(err, | |
| 4009 | "intintLCGQuadraticOpenCompactCLHash_Insert", | |
| 4010 | "clCreateBuffer"); | |
| 4011 | cl_mem valuesBuffer = | |
| 4012 | clCreateBuffer(table->context, | |
| 4013 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 4014 | sizeof(int) * numEntries, values, &err); | |
| 4015 | CLHash_Utilities_HandleError(err, | |
| 4016 | "intintLCGQuadraticOpenCompactCLHash_Insert", | |
| 4017 | "clCreateBuffer"); | |
| 4018 | intintLCGQuadraticOpenCompactCLHash_BufferInsert(table, numEntries, | |
| 4019 | keysBuffer, | |
| 4020 | valuesBuffer); | |
| 4021 | clReleaseMemObject(keysBuffer); | |
| 4022 | clReleaseMemObject(valuesBuffer); | |
| 4023 | return HASH_EXIT_CODE_NORMAL; | |
| 4024 | } | |
| 4025 | int intintLCGQuadraticOpenCompactCLHash_BufferInsert(intintHash_Table * table, | |
| 4026 | size_t numEntries, | |
| 4027 | cl_mem keysBuffer, | |
| 4028 | cl_mem valuesBuffer) { | |
| 4029 | cl_int err; | |
| 4030 | err = | |
| 4031 | clSetKernelArg(table->insertSingleKernel, 0, sizeof(cl_mem), | |
| 4032 | &table->tableDataBuffer); | |
| 4033 | CLHash_Utilities_HandleError(err, | |
| 4034 | "intintLCGQuadraticOpenCompactCLHash_BufferInsert", | |
| 4035 | "clSetKernelArg"); | |
| 4036 | err = | |
| 4037 | clSetKernelArg(table->insertSingleKernel, 1, sizeof(unsigned int), | |
| 4038 | &numEntries); | |
| 4039 | CLHash_Utilities_HandleError(err, | |
| 4040 | "intintLCGQuadraticOpenCompactCLHash_BufferInsert", | |
| 4041 | "clSetKernelArg"); | |
| 4042 | err = | |
| 4043 | clSetKernelArg(table->insertSingleKernel, 2, sizeof(cl_mem), | |
| 4044 | &keysBuffer); | |
| 4045 | CLHash_Utilities_HandleError(err, | |
| 4046 | "intintLCGQuadraticOpenCompactCLHash_BufferInsert", | |
| 4047 | "clSetKernelArg"); | |
| 4048 | err = | |
| 4049 | clSetKernelArg(table->insertSingleKernel, 3, sizeof(cl_mem), | |
| 4050 | &valuesBuffer); | |
| 4051 | CLHash_Utilities_HandleError(err, | |
| 4052 | "intintLCGQuadraticOpenCompactCLHash_BufferInsert", | |
| 4053 | "clSetKernelArg"); | |
| 4054 | const size_t groupWorkSize = | |
| 4055 | roundUpToNearest(numEntries, table->localWorkSize); | |
| 4056 | err = | |
| 4057 | clEnqueueNDRangeKernel(table->queue, table->insertSingleKernel, 1, | |
| 4058 | 0, &groupWorkSize, | |
| 4059 | (const size_t *)&table->localWorkSize, 0, | |
| 4060 | NULL, NULL); | |
| 4061 | CLHash_Utilities_HandleError(err, NULL, "clEnqueueNDRangeKernel"); | |
| 4062 | return (0); | |
| 4063 | } | |
| 4064 | int intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite(intintHash_Table | |
| 4065 | * table, | |
| 4066 | int key, | |
| 4067 | int value) { | |
| 4068 | return intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite(table, 1, | |
| 4069 | &key, | |
| 4070 | &value); | |
| 4071 | } | |
| 4072 | int intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite(intintHash_Table * | |
| 4073 | table, | |
| 4074 | size_t numEntries, | |
| 4075 | int *keys, | |
| 4076 | int *values) { | |
| 4077 | cl_int err; | |
| 4078 | cl_mem keysBuffer = | |
| 4079 | clCreateBuffer(table->context, | |
| 4080 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 4081 | sizeof(int) * numEntries, keys, &err); | |
| 4082 | CLHash_Utilities_HandleError(err, | |
| 4083 | "intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite", | |
| 4084 | "clCreateBuffer"); | |
| 4085 | cl_mem valuesBuffer = | |
| 4086 | clCreateBuffer(table->context, | |
| 4087 | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, | |
| 4088 | sizeof(int) * numEntries, values, &err); | |
| 4089 | CLHash_Utilities_HandleError(err, | |
| 4090 | "intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite", | |
| 4091 | "clCreateBuffer"); | |
| 4092 | intintLCGQuadraticOpenCompactCLHash_BufferInsertNoOverwrite(table, | |
| 4093 | numEntries, | |
| 4094 | keysBuffer, | |
| 4095 | valuesBuffer); | |
| 4096 | clReleaseMemObject(keysBuffer); | |
| 4097 | clReleaseMemObject(valuesBuffer); | |
| 4098 | return HASH_EXIT_CODE_NORMAL; | |
| 4099 | } | |
| 4100 | int intintLCGQuadraticOpenCompactCLHash_BufferInsertNoOverwrite(intintHash_Table | |
| 4101 | * table, | |
| 4102 | size_t | |
| 4103 | numEntries, | |
| 4104 | cl_mem | |
| 4105 | keysBuffer, | |
| 4106 | cl_mem | |
| 4107 | valuesBuffer) { | |
| 4108 | cl_int err; | |
| 4109 | err = | |
| 4110 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 0, | |
| 4111 | sizeof(cl_mem), &table->tableDataBuffer); | |
| 4112 | CLHash_Utilities_HandleError(err, | |
| 4113 | "intintLCGQuadraticOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 4114 | "clSetKernelArg"); | |
| 4115 | err = | |
| 4116 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 1, | |
| 4117 | sizeof(unsigned int), &numEntries); | |
| 4118 | CLHash_Utilities_HandleError(err, | |
| 4119 | "intintLCGQuadraticOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 4120 | "ClSetKernelArg"); | |
| 4121 | err = | |
| 4122 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 2, | |
| 4123 | sizeof(cl_mem), &keysBuffer); | |
| 4124 | CLHash_Utilities_HandleError(err, | |
| 4125 | "intintLCGQuadraticOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 4126 | "clSetKernelArg"); | |
| 4127 | err = | |
| 4128 | clSetKernelArg(table->insertSingleNoOverwriteKernel, 3, | |
| 4129 | sizeof(cl_mem), &valuesBuffer); | |
| 4130 | CLHash_Utilities_HandleError(err, | |
| 4131 | "intintLCGQuadraticOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 4132 | "clSetKernelArg"); | |
| 4133 | const size_t groupWorkSize = | |
| 4134 | roundUpToNearest(numEntries, table->localWorkSize); | |
| 4135 | err = | |
| 4136 | clEnqueueNDRangeKernel(table->queue, | |
| 4137 | table->insertSingleNoOverwriteKernel, 1, 0, | |
| 4138 | &groupWorkSize, | |
| 4139 | (const size_t *)&table->localWorkSize, 0, | |
| 4140 | NULL, NULL); | |
| 4141 | CLHash_Utilities_HandleError(err, | |
| 4142 | "intintLCGQuadraticOpenCompactCLHash_BufferInsertNoOverwrite", | |
| 4143 | "clEnqueueNDRangeKernel"); | |
| 4144 | return (0); | |
| 4145 | } | |
| 4146 | const char *hash_source = | |
| 4147 | "\n" | |
| 4148 | "/* Copyright (C) 1991-2012 Free Software Foundation, Inc.\n" | |
| 4149 | " This file is part of the GNU C Library.\n" | |
| 4150 | "\n" | |
| 4151 | " The GNU C Library is free software; you can redistribute it and/or\n" | |
| 4152 | " modify it under the terms of the GNU Lesser General Public\n" | |
| 4153 | " License as published by the Free Software Foundation; either\n" | |
| 4154 | " version 2.1 of the License, or (at your option) any later version.\n" | |
| 4155 | "\n" | |
| 4156 | " The GNU C Library is distributed in the hope that it will be useful,\n" | |
| 4157 | " but WITHOUT ANY WARRANTY; without even the implied warranty of\n" | |
| 4158 | " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n" | |
| 4159 | " Lesser General Public License for more details.\n" | |
| 4160 | "\n" | |
| 4161 | " You should have received a copy of the GNU Lesser General Public\n" | |
| 4162 | " License along with the GNU C Library; if not, see\n" | |
| 4163 | " <http://www.gnu.org/licenses/>. */\n" | |
| 4164 | "/* This header is separate from features.h so that the compiler can\n" | |
| 4165 | " include it implicitly at the start of every compilation. It must\n" | |
| 4166 | " not itself include <features.h> or any other header that includes\n" | |
| 4167 | " <features.h> because the implicit include comes before any feature\n" | |
| 4168 | " test macros that may be defined in a source file before it first\n" | |
| 4169 | " explicitly includes a system header. GCC knows the name of this\n" | |
| 4170 | " header in order to preinclude it. */\n" | |
| 4171 | "/* We do support the IEC 559 math functionality, real and complex. */\n" | |
| 4172 | "/* wchar_t uses ISO/IEC 10646 (2nd ed., published 2011-03-15) /\n" | |
| 4173 | " Unicode 6.0. */\n" | |
| 4174 | "/* We do not support C11 <threads.h>. */\n" | |
| 4175 | "/* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced\n" | |
| 4176 | " * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National \n" | |
| 4177 | " * Laboratory (LANL), which is operated by Los Alamos National Security, LLC\n" | |
| 4178 | " * for the U.S. Department of Energy. The U.S. Government has rights to use,\n" | |
| 4179 | " * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS\n" | |
| 4180 | " * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR\n" | |
| 4181 | " * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified\n" | |
| 4182 | " * to produce derivative works, such modified software should be clearly marked,\n" | |
| 4183 | " * so as not to confuse it with the version available from LANL. \n" | |
| 4184 | " *\n" | |
| 4185 | " * Licensed under the Apache License, Version 2.0 (the ""License""); you may not\n" | |
| 4186 | " * use this file except in compliance with the License. You may obtain a copy\n" | |
| 4187 | " * of the License at \n" | |
| 4188 | " *\n" | |
| 4189 | " * http://www.apache.org/licenses/LICENSE-2.0\n" | |
| 4190 | " *\n" | |
| 4191 | " * Unless required by applicable law or agreed to in writing, software distributed\n" | |
| 4192 | " * under the License is distributed on an ""AS IS"" BASIS, WITHOUT WARRANTIES OR\n" | |
| 4193 | " * CONDITIONS OF ANY KIND, either express or implied. See the License for the\n" | |
| 4194 | " * specific language governing permissions and limitations under the License.\n" | |
| 4195 | " *\n" | |
| 4196 | " * Under this license, it is required to include a reference to this work. We\n" | |
| 4197 | " * request that each derivative work contain a reference to LANL Copyright \n" | |
| 4198 | " * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly\n" | |
| 4199 | " * measured. In addition, it is requested that a modifier is included as in\n" | |
| 4200 | " * the following example:\n" | |
| 4201 | " *\n" | |
| 4202 | " * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003\n" | |
| 4203 | " *\n" | |
| 4204 | " * This is LANL Copyright Disclosure C14043/LA-CC-14-003\n" | |
| 4205 | " */\n" | |
| 4206 | "int intintIdentityPerfectCLHash_InsertSingle(__global char *tableData,\n" | |
| 4207 | " int key, int value);\n" | |
| 4208 | "int intintIdentityPerfectCLHash_InnerInsertSingle(__global char *tableData,\n" | |
| 4209 | " int key, int value);\n" | |
| 4210 | "int intintHash_InsertSingle(__global char *tableData, int key, int value);\n" | |
| 4211 | "int intintIdentityPerfectCLHash_InnerQuery(__global char *tableData,\n" | |
| 4212 | " unsigned int numKeys,\n" | |
| 4213 | " __global int *keys,\n" | |
| 4214 | " __global int *valuesOutput);\n" | |
| 4215 | "int intintIdentityPerfectCLHash_InnerQuerySingle(__global char *tableData,\n" | |
| 4216 | " int key,\n" | |
| 4217 | " __global int *valueOutput);\n" | |
| 4218 | "int intintIdentityPerfectCLHash_InnerInsert(__global char *tableData,\n" | |
| 4219 | " unsigned int numEntries,\n" | |
| 4220 | " __global int *keys,\n" | |
| 4221 | " __global int *values);\n" | |
| 4222 | "int intintIdentityPerfectCLHash_InnerInsertSingleNoOverwrite(__global char\n" | |
| 4223 | " *tableData,\n" | |
| 4224 | " int key,\n" | |
| 4225 | " int value);\n" | |
| 4226 | "int intintIdentityPerfectCLHash_InnerInsertNoOverwrite(__global char *tableData,\n" | |
| 4227 | " unsigned int numEntries,\n" | |
| 4228 | " __global int *keys,\n" | |
| 4229 | " __global int *values);\n" | |
| 4230 | "int intintIdentityPerfectCLHash_QuerySingle(__global char *tableData, int key,\n" | |
| 4231 | " __global int *valueOutput);\n" | |
| 4232 | "int intintIdentityPerfectCLHash_QuerySingle(__global char *tableData, int key,\n" | |
| 4233 | " __global int *valueOutput);\n" | |
| 4234 | "int intintIdentityPerfectCLHash_Query(__global char *tableData, size_t numKeys,\n" | |
| 4235 | " __global int *keys,\n" | |
| 4236 | " __global int *valuesOutput);\n" | |
| 4237 | "int intintIdentityPerfectCLHash_Insert(__global char *tableData,\n" | |
| 4238 | " size_t numEntries, __global int *keys,\n" | |
| 4239 | " __global int *values);\n" | |
| 4240 | "int intintIdentityPerfectCLHash_InsertSingleNoOverwrite(__global char\n" | |
| 4241 | " *tableData, int key,\n" | |
| 4242 | " int value);\n" | |
| 4243 | "int intintIdentityPerfectCLHash_InsertNoOverwrite(__global char *tableData,\n" | |
| 4244 | " size_t numEntries,\n" | |
| 4245 | " __global int *keys,\n" | |
| 4246 | " __global int *values);\n" | |
| 4247 | "int intintIdentitySentinelPerfectCLHash_InnerInsertNoOverwrite(__global char\n" | |
| 4248 | " *tableData,\n" | |
| 4249 | " unsigned int\n" | |
| 4250 | " numEntries,\n" | |
| 4251 | " __global int\n" | |
| 4252 | " *keys,\n" | |
| 4253 | " __global int\n" | |
| 4254 | " *values);\n" | |
| 4255 | "int intintIdentitySentinelPerfectCLHash_InnerQuerySingle(__global char\n" | |
| 4256 | " *tableData, int key,\n" | |
| 4257 | " __global int\n" | |
| 4258 | " *valueOutput);\n" | |
| 4259 | "int intintIdentitySentinelPerfectCLHash_InnerQuery(__global char *tableData,\n" | |
| 4260 | " unsigned int numKeys,\n" | |
| 4261 | " __global int *keys,\n" | |
| 4262 | " __global int *valuesOutput);\n" | |
| 4263 | "int intintIdentitySentinelPerfectCLHash_InnerInsertSingle(__global char\n" | |
| 4264 | " *tableData, int key,\n" | |
| 4265 | " int value);\n" | |
| 4266 | "int intintIdentitySentinelPerfectCLHash_InnerInsert(__global char *tableData,\n" | |
| 4267 | " unsigned int numEntries,\n" | |
| 4268 | " __global int *keys,\n" | |
| 4269 | " __global int *values);\n" | |
| 4270 | "int intintIdentitySentinelPerfectCLHash_InnerInsertSingleNoOverwrite(__global\n" | |
| 4271 | " char\n" | |
| 4272 | " *tableData,\n" | |
| 4273 | " int key,\n" | |
| 4274 | " int value);\n" | |
| 4275 | "int intintIdentitySentinelPerfectCLHash_QuerySingle(__global char *tableData,\n" | |
| 4276 | " int key,\n" | |
| 4277 | " __global int *valueOutput);\n" | |
| 4278 | "int intintIdentitySentinelPerfectCLHash_Query(__global char *tableData,\n" | |
| 4279 | " size_t numKeys,\n" | |
| 4280 | " __global int *keys,\n" | |
| 4281 | " __global int *valuesOutput);\n" | |
| 4282 | "int intintIdentitySentinelPerfectCLHash_InsertSingle(__global char *tableData,\n" | |
| 4283 | " int key, int value);\n" | |
| 4284 | "int intintIdentitySentinelPerfectCLHash_Insert(__global char *tableData,\n" | |
| 4285 | " size_t numEntries,\n" | |
| 4286 | " __global int *keys,\n" | |
| 4287 | " __global int *values);\n" | |
| 4288 | "int intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite(__global char\n" | |
| 4289 | " *tableData,\n" | |
| 4290 | " int key,\n" | |
| 4291 | " int value);\n" | |
| 4292 | "int intintIdentitySentinelPerfectCLHash_InsertNoOverwrite(__global char\n" | |
| 4293 | " *tableData,\n" | |
| 4294 | " size_t numEntries,\n" | |
| 4295 | " __global int *keys,\n" | |
| 4296 | " __global int *values);\n" | |
| 4297 | "int intintLCGLinearOpenCompactCLHash_InnerQuerySingle(__global char *tableData,\n" | |
| 4298 | " int key,\n" | |
| 4299 | " __global int\n" | |
| 4300 | " *valueOutput);\n" | |
| 4301 | "int intintLCGLinearOpenCompactCLHash_QuerySingle(__global char *tableData,\n" | |
| 4302 | " int key,\n" | |
| 4303 | " __global int *valueOutput);\n" | |
| 4304 | "int intintLCGLinearOpenCompactCLHash_Query(__global char *tableData,\n" | |
| 4305 | " size_t numKeys, __global int *keys,\n" | |
| 4306 | " __global int *valuesOutput);\n" | |
| 4307 | "int intintLCGLinearOpenCompactCLHash_InsertSingle(__global char *tableData,\n" | |
| 4308 | " int key, int value);\n" | |
| 4309 | "int intintLCGLinearOpenCompactCLHash_Insert(__global char *tableData,\n" | |
| 4310 | " size_t numEntries,\n" | |
| 4311 | " __global int *keys,\n" | |
| 4312 | " __global int *values);\n" | |
| 4313 | "int intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite(__global char\n" | |
| 4314 | " *tableData,\n" | |
| 4315 | " int key,\n" | |
| 4316 | " int value);\n" | |
| 4317 | "int intintLCGLinearOpenCompactCLHash_InsertNoOverwrite(__global char *tableData,\n" | |
| 4318 | " size_t numEntries,\n" | |
| 4319 | " __global int *keys,\n" | |
| 4320 | " __global int *values);\n" | |
| 4321 | "int intintLCGLinearOpenCompactCLHash_InnerQuery(__global char *tableData,\n" | |
| 4322 | " unsigned int numKeys,\n" | |
| 4323 | " __global int *keys,\n" | |
| 4324 | " __global int *valuesOutput);\n" | |
| 4325 | "int intintLCGLinearOpenCompactCLHash_InnerInsertNoOverwrite(__global char\n" | |
| 4326 | " *tableData,\n" | |
| 4327 | " unsigned int\n" | |
| 4328 | " numEntries,\n" | |
| 4329 | " __global int *keys,\n" | |
| 4330 | " __global int\n" | |
| 4331 | " *values);\n" | |
| 4332 | "int intintLCGLinearOpenCompactCLHash_InnerInsertSingle(__global char *tableData,\n" | |
| 4333 | " int key, int value);\n" | |
| 4334 | "int intintLCGLinearOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global char\n" | |
| 4335 | " *tableData,\n" | |
| 4336 | " int key,\n" | |
| 4337 | " int value);\n" | |
| 4338 | "int intintLCGLinearOpenCompactCLHash_InnerInsert(__global char *tableData,\n" | |
| 4339 | " unsigned int numEntries,\n" | |
| 4340 | " __global int *keys,\n" | |
| 4341 | " __global int *values);\n" | |
| 4342 | "int intintLCGQuadraticOpenCompactCLHash_InnerQuerySingle(__global char\n" | |
| 4343 | " *tableData, int key,\n" | |
| 4344 | " __global int\n" | |
| 4345 | " *valueOutput);\n" | |
| 4346 | "int intintLCGQuadraticOpenCompactCLHash_InnerQuery(__global char *tableData,\n" | |
| 4347 | " unsigned int numKeys,\n" | |
| 4348 | " __global int *keys,\n" | |
| 4349 | " __global int *valuesOutput);\n" | |
| 4350 | "int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingle(__global char\n" | |
| 4351 | " *tableData, int key,\n" | |
| 4352 | " int value);\n" | |
| 4353 | "int intintLCGQuadraticOpenCompactCLHash_InnerInsert(__global char *tableData,\n" | |
| 4354 | " unsigned int numEntries,\n" | |
| 4355 | " __global int *keys,\n" | |
| 4356 | " __global int *values);\n" | |
| 4357 | "int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global\n" | |
| 4358 | " char\n" | |
| 4359 | " *tableData,\n" | |
| 4360 | " int key,\n" | |
| 4361 | " int value);\n" | |
| 4362 | "int intintLCGQuadraticOpenCompactCLHash_InnerInsertNoOverwrite(__global char\n" | |
| 4363 | " *tableData,\n" | |
| 4364 | " unsigned int\n" | |
| 4365 | " numEntries,\n" | |
| 4366 | " __global int\n" | |
| 4367 | " *keys,\n" | |
| 4368 | " __global int\n" | |
| 4369 | " *values);\n" | |
| 4370 | "int intintLCGQuadraticOpenCompactCLHash_QuerySingle(__global char *tableData,\n" | |
| 4371 | " int key,\n" | |
| 4372 | " __global int *valueOutput);\n" | |
| 4373 | "int intintLCGQuadraticOpenCompactCLHash_Query(__global char *tableData,\n" | |
| 4374 | " size_t numKeys,\n" | |
| 4375 | " __global int *keys,\n" | |
| 4376 | " __global int *valuesOutput);\n" | |
| 4377 | "int intintLCGQuadraticOpenCompactCLHash_InsertSingle(__global char *tableData,\n" | |
| 4378 | " int key, int value);\n" | |
| 4379 | "int intintLCGQuadraticOpenCompactCLHash_Insert(__global char *tableData,\n" | |
| 4380 | " size_t numEntries,\n" | |
| 4381 | " __global int *keys,\n" | |
| 4382 | " __global int *values);\n" | |
| 4383 | "int intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite(__global char\n" | |
| 4384 | " *tableData,\n" | |
| 4385 | " int key,\n" | |
| 4386 | " int value);\n" | |
| 4387 | "int intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite(__global char\n" | |
| 4388 | " *tableData,\n" | |
| 4389 | " size_t numEntries,\n" | |
| 4390 | " __global int *keys,\n" | |
| 4391 | " __global int *values);\n" | |
| 4392 | "int intintHash_Query(__global char *tableData, unsigned int numKeys,\n" | |
| 4393 | " __global int *keys, __global int *valuesOutput);\n" | |
| 4394 | "int intintHash_QuerySingle(__global char *tableData, int key,\n" | |
| 4395 | " __global int *valueOutput);\n" | |
| 4396 | "int intintHash_Insert(__global char *tableData, unsigned int numEntries,\n" | |
| 4397 | " __global int *keys, __global int *values);\n" | |
| 4398 | "int intintHash_InsertNoOverwrite(__global char *tableData,\n" | |
| 4399 | " unsigned int numEntries, __global int *keys,\n" | |
| 4400 | " __global int *values);\n" | |
| 4401 | "int intintHash_InsertSingleNoOverwrite(__global char *tableData, int key,\n" | |
| 4402 | " int value);\n" | |
| 4403 | "#define HASH_REPORT_NEVER /**/ 0\n" | |
| 4404 | "#define HASH_REPORT_CYCLE /**/ 1\n" | |
| 4405 | "#define HASH_REPORT_END /****/ 2\n" | |
| 4406 | "//\n" | |
| 4407 | "#define HASH_EXIT_CODE_NORMAL /****************/ -1\n" | |
| 4408 | "#define HASH_EXIT_CODE_ERROR /*****************/ -2\n" | |
| 4409 | "#define HASH_EXIT_CODE_OVERWRITE /*************/ -3\n" | |
| 4410 | "#define HASH_EXIT_CODE_KEY_DNE /***************/ -4\n" | |
| 4411 | "#define HASH_EXIT_CODE_CYCLE /*****************/ -5\n" | |
| 4412 | "#define HASH_EXIT_CODE_MAX_ENTRIES_EXCEEDED /**/ -6\n" | |
| 4413 | "#define HASH_EXIT_CODE_BUCKET_INDEX_OOB /******/ -7\n" | |
| 4414 | "//\n" | |
| 4415 | "#define HASH_SEARCH_CODE_MATCH /*****/ 0\n" | |
| 4416 | "#define HASH_SEARCH_CODE_MISMATCH /**/ 1\n" | |
| 4417 | "#define HASH_SEARCH_CODE_EMPTY /*****/ 2\n" | |
| 4418 | "//\n" | |
| 4419 | "#define LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID /**/ 8\n" | |
| 4420 | "#define LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID /**/ 4\n" | |
| 4421 | "#define IDENTITY_SENTINEL_PERFECT_CL_HASH_ID /*******/ 2\n" | |
| 4422 | "#define IDENTITY_PERFECT_CL_HASH_ID /*******/ 1\n" | |
| 4423 | "//\n" | |
| 4424 | "#define HASH_BUCKET_STATUS_EMPTY /**/ -1\n" | |
| 4425 | "#define HASH_BUCKET_STATUS_FULL /***/ -2\n" | |
| 4426 | "#define HASH_BUCKET_STATUS_LOCK /***/ -3\n" | |
| 4427 | "static inline unsigned int intintHash_CompressIdentity(char data, int hashCode) {\n" | |
| 4428 | " return hashCode;\n" | |
| 4429 | "}\n" | |
| 4430 | "\n" | |
| 4431 | "typedef struct intintHash_CompressLCGData {\n" | |
| 4432 | " long unsigned int a;\n" | |
| 4433 | " long unsigned int c;\n" | |
| 4434 | " unsigned int m;\n" | |
| 4435 | " unsigned int n;\n" | |
| 4436 | "} intintHash_CompressLCGData;\n" | |
| 4437 | "static inline unsigned int intintHash_CompressLCG(intintHash_CompressLCGData\n" | |
| 4438 | " compressLCGData,\n" | |
| 4439 | " int hashCode) {\n" | |
| 4440 | " return ((compressLCGData.a * hashCode +\n" | |
| 4441 | " compressLCGData.c) % compressLCGData.m) % compressLCGData.n;\n" | |
| 4442 | "}\n" | |
| 4443 | "\n" | |
| 4444 | "typedef struct intintIdentityPerfectCLHash_TableData {\n" | |
| 4445 | " int hashID;\n" | |
| 4446 | " unsigned int numBuckets;\n" | |
| 4447 | " char compressFuncData;\n" | |
| 4448 | "} intintIdentityPerfectCLHash_TableData;\n" | |
| 4449 | "typedef struct intintIdentityPerfectCLHash_Bucket {\n" | |
| 4450 | " int key;\n" | |
| 4451 | " int value;\n" | |
| 4452 | "} intintIdentityPerfectCLHash_Bucket;\n" | |
| 4453 | "int intintIdentityPerfectCLHash_InnerQuerySingle(__global char *tableData,\n" | |
| 4454 | " int key,\n" | |
| 4455 | " __global int *valueOutput) {\n" | |
| 4456 | " __global intintIdentityPerfectCLHash_Bucket *buckets =\n" | |
| 4457 | " (__global intintIdentityPerfectCLHash_Bucket *) &\n" | |
| 4458 | " tableData[sizeof(intintIdentityPerfectCLHash_TableData)];\n" | |
| 4459 | " int index;\n" | |
| 4460 | " int exitCode;\n" | |
| 4461 | " index =\n" | |
| 4462 | " intintHash_CompressIdentity(((__global\n" | |
| 4463 | " intintIdentityPerfectCLHash_TableData\n" | |
| 4464 | " *) tableData)->compressFuncData, key);\n" | |
| 4465 | " if ((buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 4466 | " if (key == buckets[index].key) {\n" | |
| 4467 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4468 | " } else {\n" | |
| 4469 | " exitCode = HASH_SEARCH_CODE_MISMATCH;\n" | |
| 4470 | " }\n" | |
| 4471 | " } else {\n" | |
| 4472 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4473 | " }\n" | |
| 4474 | " switch (exitCode) {\n" | |
| 4475 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4476 | " *valueOutput = buckets[index].value;\n" | |
| 4477 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 4478 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4479 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4480 | " return HASH_EXIT_CODE_KEY_DNE;\n" | |
| 4481 | " default:\n" | |
| 4482 | " return exitCode;\n" | |
| 4483 | " }\n" | |
| 4484 | "}\n" | |
| 4485 | "int intintIdentityPerfectCLHash_InnerQuery(__global char *tableData,\n" | |
| 4486 | " unsigned int numKeys,\n" | |
| 4487 | " __global int *keys,\n" | |
| 4488 | " __global int *valuesOutput) {\n" | |
| 4489 | " __global intintIdentityPerfectCLHash_Bucket *buckets =\n" | |
| 4490 | " (__global intintIdentityPerfectCLHash_Bucket *) &\n" | |
| 4491 | " tableData[sizeof(intintIdentityPerfectCLHash_TableData)];\n" | |
| 4492 | " int key;\n" | |
| 4493 | " __global int *valueOutput;\n" | |
| 4494 | " int index;\n" | |
| 4495 | " int exitCode;\n" | |
| 4496 | " uint i;\n" | |
| 4497 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 4498 | " for (i = 0; i < numKeys; i++) {\n" | |
| 4499 | " key = keys[i];\n" | |
| 4500 | " valueOutput = &valuesOutput[i];\n" | |
| 4501 | " index =\n" | |
| 4502 | " intintHash_CompressIdentity(((__global\n" | |
| 4503 | " intintIdentityPerfectCLHash_TableData\n" | |
| 4504 | " *) tableData)->\n" | |
| 4505 | " compressFuncData, key);\n" | |
| 4506 | " if ((buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 4507 | " if (key == buckets[index].key) {\n" | |
| 4508 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4509 | " } else {\n" | |
| 4510 | " exitCode = HASH_SEARCH_CODE_MISMATCH;\n" | |
| 4511 | " }\n" | |
| 4512 | " } else {\n" | |
| 4513 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4514 | " }\n" | |
| 4515 | " switch (exitCode) {\n" | |
| 4516 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4517 | " *valueOutput = buckets[index].value;\n" | |
| 4518 | " break;\n" | |
| 4519 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4520 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4521 | " resultExitCode = HASH_EXIT_CODE_KEY_DNE;\n" | |
| 4522 | " break;\n" | |
| 4523 | " default:\n" | |
| 4524 | " return exitCode;\n" | |
| 4525 | " }\n" | |
| 4526 | " }\n" | |
| 4527 | " return resultExitCode;\n" | |
| 4528 | "}\n" | |
| 4529 | "int intintIdentityPerfectCLHash_InnerInsertSingle(__global char *tableData,\n" | |
| 4530 | " int key, int value) {\n" | |
| 4531 | " __global intintIdentityPerfectCLHash_Bucket *buckets =\n" | |
| 4532 | " (__global intintIdentityPerfectCLHash_Bucket *) &\n" | |
| 4533 | " tableData[sizeof(intintIdentityPerfectCLHash_TableData)];\n" | |
| 4534 | " int index;\n" | |
| 4535 | " int exitCode;\n" | |
| 4536 | " index =\n" | |
| 4537 | " intintHash_CompressIdentity(((__global\n" | |
| 4538 | " intintIdentityPerfectCLHash_TableData\n" | |
| 4539 | " *) tableData)->compressFuncData, key);\n" | |
| 4540 | " if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( {\n" | |
| 4541 | " buckets[index].\n" | |
| 4542 | " key = key;\n" | |
| 4543 | " HASH_BUCKET_STATUS_EMPTY;}\n" | |
| 4544 | " ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 4545 | " if (key == buckets[index].key) {\n" | |
| 4546 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4547 | " } else {\n" | |
| 4548 | " exitCode = HASH_SEARCH_CODE_MISMATCH;\n" | |
| 4549 | " }\n" | |
| 4550 | " } else {\n" | |
| 4551 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4552 | " }\n" | |
| 4553 | " switch (exitCode) {\n" | |
| 4554 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4555 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4556 | " buckets[index].value = value;\n" | |
| 4557 | " return HASH_EXIT_CODE_OVERWRITE;\n" | |
| 4558 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4559 | " buckets[index].value = value;\n" | |
| 4560 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 4561 | " default:\n" | |
| 4562 | " return exitCode;\n" | |
| 4563 | " }\n" | |
| 4564 | "}\n" | |
| 4565 | "int intintIdentityPerfectCLHash_InnerInsert(__global char *tableData,\n" | |
| 4566 | " unsigned int numEntries,\n" | |
| 4567 | " __global int *keys,\n" | |
| 4568 | " __global int *values) {\n" | |
| 4569 | " __global intintIdentityPerfectCLHash_Bucket *buckets =\n" | |
| 4570 | " (__global intintIdentityPerfectCLHash_Bucket *) &\n" | |
| 4571 | " tableData[sizeof(intintIdentityPerfectCLHash_TableData)];\n" | |
| 4572 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 4573 | " int key;\n" | |
| 4574 | " int value;\n" | |
| 4575 | " int index;\n" | |
| 4576 | " int exitCode;\n" | |
| 4577 | " uint i;\n" | |
| 4578 | " for (i = 0; i < numEntries; i++) {\n" | |
| 4579 | " key = keys[i];\n" | |
| 4580 | " index =\n" | |
| 4581 | " intintHash_CompressIdentity(((__global\n" | |
| 4582 | " intintIdentityPerfectCLHash_TableData\n" | |
| 4583 | " *) tableData)->\n" | |
| 4584 | " compressFuncData, key);\n" | |
| 4585 | " if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( {\n" | |
| 4586 | " buckets\n" | |
| 4587 | " [index].\n" | |
| 4588 | " key =\n" | |
| 4589 | " key;\n" | |
| 4590 | " HASH_BUCKET_STATUS_EMPTY;}\n" | |
| 4591 | " ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 4592 | " if (key == buckets[index].key) {\n" | |
| 4593 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4594 | " } else {\n" | |
| 4595 | " exitCode = HASH_SEARCH_CODE_MISMATCH;\n" | |
| 4596 | " }\n" | |
| 4597 | " } else {\n" | |
| 4598 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4599 | " }\n" | |
| 4600 | " switch (exitCode) {\n" | |
| 4601 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4602 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4603 | " resultExitCode = HASH_EXIT_CODE_OVERWRITE;\n" | |
| 4604 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4605 | " buckets[index].value = values[i];\n" | |
| 4606 | " break;\n" | |
| 4607 | " default:\n" | |
| 4608 | " return exitCode;\n" | |
| 4609 | " }\n" | |
| 4610 | " }\n" | |
| 4611 | " return resultExitCode;\n" | |
| 4612 | "}\n" | |
| 4613 | "int intintIdentityPerfectCLHash_InnerInsertSingleNoOverwrite(__global char\n" | |
| 4614 | " *tableData,\n" | |
| 4615 | " int key,\n" | |
| 4616 | " int value) {\n" | |
| 4617 | " __global intintIdentityPerfectCLHash_Bucket *buckets =\n" | |
| 4618 | " (__global intintIdentityPerfectCLHash_Bucket *) &\n" | |
| 4619 | " tableData[sizeof(intintIdentityPerfectCLHash_TableData)];\n" | |
| 4620 | " int index;\n" | |
| 4621 | " int exitCode;\n" | |
| 4622 | " index =\n" | |
| 4623 | " intintHash_CompressIdentity(((__global\n" | |
| 4624 | " intintIdentityPerfectCLHash_TableData\n" | |
| 4625 | " *) tableData)->compressFuncData, key);\n" | |
| 4626 | " if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( {\n" | |
| 4627 | " buckets[index].\n" | |
| 4628 | " key = key;\n" | |
| 4629 | " HASH_BUCKET_STATUS_EMPTY;}\n" | |
| 4630 | " ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 4631 | " if (key == buckets[index].key) {\n" | |
| 4632 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4633 | " } else {\n" | |
| 4634 | " exitCode = HASH_SEARCH_CODE_MISMATCH;\n" | |
| 4635 | " }\n" | |
| 4636 | " } else {\n" | |
| 4637 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4638 | " }\n" | |
| 4639 | " switch (exitCode) {\n" | |
| 4640 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4641 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4642 | " return HASH_EXIT_CODE_OVERWRITE;\n" | |
| 4643 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4644 | " buckets[index].value = value;\n" | |
| 4645 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 4646 | " default:\n" | |
| 4647 | " return exitCode;\n" | |
| 4648 | " }\n" | |
| 4649 | "}\n" | |
| 4650 | "int intintIdentityPerfectCLHash_InnerInsertNoOverwrite(__global char *tableData,\n" | |
| 4651 | " unsigned int numEntries,\n" | |
| 4652 | " __global int *keys,\n" | |
| 4653 | " __global int *values) {\n" | |
| 4654 | " __global intintIdentityPerfectCLHash_Bucket *buckets =\n" | |
| 4655 | " (__global intintIdentityPerfectCLHash_Bucket *) &\n" | |
| 4656 | " tableData[sizeof(intintIdentityPerfectCLHash_TableData)];\n" | |
| 4657 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 4658 | " int key;\n" | |
| 4659 | " int value;\n" | |
| 4660 | " int index;\n" | |
| 4661 | " int exitCode;\n" | |
| 4662 | " uint i;\n" | |
| 4663 | " for (i = 0; i < numEntries; i++) {\n" | |
| 4664 | " key = keys[i];\n" | |
| 4665 | " index =\n" | |
| 4666 | " intintHash_CompressIdentity(((__global\n" | |
| 4667 | " intintIdentityPerfectCLHash_TableData\n" | |
| 4668 | " *) tableData)->\n" | |
| 4669 | " compressFuncData, key);\n" | |
| 4670 | " if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( {\n" | |
| 4671 | " buckets\n" | |
| 4672 | " [index].\n" | |
| 4673 | " key =\n" | |
| 4674 | " key;\n" | |
| 4675 | " HASH_BUCKET_STATUS_EMPTY;}\n" | |
| 4676 | " ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 4677 | " if (key == buckets[index].key) {\n" | |
| 4678 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4679 | " } else {\n" | |
| 4680 | " exitCode = HASH_SEARCH_CODE_MISMATCH;\n" | |
| 4681 | " }\n" | |
| 4682 | " } else {\n" | |
| 4683 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4684 | " }\n" | |
| 4685 | " switch (exitCode) {\n" | |
| 4686 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4687 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4688 | " resultExitCode = HASH_EXIT_CODE_OVERWRITE;\n" | |
| 4689 | " break;\n" | |
| 4690 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4691 | " buckets[index].value = values[i];\n" | |
| 4692 | " break;\n" | |
| 4693 | " default:\n" | |
| 4694 | " return exitCode;\n" | |
| 4695 | " }\n" | |
| 4696 | " }\n" | |
| 4697 | " return resultExitCode;\n" | |
| 4698 | "}\n" | |
| 4699 | "int intintIdentityPerfectCLHash_QuerySingle(__global char *tableData, int key,\n" | |
| 4700 | " __global int *valueOutput) {\n" | |
| 4701 | " return intintIdentityPerfectCLHash_InnerQuerySingle(tableData, key,\n" | |
| 4702 | " valueOutput);\n" | |
| 4703 | "}\n" | |
| 4704 | "int intintIdentityPerfectCLHash_Query(__global char *tableData, size_t numKeys,\n" | |
| 4705 | " __global int *keys,\n" | |
| 4706 | " __global int *valuesOutput) {\n" | |
| 4707 | " return intintIdentityPerfectCLHash_InnerQuery(tableData, numKeys, keys,\n" | |
| 4708 | " valuesOutput);\n" | |
| 4709 | "}\n" | |
| 4710 | "int intintIdentityPerfectCLHash_InsertSingle(__global char *tableData, int key,\n" | |
| 4711 | " int value) {\n" | |
| 4712 | " return intintIdentityPerfectCLHash_InnerInsertSingle(tableData, key,\n" | |
| 4713 | " value);\n" | |
| 4714 | "}\n" | |
| 4715 | "int intintIdentityPerfectCLHash_Insert(__global char *tableData,\n" | |
| 4716 | " size_t numEntries, __global int *keys,\n" | |
| 4717 | " __global int *values) {\n" | |
| 4718 | " return intintIdentityPerfectCLHash_InnerInsert(tableData, numEntries,\n" | |
| 4719 | " keys, values);\n" | |
| 4720 | "}\n" | |
| 4721 | "int intintIdentityPerfectCLHash_InsertSingleNoOverwrite(__global char\n" | |
| 4722 | " *tableData, int key,\n" | |
| 4723 | " int value) {\n" | |
| 4724 | " return\n" | |
| 4725 | " intintIdentityPerfectCLHash_InnerInsertSingleNoOverwrite(tableData,\n" | |
| 4726 | " key,\n" | |
| 4727 | " value);\n" | |
| 4728 | "}\n" | |
| 4729 | "int intintIdentityPerfectCLHash_InsertNoOverwrite(__global char *tableData,\n" | |
| 4730 | " size_t numEntries,\n" | |
| 4731 | " __global int *keys,\n" | |
| 4732 | " __global int *values) {\n" | |
| 4733 | " return intintIdentityPerfectCLHash_InnerInsertNoOverwrite(tableData,\n" | |
| 4734 | " numEntries,\n" | |
| 4735 | " keys, values);\n" | |
| 4736 | "}\n" | |
| 4737 | "__kernel void intintIdentityPerfectCLHash_RangeQuerySingle(__global char\n" | |
| 4738 | " *tableData,\n" | |
| 4739 | " unsigned int\n" | |
| 4740 | " numQueries,\n" | |
| 4741 | " __global int *keys,\n" | |
| 4742 | " __global int\n" | |
| 4743 | " *valuesOutput) {\n" | |
| 4744 | " uint i = get_global_id(0);\n" | |
| 4745 | " if (i >= numQueries) {\n" | |
| 4746 | " return;\n" | |
| 4747 | " }\n" | |
| 4748 | " intintIdentityPerfectCLHash_InnerQuerySingle(tableData, keys[i],\n" | |
| 4749 | " valuesOutput + i);\n" | |
| 4750 | "}\n" | |
| 4751 | "__kernel void intintIdentityPerfectCLHash_RangeQuery(__global char *tableData,\n" | |
| 4752 | " unsigned int numQueries,\n" | |
| 4753 | " unsigned int numKeys,\n" | |
| 4754 | " __global int *keys,\n" | |
| 4755 | " __global int\n" | |
| 4756 | " *valuesOutput) {\n" | |
| 4757 | " uint i = get_global_id(0);\n" | |
| 4758 | " if (i >= numQueries) {\n" | |
| 4759 | " return;\n" | |
| 4760 | " }\n" | |
| 4761 | " intintIdentityPerfectCLHash_InnerQuery(tableData, numKeys,\n" | |
| 4762 | " keys + (i * numKeys),\n" | |
| 4763 | " valuesOutput + (i * numKeys));\n" | |
| 4764 | "}\n" | |
| 4765 | "__kernel void intintIdentityPerfectCLHash_RangeInsertSingle(__global char\n" | |
| 4766 | " *tableData,\n" | |
| 4767 | " unsigned int\n" | |
| 4768 | " numInsertions,\n" | |
| 4769 | " __global int *keys,\n" | |
| 4770 | " __global int\n" | |
| 4771 | " *values) {\n" | |
| 4772 | " uint i = get_global_id(0);\n" | |
| 4773 | " if (i >= numInsertions) {\n" | |
| 4774 | " return;\n" | |
| 4775 | " }\n" | |
| 4776 | " intintIdentityPerfectCLHash_InnerInsertSingle(tableData, keys[i],\n" | |
| 4777 | " values[i]);\n" | |
| 4778 | "}\n" | |
| 4779 | "__kernel void intintIdentityPerfectCLHash_RangeInsert(__global char *tableData,\n" | |
| 4780 | " unsigned int\n" | |
| 4781 | " numInsertions,\n" | |
| 4782 | " unsigned int numEntries,\n" | |
| 4783 | " __global int *keys,\n" | |
| 4784 | " __global int *values) {\n" | |
| 4785 | " uint i = get_global_id(0);\n" | |
| 4786 | " if (i >= numInsertions) {\n" | |
| 4787 | " return;\n" | |
| 4788 | " }\n" | |
| 4789 | " intintIdentityPerfectCLHash_InnerInsert(tableData, numEntries,\n" | |
| 4790 | " keys + (i * numEntries),\n" | |
| 4791 | " values + (i * numEntries));\n" | |
| 4792 | "}\n" | |
| 4793 | "__kernel void intintIdentityPerfectCLHash_RangeInsertSingleNoOverwrite(__global\n" | |
| 4794 | " char\n" | |
| 4795 | " *tableData,\n" | |
| 4796 | " unsigned\n" | |
| 4797 | " int\n" | |
| 4798 | " numInsertions,\n" | |
| 4799 | " __global\n" | |
| 4800 | " int\n" | |
| 4801 | " *keys,\n" | |
| 4802 | " __global\n" | |
| 4803 | " int\n" | |
| 4804 | " *values) \n" | |
| 4805 | "{\n" | |
| 4806 | " uint i = get_global_id(0);\n" | |
| 4807 | " if (i >= numInsertions) {\n" | |
| 4808 | " return;\n" | |
| 4809 | " }\n" | |
| 4810 | " intintIdentityPerfectCLHash_InnerInsertSingleNoOverwrite(tableData,\n" | |
| 4811 | " keys[i],\n" | |
| 4812 | " values[i]);\n" | |
| 4813 | "}\n" | |
| 4814 | "__kernel void intintIdentityPerfectCLHash_RangeInsertNoOverwrite(__global char\n" | |
| 4815 | " *tableData,\n" | |
| 4816 | " unsigned int\n" | |
| 4817 | " numInsertions,\n" | |
| 4818 | " unsigned int\n" | |
| 4819 | " numEntries,\n" | |
| 4820 | " __global int\n" | |
| 4821 | " *keys,\n" | |
| 4822 | " __global int\n" | |
| 4823 | " *values) {\n" | |
| 4824 | " uint i = get_global_id(0);\n" | |
| 4825 | " if (i >= numInsertions) {\n" | |
| 4826 | " return;\n" | |
| 4827 | " }\n" | |
| 4828 | " intintIdentityPerfectCLHash_InnerInsertNoOverwrite(tableData,\n" | |
| 4829 | " numEntries,\n" | |
| 4830 | " keys +\n" | |
| 4831 | " (i * numEntries),\n" | |
| 4832 | " values +\n" | |
| 4833 | " (i * numEntries));\n" | |
| 4834 | "}\n" | |
| 4835 | "\n" | |
| 4836 | "typedef struct intintIdentitySentinelPerfectCLHash_TableData {\n" | |
| 4837 | " int hashID;\n" | |
| 4838 | " unsigned int numBuckets;\n" | |
| 4839 | " char compressFuncData;\n" | |
| 4840 | " int emptyValue;\n" | |
| 4841 | "} intintIdentitySentinelPerfectCLHash_TableData;\n" | |
| 4842 | "typedef struct intintIdentitySentinelPerfectCLHash_Bucket {\n" | |
| 4843 | " int value;\n" | |
| 4844 | "} intintIdentitySentinelPerfectCLHash_Bucket;\n" | |
| 4845 | "int intintIdentitySentinelPerfectCLHash_InnerQuerySingle(__global char\n" | |
| 4846 | " *tableData, int key,\n" | |
| 4847 | " __global int\n" | |
| 4848 | " *valueOutput) {\n" | |
| 4849 | " __global intintIdentitySentinelPerfectCLHash_Bucket *buckets =\n" | |
| 4850 | " (__global intintIdentitySentinelPerfectCLHash_Bucket *) &\n" | |
| 4851 | " tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)];\n" | |
| 4852 | " int index;\n" | |
| 4853 | " int exitCode;\n" | |
| 4854 | " index =\n" | |
| 4855 | " intintHash_CompressIdentity(((__global\n" | |
| 4856 | " intintIdentitySentinelPerfectCLHash_TableData\n" | |
| 4857 | " *) tableData)->compressFuncData, key);\n" | |
| 4858 | " if (buckets[index].value !=\n" | |
| 4859 | " ((__global intintIdentitySentinelPerfectCLHash_TableData *)\n" | |
| 4860 | " tableData)->emptyValue) {\n" | |
| 4861 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4862 | " } else {\n" | |
| 4863 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4864 | " }\n" | |
| 4865 | " switch (exitCode) {\n" | |
| 4866 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4867 | " *valueOutput = buckets[index].value;\n" | |
| 4868 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 4869 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4870 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4871 | " return HASH_EXIT_CODE_KEY_DNE;\n" | |
| 4872 | " default:\n" | |
| 4873 | " return exitCode;\n" | |
| 4874 | " }\n" | |
| 4875 | "}\n" | |
| 4876 | "int intintIdentitySentinelPerfectCLHash_InnerQuery(__global char *tableData,\n" | |
| 4877 | " unsigned int numKeys,\n" | |
| 4878 | " __global int *keys,\n" | |
| 4879 | " __global int *valuesOutput) {\n" | |
| 4880 | " __global intintIdentitySentinelPerfectCLHash_Bucket *buckets =\n" | |
| 4881 | " (__global intintIdentitySentinelPerfectCLHash_Bucket *) &\n" | |
| 4882 | " tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)];\n" | |
| 4883 | " int key;\n" | |
| 4884 | " __global int *valueOutput;\n" | |
| 4885 | " int index;\n" | |
| 4886 | " int exitCode;\n" | |
| 4887 | " uint i;\n" | |
| 4888 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 4889 | " for (i = 0; i < numKeys; i++) {\n" | |
| 4890 | " key = keys[i];\n" | |
| 4891 | " valueOutput = &valuesOutput[i];\n" | |
| 4892 | " index =\n" | |
| 4893 | " intintHash_CompressIdentity(((__global\n" | |
| 4894 | " intintIdentitySentinelPerfectCLHash_TableData\n" | |
| 4895 | " *) tableData)->\n" | |
| 4896 | " compressFuncData, key);\n" | |
| 4897 | " if (buckets[index].value !=\n" | |
| 4898 | " ((__global intintIdentitySentinelPerfectCLHash_TableData *)\n" | |
| 4899 | " tableData)->emptyValue) {\n" | |
| 4900 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4901 | " } else {\n" | |
| 4902 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4903 | " }\n" | |
| 4904 | " switch (exitCode) {\n" | |
| 4905 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4906 | " *valueOutput = buckets[index].value;\n" | |
| 4907 | " break;\n" | |
| 4908 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4909 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4910 | " resultExitCode = HASH_EXIT_CODE_KEY_DNE;\n" | |
| 4911 | " break;\n" | |
| 4912 | " default:\n" | |
| 4913 | " return exitCode;\n" | |
| 4914 | " }\n" | |
| 4915 | " }\n" | |
| 4916 | " return resultExitCode;\n" | |
| 4917 | "}\n" | |
| 4918 | "int intintIdentitySentinelPerfectCLHash_InnerInsertSingle(__global char\n" | |
| 4919 | " *tableData, int key,\n" | |
| 4920 | " int value) {\n" | |
| 4921 | " __global intintIdentitySentinelPerfectCLHash_Bucket *buckets =\n" | |
| 4922 | " (__global intintIdentitySentinelPerfectCLHash_Bucket *) &\n" | |
| 4923 | " tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)];\n" | |
| 4924 | " int index;\n" | |
| 4925 | " int exitCode;\n" | |
| 4926 | " index =\n" | |
| 4927 | " intintHash_CompressIdentity(((__global\n" | |
| 4928 | " intintIdentitySentinelPerfectCLHash_TableData\n" | |
| 4929 | " *) tableData)->compressFuncData, key);\n" | |
| 4930 | " if (buckets[index].value !=\n" | |
| 4931 | " ((__global intintIdentitySentinelPerfectCLHash_TableData *)\n" | |
| 4932 | " tableData)->emptyValue) {\n" | |
| 4933 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4934 | " } else {\n" | |
| 4935 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4936 | " }\n" | |
| 4937 | " switch (exitCode) {\n" | |
| 4938 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4939 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4940 | " buckets[index].value = value;\n" | |
| 4941 | " return HASH_EXIT_CODE_OVERWRITE;\n" | |
| 4942 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4943 | " buckets[index].value = value;\n" | |
| 4944 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 4945 | " default:\n" | |
| 4946 | " return exitCode;\n" | |
| 4947 | " }\n" | |
| 4948 | "}\n" | |
| 4949 | "int intintIdentitySentinelPerfectCLHash_InnerInsert(__global char *tableData,\n" | |
| 4950 | " unsigned int numEntries,\n" | |
| 4951 | " __global int *keys,\n" | |
| 4952 | " __global int *values) {\n" | |
| 4953 | " __global intintIdentitySentinelPerfectCLHash_Bucket *buckets =\n" | |
| 4954 | " (__global intintIdentitySentinelPerfectCLHash_Bucket *) &\n" | |
| 4955 | " tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)];\n" | |
| 4956 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 4957 | " int key;\n" | |
| 4958 | " int value;\n" | |
| 4959 | " int index;\n" | |
| 4960 | " int exitCode;\n" | |
| 4961 | " uint i;\n" | |
| 4962 | " for (i = 0; i < numEntries; i++) {\n" | |
| 4963 | " key = keys[i];\n" | |
| 4964 | " index =\n" | |
| 4965 | " intintHash_CompressIdentity(((__global\n" | |
| 4966 | " intintIdentitySentinelPerfectCLHash_TableData\n" | |
| 4967 | " *) tableData)->\n" | |
| 4968 | " compressFuncData, key);\n" | |
| 4969 | " if (buckets[index].value !=\n" | |
| 4970 | " ((__global intintIdentitySentinelPerfectCLHash_TableData *)\n" | |
| 4971 | " tableData)->emptyValue) {\n" | |
| 4972 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 4973 | " } else {\n" | |
| 4974 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 4975 | " }\n" | |
| 4976 | " switch (exitCode) {\n" | |
| 4977 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 4978 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 4979 | " resultExitCode = HASH_EXIT_CODE_OVERWRITE;\n" | |
| 4980 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 4981 | " buckets[index].value = values[i];\n" | |
| 4982 | " break;\n" | |
| 4983 | " default:\n" | |
| 4984 | " return exitCode;\n" | |
| 4985 | " }\n" | |
| 4986 | " }\n" | |
| 4987 | " return resultExitCode;\n" | |
| 4988 | "}\n" | |
| 4989 | "int intintIdentitySentinelPerfectCLHash_InnerInsertSingleNoOverwrite(__global\n" | |
| 4990 | " char\n" | |
| 4991 | " *tableData,\n" | |
| 4992 | " int key,\n" | |
| 4993 | " int value) \n" | |
| 4994 | "{\n" | |
| 4995 | " __global intintIdentitySentinelPerfectCLHash_Bucket *buckets =\n" | |
| 4996 | " (__global intintIdentitySentinelPerfectCLHash_Bucket *) &\n" | |
| 4997 | " tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)];\n" | |
| 4998 | " int index;\n" | |
| 4999 | " int exitCode;\n" | |
| 5000 | " index =\n" | |
| 5001 | " intintHash_CompressIdentity(((__global\n" | |
| 5002 | " intintIdentitySentinelPerfectCLHash_TableData\n" | |
| 5003 | " *) tableData)->compressFuncData, key);\n" | |
| 5004 | " if (buckets[index].value !=\n" | |
| 5005 | " ((__global intintIdentitySentinelPerfectCLHash_TableData *)\n" | |
| 5006 | " tableData)->emptyValue) {\n" | |
| 5007 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5008 | " } else {\n" | |
| 5009 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5010 | " }\n" | |
| 5011 | " switch (exitCode) {\n" | |
| 5012 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5013 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5014 | " return HASH_EXIT_CODE_OVERWRITE;\n" | |
| 5015 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5016 | " buckets[index].value = value;\n" | |
| 5017 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 5018 | " default:\n" | |
| 5019 | " return exitCode;\n" | |
| 5020 | " }\n" | |
| 5021 | "}\n" | |
| 5022 | "int intintIdentitySentinelPerfectCLHash_InnerInsertNoOverwrite(__global char\n" | |
| 5023 | " *tableData,\n" | |
| 5024 | " unsigned int\n" | |
| 5025 | " numEntries,\n" | |
| 5026 | " __global int\n" | |
| 5027 | " *keys,\n" | |
| 5028 | " __global int\n" | |
| 5029 | " *values) {\n" | |
| 5030 | " __global intintIdentitySentinelPerfectCLHash_Bucket *buckets =\n" | |
| 5031 | " (__global intintIdentitySentinelPerfectCLHash_Bucket *) &\n" | |
| 5032 | " tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)];\n" | |
| 5033 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 5034 | " int key;\n" | |
| 5035 | " int value;\n" | |
| 5036 | " int index;\n" | |
| 5037 | " int exitCode;\n" | |
| 5038 | " uint i;\n" | |
| 5039 | " for (i = 0; i < numEntries; i++) {\n" | |
| 5040 | " key = keys[i];\n" | |
| 5041 | " index =\n" | |
| 5042 | " intintHash_CompressIdentity(((__global\n" | |
| 5043 | " intintIdentitySentinelPerfectCLHash_TableData\n" | |
| 5044 | " *) tableData)->\n" | |
| 5045 | " compressFuncData, key);\n" | |
| 5046 | " if (buckets[index].value !=\n" | |
| 5047 | " ((__global intintIdentitySentinelPerfectCLHash_TableData *)\n" | |
| 5048 | " tableData)->emptyValue) {\n" | |
| 5049 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5050 | " } else {\n" | |
| 5051 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5052 | " }\n" | |
| 5053 | " switch (exitCode) {\n" | |
| 5054 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5055 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5056 | " resultExitCode = HASH_EXIT_CODE_OVERWRITE;\n" | |
| 5057 | " break;\n" | |
| 5058 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5059 | " buckets[index].value = values[i];\n" | |
| 5060 | " break;\n" | |
| 5061 | " default:\n" | |
| 5062 | " return exitCode;\n" | |
| 5063 | " }\n" | |
| 5064 | " }\n" | |
| 5065 | " return resultExitCode;\n" | |
| 5066 | "}\n" | |
| 5067 | "int intintIdentitySentinelPerfectCLHash_QuerySingle(__global char *tableData,\n" | |
| 5068 | " int key,\n" | |
| 5069 | " __global int *valueOutput) {\n" | |
| 5070 | " return intintIdentitySentinelPerfectCLHash_InnerQuerySingle(tableData,\n" | |
| 5071 | " key,\n" | |
| 5072 | " valueOutput);\n" | |
| 5073 | "}\n" | |
| 5074 | "int intintIdentitySentinelPerfectCLHash_Query(__global char *tableData,\n" | |
| 5075 | " size_t numKeys,\n" | |
| 5076 | " __global int *keys,\n" | |
| 5077 | " __global int *valuesOutput) {\n" | |
| 5078 | " return intintIdentitySentinelPerfectCLHash_InnerQuery(tableData,\n" | |
| 5079 | " numKeys, keys,\n" | |
| 5080 | " valuesOutput);\n" | |
| 5081 | "}\n" | |
| 5082 | "int intintIdentitySentinelPerfectCLHash_InsertSingle(__global char *tableData,\n" | |
| 5083 | " int key, int value) {\n" | |
| 5084 | " return intintIdentitySentinelPerfectCLHash_InnerInsertSingle(tableData,\n" | |
| 5085 | " key,\n" | |
| 5086 | " value);\n" | |
| 5087 | "}\n" | |
| 5088 | "int intintIdentitySentinelPerfectCLHash_Insert(__global char *tableData,\n" | |
| 5089 | " size_t numEntries,\n" | |
| 5090 | " __global int *keys,\n" | |
| 5091 | " __global int *values) {\n" | |
| 5092 | " return intintIdentitySentinelPerfectCLHash_InnerInsert(tableData,\n" | |
| 5093 | " numEntries, keys,\n" | |
| 5094 | " values);\n" | |
| 5095 | "}\n" | |
| 5096 | "int intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite(__global char\n" | |
| 5097 | " *tableData,\n" | |
| 5098 | " int key,\n" | |
| 5099 | " int value) {\n" | |
| 5100 | " return\n" | |
| 5101 | " intintIdentitySentinelPerfectCLHash_InnerInsertSingleNoOverwrite\n" | |
| 5102 | " (tableData, key, value);\n" | |
| 5103 | "}\n" | |
| 5104 | "int intintIdentitySentinelPerfectCLHash_InsertNoOverwrite(__global char\n" | |
| 5105 | " *tableData,\n" | |
| 5106 | " size_t numEntries,\n" | |
| 5107 | " __global int *keys,\n" | |
| 5108 | " __global int *values) \n" | |
| 5109 | "{\n" | |
| 5110 | " return\n" | |
| 5111 | " intintIdentitySentinelPerfectCLHash_InnerInsertNoOverwrite\n" | |
| 5112 | " (tableData, numEntries, keys, values);\n" | |
| 5113 | "}\n" | |
| 5114 | "__kernel void intintIdentitySentinelPerfectCLHash_RangeQuerySingle(__global char\n" | |
| 5115 | " *tableData,\n" | |
| 5116 | " unsigned int\n" | |
| 5117 | " numQueries,\n" | |
| 5118 | " __global int\n" | |
| 5119 | " *keys,\n" | |
| 5120 | " __global int\n" | |
| 5121 | " *valuesOutput) \n" | |
| 5122 | "{\n" | |
| 5123 | " uint i = get_global_id(0);\n" | |
| 5124 | " if (i >= numQueries) {\n" | |
| 5125 | " return;\n" | |
| 5126 | " }\n" | |
| 5127 | " intintIdentitySentinelPerfectCLHash_InnerQuerySingle(tableData, keys[i],\n" | |
| 5128 | " valuesOutput + i);\n" | |
| 5129 | "}\n" | |
| 5130 | "__kernel void intintIdentitySentinelPerfectCLHash_RangeQuery(__global char\n" | |
| 5131 | " *tableData,\n" | |
| 5132 | " unsigned int\n" | |
| 5133 | " numQueries,\n" | |
| 5134 | " unsigned int\n" | |
| 5135 | " numKeys,\n" | |
| 5136 | " __global int *keys,\n" | |
| 5137 | " __global int\n" | |
| 5138 | " *valuesOutput) {\n" | |
| 5139 | " uint i = get_global_id(0);\n" | |
| 5140 | " if (i >= numQueries) {\n" | |
| 5141 | " return;\n" | |
| 5142 | " }\n" | |
| 5143 | " intintIdentitySentinelPerfectCLHash_InnerQuery(tableData, numKeys,\n" | |
| 5144 | " keys + (i * numKeys),\n" | |
| 5145 | " valuesOutput +\n" | |
| 5146 | " (i * numKeys));\n" | |
| 5147 | "}\n" | |
| 5148 | "__kernel void intintIdentitySentinelPerfectCLHash_RangeInsertSingle(__global\n" | |
| 5149 | " char\n" | |
| 5150 | " *tableData,\n" | |
| 5151 | " unsigned int\n" | |
| 5152 | " numInsertions,\n" | |
| 5153 | " __global int\n" | |
| 5154 | " *keys,\n" | |
| 5155 | " __global int\n" | |
| 5156 | " *values) {\n" | |
| 5157 | " uint i = get_global_id(0);\n" | |
| 5158 | " if (i >= numInsertions) {\n" | |
| 5159 | " return;\n" | |
| 5160 | " }\n" | |
| 5161 | " intintIdentitySentinelPerfectCLHash_InnerInsertSingle(tableData,\n" | |
| 5162 | " keys[i],\n" | |
| 5163 | " values[i]);\n" | |
| 5164 | "}\n" | |
| 5165 | "__kernel void intintIdentitySentinelPerfectCLHash_RangeInsert(__global char\n" | |
| 5166 | " *tableData,\n" | |
| 5167 | " unsigned int\n" | |
| 5168 | " numInsertions,\n" | |
| 5169 | " unsigned int\n" | |
| 5170 | " numEntries,\n" | |
| 5171 | " __global int\n" | |
| 5172 | " *keys,\n" | |
| 5173 | " __global int\n" | |
| 5174 | " *values) {\n" | |
| 5175 | " uint i = get_global_id(0);\n" | |
| 5176 | " if (i >= numInsertions) {\n" | |
| 5177 | " return;\n" | |
| 5178 | " }\n" | |
| 5179 | " intintIdentitySentinelPerfectCLHash_InnerInsert(tableData, numEntries,\n" | |
| 5180 | " keys + (i * numEntries),\n" | |
| 5181 | " values +\n" | |
| 5182 | " (i * numEntries));\n" | |
| 5183 | "}\n" | |
| 5184 | "__kernel void\n" | |
| 5185 | "intintIdentitySentinelPerfectCLHash_RangeInsertSingleNoOverwrite(__global char\n" | |
| 5186 | " *tableData,\n" | |
| 5187 | " unsigned int\n" | |
| 5188 | " numInsertions,\n" | |
| 5189 | " __global int\n" | |
| 5190 | " *keys,\n" | |
| 5191 | " __global int\n" | |
| 5192 | " *values) {\n" | |
| 5193 | " uint i = get_global_id(0);\n" | |
| 5194 | " if (i >= numInsertions) {\n" | |
| 5195 | " return;\n" | |
| 5196 | " }\n" | |
| 5197 | " intintIdentitySentinelPerfectCLHash_InnerInsertSingleNoOverwrite\n" | |
| 5198 | " (tableData, keys[i], values[i]);\n" | |
| 5199 | "}\n" | |
| 5200 | "__kernel void\n" | |
| 5201 | "intintIdentitySentinelPerfectCLHash_RangeInsertNoOverwrite(__global char\n" | |
| 5202 | " *tableData,\n" | |
| 5203 | " unsigned int\n" | |
| 5204 | " numInsertions,\n" | |
| 5205 | " unsigned int\n" | |
| 5206 | " numEntries,\n" | |
| 5207 | " __global int *keys,\n" | |
| 5208 | " __global int\n" | |
| 5209 | " *values) {\n" | |
| 5210 | " uint i = get_global_id(0);\n" | |
| 5211 | " if (i >= numInsertions) {\n" | |
| 5212 | " return;\n" | |
| 5213 | " }\n" | |
| 5214 | " intintIdentitySentinelPerfectCLHash_InnerInsertNoOverwrite(tableData,\n" | |
| 5215 | " numEntries,\n" | |
| 5216 | " keys +\n" | |
| 5217 | " (i *\n" | |
| 5218 | " numEntries),\n" | |
| 5219 | " values +\n" | |
| 5220 | " (i *\n" | |
| 5221 | " numEntries));\n" | |
| 5222 | "}\n" | |
| 5223 | "\n" | |
| 5224 | "typedef struct intintLCGLinearOpenCompactCLHash_TableData {\n" | |
| 5225 | " int hashID;\n" | |
| 5226 | " unsigned int numBuckets;\n" | |
| 5227 | " intintHash_CompressLCGData compressFuncData;\n" | |
| 5228 | "} intintLCGLinearOpenCompactCLHash_TableData;\n" | |
| 5229 | "typedef struct intintLCGLinearOpenCompactCLHash_Bucket {\n" | |
| 5230 | " int key;\n" | |
| 5231 | " int value;\n" | |
| 5232 | "} intintLCGLinearOpenCompactCLHash_Bucket;\n" | |
| 5233 | "int intintLCGLinearOpenCompactCLHash_InnerQuerySingle(__global char *tableData,\n" | |
| 5234 | " int key,\n" | |
| 5235 | " __global int\n" | |
| 5236 | " *valueOutput) {\n" | |
| 5237 | " __global intintLCGLinearOpenCompactCLHash_Bucket *buckets =\n" | |
| 5238 | " (__global intintLCGLinearOpenCompactCLHash_Bucket *) &\n" | |
| 5239 | " tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)];\n" | |
| 5240 | " int index;\n" | |
| 5241 | " int exitCode;\n" | |
| 5242 | " __global intintLCGLinearOpenCompactCLHash_TableData *mytableData =\n" | |
| 5243 | " (__global intintLCGLinearOpenCompactCLHash_TableData *) tableData;\n" | |
| 5244 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5245 | " mytableData->compressFuncData;\n" | |
| 5246 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5247 | " unsigned long int iteration = 0;\n" | |
| 5248 | " for (;;) {\n" | |
| 5249 | " index =\n" | |
| 5250 | " ((1 * iteration +\n" | |
| 5251 | " c) %\n" | |
| 5252 | " ((__global intintLCGLinearOpenCompactCLHash_TableData *)\n" | |
| 5253 | " tableData)->numBuckets);\n" | |
| 5254 | " if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5255 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5256 | " break;\n" | |
| 5257 | " } else if (key == buckets[index].key) {\n" | |
| 5258 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5259 | " break;\n" | |
| 5260 | " } else if ((index == c && iteration > 0)) {\n" | |
| 5261 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5262 | " break;\n" | |
| 5263 | " }\n" | |
| 5264 | " iteration++;\n" | |
| 5265 | " }\n" | |
| 5266 | " switch (exitCode) {\n" | |
| 5267 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5268 | " *valueOutput = buckets[index].value;\n" | |
| 5269 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 5270 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5271 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5272 | " return HASH_EXIT_CODE_KEY_DNE;\n" | |
| 5273 | " default:\n" | |
| 5274 | " return exitCode;\n" | |
| 5275 | " }\n" | |
| 5276 | "}\n" | |
| 5277 | "int intintLCGLinearOpenCompactCLHash_InnerQuery(__global char *tableData,\n" | |
| 5278 | " unsigned int numKeys,\n" | |
| 5279 | " __global int *keys,\n" | |
| 5280 | " __global int *valuesOutput) {\n" | |
| 5281 | " __global intintLCGLinearOpenCompactCLHash_Bucket *buckets =\n" | |
| 5282 | " (__global intintLCGLinearOpenCompactCLHash_Bucket *) &\n" | |
| 5283 | " tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)];\n" | |
| 5284 | " int key;\n" | |
| 5285 | " __global int *valueOutput;\n" | |
| 5286 | " int index;\n" | |
| 5287 | " int exitCode;\n" | |
| 5288 | " uint i;\n" | |
| 5289 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 5290 | " for (i = 0; i < numKeys; i++) {\n" | |
| 5291 | " key = keys[i];\n" | |
| 5292 | " valueOutput = &valuesOutput[i];\n" | |
| 5293 | " __global intintLCGLinearOpenCompactCLHash_TableData *mytableData\n" | |
| 5294 | " =\n" | |
| 5295 | " (__global intintLCGLinearOpenCompactCLHash_TableData *)\n" | |
| 5296 | " tableData;\n" | |
| 5297 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5298 | " mytableData->compressFuncData;\n" | |
| 5299 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5300 | " unsigned long int iteration = 0;\n" | |
| 5301 | " for (;;) {\n" | |
| 5302 | " index =\n" | |
| 5303 | " ((1 * iteration +\n" | |
| 5304 | " c) %\n" | |
| 5305 | " ((__global\n" | |
| 5306 | " intintLCGLinearOpenCompactCLHash_TableData *)\n" | |
| 5307 | " tableData)->numBuckets);\n" | |
| 5308 | " if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5309 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5310 | " break;\n" | |
| 5311 | " } else if (key == buckets[index].key) {\n" | |
| 5312 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5313 | " break;\n" | |
| 5314 | " } else if ((index == c && iteration > 0)) {\n" | |
| 5315 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5316 | " break;\n" | |
| 5317 | " }\n" | |
| 5318 | " iteration++;\n" | |
| 5319 | " }\n" | |
| 5320 | " switch (exitCode) {\n" | |
| 5321 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5322 | " *valueOutput = buckets[index].value;\n" | |
| 5323 | " break;\n" | |
| 5324 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5325 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5326 | " resultExitCode = HASH_EXIT_CODE_KEY_DNE;\n" | |
| 5327 | " break;\n" | |
| 5328 | " default:\n" | |
| 5329 | " return exitCode;\n" | |
| 5330 | " }\n" | |
| 5331 | " }\n" | |
| 5332 | " return resultExitCode;\n" | |
| 5333 | "}\n" | |
| 5334 | "int intintLCGLinearOpenCompactCLHash_InnerInsertSingle(__global char *tableData,\n" | |
| 5335 | " int key, int value) {\n" | |
| 5336 | " __global intintLCGLinearOpenCompactCLHash_Bucket *buckets =\n" | |
| 5337 | " (__global intintLCGLinearOpenCompactCLHash_Bucket *) &\n" | |
| 5338 | " tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)];\n" | |
| 5339 | " int index;\n" | |
| 5340 | " int exitCode;\n" | |
| 5341 | " __global intintLCGLinearOpenCompactCLHash_TableData *mytableData =\n" | |
| 5342 | " (__global intintLCGLinearOpenCompactCLHash_TableData *) tableData;\n" | |
| 5343 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5344 | " mytableData->compressFuncData;\n" | |
| 5345 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5346 | " unsigned long int iteration = 0;\n" | |
| 5347 | " for (;;) {\n" | |
| 5348 | " index =\n" | |
| 5349 | " ((1 * iteration +\n" | |
| 5350 | " c) %\n" | |
| 5351 | " ((__global intintLCGLinearOpenCompactCLHash_TableData *)\n" | |
| 5352 | " tableData)->numBuckets);\n" | |
| 5353 | " if ((atomic_cmpxchg\n" | |
| 5354 | " (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY,\n" | |
| 5355 | " key)) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5356 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5357 | " break;\n" | |
| 5358 | " } else if (key == buckets[index].key) {\n" | |
| 5359 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5360 | " break;\n" | |
| 5361 | " } else if ((index == c && iteration > 0)) {\n" | |
| 5362 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5363 | " break;\n" | |
| 5364 | " }\n" | |
| 5365 | " iteration++;\n" | |
| 5366 | " }\n" | |
| 5367 | " switch (exitCode) {\n" | |
| 5368 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5369 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5370 | " buckets[index].value = value;\n" | |
| 5371 | " return HASH_EXIT_CODE_OVERWRITE;\n" | |
| 5372 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5373 | " buckets[index].value = value;\n" | |
| 5374 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 5375 | " default:\n" | |
| 5376 | " return exitCode;\n" | |
| 5377 | " }\n" | |
| 5378 | "}\n" | |
| 5379 | "int intintLCGLinearOpenCompactCLHash_InnerInsert(__global char *tableData,\n" | |
| 5380 | " unsigned int numEntries,\n" | |
| 5381 | " __global int *keys,\n" | |
| 5382 | " __global int *values) {\n" | |
| 5383 | " __global intintLCGLinearOpenCompactCLHash_Bucket *buckets =\n" | |
| 5384 | " (__global intintLCGLinearOpenCompactCLHash_Bucket *) &\n" | |
| 5385 | " tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)];\n" | |
| 5386 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 5387 | " int key;\n" | |
| 5388 | " int value;\n" | |
| 5389 | " int index;\n" | |
| 5390 | " int exitCode;\n" | |
| 5391 | " uint i;\n" | |
| 5392 | " for (i = 0; i < numEntries; i++) {\n" | |
| 5393 | " key = keys[i];\n" | |
| 5394 | " __global intintLCGLinearOpenCompactCLHash_TableData *mytableData\n" | |
| 5395 | " =\n" | |
| 5396 | " (__global intintLCGLinearOpenCompactCLHash_TableData *)\n" | |
| 5397 | " tableData;\n" | |
| 5398 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5399 | " mytableData->compressFuncData;\n" | |
| 5400 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5401 | " unsigned long int iteration = 0;\n" | |
| 5402 | " for (;;) {\n" | |
| 5403 | " index =\n" | |
| 5404 | " ((1 * iteration +\n" | |
| 5405 | " c) %\n" | |
| 5406 | " ((__global\n" | |
| 5407 | " intintLCGLinearOpenCompactCLHash_TableData *)\n" | |
| 5408 | " tableData)->numBuckets);\n" | |
| 5409 | " if ((atomic_cmpxchg\n" | |
| 5410 | " (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY,\n" | |
| 5411 | " key)) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5412 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5413 | " break;\n" | |
| 5414 | " } else if (key == buckets[index].key) {\n" | |
| 5415 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5416 | " break;\n" | |
| 5417 | " } else if ((index == c && iteration > 0)) {\n" | |
| 5418 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5419 | " break;\n" | |
| 5420 | " }\n" | |
| 5421 | " iteration++;\n" | |
| 5422 | " }\n" | |
| 5423 | " switch (exitCode) {\n" | |
| 5424 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5425 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5426 | " resultExitCode = HASH_EXIT_CODE_OVERWRITE;\n" | |
| 5427 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5428 | " buckets[index].value = values[i];\n" | |
| 5429 | " break;\n" | |
| 5430 | " default:\n" | |
| 5431 | " return exitCode;\n" | |
| 5432 | " }\n" | |
| 5433 | " }\n" | |
| 5434 | " return resultExitCode;\n" | |
| 5435 | "}\n" | |
| 5436 | "int intintLCGLinearOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global char\n" | |
| 5437 | " *tableData,\n" | |
| 5438 | " int key,\n" | |
| 5439 | " int value) {\n" | |
| 5440 | " __global intintLCGLinearOpenCompactCLHash_Bucket *buckets =\n" | |
| 5441 | " (__global intintLCGLinearOpenCompactCLHash_Bucket *) &\n" | |
| 5442 | " tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)];\n" | |
| 5443 | " int index;\n" | |
| 5444 | " int exitCode;\n" | |
| 5445 | " __global intintLCGLinearOpenCompactCLHash_TableData *mytableData =\n" | |
| 5446 | " (__global intintLCGLinearOpenCompactCLHash_TableData *) tableData;\n" | |
| 5447 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5448 | " mytableData->compressFuncData;\n" | |
| 5449 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5450 | " unsigned long int iteration = 0;\n" | |
| 5451 | " for (;;) {\n" | |
| 5452 | " index =\n" | |
| 5453 | " ((1 * iteration +\n" | |
| 5454 | " c) %\n" | |
| 5455 | " ((__global intintLCGLinearOpenCompactCLHash_TableData *)\n" | |
| 5456 | " tableData)->numBuckets);\n" | |
| 5457 | " if ((atomic_cmpxchg\n" | |
| 5458 | " (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY,\n" | |
| 5459 | " key)) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5460 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5461 | " break;\n" | |
| 5462 | " } else if (key == buckets[index].key) {\n" | |
| 5463 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5464 | " break;\n" | |
| 5465 | " } else if ((index == c && iteration > 0)) {\n" | |
| 5466 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5467 | " break;\n" | |
| 5468 | " }\n" | |
| 5469 | " iteration++;\n" | |
| 5470 | " }\n" | |
| 5471 | " switch (exitCode) {\n" | |
| 5472 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5473 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5474 | " return HASH_EXIT_CODE_OVERWRITE;\n" | |
| 5475 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5476 | " buckets[index].value = value;\n" | |
| 5477 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 5478 | " default:\n" | |
| 5479 | " return exitCode;\n" | |
| 5480 | " }\n" | |
| 5481 | "}\n" | |
| 5482 | "int intintLCGLinearOpenCompactCLHash_InnerInsertNoOverwrite(__global char\n" | |
| 5483 | " *tableData,\n" | |
| 5484 | " unsigned int\n" | |
| 5485 | " numEntries,\n" | |
| 5486 | " __global int *keys,\n" | |
| 5487 | " __global int\n" | |
| 5488 | " *values) {\n" | |
| 5489 | " __global intintLCGLinearOpenCompactCLHash_Bucket *buckets =\n" | |
| 5490 | " (__global intintLCGLinearOpenCompactCLHash_Bucket *) &\n" | |
| 5491 | " tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)];\n" | |
| 5492 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 5493 | " int key;\n" | |
| 5494 | " int value;\n" | |
| 5495 | " int index;\n" | |
| 5496 | " int exitCode;\n" | |
| 5497 | " uint i;\n" | |
| 5498 | " for (i = 0; i < numEntries; i++) {\n" | |
| 5499 | " key = keys[i];\n" | |
| 5500 | " __global intintLCGLinearOpenCompactCLHash_TableData *mytableData\n" | |
| 5501 | " =\n" | |
| 5502 | " (__global intintLCGLinearOpenCompactCLHash_TableData *)\n" | |
| 5503 | " tableData;\n" | |
| 5504 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5505 | " mytableData->compressFuncData;\n" | |
| 5506 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5507 | " unsigned long int iteration = 0;\n" | |
| 5508 | " for (;;) {\n" | |
| 5509 | " index =\n" | |
| 5510 | " ((1 * iteration +\n" | |
| 5511 | " c) %\n" | |
| 5512 | " ((__global\n" | |
| 5513 | " intintLCGLinearOpenCompactCLHash_TableData *)\n" | |
| 5514 | " tableData)->numBuckets);\n" | |
| 5515 | " if ((atomic_cmpxchg\n" | |
| 5516 | " (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY,\n" | |
| 5517 | " key)) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5518 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5519 | " break;\n" | |
| 5520 | " } else if (key == buckets[index].key) {\n" | |
| 5521 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5522 | " break;\n" | |
| 5523 | " } else if ((index == c && iteration > 0)) {\n" | |
| 5524 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5525 | " break;\n" | |
| 5526 | " }\n" | |
| 5527 | " iteration++;\n" | |
| 5528 | " }\n" | |
| 5529 | " switch (exitCode) {\n" | |
| 5530 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5531 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5532 | " resultExitCode = HASH_EXIT_CODE_OVERWRITE;\n" | |
| 5533 | " break;\n" | |
| 5534 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5535 | " buckets[index].value = values[i];\n" | |
| 5536 | " break;\n" | |
| 5537 | " default:\n" | |
| 5538 | " return exitCode;\n" | |
| 5539 | " }\n" | |
| 5540 | " }\n" | |
| 5541 | " return resultExitCode;\n" | |
| 5542 | "}\n" | |
| 5543 | "int intintLCGLinearOpenCompactCLHash_QuerySingle(__global char *tableData,\n" | |
| 5544 | " int key,\n" | |
| 5545 | " __global int *valueOutput) {\n" | |
| 5546 | " return intintLCGLinearOpenCompactCLHash_InnerQuerySingle(tableData, key,\n" | |
| 5547 | " valueOutput);\n" | |
| 5548 | "}\n" | |
| 5549 | "int intintLCGLinearOpenCompactCLHash_Query(__global char *tableData,\n" | |
| 5550 | " size_t numKeys, __global int *keys,\n" | |
| 5551 | " __global int *valuesOutput) {\n" | |
| 5552 | " return intintLCGLinearOpenCompactCLHash_InnerQuery(tableData, numKeys,\n" | |
| 5553 | " keys, valuesOutput);\n" | |
| 5554 | "}\n" | |
| 5555 | "int intintLCGLinearOpenCompactCLHash_InsertSingle(__global char *tableData,\n" | |
| 5556 | " int key, int value) {\n" | |
| 5557 | " return intintLCGLinearOpenCompactCLHash_InnerInsertSingle(tableData,\n" | |
| 5558 | " key, value);\n" | |
| 5559 | "}\n" | |
| 5560 | "int intintLCGLinearOpenCompactCLHash_Insert(__global char *tableData,\n" | |
| 5561 | " size_t numEntries,\n" | |
| 5562 | " __global int *keys,\n" | |
| 5563 | " __global int *values) {\n" | |
| 5564 | " return intintLCGLinearOpenCompactCLHash_InnerInsert(tableData,\n" | |
| 5565 | " numEntries, keys,\n" | |
| 5566 | " values);\n" | |
| 5567 | "}\n" | |
| 5568 | "int intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite(__global char\n" | |
| 5569 | " *tableData,\n" | |
| 5570 | " int key,\n" | |
| 5571 | " int value) {\n" | |
| 5572 | " return\n" | |
| 5573 | " intintLCGLinearOpenCompactCLHash_InnerInsertSingleNoOverwrite\n" | |
| 5574 | " (tableData, key, value);\n" | |
| 5575 | "}\n" | |
| 5576 | "int intintLCGLinearOpenCompactCLHash_InsertNoOverwrite(__global char *tableData,\n" | |
| 5577 | " size_t numEntries,\n" | |
| 5578 | " __global int *keys,\n" | |
| 5579 | " __global int *values) {\n" | |
| 5580 | " return\n" | |
| 5581 | " intintLCGLinearOpenCompactCLHash_InnerInsertNoOverwrite(tableData,\n" | |
| 5582 | " numEntries,\n" | |
| 5583 | " keys,\n" | |
| 5584 | " values);\n" | |
| 5585 | "}\n" | |
| 5586 | "__kernel void intintLCGLinearOpenCompactCLHash_RangeQuerySingle(__global char\n" | |
| 5587 | " *tableData,\n" | |
| 5588 | " unsigned int\n" | |
| 5589 | " numQueries,\n" | |
| 5590 | " __global int\n" | |
| 5591 | " *keys,\n" | |
| 5592 | " __global int\n" | |
| 5593 | " *valuesOutput) {\n" | |
| 5594 | " uint i = get_global_id(0);\n" | |
| 5595 | " if (i >= numQueries) {\n" | |
| 5596 | " return;\n" | |
| 5597 | " }\n" | |
| 5598 | " intintLCGLinearOpenCompactCLHash_InnerQuerySingle(tableData, keys[i],\n" | |
| 5599 | " valuesOutput + i);\n" | |
| 5600 | "}\n" | |
| 5601 | "__kernel void intintLCGLinearOpenCompactCLHash_RangeQuery(__global char\n" | |
| 5602 | " *tableData,\n" | |
| 5603 | " unsigned int\n" | |
| 5604 | " numQueries,\n" | |
| 5605 | " unsigned int numKeys,\n" | |
| 5606 | " __global int *keys,\n" | |
| 5607 | " __global int\n" | |
| 5608 | " *valuesOutput) {\n" | |
| 5609 | " uint i = get_global_id(0);\n" | |
| 5610 | " if (i >= numQueries) {\n" | |
| 5611 | " return;\n" | |
| 5612 | " }\n" | |
| 5613 | " intintLCGLinearOpenCompactCLHash_InnerQuery(tableData, numKeys,\n" | |
| 5614 | " keys + (i * numKeys),\n" | |
| 5615 | " valuesOutput +\n" | |
| 5616 | " (i * numKeys));\n" | |
| 5617 | "}\n" | |
| 5618 | "__kernel void intintLCGLinearOpenCompactCLHash_RangeInsertSingle(__global char\n" | |
| 5619 | " *tableData,\n" | |
| 5620 | " unsigned int\n" | |
| 5621 | " numInsertions,\n" | |
| 5622 | " __global int\n" | |
| 5623 | " *keys,\n" | |
| 5624 | " __global int\n" | |
| 5625 | " *values) {\n" | |
| 5626 | " uint i = get_global_id(0);\n" | |
| 5627 | " if (i >= numInsertions) {\n" | |
| 5628 | " return;\n" | |
| 5629 | " }\n" | |
| 5630 | " intintLCGLinearOpenCompactCLHash_InnerInsertSingle(tableData, keys[i],\n" | |
| 5631 | " values[i]);\n" | |
| 5632 | "}\n" | |
| 5633 | "__kernel void intintLCGLinearOpenCompactCLHash_RangeInsert(__global char\n" | |
| 5634 | " *tableData,\n" | |
| 5635 | " unsigned int\n" | |
| 5636 | " numInsertions,\n" | |
| 5637 | " unsigned int\n" | |
| 5638 | " numEntries,\n" | |
| 5639 | " __global int *keys,\n" | |
| 5640 | " __global int\n" | |
| 5641 | " *values) {\n" | |
| 5642 | " uint i = get_global_id(0);\n" | |
| 5643 | " if (i >= numInsertions) {\n" | |
| 5644 | " return;\n" | |
| 5645 | " }\n" | |
| 5646 | " intintLCGLinearOpenCompactCLHash_InnerInsert(tableData, numEntries,\n" | |
| 5647 | " keys + (i * numEntries),\n" | |
| 5648 | " values + (i * numEntries));\n" | |
| 5649 | "}\n" | |
| 5650 | "__kernel void\n" | |
| 5651 | "intintLCGLinearOpenCompactCLHash_RangeInsertSingleNoOverwrite(__global char\n" | |
| 5652 | " *tableData,\n" | |
| 5653 | " unsigned int\n" | |
| 5654 | " numInsertions,\n" | |
| 5655 | " __global int\n" | |
| 5656 | " *keys,\n" | |
| 5657 | " __global int\n" | |
| 5658 | " *values) {\n" | |
| 5659 | " uint i = get_global_id(0);\n" | |
| 5660 | " if (i >= numInsertions) {\n" | |
| 5661 | " return;\n" | |
| 5662 | " }\n" | |
| 5663 | " intintLCGLinearOpenCompactCLHash_InnerInsertSingleNoOverwrite(tableData,\n" | |
| 5664 | " keys[i],\n" | |
| 5665 | " values\n" | |
| 5666 | " [i]);\n" | |
| 5667 | "}\n" | |
| 5668 | "__kernel void intintLCGLinearOpenCompactCLHash_RangeInsertNoOverwrite(__global\n" | |
| 5669 | " char\n" | |
| 5670 | " *tableData,\n" | |
| 5671 | " unsigned\n" | |
| 5672 | " int\n" | |
| 5673 | " numInsertions,\n" | |
| 5674 | " unsigned\n" | |
| 5675 | " int\n" | |
| 5676 | " numEntries,\n" | |
| 5677 | " __global\n" | |
| 5678 | " int *keys,\n" | |
| 5679 | " __global\n" | |
| 5680 | " int\n" | |
| 5681 | " *values) {\n" | |
| 5682 | " uint i = get_global_id(0);\n" | |
| 5683 | " if (i >= numInsertions) {\n" | |
| 5684 | " return;\n" | |
| 5685 | " }\n" | |
| 5686 | " intintLCGLinearOpenCompactCLHash_InnerInsertNoOverwrite(tableData,\n" | |
| 5687 | " numEntries,\n" | |
| 5688 | " keys +\n" | |
| 5689 | " (i *\n" | |
| 5690 | " numEntries),\n" | |
| 5691 | " values +\n" | |
| 5692 | " (i *\n" | |
| 5693 | " numEntries));\n" | |
| 5694 | "}\n" | |
| 5695 | "\n" | |
| 5696 | "typedef struct intintLCGQuadraticOpenCompactCLHash_TableData {\n" | |
| 5697 | " int hashID;\n" | |
| 5698 | " unsigned int numBuckets;\n" | |
| 5699 | " intintHash_CompressLCGData compressFuncData;\n" | |
| 5700 | "} intintLCGQuadraticOpenCompactCLHash_TableData;\n" | |
| 5701 | "typedef struct intintLCGQuadraticOpenCompactCLHash_Bucket {\n" | |
| 5702 | " int key;\n" | |
| 5703 | " int value;\n" | |
| 5704 | "} intintLCGQuadraticOpenCompactCLHash_Bucket;\n" | |
| 5705 | "int intintLCGQuadraticOpenCompactCLHash_InnerQuerySingle(__global char\n" | |
| 5706 | " *tableData, int key,\n" | |
| 5707 | " __global int\n" | |
| 5708 | " *valueOutput) {\n" | |
| 5709 | " __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets =\n" | |
| 5710 | " (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) &\n" | |
| 5711 | " tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)];\n" | |
| 5712 | " int index;\n" | |
| 5713 | " int exitCode;\n" | |
| 5714 | " __global intintLCGQuadraticOpenCompactCLHash_TableData *mytableData =\n" | |
| 5715 | " (__global intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5716 | " tableData;\n" | |
| 5717 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5718 | " mytableData->compressFuncData;\n" | |
| 5719 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5720 | " unsigned long int iteration = 0;\n" | |
| 5721 | " for (;;) {\n" | |
| 5722 | " index =\n" | |
| 5723 | " ((1 * iteration * iteration + 0 * iteration +\n" | |
| 5724 | " c) %\n" | |
| 5725 | " ((__global intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5726 | " tableData)->numBuckets);\n" | |
| 5727 | " if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5728 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5729 | " break;\n" | |
| 5730 | " } else if (key == buckets[index].key) {\n" | |
| 5731 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5732 | " break;\n" | |
| 5733 | " } else\n" | |
| 5734 | " if ((iteration >\n" | |
| 5735 | " ((__global\n" | |
| 5736 | " intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5737 | " tableData)->numBuckets)) {\n" | |
| 5738 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5739 | " break;\n" | |
| 5740 | " }\n" | |
| 5741 | " iteration++;\n" | |
| 5742 | " }\n" | |
| 5743 | " switch (exitCode) {\n" | |
| 5744 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5745 | " *valueOutput = buckets[index].value;\n" | |
| 5746 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 5747 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5748 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5749 | " return HASH_EXIT_CODE_KEY_DNE;\n" | |
| 5750 | " default:\n" | |
| 5751 | " return exitCode;\n" | |
| 5752 | " }\n" | |
| 5753 | "}\n" | |
| 5754 | "int intintLCGQuadraticOpenCompactCLHash_InnerQuery(__global char *tableData,\n" | |
| 5755 | " unsigned int numKeys,\n" | |
| 5756 | " __global int *keys,\n" | |
| 5757 | " __global int *valuesOutput) {\n" | |
| 5758 | " __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets =\n" | |
| 5759 | " (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) &\n" | |
| 5760 | " tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)];\n" | |
| 5761 | " int key;\n" | |
| 5762 | " __global int *valueOutput;\n" | |
| 5763 | " int index;\n" | |
| 5764 | " int exitCode;\n" | |
| 5765 | " uint i;\n" | |
| 5766 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 5767 | " for (i = 0; i < numKeys; i++) {\n" | |
| 5768 | " key = keys[i];\n" | |
| 5769 | " valueOutput = &valuesOutput[i];\n" | |
| 5770 | " __global intintLCGQuadraticOpenCompactCLHash_TableData\n" | |
| 5771 | " *mytableData =\n" | |
| 5772 | " (__global intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5773 | " tableData;\n" | |
| 5774 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5775 | " mytableData->compressFuncData;\n" | |
| 5776 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5777 | " unsigned long int iteration = 0;\n" | |
| 5778 | " for (;;) {\n" | |
| 5779 | " index =\n" | |
| 5780 | " ((1 * iteration * iteration + 0 * iteration +\n" | |
| 5781 | " c) %\n" | |
| 5782 | " ((__global\n" | |
| 5783 | " intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5784 | " tableData)->numBuckets);\n" | |
| 5785 | " if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5786 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5787 | " break;\n" | |
| 5788 | " } else if (key == buckets[index].key) {\n" | |
| 5789 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5790 | " break;\n" | |
| 5791 | " } else\n" | |
| 5792 | " if ((iteration >\n" | |
| 5793 | " ((__global\n" | |
| 5794 | " intintLCGQuadraticOpenCompactCLHash_TableData\n" | |
| 5795 | " *) tableData)->numBuckets)) {\n" | |
| 5796 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5797 | " break;\n" | |
| 5798 | " }\n" | |
| 5799 | " iteration++;\n" | |
| 5800 | " }\n" | |
| 5801 | " switch (exitCode) {\n" | |
| 5802 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5803 | " *valueOutput = buckets[index].value;\n" | |
| 5804 | " break;\n" | |
| 5805 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5806 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5807 | " resultExitCode = HASH_EXIT_CODE_KEY_DNE;\n" | |
| 5808 | " break;\n" | |
| 5809 | " default:\n" | |
| 5810 | " return exitCode;\n" | |
| 5811 | " }\n" | |
| 5812 | " }\n" | |
| 5813 | " return resultExitCode;\n" | |
| 5814 | "}\n" | |
| 5815 | "int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingle(__global char\n" | |
| 5816 | " *tableData, int key,\n" | |
| 5817 | " int value) {\n" | |
| 5818 | " __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets =\n" | |
| 5819 | " (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) &\n" | |
| 5820 | " tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)];\n" | |
| 5821 | " int index;\n" | |
| 5822 | " int exitCode;\n" | |
| 5823 | " __global intintLCGQuadraticOpenCompactCLHash_TableData *mytableData =\n" | |
| 5824 | " (__global intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5825 | " tableData;\n" | |
| 5826 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5827 | " mytableData->compressFuncData;\n" | |
| 5828 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5829 | " unsigned long int iteration = 0;\n" | |
| 5830 | " for (;;) {\n" | |
| 5831 | " index =\n" | |
| 5832 | " ((1 * iteration * iteration + 0 * iteration +\n" | |
| 5833 | " c) %\n" | |
| 5834 | " ((__global intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5835 | " tableData)->numBuckets);\n" | |
| 5836 | " if ((atomic_cmpxchg\n" | |
| 5837 | " (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY,\n" | |
| 5838 | " key)) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5839 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5840 | " break;\n" | |
| 5841 | " } else if (key == buckets[index].key) {\n" | |
| 5842 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5843 | " break;\n" | |
| 5844 | " } else\n" | |
| 5845 | " if ((iteration >\n" | |
| 5846 | " ((__global\n" | |
| 5847 | " intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5848 | " tableData)->numBuckets)) {\n" | |
| 5849 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5850 | " break;\n" | |
| 5851 | " }\n" | |
| 5852 | " iteration++;\n" | |
| 5853 | " }\n" | |
| 5854 | " switch (exitCode) {\n" | |
| 5855 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5856 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5857 | " buckets[index].value = value;\n" | |
| 5858 | " return HASH_EXIT_CODE_OVERWRITE;\n" | |
| 5859 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5860 | " buckets[index].value = value;\n" | |
| 5861 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 5862 | " default:\n" | |
| 5863 | " return exitCode;\n" | |
| 5864 | " }\n" | |
| 5865 | "}\n" | |
| 5866 | "int intintLCGQuadraticOpenCompactCLHash_InnerInsert(__global char *tableData,\n" | |
| 5867 | " unsigned int numEntries,\n" | |
| 5868 | " __global int *keys,\n" | |
| 5869 | " __global int *values) {\n" | |
| 5870 | " __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets =\n" | |
| 5871 | " (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) &\n" | |
| 5872 | " tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)];\n" | |
| 5873 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 5874 | " int key;\n" | |
| 5875 | " int value;\n" | |
| 5876 | " int index;\n" | |
| 5877 | " int exitCode;\n" | |
| 5878 | " uint i;\n" | |
| 5879 | " for (i = 0; i < numEntries; i++) {\n" | |
| 5880 | " key = keys[i];\n" | |
| 5881 | " __global intintLCGQuadraticOpenCompactCLHash_TableData\n" | |
| 5882 | " *mytableData =\n" | |
| 5883 | " (__global intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5884 | " tableData;\n" | |
| 5885 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5886 | " mytableData->compressFuncData;\n" | |
| 5887 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5888 | " unsigned long int iteration = 0;\n" | |
| 5889 | " for (;;) {\n" | |
| 5890 | " index =\n" | |
| 5891 | " ((1 * iteration * iteration + 0 * iteration +\n" | |
| 5892 | " c) %\n" | |
| 5893 | " ((__global\n" | |
| 5894 | " intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5895 | " tableData)->numBuckets);\n" | |
| 5896 | " if ((atomic_cmpxchg\n" | |
| 5897 | " (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY,\n" | |
| 5898 | " key)) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5899 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5900 | " break;\n" | |
| 5901 | " } else if (key == buckets[index].key) {\n" | |
| 5902 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5903 | " break;\n" | |
| 5904 | " } else\n" | |
| 5905 | " if ((iteration >\n" | |
| 5906 | " ((__global\n" | |
| 5907 | " intintLCGQuadraticOpenCompactCLHash_TableData\n" | |
| 5908 | " *) tableData)->numBuckets)) {\n" | |
| 5909 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5910 | " break;\n" | |
| 5911 | " }\n" | |
| 5912 | " iteration++;\n" | |
| 5913 | " }\n" | |
| 5914 | " switch (exitCode) {\n" | |
| 5915 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5916 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5917 | " resultExitCode = HASH_EXIT_CODE_OVERWRITE;\n" | |
| 5918 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5919 | " buckets[index].value = values[i];\n" | |
| 5920 | " break;\n" | |
| 5921 | " default:\n" | |
| 5922 | " return exitCode;\n" | |
| 5923 | " }\n" | |
| 5924 | " }\n" | |
| 5925 | " return resultExitCode;\n" | |
| 5926 | "}\n" | |
| 5927 | "int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global\n" | |
| 5928 | " char\n" | |
| 5929 | " *tableData,\n" | |
| 5930 | " int key,\n" | |
| 5931 | " int value) \n" | |
| 5932 | "{\n" | |
| 5933 | " __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets =\n" | |
| 5934 | " (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) &\n" | |
| 5935 | " tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)];\n" | |
| 5936 | " int index;\n" | |
| 5937 | " int exitCode;\n" | |
| 5938 | " __global intintLCGQuadraticOpenCompactCLHash_TableData *mytableData =\n" | |
| 5939 | " (__global intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5940 | " tableData;\n" | |
| 5941 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 5942 | " mytableData->compressFuncData;\n" | |
| 5943 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 5944 | " unsigned long int iteration = 0;\n" | |
| 5945 | " for (;;) {\n" | |
| 5946 | " index =\n" | |
| 5947 | " ((1 * iteration * iteration + 0 * iteration +\n" | |
| 5948 | " c) %\n" | |
| 5949 | " ((__global intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5950 | " tableData)->numBuckets);\n" | |
| 5951 | " if ((atomic_cmpxchg\n" | |
| 5952 | " (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY,\n" | |
| 5953 | " key)) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 5954 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 5955 | " break;\n" | |
| 5956 | " } else if (key == buckets[index].key) {\n" | |
| 5957 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 5958 | " break;\n" | |
| 5959 | " } else\n" | |
| 5960 | " if ((iteration >\n" | |
| 5961 | " ((__global\n" | |
| 5962 | " intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 5963 | " tableData)->numBuckets)) {\n" | |
| 5964 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 5965 | " break;\n" | |
| 5966 | " }\n" | |
| 5967 | " iteration++;\n" | |
| 5968 | " }\n" | |
| 5969 | " switch (exitCode) {\n" | |
| 5970 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 5971 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 5972 | " return HASH_EXIT_CODE_OVERWRITE;\n" | |
| 5973 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 5974 | " buckets[index].value = value;\n" | |
| 5975 | " return HASH_EXIT_CODE_NORMAL;\n" | |
| 5976 | " default:\n" | |
| 5977 | " return exitCode;\n" | |
| 5978 | " }\n" | |
| 5979 | "}\n" | |
| 5980 | "int intintLCGQuadraticOpenCompactCLHash_InnerInsertNoOverwrite(__global char\n" | |
| 5981 | " *tableData,\n" | |
| 5982 | " unsigned int\n" | |
| 5983 | " numEntries,\n" | |
| 5984 | " __global int\n" | |
| 5985 | " *keys,\n" | |
| 5986 | " __global int\n" | |
| 5987 | " *values) {\n" | |
| 5988 | " __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets =\n" | |
| 5989 | " (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) &\n" | |
| 5990 | " tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)];\n" | |
| 5991 | " int resultExitCode = HASH_EXIT_CODE_NORMAL;\n" | |
| 5992 | " int key;\n" | |
| 5993 | " int value;\n" | |
| 5994 | " int index;\n" | |
| 5995 | " int exitCode;\n" | |
| 5996 | " uint i;\n" | |
| 5997 | " for (i = 0; i < numEntries; i++) {\n" | |
| 5998 | " key = keys[i];\n" | |
| 5999 | " __global intintLCGQuadraticOpenCompactCLHash_TableData\n" | |
| 6000 | " *mytableData =\n" | |
| 6001 | " (__global intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 6002 | " tableData;\n" | |
| 6003 | " intintHash_CompressLCGData compressFuncData =\n" | |
| 6004 | " mytableData->compressFuncData;\n" | |
| 6005 | " unsigned int c = intintHash_CompressLCG(compressFuncData, key);\n" | |
| 6006 | " unsigned long int iteration = 0;\n" | |
| 6007 | " for (;;) {\n" | |
| 6008 | " index =\n" | |
| 6009 | " ((1 * iteration * iteration + 0 * iteration +\n" | |
| 6010 | " c) %\n" | |
| 6011 | " ((__global\n" | |
| 6012 | " intintLCGQuadraticOpenCompactCLHash_TableData *)\n" | |
| 6013 | " tableData)->numBuckets);\n" | |
| 6014 | " if ((atomic_cmpxchg\n" | |
| 6015 | " (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY,\n" | |
| 6016 | " key)) == HASH_BUCKET_STATUS_EMPTY) {\n" | |
| 6017 | " exitCode = HASH_SEARCH_CODE_EMPTY;\n" | |
| 6018 | " break;\n" | |
| 6019 | " } else if (key == buckets[index].key) {\n" | |
| 6020 | " exitCode = HASH_SEARCH_CODE_MATCH;\n" | |
| 6021 | " break;\n" | |
| 6022 | " } else\n" | |
| 6023 | " if ((iteration >\n" | |
| 6024 | " ((__global\n" | |
| 6025 | " intintLCGQuadraticOpenCompactCLHash_TableData\n" | |
| 6026 | " *) tableData)->numBuckets)) {\n" | |
| 6027 | " exitCode = HASH_EXIT_CODE_CYCLE;\n" | |
| 6028 | " break;\n" | |
| 6029 | " }\n" | |
| 6030 | " iteration++;\n" | |
| 6031 | " }\n" | |
| 6032 | " switch (exitCode) {\n" | |
| 6033 | " case HASH_SEARCH_CODE_MATCH:\n" | |
| 6034 | " case HASH_SEARCH_CODE_MISMATCH:\n" | |
| 6035 | " resultExitCode = HASH_EXIT_CODE_OVERWRITE;\n" | |
| 6036 | " break;\n" | |
| 6037 | " case HASH_SEARCH_CODE_EMPTY:\n" | |
| 6038 | " buckets[index].value = values[i];\n" | |
| 6039 | " break;\n" | |
| 6040 | " default:\n" | |
| 6041 | " return exitCode;\n" | |
| 6042 | " }\n" | |
| 6043 | " }\n" | |
| 6044 | " return resultExitCode;\n" | |
| 6045 | "}\n" | |
| 6046 | "int intintLCGQuadraticOpenCompactCLHash_QuerySingle(__global char *tableData,\n" | |
| 6047 | " int key,\n" | |
| 6048 | " __global int *valueOutput) {\n" | |
| 6049 | " return intintLCGQuadraticOpenCompactCLHash_InnerQuerySingle(tableData,\n" | |
| 6050 | " key,\n" | |
| 6051 | " valueOutput);\n" | |
| 6052 | "}\n" | |
| 6053 | "int intintLCGQuadraticOpenCompactCLHash_Query(__global char *tableData,\n" | |
| 6054 | " size_t numKeys,\n" | |
| 6055 | " __global int *keys,\n" | |
| 6056 | " __global int *valuesOutput) {\n" | |
| 6057 | " return intintLCGQuadraticOpenCompactCLHash_InnerQuery(tableData,\n" | |
| 6058 | " numKeys, keys,\n" | |
| 6059 | " valuesOutput);\n" | |
| 6060 | "}\n" | |
| 6061 | "int intintLCGQuadraticOpenCompactCLHash_InsertSingle(__global char *tableData,\n" | |
| 6062 | " int key, int value) {\n" | |
| 6063 | " return intintLCGQuadraticOpenCompactCLHash_InnerInsertSingle(tableData,\n" | |
| 6064 | " key,\n" | |
| 6065 | " value);\n" | |
| 6066 | "}\n" | |
| 6067 | "int intintLCGQuadraticOpenCompactCLHash_Insert(__global char *tableData,\n" | |
| 6068 | " size_t numEntries,\n" | |
| 6069 | " __global int *keys,\n" | |
| 6070 | " __global int *values) {\n" | |
| 6071 | " return intintLCGQuadraticOpenCompactCLHash_InnerInsert(tableData,\n" | |
| 6072 | " numEntries, keys,\n" | |
| 6073 | " values);\n" | |
| 6074 | "}\n" | |
| 6075 | "int intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite(__global char\n" | |
| 6076 | " *tableData,\n" | |
| 6077 | " int key,\n" | |
| 6078 | " int value) {\n" | |
| 6079 | " return\n" | |
| 6080 | " intintLCGQuadraticOpenCompactCLHash_InnerInsertSingleNoOverwrite\n" | |
| 6081 | " (tableData, key, value);\n" | |
| 6082 | "}\n" | |
| 6083 | "int intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite(__global char\n" | |
| 6084 | " *tableData,\n" | |
| 6085 | " size_t numEntries,\n" | |
| 6086 | " __global int *keys,\n" | |
| 6087 | " __global int *values) \n" | |
| 6088 | "{\n" | |
| 6089 | " return\n" | |
| 6090 | " intintLCGQuadraticOpenCompactCLHash_InnerInsertNoOverwrite\n" | |
| 6091 | " (tableData, numEntries, keys, values);\n" | |
| 6092 | "}\n" | |
| 6093 | "__kernel void intintLCGQuadraticOpenCompactCLHash_RangeQuerySingle(__global char\n" | |
| 6094 | " *tableData,\n" | |
| 6095 | " unsigned int\n" | |
| 6096 | " numQueries,\n" | |
| 6097 | " __global int\n" | |
| 6098 | " *keys,\n" | |
| 6099 | " __global int\n" | |
| 6100 | " *valuesOutput) \n" | |
| 6101 | "{\n" | |
| 6102 | " uint i = get_global_id(0);\n" | |
| 6103 | " if (i >= numQueries) {\n" | |
| 6104 | " return;\n" | |
| 6105 | " }\n" | |
| 6106 | " intintLCGQuadraticOpenCompactCLHash_InnerQuerySingle(tableData, keys[i],\n" | |
| 6107 | " valuesOutput + i);\n" | |
| 6108 | "}\n" | |
| 6109 | "__kernel void intintLCGQuadraticOpenCompactCLHash_RangeQuery(__global char\n" | |
| 6110 | " *tableData,\n" | |
| 6111 | " unsigned int\n" | |
| 6112 | " numQueries,\n" | |
| 6113 | " unsigned int\n" | |
| 6114 | " numKeys,\n" | |
| 6115 | " __global int *keys,\n" | |
| 6116 | " __global int\n" | |
| 6117 | " *valuesOutput) {\n" | |
| 6118 | " uint i = get_global_id(0);\n" | |
| 6119 | " if (i >= numQueries) {\n" | |
| 6120 | " return;\n" | |
| 6121 | " }\n" | |
| 6122 | " intintLCGQuadraticOpenCompactCLHash_InnerQuery(tableData, numKeys,\n" | |
| 6123 | " keys + (i * numKeys),\n" | |
| 6124 | " valuesOutput +\n" | |
| 6125 | " (i * numKeys));\n" | |
| 6126 | "}\n" | |
| 6127 | "__kernel void intintLCGQuadraticOpenCompactCLHash_RangeInsertSingle(__global\n" | |
| 6128 | " char\n" | |
| 6129 | " *tableData,\n" | |
| 6130 | " unsigned int\n" | |
| 6131 | " numInsertions,\n" | |
| 6132 | " __global int\n" | |
| 6133 | " *keys,\n" | |
| 6134 | " __global int\n" | |
| 6135 | " *values) {\n" | |
| 6136 | " uint i = get_global_id(0);\n" | |
| 6137 | " if (i >= numInsertions) {\n" | |
| 6138 | " return;\n" | |
| 6139 | " }\n" | |
| 6140 | " intintLCGQuadraticOpenCompactCLHash_InnerInsertSingle(tableData,\n" | |
| 6141 | " keys[i],\n" | |
| 6142 | " values[i]);\n" | |
| 6143 | "}\n" | |
| 6144 | "__kernel void intintLCGQuadraticOpenCompactCLHash_RangeInsert(__global char\n" | |
| 6145 | " *tableData,\n" | |
| 6146 | " unsigned int\n" | |
| 6147 | " numInsertions,\n" | |
| 6148 | " unsigned int\n" | |
| 6149 | " numEntries,\n" | |
| 6150 | " __global int\n" | |
| 6151 | " *keys,\n" | |
| 6152 | " __global int\n" | |
| 6153 | " *values) {\n" | |
| 6154 | " uint i = get_global_id(0);\n" | |
| 6155 | " if (i >= numInsertions) {\n" | |
| 6156 | " return;\n" | |
| 6157 | " }\n" | |
| 6158 | " intintLCGQuadraticOpenCompactCLHash_InnerInsert(tableData, numEntries,\n" | |
| 6159 | " keys + (i * numEntries),\n" | |
| 6160 | " values +\n" | |
| 6161 | " (i * numEntries));\n" | |
| 6162 | "}\n" | |
| 6163 | "__kernel void\n" | |
| 6164 | "intintLCGQuadraticOpenCompactCLHash_RangeInsertSingleNoOverwrite(__global char\n" | |
| 6165 | " *tableData,\n" | |
| 6166 | " unsigned int\n" | |
| 6167 | " numInsertions,\n" | |
| 6168 | " __global int\n" | |
| 6169 | " *keys,\n" | |
| 6170 | " __global int\n" | |
| 6171 | " *values) {\n" | |
| 6172 | " uint i = get_global_id(0);\n" | |
| 6173 | " if (i >= numInsertions) {\n" | |
| 6174 | " return;\n" | |
| 6175 | " }\n" | |
| 6176 | " intintLCGQuadraticOpenCompactCLHash_InnerInsertSingleNoOverwrite\n" | |
| 6177 | " (tableData, keys[i], values[i]);\n" | |
| 6178 | "}\n" | |
| 6179 | "__kernel void\n" | |
| 6180 | "intintLCGQuadraticOpenCompactCLHash_RangeInsertNoOverwrite(__global char\n" | |
| 6181 | " *tableData,\n" | |
| 6182 | " unsigned int\n" | |
| 6183 | " numInsertions,\n" | |
| 6184 | " unsigned int\n" | |
| 6185 | " numEntries,\n" | |
| 6186 | " __global int *keys,\n" | |
| 6187 | " __global int\n" | |
| 6188 | " *values) {\n" | |
| 6189 | " uint i = get_global_id(0);\n" | |
| 6190 | " if (i >= numInsertions) {\n" | |
| 6191 | " return;\n" | |
| 6192 | " }\n" | |
| 6193 | " intintLCGQuadraticOpenCompactCLHash_InnerInsertNoOverwrite(tableData,\n" | |
| 6194 | " numEntries,\n" | |
| 6195 | " keys +\n" | |
| 6196 | " (i *\n" | |
| 6197 | " numEntries),\n" | |
| 6198 | " values +\n" | |
| 6199 | " (i *\n" | |
| 6200 | " numEntries));\n" | |
| 6201 | "}\n" | |
| 6202 | "__kernel void intintHash_RangeQuery(__global char *tableData,\n" | |
| 6203 | " unsigned int numQueries,\n" | |
| 6204 | " unsigned int numKeys, __global int *keys,\n" | |
| 6205 | " __global int *valuesOutput) {\n" | |
| 6206 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6207 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6208 | " return intintIdentityPerfectCLHash_RangeQuery(tableData,\n" | |
| 6209 | " numQueries,\n" | |
| 6210 | " numKeys, keys,\n" | |
| 6211 | " valuesOutput);\n" | |
| 6212 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6213 | " return intintIdentitySentinelPerfectCLHash_RangeQuery(tableData,\n" | |
| 6214 | " numQueries,\n" | |
| 6215 | " numKeys,\n" | |
| 6216 | " keys,\n" | |
| 6217 | " valuesOutput);\n" | |
| 6218 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6219 | " return intintLCGLinearOpenCompactCLHash_RangeQuery(tableData,\n" | |
| 6220 | " numQueries,\n" | |
| 6221 | " numKeys,\n" | |
| 6222 | " keys,\n" | |
| 6223 | " valuesOutput);\n" | |
| 6224 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6225 | " return intintLCGQuadraticOpenCompactCLHash_RangeQuery(tableData,\n" | |
| 6226 | " numQueries,\n" | |
| 6227 | " numKeys,\n" | |
| 6228 | " keys,\n" | |
| 6229 | " valuesOutput);\n" | |
| 6230 | " }\n" | |
| 6231 | "}\n" | |
| 6232 | "__kernel void intintHash_RangeQuerySingle(__global char *tableData,\n" | |
| 6233 | " unsigned int numQueries,\n" | |
| 6234 | " __global int *keys,\n" | |
| 6235 | " __global int *valueOutput) {\n" | |
| 6236 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6237 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6238 | " return intintIdentityPerfectCLHash_RangeQuerySingle(tableData,\n" | |
| 6239 | " numQueries,\n" | |
| 6240 | " keys,\n" | |
| 6241 | " valueOutput);\n" | |
| 6242 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6243 | " return\n" | |
| 6244 | " intintIdentitySentinelPerfectCLHash_RangeQuerySingle\n" | |
| 6245 | " (tableData, numQueries, keys, valueOutput);\n" | |
| 6246 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6247 | " return\n" | |
| 6248 | " intintLCGLinearOpenCompactCLHash_RangeQuerySingle(tableData,\n" | |
| 6249 | " numQueries,\n" | |
| 6250 | " keys,\n" | |
| 6251 | " valueOutput);\n" | |
| 6252 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6253 | " return\n" | |
| 6254 | " intintLCGQuadraticOpenCompactCLHash_RangeQuerySingle\n" | |
| 6255 | " (tableData, numQueries, keys, valueOutput);\n" | |
| 6256 | " }\n" | |
| 6257 | "}\n" | |
| 6258 | "__kernel void intintHash_RangeInsert(__global char *tableData,\n" | |
| 6259 | " unsigned int numInsertions,\n" | |
| 6260 | " unsigned int numEntries,\n" | |
| 6261 | " __global int *keys, __global int *values) {\n" | |
| 6262 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6263 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6264 | " return intintIdentityPerfectCLHash_RangeInsert(tableData,\n" | |
| 6265 | " numInsertions,\n" | |
| 6266 | " numEntries, keys,\n" | |
| 6267 | " values);\n" | |
| 6268 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6269 | " return\n" | |
| 6270 | " intintIdentitySentinelPerfectCLHash_RangeInsert(tableData,\n" | |
| 6271 | " numInsertions,\n" | |
| 6272 | " numEntries,\n" | |
| 6273 | " keys,\n" | |
| 6274 | " values);\n" | |
| 6275 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6276 | " return intintLCGLinearOpenCompactCLHash_RangeInsert(tableData,\n" | |
| 6277 | " numInsertions,\n" | |
| 6278 | " numEntries,\n" | |
| 6279 | " keys,\n" | |
| 6280 | " values);\n" | |
| 6281 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6282 | " return\n" | |
| 6283 | " intintLCGQuadraticOpenCompactCLHash_RangeInsert(tableData,\n" | |
| 6284 | " numInsertions,\n" | |
| 6285 | " numEntries,\n" | |
| 6286 | " keys,\n" | |
| 6287 | " values);\n" | |
| 6288 | " }\n" | |
| 6289 | "}\n" | |
| 6290 | "__kernel void intintHash_RangeInsertSingle(__global char *tableData,\n" | |
| 6291 | " unsigned int numInsertions,\n" | |
| 6292 | " __global int *keys,\n" | |
| 6293 | " __global int *values) {\n" | |
| 6294 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6295 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6296 | " return intintIdentityPerfectCLHash_RangeInsertSingle(tableData,\n" | |
| 6297 | " numInsertions,\n" | |
| 6298 | " keys,\n" | |
| 6299 | " values);\n" | |
| 6300 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6301 | " return\n" | |
| 6302 | " intintIdentitySentinelPerfectCLHash_RangeInsertSingle\n" | |
| 6303 | " (tableData, numInsertions, keys, values);\n" | |
| 6304 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6305 | " return\n" | |
| 6306 | " intintLCGLinearOpenCompactCLHash_RangeInsertSingle\n" | |
| 6307 | " (tableData, numInsertions, keys, values);\n" | |
| 6308 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6309 | " return\n" | |
| 6310 | " intintLCGQuadraticOpenCompactCLHash_RangeInsertSingle\n" | |
| 6311 | " (tableData, numInsertions, keys, values);\n" | |
| 6312 | " }\n" | |
| 6313 | "}\n" | |
| 6314 | "__kernel void intintHash_RangeInsertNoOverwrite(__global char *tableData,\n" | |
| 6315 | " unsigned int numInsertions,\n" | |
| 6316 | " unsigned int numEntries,\n" | |
| 6317 | " __global int *keys,\n" | |
| 6318 | " __global int *values) {\n" | |
| 6319 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6320 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6321 | " return\n" | |
| 6322 | " intintIdentityPerfectCLHash_RangeInsertNoOverwrite\n" | |
| 6323 | " (tableData, numInsertions, numEntries, keys, values);\n" | |
| 6324 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6325 | " return\n" | |
| 6326 | " intintIdentitySentinelPerfectCLHash_RangeInsertNoOverwrite\n" | |
| 6327 | " (tableData, numInsertions, numEntries, keys, values);\n" | |
| 6328 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6329 | " return\n" | |
| 6330 | " intintLCGLinearOpenCompactCLHash_RangeInsertNoOverwrite\n" | |
| 6331 | " (tableData, numInsertions, numEntries, keys, values);\n" | |
| 6332 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6333 | " return\n" | |
| 6334 | " intintLCGQuadraticOpenCompactCLHash_RangeInsertNoOverwrite\n" | |
| 6335 | " (tableData, numInsertions, numEntries, keys, values);\n" | |
| 6336 | " }\n" | |
| 6337 | "}\n" | |
| 6338 | "__kernel void intintHash_RangeInsertSingleNoOverwrite(__global char *tableData,\n" | |
| 6339 | " unsigned int\n" | |
| 6340 | " numInsertions,\n" | |
| 6341 | " __global int *keys,\n" | |
| 6342 | " __global int *values) {\n" | |
| 6343 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6344 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6345 | " return\n" | |
| 6346 | " intintIdentityPerfectCLHash_RangeInsertSingleNoOverwrite\n" | |
| 6347 | " (tableData, numInsertions, keys, values);\n" | |
| 6348 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6349 | " return\n" | |
| 6350 | " intintIdentitySentinelPerfectCLHash_RangeInsertSingleNoOverwrite\n" | |
| 6351 | " (tableData, numInsertions, keys, values);\n" | |
| 6352 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6353 | " return\n" | |
| 6354 | " intintLCGLinearOpenCompactCLHash_RangeInsertSingleNoOverwrite\n" | |
| 6355 | " (tableData, numInsertions, keys, values);\n" | |
| 6356 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6357 | " return\n" | |
| 6358 | " intintLCGQuadraticOpenCompactCLHash_RangeInsertSingleNoOverwrite\n" | |
| 6359 | " (tableData, numInsertions, keys, values);\n" | |
| 6360 | " }\n" | |
| 6361 | "}\n" | |
| 6362 | "int intintHash_Query(__global char *tableData, unsigned int numKeys,\n" | |
| 6363 | " __global int *keys, __global int *valuesOutput) {\n" | |
| 6364 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6365 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6366 | " return intintIdentityPerfectCLHash_Query(tableData, numKeys,\n" | |
| 6367 | " keys, valuesOutput);\n" | |
| 6368 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6369 | " return intintIdentitySentinelPerfectCLHash_Query(tableData,\n" | |
| 6370 | " numKeys, keys,\n" | |
| 6371 | " valuesOutput);\n" | |
| 6372 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6373 | " return intintLCGLinearOpenCompactCLHash_Query(tableData,\n" | |
| 6374 | " numKeys, keys,\n" | |
| 6375 | " valuesOutput);\n" | |
| 6376 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6377 | " return intintLCGQuadraticOpenCompactCLHash_Query(tableData,\n" | |
| 6378 | " numKeys, keys,\n" | |
| 6379 | " valuesOutput);\n" | |
| 6380 | " }\n" | |
| 6381 | " return HASH_EXIT_CODE_ERROR;\n" | |
| 6382 | "}\n" | |
| 6383 | "int intintHash_QuerySingle(__global char *tableData, int key,\n" | |
| 6384 | " __global int *valueOutput) {\n" | |
| 6385 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6386 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6387 | " return intintIdentityPerfectCLHash_QuerySingle(tableData, key,\n" | |
| 6388 | " valueOutput);\n" | |
| 6389 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6390 | " return\n" | |
| 6391 | " intintIdentitySentinelPerfectCLHash_QuerySingle(tableData,\n" | |
| 6392 | " key,\n" | |
| 6393 | " valueOutput);\n" | |
| 6394 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6395 | " return intintLCGLinearOpenCompactCLHash_QuerySingle(tableData,\n" | |
| 6396 | " key,\n" | |
| 6397 | " valueOutput);\n" | |
| 6398 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6399 | " return\n" | |
| 6400 | " intintLCGQuadraticOpenCompactCLHash_QuerySingle(tableData,\n" | |
| 6401 | " key,\n" | |
| 6402 | " valueOutput);\n" | |
| 6403 | " }\n" | |
| 6404 | " return HASH_EXIT_CODE_ERROR;\n" | |
| 6405 | "}\n" | |
| 6406 | "int intintHash_Insert(__global char *tableData, unsigned int numEntries,\n" | |
| 6407 | " __global int *keys, __global int *values) {\n" | |
| 6408 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6409 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6410 | " return intintIdentityPerfectCLHash_Insert(tableData, numEntries,\n" | |
| 6411 | " keys, values);\n" | |
| 6412 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6413 | " return intintIdentitySentinelPerfectCLHash_Insert(tableData,\n" | |
| 6414 | " numEntries,\n" | |
| 6415 | " keys, values);\n" | |
| 6416 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6417 | " return intintLCGLinearOpenCompactCLHash_Insert(tableData,\n" | |
| 6418 | " numEntries, keys,\n" | |
| 6419 | " values);\n" | |
| 6420 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6421 | " return intintLCGQuadraticOpenCompactCLHash_Insert(tableData,\n" | |
| 6422 | " numEntries,\n" | |
| 6423 | " keys, values);\n" | |
| 6424 | " }\n" | |
| 6425 | " return HASH_EXIT_CODE_ERROR;\n" | |
| 6426 | "}\n" | |
| 6427 | "int intintHash_InsertSingle(__global char *tableData, int key, int value) {\n" | |
| 6428 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6429 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6430 | " return intintIdentityPerfectCLHash_InsertSingle(tableData, key,\n" | |
| 6431 | " value);\n" | |
| 6432 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6433 | " return\n" | |
| 6434 | " intintIdentitySentinelPerfectCLHash_InsertSingle(tableData,\n" | |
| 6435 | " key,\n" | |
| 6436 | " value);\n" | |
| 6437 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6438 | " return intintLCGLinearOpenCompactCLHash_InsertSingle(tableData,\n" | |
| 6439 | " key,\n" | |
| 6440 | " value);\n" | |
| 6441 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6442 | " return\n" | |
| 6443 | " intintLCGQuadraticOpenCompactCLHash_InsertSingle(tableData,\n" | |
| 6444 | " key,\n" | |
| 6445 | " value);\n" | |
| 6446 | " }\n" | |
| 6447 | " return HASH_EXIT_CODE_ERROR;\n" | |
| 6448 | "}\n" | |
| 6449 | "int intintHash_InsertNoOverwrite(__global char *tableData,\n" | |
| 6450 | " unsigned int numEntries, __global int *keys,\n" | |
| 6451 | " __global int *values) {\n" | |
| 6452 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6453 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6454 | " return intintIdentityPerfectCLHash_InsertNoOverwrite(tableData,\n" | |
| 6455 | " numEntries,\n" | |
| 6456 | " keys,\n" | |
| 6457 | " values);\n" | |
| 6458 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6459 | " return\n" | |
| 6460 | " intintIdentitySentinelPerfectCLHash_InsertNoOverwrite\n" | |
| 6461 | " (tableData, numEntries, keys, values);\n" | |
| 6462 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6463 | " return\n" | |
| 6464 | " intintLCGLinearOpenCompactCLHash_InsertNoOverwrite\n" | |
| 6465 | " (tableData, numEntries, keys, values);\n" | |
| 6466 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6467 | " return\n" | |
| 6468 | " intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite\n" | |
| 6469 | " (tableData, numEntries, keys, values);\n" | |
| 6470 | " }\n" | |
| 6471 | " return HASH_EXIT_CODE_ERROR;\n" | |
| 6472 | "}\n" | |
| 6473 | "int intintHash_InsertSingleNoOverwrite(__global char *tableData, int key,\n" | |
| 6474 | " int value) {\n" | |
| 6475 | " switch (((__global int *)tableData)[0]) {\n" | |
| 6476 | " case IDENTITY_PERFECT_CL_HASH_ID:\n" | |
| 6477 | " return\n" | |
| 6478 | " intintIdentityPerfectCLHash_InsertSingleNoOverwrite\n" | |
| 6479 | " (tableData, key, value);\n" | |
| 6480 | " case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID:\n" | |
| 6481 | " return\n" | |
| 6482 | " intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite\n" | |
| 6483 | " (tableData, key, value);\n" | |
| 6484 | " case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6485 | " return\n" | |
| 6486 | " intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite\n" | |
| 6487 | " (tableData, key, value);\n" | |
| 6488 | " case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID:\n" | |
| 6489 | " return\n" | |
| 6490 | " intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite\n" | |
| 6491 | " (tableData, key, value);\n" | |
| 6492 | " }\n" | |
| 6493 | " return HASH_EXIT_CODE_ERROR;\n" | |
| 6494 | "}\n" | |
| 6495 | ; |
| … | … | @@ -1,2348 +0,0 @@ |
| 1 | ||
| 2 | /* Copyright (C) 1991-2012 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public | |
| 7 | License as published by the Free Software Foundation; either | |
| 8 | version 2.1 of the License, or (at your option) any later version. | |
| 9 | ||
| 10 | The GNU C Library is distributed in the hope that it will be useful, | |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | Lesser General Public License for more details. | |
| 14 | ||
| 15 | You should have received a copy of the GNU Lesser General Public | |
| 16 | License along with the GNU C Library; if not, see | |
| 17 | <http://www.gnu.org/licenses/>. */ | |
| 18 | /* This header is separate from features.h so that the compiler can | |
| 19 | include it implicitly at the start of every compilation. It must | |
| 20 | not itself include <features.h> or any other header that includes | |
| 21 | <features.h> because the implicit include comes before any feature | |
| 22 | test macros that may be defined in a source file before it first | |
| 23 | explicitly includes a system header. GCC knows the name of this | |
| 24 | header in order to preinclude it. */ | |
| 25 | /* We do support the IEC 559 math functionality, real and complex. */ | |
| 26 | /* wchar_t uses ISO/IEC 10646 (2nd ed., published 2011-03-15) / | |
| 27 | Unicode 6.0. */ | |
| 28 | /* We do not support C11 <threads.h>. */ | |
| 29 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 30 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 31 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 32 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 33 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 34 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 35 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 36 | * to produce derivative works, such modified software should be clearly marked, | |
| 37 | * so as not to confuse it with the version available from LANL. | |
| 38 | * | |
| 39 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 40 | * use this file except in compliance with the License. You may obtain a copy | |
| 41 | * of the License at | |
| 42 | * | |
| 43 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 44 | * | |
| 45 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 46 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 47 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 48 | * specific language governing permissions and limitations under the License. | |
| 49 | * | |
| 50 | * Under this license, it is required to include a reference to this work. We | |
| 51 | * request that each derivative work contain a reference to LANL Copyright | |
| 52 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 53 | * measured. In addition, it is requested that a modifier is included as in | |
| 54 | * the following example: | |
| 55 | * | |
| 56 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 57 | * | |
| 58 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 59 | */ | |
| 60 | int intintIdentityPerfectCLHash_InsertSingle(__global char *tableData, | |
| 61 | int key, int value); | |
| 62 | int intintIdentityPerfectCLHash_InnerInsertSingle(__global char *tableData, | |
| 63 | int key, int value); | |
| 64 | int intintHash_InsertSingle(__global char *tableData, int key, int value); | |
| 65 | int intintIdentityPerfectCLHash_InnerQuery(__global char *tableData, | |
| 66 | unsigned int numKeys, | |
| 67 | __global int *keys, | |
| 68 | __global int *valuesOutput); | |
| 69 | int intintIdentityPerfectCLHash_InnerQuerySingle(__global char *tableData, | |
| 70 | int key, | |
| 71 | __global int *valueOutput); | |
| 72 | int intintIdentityPerfectCLHash_InnerInsert(__global char *tableData, | |
| 73 | unsigned int numEntries, | |
| 74 | __global int *keys, | |
| 75 | __global int *values); | |
| 76 | int intintIdentityPerfectCLHash_InnerInsertSingleNoOverwrite(__global char | |
| 77 | *tableData, | |
| 78 | int key, | |
| 79 | int value); | |
| 80 | int intintIdentityPerfectCLHash_InnerInsertNoOverwrite(__global char *tableData, | |
| 81 | unsigned int numEntries, | |
| 82 | __global int *keys, | |
| 83 | __global int *values); | |
| 84 | int intintIdentityPerfectCLHash_QuerySingle(__global char *tableData, int key, | |
| 85 | __global int *valueOutput); | |
| 86 | int intintIdentityPerfectCLHash_QuerySingle(__global char *tableData, int key, | |
| 87 | __global int *valueOutput); | |
| 88 | int intintIdentityPerfectCLHash_Query(__global char *tableData, size_t numKeys, | |
| 89 | __global int *keys, | |
| 90 | __global int *valuesOutput); | |
| 91 | int intintIdentityPerfectCLHash_Insert(__global char *tableData, | |
| 92 | size_t numEntries, __global int *keys, | |
| 93 | __global int *values); | |
| 94 | int intintIdentityPerfectCLHash_InsertSingleNoOverwrite(__global char | |
| 95 | *tableData, int key, | |
| 96 | int value); | |
| 97 | int intintIdentityPerfectCLHash_InsertNoOverwrite(__global char *tableData, | |
| 98 | size_t numEntries, | |
| 99 | __global int *keys, | |
| 100 | __global int *values); | |
| 101 | int intintIdentitySentinelPerfectCLHash_InnerInsertNoOverwrite(__global char | |
| 102 | *tableData, | |
| 103 | unsigned int | |
| 104 | numEntries, | |
| 105 | __global int | |
| 106 | *keys, | |
| 107 | __global int | |
| 108 | *values); | |
| 109 | int intintIdentitySentinelPerfectCLHash_InnerQuerySingle(__global char | |
| 110 | *tableData, int key, | |
| 111 | __global int | |
| 112 | *valueOutput); | |
| 113 | int intintIdentitySentinelPerfectCLHash_InnerQuery(__global char *tableData, | |
| 114 | unsigned int numKeys, | |
| 115 | __global int *keys, | |
| 116 | __global int *valuesOutput); | |
| 117 | int intintIdentitySentinelPerfectCLHash_InnerInsertSingle(__global char | |
| 118 | *tableData, int key, | |
| 119 | int value); | |
| 120 | int intintIdentitySentinelPerfectCLHash_InnerInsert(__global char *tableData, | |
| 121 | unsigned int numEntries, | |
| 122 | __global int *keys, | |
| 123 | __global int *values); | |
| 124 | int intintIdentitySentinelPerfectCLHash_InnerInsertSingleNoOverwrite(__global | |
| 125 | char | |
| 126 | *tableData, | |
| 127 | int key, | |
| 128 | int value); | |
| 129 | int intintIdentitySentinelPerfectCLHash_QuerySingle(__global char *tableData, | |
| 130 | int key, | |
| 131 | __global int *valueOutput); | |
| 132 | int intintIdentitySentinelPerfectCLHash_Query(__global char *tableData, | |
| 133 | size_t numKeys, | |
| 134 | __global int *keys, | |
| 135 | __global int *valuesOutput); | |
| 136 | int intintIdentitySentinelPerfectCLHash_InsertSingle(__global char *tableData, | |
| 137 | int key, int value); | |
| 138 | int intintIdentitySentinelPerfectCLHash_Insert(__global char *tableData, | |
| 139 | size_t numEntries, | |
| 140 | __global int *keys, | |
| 141 | __global int *values); | |
| 142 | int intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite(__global char | |
| 143 | *tableData, | |
| 144 | int key, | |
| 145 | int value); | |
| 146 | int intintIdentitySentinelPerfectCLHash_InsertNoOverwrite(__global char | |
| 147 | *tableData, | |
| 148 | size_t numEntries, | |
| 149 | __global int *keys, | |
| 150 | __global int *values); | |
| 151 | int intintLCGLinearOpenCompactCLHash_InnerQuerySingle(__global char *tableData, | |
| 152 | int key, | |
| 153 | __global int | |
| 154 | *valueOutput); | |
| 155 | int intintLCGLinearOpenCompactCLHash_QuerySingle(__global char *tableData, | |
| 156 | int key, | |
| 157 | __global int *valueOutput); | |
| 158 | int intintLCGLinearOpenCompactCLHash_Query(__global char *tableData, | |
| 159 | size_t numKeys, __global int *keys, | |
| 160 | __global int *valuesOutput); | |
| 161 | int intintLCGLinearOpenCompactCLHash_InsertSingle(__global char *tableData, | |
| 162 | int key, int value); | |
| 163 | int intintLCGLinearOpenCompactCLHash_Insert(__global char *tableData, | |
| 164 | size_t numEntries, | |
| 165 | __global int *keys, | |
| 166 | __global int *values); | |
| 167 | int intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite(__global char | |
| 168 | *tableData, | |
| 169 | int key, | |
| 170 | int value); | |
| 171 | int intintLCGLinearOpenCompactCLHash_InsertNoOverwrite(__global char *tableData, | |
| 172 | size_t numEntries, | |
| 173 | __global int *keys, | |
| 174 | __global int *values); | |
| 175 | int intintLCGLinearOpenCompactCLHash_InnerQuery(__global char *tableData, | |
| 176 | unsigned int numKeys, | |
| 177 | __global int *keys, | |
| 178 | __global int *valuesOutput); | |
| 179 | int intintLCGLinearOpenCompactCLHash_InnerInsertNoOverwrite(__global char | |
| 180 | *tableData, | |
| 181 | unsigned int | |
| 182 | numEntries, | |
| 183 | __global int *keys, | |
| 184 | __global int | |
| 185 | *values); | |
| 186 | int intintLCGLinearOpenCompactCLHash_InnerInsertSingle(__global char *tableData, | |
| 187 | int key, int value); | |
| 188 | int intintLCGLinearOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global char | |
| 189 | *tableData, | |
| 190 | int key, | |
| 191 | int value); | |
| 192 | int intintLCGLinearOpenCompactCLHash_InnerInsert(__global char *tableData, | |
| 193 | unsigned int numEntries, | |
| 194 | __global int *keys, | |
| 195 | __global int *values); | |
| 196 | int intintLCGQuadraticOpenCompactCLHash_InnerQuerySingle(__global char | |
| 197 | *tableData, int key, | |
| 198 | __global int | |
| 199 | *valueOutput); | |
| 200 | int intintLCGQuadraticOpenCompactCLHash_InnerQuery(__global char *tableData, | |
| 201 | unsigned int numKeys, | |
| 202 | __global int *keys, | |
| 203 | __global int *valuesOutput); | |
| 204 | int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingle(__global char | |
| 205 | *tableData, int key, | |
| 206 | int value); | |
| 207 | int intintLCGQuadraticOpenCompactCLHash_InnerInsert(__global char *tableData, | |
| 208 | unsigned int numEntries, | |
| 209 | __global int *keys, | |
| 210 | __global int *values); | |
| 211 | int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global | |
| 212 | char | |
| 213 | *tableData, | |
| 214 | int key, | |
| 215 | int value); | |
| 216 | int intintLCGQuadraticOpenCompactCLHash_InnerInsertNoOverwrite(__global char | |
| 217 | *tableData, | |
| 218 | unsigned int | |
| 219 | numEntries, | |
| 220 | __global int | |
| 221 | *keys, | |
| 222 | __global int | |
| 223 | *values); | |
| 224 | int intintLCGQuadraticOpenCompactCLHash_QuerySingle(__global char *tableData, | |
| 225 | int key, | |
| 226 | __global int *valueOutput); | |
| 227 | int intintLCGQuadraticOpenCompactCLHash_Query(__global char *tableData, | |
| 228 | size_t numKeys, | |
| 229 | __global int *keys, | |
| 230 | __global int *valuesOutput); | |
| 231 | int intintLCGQuadraticOpenCompactCLHash_InsertSingle(__global char *tableData, | |
| 232 | int key, int value); | |
| 233 | int intintLCGQuadraticOpenCompactCLHash_Insert(__global char *tableData, | |
| 234 | size_t numEntries, | |
| 235 | __global int *keys, | |
| 236 | __global int *values); | |
| 237 | int intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite(__global char | |
| 238 | *tableData, | |
| 239 | int key, | |
| 240 | int value); | |
| 241 | int intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite(__global char | |
| 242 | *tableData, | |
| 243 | size_t numEntries, | |
| 244 | __global int *keys, | |
| 245 | __global int *values); | |
| 246 | int intintHash_Query(__global char *tableData, unsigned int numKeys, | |
| 247 | __global int *keys, __global int *valuesOutput); | |
| 248 | int intintHash_QuerySingle(__global char *tableData, int key, | |
| 249 | __global int *valueOutput); | |
| 250 | int intintHash_Insert(__global char *tableData, unsigned int numEntries, | |
| 251 | __global int *keys, __global int *values); | |
| 252 | int intintHash_InsertNoOverwrite(__global char *tableData, | |
| 253 | unsigned int numEntries, __global int *keys, | |
| 254 | __global int *values); | |
| 255 | int intintHash_InsertSingleNoOverwrite(__global char *tableData, int key, | |
| 256 | int value); | |
| 257 | #define HASH_REPORT_NEVER /**/ 0 | |
| 258 | #define HASH_REPORT_CYCLE /**/ 1 | |
| 259 | #define HASH_REPORT_END /****/ 2 | |
| 260 | // | |
| 261 | #define HASH_EXIT_CODE_NORMAL /****************/ -1 | |
| 262 | #define HASH_EXIT_CODE_ERROR /*****************/ -2 | |
| 263 | #define HASH_EXIT_CODE_OVERWRITE /*************/ -3 | |
| 264 | #define HASH_EXIT_CODE_KEY_DNE /***************/ -4 | |
| 265 | #define HASH_EXIT_CODE_CYCLE /*****************/ -5 | |
| 266 | #define HASH_EXIT_CODE_MAX_ENTRIES_EXCEEDED /**/ -6 | |
| 267 | #define HASH_EXIT_CODE_BUCKET_INDEX_OOB /******/ -7 | |
| 268 | // | |
| 269 | #define HASH_SEARCH_CODE_MATCH /*****/ 0 | |
| 270 | #define HASH_SEARCH_CODE_MISMATCH /**/ 1 | |
| 271 | #define HASH_SEARCH_CODE_EMPTY /*****/ 2 | |
| 272 | // | |
| 273 | #define LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID /**/ 8 | |
| 274 | #define LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID /**/ 4 | |
| 275 | #define IDENTITY_SENTINEL_PERFECT_CL_HASH_ID /*******/ 2 | |
| 276 | #define IDENTITY_PERFECT_CL_HASH_ID /*******/ 1 | |
| 277 | // | |
| 278 | #define HASH_BUCKET_STATUS_EMPTY /**/ -1 | |
| 279 | #define HASH_BUCKET_STATUS_FULL /***/ -2 | |
| 280 | #define HASH_BUCKET_STATUS_LOCK /***/ -3 | |
| 281 | static inline unsigned int intintHash_CompressIdentity(char data, int hashCode) { | |
| 282 | return hashCode; | |
| 283 | } | |
| 284 | ||
| 285 | typedef struct intintHash_CompressLCGData { | |
| 286 | long unsigned int a; | |
| 287 | long unsigned int c; | |
| 288 | unsigned int m; | |
| 289 | unsigned int n; | |
| 290 | } intintHash_CompressLCGData; | |
| 291 | static inline unsigned int intintHash_CompressLCG(intintHash_CompressLCGData | |
| 292 | compressLCGData, | |
| 293 | int hashCode) { | |
| 294 | return ((compressLCGData.a * hashCode + | |
| 295 | compressLCGData.c) % compressLCGData.m) % compressLCGData.n; | |
| 296 | } | |
| 297 | ||
| 298 | typedef struct intintIdentityPerfectCLHash_TableData { | |
| 299 | int hashID; | |
| 300 | unsigned int numBuckets; | |
| 301 | char compressFuncData; | |
| 302 | } intintIdentityPerfectCLHash_TableData; | |
| 303 | typedef struct intintIdentityPerfectCLHash_Bucket { | |
| 304 | int key; | |
| 305 | int value; | |
| 306 | } intintIdentityPerfectCLHash_Bucket; | |
| 307 | int intintIdentityPerfectCLHash_InnerQuerySingle(__global char *tableData, | |
| 308 | int key, | |
| 309 | __global int *valueOutput) { | |
| 310 | __global intintIdentityPerfectCLHash_Bucket *buckets = | |
| 311 | (__global intintIdentityPerfectCLHash_Bucket *) & | |
| 312 | tableData[sizeof(intintIdentityPerfectCLHash_TableData)]; | |
| 313 | int index; | |
| 314 | int exitCode; | |
| 315 | index = | |
| 316 | intintHash_CompressIdentity(((__global | |
| 317 | intintIdentityPerfectCLHash_TableData | |
| 318 | *) tableData)->compressFuncData, key); | |
| 319 | if ((buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 320 | if (key == buckets[index].key) { | |
| 321 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 322 | } else { | |
| 323 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 324 | } | |
| 325 | } else { | |
| 326 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 327 | } | |
| 328 | switch (exitCode) { | |
| 329 | case HASH_SEARCH_CODE_MATCH: | |
| 330 | *valueOutput = buckets[index].value; | |
| 331 | return HASH_EXIT_CODE_NORMAL; | |
| 332 | case HASH_SEARCH_CODE_MISMATCH: | |
| 333 | case HASH_SEARCH_CODE_EMPTY: | |
| 334 | return HASH_EXIT_CODE_KEY_DNE; | |
| 335 | default: | |
| 336 | return exitCode; | |
| 337 | } | |
| 338 | } | |
| 339 | int intintIdentityPerfectCLHash_InnerQuery(__global char *tableData, | |
| 340 | unsigned int numKeys, | |
| 341 | __global int *keys, | |
| 342 | __global int *valuesOutput) { | |
| 343 | __global intintIdentityPerfectCLHash_Bucket *buckets = | |
| 344 | (__global intintIdentityPerfectCLHash_Bucket *) & | |
| 345 | tableData[sizeof(intintIdentityPerfectCLHash_TableData)]; | |
| 346 | int key; | |
| 347 | __global int *valueOutput; | |
| 348 | int index; | |
| 349 | int exitCode; | |
| 350 | uint i; | |
| 351 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 352 | for (i = 0; i < numKeys; i++) { | |
| 353 | key = keys[i]; | |
| 354 | valueOutput = &valuesOutput[i]; | |
| 355 | index = | |
| 356 | intintHash_CompressIdentity(((__global | |
| 357 | intintIdentityPerfectCLHash_TableData | |
| 358 | *) tableData)-> | |
| 359 | compressFuncData, key); | |
| 360 | if ((buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 361 | if (key == buckets[index].key) { | |
| 362 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 363 | } else { | |
| 364 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 365 | } | |
| 366 | } else { | |
| 367 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 368 | } | |
| 369 | switch (exitCode) { | |
| 370 | case HASH_SEARCH_CODE_MATCH: | |
| 371 | *valueOutput = buckets[index].value; | |
| 372 | break; | |
| 373 | case HASH_SEARCH_CODE_MISMATCH: | |
| 374 | case HASH_SEARCH_CODE_EMPTY: | |
| 375 | resultExitCode = HASH_EXIT_CODE_KEY_DNE; | |
| 376 | break; | |
| 377 | default: | |
| 378 | return exitCode; | |
| 379 | } | |
| 380 | } | |
| 381 | return resultExitCode; | |
| 382 | } | |
| 383 | int intintIdentityPerfectCLHash_InnerInsertSingle(__global char *tableData, | |
| 384 | int key, int value) { | |
| 385 | __global intintIdentityPerfectCLHash_Bucket *buckets = | |
| 386 | (__global intintIdentityPerfectCLHash_Bucket *) & | |
| 387 | tableData[sizeof(intintIdentityPerfectCLHash_TableData)]; | |
| 388 | int index; | |
| 389 | int exitCode; | |
| 390 | index = | |
| 391 | intintHash_CompressIdentity(((__global | |
| 392 | intintIdentityPerfectCLHash_TableData | |
| 393 | *) tableData)->compressFuncData, key); | |
| 394 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 395 | buckets[index]. | |
| 396 | key = key; | |
| 397 | HASH_BUCKET_STATUS_EMPTY;} | |
| 398 | ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 399 | if (key == buckets[index].key) { | |
| 400 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 401 | } else { | |
| 402 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 403 | } | |
| 404 | } else { | |
| 405 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 406 | } | |
| 407 | switch (exitCode) { | |
| 408 | case HASH_SEARCH_CODE_MATCH: | |
| 409 | case HASH_SEARCH_CODE_MISMATCH: | |
| 410 | buckets[index].value = value; | |
| 411 | return HASH_EXIT_CODE_OVERWRITE; | |
| 412 | case HASH_SEARCH_CODE_EMPTY: | |
| 413 | buckets[index].value = value; | |
| 414 | return HASH_EXIT_CODE_NORMAL; | |
| 415 | default: | |
| 416 | return exitCode; | |
| 417 | } | |
| 418 | } | |
| 419 | int intintIdentityPerfectCLHash_InnerInsert(__global char *tableData, | |
| 420 | unsigned int numEntries, | |
| 421 | __global int *keys, | |
| 422 | __global int *values) { | |
| 423 | __global intintIdentityPerfectCLHash_Bucket *buckets = | |
| 424 | (__global intintIdentityPerfectCLHash_Bucket *) & | |
| 425 | tableData[sizeof(intintIdentityPerfectCLHash_TableData)]; | |
| 426 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 427 | int key; | |
| 428 | int value; | |
| 429 | int index; | |
| 430 | int exitCode; | |
| 431 | uint i; | |
| 432 | for (i = 0; i < numEntries; i++) { | |
| 433 | key = keys[i]; | |
| 434 | index = | |
| 435 | intintHash_CompressIdentity(((__global | |
| 436 | intintIdentityPerfectCLHash_TableData | |
| 437 | *) tableData)-> | |
| 438 | compressFuncData, key); | |
| 439 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 440 | buckets | |
| 441 | [index]. | |
| 442 | key = | |
| 443 | key; | |
| 444 | HASH_BUCKET_STATUS_EMPTY;} | |
| 445 | ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 446 | if (key == buckets[index].key) { | |
| 447 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 448 | } else { | |
| 449 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 450 | } | |
| 451 | } else { | |
| 452 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 453 | } | |
| 454 | switch (exitCode) { | |
| 455 | case HASH_SEARCH_CODE_MATCH: | |
| 456 | case HASH_SEARCH_CODE_MISMATCH: | |
| 457 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 458 | case HASH_SEARCH_CODE_EMPTY: | |
| 459 | buckets[index].value = values[i]; | |
| 460 | break; | |
| 461 | default: | |
| 462 | return exitCode; | |
| 463 | } | |
| 464 | } | |
| 465 | return resultExitCode; | |
| 466 | } | |
| 467 | int intintIdentityPerfectCLHash_InnerInsertSingleNoOverwrite(__global char | |
| 468 | *tableData, | |
| 469 | int key, | |
| 470 | int value) { | |
| 471 | __global intintIdentityPerfectCLHash_Bucket *buckets = | |
| 472 | (__global intintIdentityPerfectCLHash_Bucket *) & | |
| 473 | tableData[sizeof(intintIdentityPerfectCLHash_TableData)]; | |
| 474 | int index; | |
| 475 | int exitCode; | |
| 476 | index = | |
| 477 | intintHash_CompressIdentity(((__global | |
| 478 | intintIdentityPerfectCLHash_TableData | |
| 479 | *) tableData)->compressFuncData, key); | |
| 480 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 481 | buckets[index]. | |
| 482 | key = key; | |
| 483 | HASH_BUCKET_STATUS_EMPTY;} | |
| 484 | ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 485 | if (key == buckets[index].key) { | |
| 486 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 487 | } else { | |
| 488 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 489 | } | |
| 490 | } else { | |
| 491 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 492 | } | |
| 493 | switch (exitCode) { | |
| 494 | case HASH_SEARCH_CODE_MATCH: | |
| 495 | case HASH_SEARCH_CODE_MISMATCH: | |
| 496 | return HASH_EXIT_CODE_OVERWRITE; | |
| 497 | case HASH_SEARCH_CODE_EMPTY: | |
| 498 | buckets[index].value = value; | |
| 499 | return HASH_EXIT_CODE_NORMAL; | |
| 500 | default: | |
| 501 | return exitCode; | |
| 502 | } | |
| 503 | } | |
| 504 | int intintIdentityPerfectCLHash_InnerInsertNoOverwrite(__global char *tableData, | |
| 505 | unsigned int numEntries, | |
| 506 | __global int *keys, | |
| 507 | __global int *values) { | |
| 508 | __global intintIdentityPerfectCLHash_Bucket *buckets = | |
| 509 | (__global intintIdentityPerfectCLHash_Bucket *) & | |
| 510 | tableData[sizeof(intintIdentityPerfectCLHash_TableData)]; | |
| 511 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 512 | int key; | |
| 513 | int value; | |
| 514 | int index; | |
| 515 | int exitCode; | |
| 516 | uint i; | |
| 517 | for (i = 0; i < numEntries; i++) { | |
| 518 | key = keys[i]; | |
| 519 | index = | |
| 520 | intintHash_CompressIdentity(((__global | |
| 521 | intintIdentityPerfectCLHash_TableData | |
| 522 | *) tableData)-> | |
| 523 | compressFuncData, key); | |
| 524 | if (((buckets[index].key == HASH_BUCKET_STATUS_EMPTY) ? ( { | |
| 525 | buckets | |
| 526 | [index]. | |
| 527 | key = | |
| 528 | key; | |
| 529 | HASH_BUCKET_STATUS_EMPTY;} | |
| 530 | ): buckets[index].key) != HASH_BUCKET_STATUS_EMPTY) { | |
| 531 | if (key == buckets[index].key) { | |
| 532 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 533 | } else { | |
| 534 | exitCode = HASH_SEARCH_CODE_MISMATCH; | |
| 535 | } | |
| 536 | } else { | |
| 537 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 538 | } | |
| 539 | switch (exitCode) { | |
| 540 | case HASH_SEARCH_CODE_MATCH: | |
| 541 | case HASH_SEARCH_CODE_MISMATCH: | |
| 542 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 543 | break; | |
| 544 | case HASH_SEARCH_CODE_EMPTY: | |
| 545 | buckets[index].value = values[i]; | |
| 546 | break; | |
| 547 | default: | |
| 548 | return exitCode; | |
| 549 | } | |
| 550 | } | |
| 551 | return resultExitCode; | |
| 552 | } | |
| 553 | int intintIdentityPerfectCLHash_QuerySingle(__global char *tableData, int key, | |
| 554 | __global int *valueOutput) { | |
| 555 | return intintIdentityPerfectCLHash_InnerQuerySingle(tableData, key, | |
| 556 | valueOutput); | |
| 557 | } | |
| 558 | int intintIdentityPerfectCLHash_Query(__global char *tableData, size_t numKeys, | |
| 559 | __global int *keys, | |
| 560 | __global int *valuesOutput) { | |
| 561 | return intintIdentityPerfectCLHash_InnerQuery(tableData, numKeys, keys, | |
| 562 | valuesOutput); | |
| 563 | } | |
| 564 | int intintIdentityPerfectCLHash_InsertSingle(__global char *tableData, int key, | |
| 565 | int value) { | |
| 566 | return intintIdentityPerfectCLHash_InnerInsertSingle(tableData, key, | |
| 567 | value); | |
| 568 | } | |
| 569 | int intintIdentityPerfectCLHash_Insert(__global char *tableData, | |
| 570 | size_t numEntries, __global int *keys, | |
| 571 | __global int *values) { | |
| 572 | return intintIdentityPerfectCLHash_InnerInsert(tableData, numEntries, | |
| 573 | keys, values); | |
| 574 | } | |
| 575 | int intintIdentityPerfectCLHash_InsertSingleNoOverwrite(__global char | |
| 576 | *tableData, int key, | |
| 577 | int value) { | |
| 578 | return | |
| 579 | intintIdentityPerfectCLHash_InnerInsertSingleNoOverwrite(tableData, | |
| 580 | key, | |
| 581 | value); | |
| 582 | } | |
| 583 | int intintIdentityPerfectCLHash_InsertNoOverwrite(__global char *tableData, | |
| 584 | size_t numEntries, | |
| 585 | __global int *keys, | |
| 586 | __global int *values) { | |
| 587 | return intintIdentityPerfectCLHash_InnerInsertNoOverwrite(tableData, | |
| 588 | numEntries, | |
| 589 | keys, values); | |
| 590 | } | |
| 591 | __kernel void intintIdentityPerfectCLHash_RangeQuerySingle(__global char | |
| 592 | *tableData, | |
| 593 | unsigned int | |
| 594 | numQueries, | |
| 595 | __global int *keys, | |
| 596 | __global int | |
| 597 | *valuesOutput) { | |
| 598 | uint i = get_global_id(0); | |
| 599 | if (i >= numQueries) { | |
| 600 | return; | |
| 601 | } | |
| 602 | intintIdentityPerfectCLHash_InnerQuerySingle(tableData, keys[i], | |
| 603 | valuesOutput + i); | |
| 604 | } | |
| 605 | __kernel void intintIdentityPerfectCLHash_RangeQuery(__global char *tableData, | |
| 606 | unsigned int numQueries, | |
| 607 | unsigned int numKeys, | |
| 608 | __global int *keys, | |
| 609 | __global int | |
| 610 | *valuesOutput) { | |
| 611 | uint i = get_global_id(0); | |
| 612 | if (i >= numQueries) { | |
| 613 | return; | |
| 614 | } | |
| 615 | intintIdentityPerfectCLHash_InnerQuery(tableData, numKeys, | |
| 616 | keys + (i * numKeys), | |
| 617 | valuesOutput + (i * numKeys)); | |
| 618 | } | |
| 619 | __kernel void intintIdentityPerfectCLHash_RangeInsertSingle(__global char | |
| 620 | *tableData, | |
| 621 | unsigned int | |
| 622 | numInsertions, | |
| 623 | __global int *keys, | |
| 624 | __global int | |
| 625 | *values) { | |
| 626 | uint i = get_global_id(0); | |
| 627 | if (i >= numInsertions) { | |
| 628 | return; | |
| 629 | } | |
| 630 | intintIdentityPerfectCLHash_InnerInsertSingle(tableData, keys[i], | |
| 631 | values[i]); | |
| 632 | } | |
| 633 | __kernel void intintIdentityPerfectCLHash_RangeInsert(__global char *tableData, | |
| 634 | unsigned int | |
| 635 | numInsertions, | |
| 636 | unsigned int numEntries, | |
| 637 | __global int *keys, | |
| 638 | __global int *values) { | |
| 639 | uint i = get_global_id(0); | |
| 640 | if (i >= numInsertions) { | |
| 641 | return; | |
| 642 | } | |
| 643 | intintIdentityPerfectCLHash_InnerInsert(tableData, numEntries, | |
| 644 | keys + (i * numEntries), | |
| 645 | values + (i * numEntries)); | |
| 646 | } | |
| 647 | __kernel void intintIdentityPerfectCLHash_RangeInsertSingleNoOverwrite(__global | |
| 648 | char | |
| 649 | *tableData, | |
| 650 | unsigned | |
| 651 | int | |
| 652 | numInsertions, | |
| 653 | __global | |
| 654 | int | |
| 655 | *keys, | |
| 656 | __global | |
| 657 | int | |
| 658 | *values) | |
| 659 | { | |
| 660 | uint i = get_global_id(0); | |
| 661 | if (i >= numInsertions) { | |
| 662 | return; | |
| 663 | } | |
| 664 | intintIdentityPerfectCLHash_InnerInsertSingleNoOverwrite(tableData, | |
| 665 | keys[i], | |
| 666 | values[i]); | |
| 667 | } | |
| 668 | __kernel void intintIdentityPerfectCLHash_RangeInsertNoOverwrite(__global char | |
| 669 | *tableData, | |
| 670 | unsigned int | |
| 671 | numInsertions, | |
| 672 | unsigned int | |
| 673 | numEntries, | |
| 674 | __global int | |
| 675 | *keys, | |
| 676 | __global int | |
| 677 | *values) { | |
| 678 | uint i = get_global_id(0); | |
| 679 | if (i >= numInsertions) { | |
| 680 | return; | |
| 681 | } | |
| 682 | intintIdentityPerfectCLHash_InnerInsertNoOverwrite(tableData, | |
| 683 | numEntries, | |
| 684 | keys + | |
| 685 | (i * numEntries), | |
| 686 | values + | |
| 687 | (i * numEntries)); | |
| 688 | } | |
| 689 | ||
| 690 | typedef struct intintIdentitySentinelPerfectCLHash_TableData { | |
| 691 | int hashID; | |
| 692 | unsigned int numBuckets; | |
| 693 | char compressFuncData; | |
| 694 | int emptyValue; | |
| 695 | } intintIdentitySentinelPerfectCLHash_TableData; | |
| 696 | typedef struct intintIdentitySentinelPerfectCLHash_Bucket { | |
| 697 | int value; | |
| 698 | } intintIdentitySentinelPerfectCLHash_Bucket; | |
| 699 | int intintIdentitySentinelPerfectCLHash_InnerQuerySingle(__global char | |
| 700 | *tableData, int key, | |
| 701 | __global int | |
| 702 | *valueOutput) { | |
| 703 | __global intintIdentitySentinelPerfectCLHash_Bucket *buckets = | |
| 704 | (__global intintIdentitySentinelPerfectCLHash_Bucket *) & | |
| 705 | tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)]; | |
| 706 | int index; | |
| 707 | int exitCode; | |
| 708 | index = | |
| 709 | intintHash_CompressIdentity(((__global | |
| 710 | intintIdentitySentinelPerfectCLHash_TableData | |
| 711 | *) tableData)->compressFuncData, key); | |
| 712 | if (buckets[index].value != | |
| 713 | ((__global intintIdentitySentinelPerfectCLHash_TableData *) | |
| 714 | tableData)->emptyValue) { | |
| 715 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 716 | } else { | |
| 717 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 718 | } | |
| 719 | switch (exitCode) { | |
| 720 | case HASH_SEARCH_CODE_MATCH: | |
| 721 | *valueOutput = buckets[index].value; | |
| 722 | return HASH_EXIT_CODE_NORMAL; | |
| 723 | case HASH_SEARCH_CODE_MISMATCH: | |
| 724 | case HASH_SEARCH_CODE_EMPTY: | |
| 725 | return HASH_EXIT_CODE_KEY_DNE; | |
| 726 | default: | |
| 727 | return exitCode; | |
| 728 | } | |
| 729 | } | |
| 730 | int intintIdentitySentinelPerfectCLHash_InnerQuery(__global char *tableData, | |
| 731 | unsigned int numKeys, | |
| 732 | __global int *keys, | |
| 733 | __global int *valuesOutput) { | |
| 734 | __global intintIdentitySentinelPerfectCLHash_Bucket *buckets = | |
| 735 | (__global intintIdentitySentinelPerfectCLHash_Bucket *) & | |
| 736 | tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)]; | |
| 737 | int key; | |
| 738 | __global int *valueOutput; | |
| 739 | int index; | |
| 740 | int exitCode; | |
| 741 | uint i; | |
| 742 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 743 | for (i = 0; i < numKeys; i++) { | |
| 744 | key = keys[i]; | |
| 745 | valueOutput = &valuesOutput[i]; | |
| 746 | index = | |
| 747 | intintHash_CompressIdentity(((__global | |
| 748 | intintIdentitySentinelPerfectCLHash_TableData | |
| 749 | *) tableData)-> | |
| 750 | compressFuncData, key); | |
| 751 | if (buckets[index].value != | |
| 752 | ((__global intintIdentitySentinelPerfectCLHash_TableData *) | |
| 753 | tableData)->emptyValue) { | |
| 754 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 755 | } else { | |
| 756 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 757 | } | |
| 758 | switch (exitCode) { | |
| 759 | case HASH_SEARCH_CODE_MATCH: | |
| 760 | *valueOutput = buckets[index].value; | |
| 761 | break; | |
| 762 | case HASH_SEARCH_CODE_MISMATCH: | |
| 763 | case HASH_SEARCH_CODE_EMPTY: | |
| 764 | resultExitCode = HASH_EXIT_CODE_KEY_DNE; | |
| 765 | break; | |
| 766 | default: | |
| 767 | return exitCode; | |
| 768 | } | |
| 769 | } | |
| 770 | return resultExitCode; | |
| 771 | } | |
| 772 | int intintIdentitySentinelPerfectCLHash_InnerInsertSingle(__global char | |
| 773 | *tableData, int key, | |
| 774 | int value) { | |
| 775 | __global intintIdentitySentinelPerfectCLHash_Bucket *buckets = | |
| 776 | (__global intintIdentitySentinelPerfectCLHash_Bucket *) & | |
| 777 | tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)]; | |
| 778 | int index; | |
| 779 | int exitCode; | |
| 780 | index = | |
| 781 | intintHash_CompressIdentity(((__global | |
| 782 | intintIdentitySentinelPerfectCLHash_TableData | |
| 783 | *) tableData)->compressFuncData, key); | |
| 784 | if (buckets[index].value != | |
| 785 | ((__global intintIdentitySentinelPerfectCLHash_TableData *) | |
| 786 | tableData)->emptyValue) { | |
| 787 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 788 | } else { | |
| 789 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 790 | } | |
| 791 | switch (exitCode) { | |
| 792 | case HASH_SEARCH_CODE_MATCH: | |
| 793 | case HASH_SEARCH_CODE_MISMATCH: | |
| 794 | buckets[index].value = value; | |
| 795 | return HASH_EXIT_CODE_OVERWRITE; | |
| 796 | case HASH_SEARCH_CODE_EMPTY: | |
| 797 | buckets[index].value = value; | |
| 798 | return HASH_EXIT_CODE_NORMAL; | |
| 799 | default: | |
| 800 | return exitCode; | |
| 801 | } | |
| 802 | } | |
| 803 | int intintIdentitySentinelPerfectCLHash_InnerInsert(__global char *tableData, | |
| 804 | unsigned int numEntries, | |
| 805 | __global int *keys, | |
| 806 | __global int *values) { | |
| 807 | __global intintIdentitySentinelPerfectCLHash_Bucket *buckets = | |
| 808 | (__global intintIdentitySentinelPerfectCLHash_Bucket *) & | |
| 809 | tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)]; | |
| 810 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 811 | int key; | |
| 812 | int value; | |
| 813 | int index; | |
| 814 | int exitCode; | |
| 815 | uint i; | |
| 816 | for (i = 0; i < numEntries; i++) { | |
| 817 | key = keys[i]; | |
| 818 | index = | |
| 819 | intintHash_CompressIdentity(((__global | |
| 820 | intintIdentitySentinelPerfectCLHash_TableData | |
| 821 | *) tableData)-> | |
| 822 | compressFuncData, key); | |
| 823 | if (buckets[index].value != | |
| 824 | ((__global intintIdentitySentinelPerfectCLHash_TableData *) | |
| 825 | tableData)->emptyValue) { | |
| 826 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 827 | } else { | |
| 828 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 829 | } | |
| 830 | switch (exitCode) { | |
| 831 | case HASH_SEARCH_CODE_MATCH: | |
| 832 | case HASH_SEARCH_CODE_MISMATCH: | |
| 833 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 834 | case HASH_SEARCH_CODE_EMPTY: | |
| 835 | buckets[index].value = values[i]; | |
| 836 | break; | |
| 837 | default: | |
| 838 | return exitCode; | |
| 839 | } | |
| 840 | } | |
| 841 | return resultExitCode; | |
| 842 | } | |
| 843 | int intintIdentitySentinelPerfectCLHash_InnerInsertSingleNoOverwrite(__global | |
| 844 | char | |
| 845 | *tableData, | |
| 846 | int key, | |
| 847 | int value) | |
| 848 | { | |
| 849 | __global intintIdentitySentinelPerfectCLHash_Bucket *buckets = | |
| 850 | (__global intintIdentitySentinelPerfectCLHash_Bucket *) & | |
| 851 | tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)]; | |
| 852 | int index; | |
| 853 | int exitCode; | |
| 854 | index = | |
| 855 | intintHash_CompressIdentity(((__global | |
| 856 | intintIdentitySentinelPerfectCLHash_TableData | |
| 857 | *) tableData)->compressFuncData, key); | |
| 858 | if (buckets[index].value != | |
| 859 | ((__global intintIdentitySentinelPerfectCLHash_TableData *) | |
| 860 | tableData)->emptyValue) { | |
| 861 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 862 | } else { | |
| 863 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 864 | } | |
| 865 | switch (exitCode) { | |
| 866 | case HASH_SEARCH_CODE_MATCH: | |
| 867 | case HASH_SEARCH_CODE_MISMATCH: | |
| 868 | return HASH_EXIT_CODE_OVERWRITE; | |
| 869 | case HASH_SEARCH_CODE_EMPTY: | |
| 870 | buckets[index].value = value; | |
| 871 | return HASH_EXIT_CODE_NORMAL; | |
| 872 | default: | |
| 873 | return exitCode; | |
| 874 | } | |
| 875 | } | |
| 876 | int intintIdentitySentinelPerfectCLHash_InnerInsertNoOverwrite(__global char | |
| 877 | *tableData, | |
| 878 | unsigned int | |
| 879 | numEntries, | |
| 880 | __global int | |
| 881 | *keys, | |
| 882 | __global int | |
| 883 | *values) { | |
| 884 | __global intintIdentitySentinelPerfectCLHash_Bucket *buckets = | |
| 885 | (__global intintIdentitySentinelPerfectCLHash_Bucket *) & | |
| 886 | tableData[sizeof(intintIdentitySentinelPerfectCLHash_TableData)]; | |
| 887 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 888 | int key; | |
| 889 | int value; | |
| 890 | int index; | |
| 891 | int exitCode; | |
| 892 | uint i; | |
| 893 | for (i = 0; i < numEntries; i++) { | |
| 894 | key = keys[i]; | |
| 895 | index = | |
| 896 | intintHash_CompressIdentity(((__global | |
| 897 | intintIdentitySentinelPerfectCLHash_TableData | |
| 898 | *) tableData)-> | |
| 899 | compressFuncData, key); | |
| 900 | if (buckets[index].value != | |
| 901 | ((__global intintIdentitySentinelPerfectCLHash_TableData *) | |
| 902 | tableData)->emptyValue) { | |
| 903 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 904 | } else { | |
| 905 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 906 | } | |
| 907 | switch (exitCode) { | |
| 908 | case HASH_SEARCH_CODE_MATCH: | |
| 909 | case HASH_SEARCH_CODE_MISMATCH: | |
| 910 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 911 | break; | |
| 912 | case HASH_SEARCH_CODE_EMPTY: | |
| 913 | buckets[index].value = values[i]; | |
| 914 | break; | |
| 915 | default: | |
| 916 | return exitCode; | |
| 917 | } | |
| 918 | } | |
| 919 | return resultExitCode; | |
| 920 | } | |
| 921 | int intintIdentitySentinelPerfectCLHash_QuerySingle(__global char *tableData, | |
| 922 | int key, | |
| 923 | __global int *valueOutput) { | |
| 924 | return intintIdentitySentinelPerfectCLHash_InnerQuerySingle(tableData, | |
| 925 | key, | |
| 926 | valueOutput); | |
| 927 | } | |
| 928 | int intintIdentitySentinelPerfectCLHash_Query(__global char *tableData, | |
| 929 | size_t numKeys, | |
| 930 | __global int *keys, | |
| 931 | __global int *valuesOutput) { | |
| 932 | return intintIdentitySentinelPerfectCLHash_InnerQuery(tableData, | |
| 933 | numKeys, keys, | |
| 934 | valuesOutput); | |
| 935 | } | |
| 936 | int intintIdentitySentinelPerfectCLHash_InsertSingle(__global char *tableData, | |
| 937 | int key, int value) { | |
| 938 | return intintIdentitySentinelPerfectCLHash_InnerInsertSingle(tableData, | |
| 939 | key, | |
| 940 | value); | |
| 941 | } | |
| 942 | int intintIdentitySentinelPerfectCLHash_Insert(__global char *tableData, | |
| 943 | size_t numEntries, | |
| 944 | __global int *keys, | |
| 945 | __global int *values) { | |
| 946 | return intintIdentitySentinelPerfectCLHash_InnerInsert(tableData, | |
| 947 | numEntries, keys, | |
| 948 | values); | |
| 949 | } | |
| 950 | int intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite(__global char | |
| 951 | *tableData, | |
| 952 | int key, | |
| 953 | int value) { | |
| 954 | return | |
| 955 | intintIdentitySentinelPerfectCLHash_InnerInsertSingleNoOverwrite | |
| 956 | (tableData, key, value); | |
| 957 | } | |
| 958 | int intintIdentitySentinelPerfectCLHash_InsertNoOverwrite(__global char | |
| 959 | *tableData, | |
| 960 | size_t numEntries, | |
| 961 | __global int *keys, | |
| 962 | __global int *values) | |
| 963 | { | |
| 964 | return | |
| 965 | intintIdentitySentinelPerfectCLHash_InnerInsertNoOverwrite | |
| 966 | (tableData, numEntries, keys, values); | |
| 967 | } | |
| 968 | __kernel void intintIdentitySentinelPerfectCLHash_RangeQuerySingle(__global char | |
| 969 | *tableData, | |
| 970 | unsigned int | |
| 971 | numQueries, | |
| 972 | __global int | |
| 973 | *keys, | |
| 974 | __global int | |
| 975 | *valuesOutput) | |
| 976 | { | |
| 977 | uint i = get_global_id(0); | |
| 978 | if (i >= numQueries) { | |
| 979 | return; | |
| 980 | } | |
| 981 | intintIdentitySentinelPerfectCLHash_InnerQuerySingle(tableData, keys[i], | |
| 982 | valuesOutput + i); | |
| 983 | } | |
| 984 | __kernel void intintIdentitySentinelPerfectCLHash_RangeQuery(__global char | |
| 985 | *tableData, | |
| 986 | unsigned int | |
| 987 | numQueries, | |
| 988 | unsigned int | |
| 989 | numKeys, | |
| 990 | __global int *keys, | |
| 991 | __global int | |
| 992 | *valuesOutput) { | |
| 993 | uint i = get_global_id(0); | |
| 994 | if (i >= numQueries) { | |
| 995 | return; | |
| 996 | } | |
| 997 | intintIdentitySentinelPerfectCLHash_InnerQuery(tableData, numKeys, | |
| 998 | keys + (i * numKeys), | |
| 999 | valuesOutput + | |
| 1000 | (i * numKeys)); | |
| 1001 | } | |
| 1002 | __kernel void intintIdentitySentinelPerfectCLHash_RangeInsertSingle(__global | |
| 1003 | char | |
| 1004 | *tableData, | |
| 1005 | unsigned int | |
| 1006 | numInsertions, | |
| 1007 | __global int | |
| 1008 | *keys, | |
| 1009 | __global int | |
| 1010 | *values) { | |
| 1011 | uint i = get_global_id(0); | |
| 1012 | if (i >= numInsertions) { | |
| 1013 | return; | |
| 1014 | } | |
| 1015 | intintIdentitySentinelPerfectCLHash_InnerInsertSingle(tableData, | |
| 1016 | keys[i], | |
| 1017 | values[i]); | |
| 1018 | } | |
| 1019 | __kernel void intintIdentitySentinelPerfectCLHash_RangeInsert(__global char | |
| 1020 | *tableData, | |
| 1021 | unsigned int | |
| 1022 | numInsertions, | |
| 1023 | unsigned int | |
| 1024 | numEntries, | |
| 1025 | __global int | |
| 1026 | *keys, | |
| 1027 | __global int | |
| 1028 | *values) { | |
| 1029 | uint i = get_global_id(0); | |
| 1030 | if (i >= numInsertions) { | |
| 1031 | return; | |
| 1032 | } | |
| 1033 | intintIdentitySentinelPerfectCLHash_InnerInsert(tableData, numEntries, | |
| 1034 | keys + (i * numEntries), | |
| 1035 | values + | |
| 1036 | (i * numEntries)); | |
| 1037 | } | |
| 1038 | __kernel void | |
| 1039 | intintIdentitySentinelPerfectCLHash_RangeInsertSingleNoOverwrite(__global char | |
| 1040 | *tableData, | |
| 1041 | unsigned int | |
| 1042 | numInsertions, | |
| 1043 | __global int | |
| 1044 | *keys, | |
| 1045 | __global int | |
| 1046 | *values) { | |
| 1047 | uint i = get_global_id(0); | |
| 1048 | if (i >= numInsertions) { | |
| 1049 | return; | |
| 1050 | } | |
| 1051 | intintIdentitySentinelPerfectCLHash_InnerInsertSingleNoOverwrite | |
| 1052 | (tableData, keys[i], values[i]); | |
| 1053 | } | |
| 1054 | __kernel void | |
| 1055 | intintIdentitySentinelPerfectCLHash_RangeInsertNoOverwrite(__global char | |
| 1056 | *tableData, | |
| 1057 | unsigned int | |
| 1058 | numInsertions, | |
| 1059 | unsigned int | |
| 1060 | numEntries, | |
| 1061 | __global int *keys, | |
| 1062 | __global int | |
| 1063 | *values) { | |
| 1064 | uint i = get_global_id(0); | |
| 1065 | if (i >= numInsertions) { | |
| 1066 | return; | |
| 1067 | } | |
| 1068 | intintIdentitySentinelPerfectCLHash_InnerInsertNoOverwrite(tableData, | |
| 1069 | numEntries, | |
| 1070 | keys + | |
| 1071 | (i * | |
| 1072 | numEntries), | |
| 1073 | values + | |
| 1074 | (i * | |
| 1075 | numEntries)); | |
| 1076 | } | |
| 1077 | ||
| 1078 | typedef struct intintLCGLinearOpenCompactCLHash_TableData { | |
| 1079 | int hashID; | |
| 1080 | unsigned int numBuckets; | |
| 1081 | intintHash_CompressLCGData compressFuncData; | |
| 1082 | } intintLCGLinearOpenCompactCLHash_TableData; | |
| 1083 | typedef struct intintLCGLinearOpenCompactCLHash_Bucket { | |
| 1084 | int key; | |
| 1085 | int value; | |
| 1086 | } intintLCGLinearOpenCompactCLHash_Bucket; | |
| 1087 | int intintLCGLinearOpenCompactCLHash_InnerQuerySingle(__global char *tableData, | |
| 1088 | int key, | |
| 1089 | __global int | |
| 1090 | *valueOutput) { | |
| 1091 | __global intintLCGLinearOpenCompactCLHash_Bucket *buckets = | |
| 1092 | (__global intintLCGLinearOpenCompactCLHash_Bucket *) & | |
| 1093 | tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)]; | |
| 1094 | int index; | |
| 1095 | int exitCode; | |
| 1096 | __global intintLCGLinearOpenCompactCLHash_TableData *mytableData = | |
| 1097 | (__global intintLCGLinearOpenCompactCLHash_TableData *) tableData; | |
| 1098 | intintHash_CompressLCGData compressFuncData = | |
| 1099 | mytableData->compressFuncData; | |
| 1100 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1101 | unsigned long int iteration = 0; | |
| 1102 | for (;;) { | |
| 1103 | index = | |
| 1104 | ((1 * iteration + | |
| 1105 | c) % | |
| 1106 | ((__global intintLCGLinearOpenCompactCLHash_TableData *) | |
| 1107 | tableData)->numBuckets); | |
| 1108 | if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1109 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1110 | break; | |
| 1111 | } else if (key == buckets[index].key) { | |
| 1112 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1113 | break; | |
| 1114 | } else if ((index == c && iteration > 0)) { | |
| 1115 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1116 | break; | |
| 1117 | } | |
| 1118 | iteration++; | |
| 1119 | } | |
| 1120 | switch (exitCode) { | |
| 1121 | case HASH_SEARCH_CODE_MATCH: | |
| 1122 | *valueOutput = buckets[index].value; | |
| 1123 | return HASH_EXIT_CODE_NORMAL; | |
| 1124 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1125 | case HASH_SEARCH_CODE_EMPTY: | |
| 1126 | return HASH_EXIT_CODE_KEY_DNE; | |
| 1127 | default: | |
| 1128 | return exitCode; | |
| 1129 | } | |
| 1130 | } | |
| 1131 | int intintLCGLinearOpenCompactCLHash_InnerQuery(__global char *tableData, | |
| 1132 | unsigned int numKeys, | |
| 1133 | __global int *keys, | |
| 1134 | __global int *valuesOutput) { | |
| 1135 | __global intintLCGLinearOpenCompactCLHash_Bucket *buckets = | |
| 1136 | (__global intintLCGLinearOpenCompactCLHash_Bucket *) & | |
| 1137 | tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)]; | |
| 1138 | int key; | |
| 1139 | __global int *valueOutput; | |
| 1140 | int index; | |
| 1141 | int exitCode; | |
| 1142 | uint i; | |
| 1143 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1144 | for (i = 0; i < numKeys; i++) { | |
| 1145 | key = keys[i]; | |
| 1146 | valueOutput = &valuesOutput[i]; | |
| 1147 | __global intintLCGLinearOpenCompactCLHash_TableData *mytableData | |
| 1148 | = | |
| 1149 | (__global intintLCGLinearOpenCompactCLHash_TableData *) | |
| 1150 | tableData; | |
| 1151 | intintHash_CompressLCGData compressFuncData = | |
| 1152 | mytableData->compressFuncData; | |
| 1153 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1154 | unsigned long int iteration = 0; | |
| 1155 | for (;;) { | |
| 1156 | index = | |
| 1157 | ((1 * iteration + | |
| 1158 | c) % | |
| 1159 | ((__global | |
| 1160 | intintLCGLinearOpenCompactCLHash_TableData *) | |
| 1161 | tableData)->numBuckets); | |
| 1162 | if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1163 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1164 | break; | |
| 1165 | } else if (key == buckets[index].key) { | |
| 1166 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1167 | break; | |
| 1168 | } else if ((index == c && iteration > 0)) { | |
| 1169 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1170 | break; | |
| 1171 | } | |
| 1172 | iteration++; | |
| 1173 | } | |
| 1174 | switch (exitCode) { | |
| 1175 | case HASH_SEARCH_CODE_MATCH: | |
| 1176 | *valueOutput = buckets[index].value; | |
| 1177 | break; | |
| 1178 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1179 | case HASH_SEARCH_CODE_EMPTY: | |
| 1180 | resultExitCode = HASH_EXIT_CODE_KEY_DNE; | |
| 1181 | break; | |
| 1182 | default: | |
| 1183 | return exitCode; | |
| 1184 | } | |
| 1185 | } | |
| 1186 | return resultExitCode; | |
| 1187 | } | |
| 1188 | int intintLCGLinearOpenCompactCLHash_InnerInsertSingle(__global char *tableData, | |
| 1189 | int key, int value) { | |
| 1190 | __global intintLCGLinearOpenCompactCLHash_Bucket *buckets = | |
| 1191 | (__global intintLCGLinearOpenCompactCLHash_Bucket *) & | |
| 1192 | tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)]; | |
| 1193 | int index; | |
| 1194 | int exitCode; | |
| 1195 | __global intintLCGLinearOpenCompactCLHash_TableData *mytableData = | |
| 1196 | (__global intintLCGLinearOpenCompactCLHash_TableData *) tableData; | |
| 1197 | intintHash_CompressLCGData compressFuncData = | |
| 1198 | mytableData->compressFuncData; | |
| 1199 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1200 | unsigned long int iteration = 0; | |
| 1201 | for (;;) { | |
| 1202 | index = | |
| 1203 | ((1 * iteration + | |
| 1204 | c) % | |
| 1205 | ((__global intintLCGLinearOpenCompactCLHash_TableData *) | |
| 1206 | tableData)->numBuckets); | |
| 1207 | if ((atomic_cmpxchg | |
| 1208 | (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY, | |
| 1209 | key)) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1210 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1211 | break; | |
| 1212 | } else if (key == buckets[index].key) { | |
| 1213 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1214 | break; | |
| 1215 | } else if ((index == c && iteration > 0)) { | |
| 1216 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1217 | break; | |
| 1218 | } | |
| 1219 | iteration++; | |
| 1220 | } | |
| 1221 | switch (exitCode) { | |
| 1222 | case HASH_SEARCH_CODE_MATCH: | |
| 1223 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1224 | buckets[index].value = value; | |
| 1225 | return HASH_EXIT_CODE_OVERWRITE; | |
| 1226 | case HASH_SEARCH_CODE_EMPTY: | |
| 1227 | buckets[index].value = value; | |
| 1228 | return HASH_EXIT_CODE_NORMAL; | |
| 1229 | default: | |
| 1230 | return exitCode; | |
| 1231 | } | |
| 1232 | } | |
| 1233 | int intintLCGLinearOpenCompactCLHash_InnerInsert(__global char *tableData, | |
| 1234 | unsigned int numEntries, | |
| 1235 | __global int *keys, | |
| 1236 | __global int *values) { | |
| 1237 | __global intintLCGLinearOpenCompactCLHash_Bucket *buckets = | |
| 1238 | (__global intintLCGLinearOpenCompactCLHash_Bucket *) & | |
| 1239 | tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)]; | |
| 1240 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1241 | int key; | |
| 1242 | int value; | |
| 1243 | int index; | |
| 1244 | int exitCode; | |
| 1245 | uint i; | |
| 1246 | for (i = 0; i < numEntries; i++) { | |
| 1247 | key = keys[i]; | |
| 1248 | __global intintLCGLinearOpenCompactCLHash_TableData *mytableData | |
| 1249 | = | |
| 1250 | (__global intintLCGLinearOpenCompactCLHash_TableData *) | |
| 1251 | tableData; | |
| 1252 | intintHash_CompressLCGData compressFuncData = | |
| 1253 | mytableData->compressFuncData; | |
| 1254 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1255 | unsigned long int iteration = 0; | |
| 1256 | for (;;) { | |
| 1257 | index = | |
| 1258 | ((1 * iteration + | |
| 1259 | c) % | |
| 1260 | ((__global | |
| 1261 | intintLCGLinearOpenCompactCLHash_TableData *) | |
| 1262 | tableData)->numBuckets); | |
| 1263 | if ((atomic_cmpxchg | |
| 1264 | (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY, | |
| 1265 | key)) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1266 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1267 | break; | |
| 1268 | } else if (key == buckets[index].key) { | |
| 1269 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1270 | break; | |
| 1271 | } else if ((index == c && iteration > 0)) { | |
| 1272 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1273 | break; | |
| 1274 | } | |
| 1275 | iteration++; | |
| 1276 | } | |
| 1277 | switch (exitCode) { | |
| 1278 | case HASH_SEARCH_CODE_MATCH: | |
| 1279 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1280 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 1281 | case HASH_SEARCH_CODE_EMPTY: | |
| 1282 | buckets[index].value = values[i]; | |
| 1283 | break; | |
| 1284 | default: | |
| 1285 | return exitCode; | |
| 1286 | } | |
| 1287 | } | |
| 1288 | return resultExitCode; | |
| 1289 | } | |
| 1290 | int intintLCGLinearOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global char | |
| 1291 | *tableData, | |
| 1292 | int key, | |
| 1293 | int value) { | |
| 1294 | __global intintLCGLinearOpenCompactCLHash_Bucket *buckets = | |
| 1295 | (__global intintLCGLinearOpenCompactCLHash_Bucket *) & | |
| 1296 | tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)]; | |
| 1297 | int index; | |
| 1298 | int exitCode; | |
| 1299 | __global intintLCGLinearOpenCompactCLHash_TableData *mytableData = | |
| 1300 | (__global intintLCGLinearOpenCompactCLHash_TableData *) tableData; | |
| 1301 | intintHash_CompressLCGData compressFuncData = | |
| 1302 | mytableData->compressFuncData; | |
| 1303 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1304 | unsigned long int iteration = 0; | |
| 1305 | for (;;) { | |
| 1306 | index = | |
| 1307 | ((1 * iteration + | |
| 1308 | c) % | |
| 1309 | ((__global intintLCGLinearOpenCompactCLHash_TableData *) | |
| 1310 | tableData)->numBuckets); | |
| 1311 | if ((atomic_cmpxchg | |
| 1312 | (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY, | |
| 1313 | key)) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1314 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1315 | break; | |
| 1316 | } else if (key == buckets[index].key) { | |
| 1317 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1318 | break; | |
| 1319 | } else if ((index == c && iteration > 0)) { | |
| 1320 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1321 | break; | |
| 1322 | } | |
| 1323 | iteration++; | |
| 1324 | } | |
| 1325 | switch (exitCode) { | |
| 1326 | case HASH_SEARCH_CODE_MATCH: | |
| 1327 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1328 | return HASH_EXIT_CODE_OVERWRITE; | |
| 1329 | case HASH_SEARCH_CODE_EMPTY: | |
| 1330 | buckets[index].value = value; | |
| 1331 | return HASH_EXIT_CODE_NORMAL; | |
| 1332 | default: | |
| 1333 | return exitCode; | |
| 1334 | } | |
| 1335 | } | |
| 1336 | int intintLCGLinearOpenCompactCLHash_InnerInsertNoOverwrite(__global char | |
| 1337 | *tableData, | |
| 1338 | unsigned int | |
| 1339 | numEntries, | |
| 1340 | __global int *keys, | |
| 1341 | __global int | |
| 1342 | *values) { | |
| 1343 | __global intintLCGLinearOpenCompactCLHash_Bucket *buckets = | |
| 1344 | (__global intintLCGLinearOpenCompactCLHash_Bucket *) & | |
| 1345 | tableData[sizeof(intintLCGLinearOpenCompactCLHash_TableData)]; | |
| 1346 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1347 | int key; | |
| 1348 | int value; | |
| 1349 | int index; | |
| 1350 | int exitCode; | |
| 1351 | uint i; | |
| 1352 | for (i = 0; i < numEntries; i++) { | |
| 1353 | key = keys[i]; | |
| 1354 | __global intintLCGLinearOpenCompactCLHash_TableData *mytableData | |
| 1355 | = | |
| 1356 | (__global intintLCGLinearOpenCompactCLHash_TableData *) | |
| 1357 | tableData; | |
| 1358 | intintHash_CompressLCGData compressFuncData = | |
| 1359 | mytableData->compressFuncData; | |
| 1360 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1361 | unsigned long int iteration = 0; | |
| 1362 | for (;;) { | |
| 1363 | index = | |
| 1364 | ((1 * iteration + | |
| 1365 | c) % | |
| 1366 | ((__global | |
| 1367 | intintLCGLinearOpenCompactCLHash_TableData *) | |
| 1368 | tableData)->numBuckets); | |
| 1369 | if ((atomic_cmpxchg | |
| 1370 | (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY, | |
| 1371 | key)) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1372 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1373 | break; | |
| 1374 | } else if (key == buckets[index].key) { | |
| 1375 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1376 | break; | |
| 1377 | } else if ((index == c && iteration > 0)) { | |
| 1378 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1379 | break; | |
| 1380 | } | |
| 1381 | iteration++; | |
| 1382 | } | |
| 1383 | switch (exitCode) { | |
| 1384 | case HASH_SEARCH_CODE_MATCH: | |
| 1385 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1386 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 1387 | break; | |
| 1388 | case HASH_SEARCH_CODE_EMPTY: | |
| 1389 | buckets[index].value = values[i]; | |
| 1390 | break; | |
| 1391 | default: | |
| 1392 | return exitCode; | |
| 1393 | } | |
| 1394 | } | |
| 1395 | return resultExitCode; | |
| 1396 | } | |
| 1397 | int intintLCGLinearOpenCompactCLHash_QuerySingle(__global char *tableData, | |
| 1398 | int key, | |
| 1399 | __global int *valueOutput) { | |
| 1400 | return intintLCGLinearOpenCompactCLHash_InnerQuerySingle(tableData, key, | |
| 1401 | valueOutput); | |
| 1402 | } | |
| 1403 | int intintLCGLinearOpenCompactCLHash_Query(__global char *tableData, | |
| 1404 | size_t numKeys, __global int *keys, | |
| 1405 | __global int *valuesOutput) { | |
| 1406 | return intintLCGLinearOpenCompactCLHash_InnerQuery(tableData, numKeys, | |
| 1407 | keys, valuesOutput); | |
| 1408 | } | |
| 1409 | int intintLCGLinearOpenCompactCLHash_InsertSingle(__global char *tableData, | |
| 1410 | int key, int value) { | |
| 1411 | return intintLCGLinearOpenCompactCLHash_InnerInsertSingle(tableData, | |
| 1412 | key, value); | |
| 1413 | } | |
| 1414 | int intintLCGLinearOpenCompactCLHash_Insert(__global char *tableData, | |
| 1415 | size_t numEntries, | |
| 1416 | __global int *keys, | |
| 1417 | __global int *values) { | |
| 1418 | return intintLCGLinearOpenCompactCLHash_InnerInsert(tableData, | |
| 1419 | numEntries, keys, | |
| 1420 | values); | |
| 1421 | } | |
| 1422 | int intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite(__global char | |
| 1423 | *tableData, | |
| 1424 | int key, | |
| 1425 | int value) { | |
| 1426 | return | |
| 1427 | intintLCGLinearOpenCompactCLHash_InnerInsertSingleNoOverwrite | |
| 1428 | (tableData, key, value); | |
| 1429 | } | |
| 1430 | int intintLCGLinearOpenCompactCLHash_InsertNoOverwrite(__global char *tableData, | |
| 1431 | size_t numEntries, | |
| 1432 | __global int *keys, | |
| 1433 | __global int *values) { | |
| 1434 | return | |
| 1435 | intintLCGLinearOpenCompactCLHash_InnerInsertNoOverwrite(tableData, | |
| 1436 | numEntries, | |
| 1437 | keys, | |
| 1438 | values); | |
| 1439 | } | |
| 1440 | __kernel void intintLCGLinearOpenCompactCLHash_RangeQuerySingle(__global char | |
| 1441 | *tableData, | |
| 1442 | unsigned int | |
| 1443 | numQueries, | |
| 1444 | __global int | |
| 1445 | *keys, | |
| 1446 | __global int | |
| 1447 | *valuesOutput) { | |
| 1448 | uint i = get_global_id(0); | |
| 1449 | if (i >= numQueries) { | |
| 1450 | return; | |
| 1451 | } | |
| 1452 | intintLCGLinearOpenCompactCLHash_InnerQuerySingle(tableData, keys[i], | |
| 1453 | valuesOutput + i); | |
| 1454 | } | |
| 1455 | __kernel void intintLCGLinearOpenCompactCLHash_RangeQuery(__global char | |
| 1456 | *tableData, | |
| 1457 | unsigned int | |
| 1458 | numQueries, | |
| 1459 | unsigned int numKeys, | |
| 1460 | __global int *keys, | |
| 1461 | __global int | |
| 1462 | *valuesOutput) { | |
| 1463 | uint i = get_global_id(0); | |
| 1464 | if (i >= numQueries) { | |
| 1465 | return; | |
| 1466 | } | |
| 1467 | intintLCGLinearOpenCompactCLHash_InnerQuery(tableData, numKeys, | |
| 1468 | keys + (i * numKeys), | |
| 1469 | valuesOutput + | |
| 1470 | (i * numKeys)); | |
| 1471 | } | |
| 1472 | __kernel void intintLCGLinearOpenCompactCLHash_RangeInsertSingle(__global char | |
| 1473 | *tableData, | |
| 1474 | unsigned int | |
| 1475 | numInsertions, | |
| 1476 | __global int | |
| 1477 | *keys, | |
| 1478 | __global int | |
| 1479 | *values) { | |
| 1480 | uint i = get_global_id(0); | |
| 1481 | if (i >= numInsertions) { | |
| 1482 | return; | |
| 1483 | } | |
| 1484 | intintLCGLinearOpenCompactCLHash_InnerInsertSingle(tableData, keys[i], | |
| 1485 | values[i]); | |
| 1486 | } | |
| 1487 | __kernel void intintLCGLinearOpenCompactCLHash_RangeInsert(__global char | |
| 1488 | *tableData, | |
| 1489 | unsigned int | |
| 1490 | numInsertions, | |
| 1491 | unsigned int | |
| 1492 | numEntries, | |
| 1493 | __global int *keys, | |
| 1494 | __global int | |
| 1495 | *values) { | |
| 1496 | uint i = get_global_id(0); | |
| 1497 | if (i >= numInsertions) { | |
| 1498 | return; | |
| 1499 | } | |
| 1500 | intintLCGLinearOpenCompactCLHash_InnerInsert(tableData, numEntries, | |
| 1501 | keys + (i * numEntries), | |
| 1502 | values + (i * numEntries)); | |
| 1503 | } | |
| 1504 | __kernel void | |
| 1505 | intintLCGLinearOpenCompactCLHash_RangeInsertSingleNoOverwrite(__global char | |
| 1506 | *tableData, | |
| 1507 | unsigned int | |
| 1508 | numInsertions, | |
| 1509 | __global int | |
| 1510 | *keys, | |
| 1511 | __global int | |
| 1512 | *values) { | |
| 1513 | uint i = get_global_id(0); | |
| 1514 | if (i >= numInsertions) { | |
| 1515 | return; | |
| 1516 | } | |
| 1517 | intintLCGLinearOpenCompactCLHash_InnerInsertSingleNoOverwrite(tableData, | |
| 1518 | keys[i], | |
| 1519 | values | |
| 1520 | [i]); | |
| 1521 | } | |
| 1522 | __kernel void intintLCGLinearOpenCompactCLHash_RangeInsertNoOverwrite(__global | |
| 1523 | char | |
| 1524 | *tableData, | |
| 1525 | unsigned | |
| 1526 | int | |
| 1527 | numInsertions, | |
| 1528 | unsigned | |
| 1529 | int | |
| 1530 | numEntries, | |
| 1531 | __global | |
| 1532 | int *keys, | |
| 1533 | __global | |
| 1534 | int | |
| 1535 | *values) { | |
| 1536 | uint i = get_global_id(0); | |
| 1537 | if (i >= numInsertions) { | |
| 1538 | return; | |
| 1539 | } | |
| 1540 | intintLCGLinearOpenCompactCLHash_InnerInsertNoOverwrite(tableData, | |
| 1541 | numEntries, | |
| 1542 | keys + | |
| 1543 | (i * | |
| 1544 | numEntries), | |
| 1545 | values + | |
| 1546 | (i * | |
| 1547 | numEntries)); | |
| 1548 | } | |
| 1549 | ||
| 1550 | typedef struct intintLCGQuadraticOpenCompactCLHash_TableData { | |
| 1551 | int hashID; | |
| 1552 | unsigned int numBuckets; | |
| 1553 | intintHash_CompressLCGData compressFuncData; | |
| 1554 | } intintLCGQuadraticOpenCompactCLHash_TableData; | |
| 1555 | typedef struct intintLCGQuadraticOpenCompactCLHash_Bucket { | |
| 1556 | int key; | |
| 1557 | int value; | |
| 1558 | } intintLCGQuadraticOpenCompactCLHash_Bucket; | |
| 1559 | int intintLCGQuadraticOpenCompactCLHash_InnerQuerySingle(__global char | |
| 1560 | *tableData, int key, | |
| 1561 | __global int | |
| 1562 | *valueOutput) { | |
| 1563 | __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets = | |
| 1564 | (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) & | |
| 1565 | tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)]; | |
| 1566 | int index; | |
| 1567 | int exitCode; | |
| 1568 | __global intintLCGQuadraticOpenCompactCLHash_TableData *mytableData = | |
| 1569 | (__global intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1570 | tableData; | |
| 1571 | intintHash_CompressLCGData compressFuncData = | |
| 1572 | mytableData->compressFuncData; | |
| 1573 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1574 | unsigned long int iteration = 0; | |
| 1575 | for (;;) { | |
| 1576 | index = | |
| 1577 | ((1 * iteration * iteration + 0 * iteration + | |
| 1578 | c) % | |
| 1579 | ((__global intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1580 | tableData)->numBuckets); | |
| 1581 | if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1582 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1583 | break; | |
| 1584 | } else if (key == buckets[index].key) { | |
| 1585 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1586 | break; | |
| 1587 | } else | |
| 1588 | if ((iteration > | |
| 1589 | ((__global | |
| 1590 | intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1591 | tableData)->numBuckets)) { | |
| 1592 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1593 | break; | |
| 1594 | } | |
| 1595 | iteration++; | |
| 1596 | } | |
| 1597 | switch (exitCode) { | |
| 1598 | case HASH_SEARCH_CODE_MATCH: | |
| 1599 | *valueOutput = buckets[index].value; | |
| 1600 | return HASH_EXIT_CODE_NORMAL; | |
| 1601 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1602 | case HASH_SEARCH_CODE_EMPTY: | |
| 1603 | return HASH_EXIT_CODE_KEY_DNE; | |
| 1604 | default: | |
| 1605 | return exitCode; | |
| 1606 | } | |
| 1607 | } | |
| 1608 | int intintLCGQuadraticOpenCompactCLHash_InnerQuery(__global char *tableData, | |
| 1609 | unsigned int numKeys, | |
| 1610 | __global int *keys, | |
| 1611 | __global int *valuesOutput) { | |
| 1612 | __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets = | |
| 1613 | (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) & | |
| 1614 | tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)]; | |
| 1615 | int key; | |
| 1616 | __global int *valueOutput; | |
| 1617 | int index; | |
| 1618 | int exitCode; | |
| 1619 | uint i; | |
| 1620 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1621 | for (i = 0; i < numKeys; i++) { | |
| 1622 | key = keys[i]; | |
| 1623 | valueOutput = &valuesOutput[i]; | |
| 1624 | __global intintLCGQuadraticOpenCompactCLHash_TableData | |
| 1625 | *mytableData = | |
| 1626 | (__global intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1627 | tableData; | |
| 1628 | intintHash_CompressLCGData compressFuncData = | |
| 1629 | mytableData->compressFuncData; | |
| 1630 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1631 | unsigned long int iteration = 0; | |
| 1632 | for (;;) { | |
| 1633 | index = | |
| 1634 | ((1 * iteration * iteration + 0 * iteration + | |
| 1635 | c) % | |
| 1636 | ((__global | |
| 1637 | intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1638 | tableData)->numBuckets); | |
| 1639 | if ((buckets[index].key) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1640 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1641 | break; | |
| 1642 | } else if (key == buckets[index].key) { | |
| 1643 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1644 | break; | |
| 1645 | } else | |
| 1646 | if ((iteration > | |
| 1647 | ((__global | |
| 1648 | intintLCGQuadraticOpenCompactCLHash_TableData | |
| 1649 | *) tableData)->numBuckets)) { | |
| 1650 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1651 | break; | |
| 1652 | } | |
| 1653 | iteration++; | |
| 1654 | } | |
| 1655 | switch (exitCode) { | |
| 1656 | case HASH_SEARCH_CODE_MATCH: | |
| 1657 | *valueOutput = buckets[index].value; | |
| 1658 | break; | |
| 1659 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1660 | case HASH_SEARCH_CODE_EMPTY: | |
| 1661 | resultExitCode = HASH_EXIT_CODE_KEY_DNE; | |
| 1662 | break; | |
| 1663 | default: | |
| 1664 | return exitCode; | |
| 1665 | } | |
| 1666 | } | |
| 1667 | return resultExitCode; | |
| 1668 | } | |
| 1669 | int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingle(__global char | |
| 1670 | *tableData, int key, | |
| 1671 | int value) { | |
| 1672 | __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets = | |
| 1673 | (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) & | |
| 1674 | tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)]; | |
| 1675 | int index; | |
| 1676 | int exitCode; | |
| 1677 | __global intintLCGQuadraticOpenCompactCLHash_TableData *mytableData = | |
| 1678 | (__global intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1679 | tableData; | |
| 1680 | intintHash_CompressLCGData compressFuncData = | |
| 1681 | mytableData->compressFuncData; | |
| 1682 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1683 | unsigned long int iteration = 0; | |
| 1684 | for (;;) { | |
| 1685 | index = | |
| 1686 | ((1 * iteration * iteration + 0 * iteration + | |
| 1687 | c) % | |
| 1688 | ((__global intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1689 | tableData)->numBuckets); | |
| 1690 | if ((atomic_cmpxchg | |
| 1691 | (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY, | |
| 1692 | key)) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1693 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1694 | break; | |
| 1695 | } else if (key == buckets[index].key) { | |
| 1696 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1697 | break; | |
| 1698 | } else | |
| 1699 | if ((iteration > | |
| 1700 | ((__global | |
| 1701 | intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1702 | tableData)->numBuckets)) { | |
| 1703 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1704 | break; | |
| 1705 | } | |
| 1706 | iteration++; | |
| 1707 | } | |
| 1708 | switch (exitCode) { | |
| 1709 | case HASH_SEARCH_CODE_MATCH: | |
| 1710 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1711 | buckets[index].value = value; | |
| 1712 | return HASH_EXIT_CODE_OVERWRITE; | |
| 1713 | case HASH_SEARCH_CODE_EMPTY: | |
| 1714 | buckets[index].value = value; | |
| 1715 | return HASH_EXIT_CODE_NORMAL; | |
| 1716 | default: | |
| 1717 | return exitCode; | |
| 1718 | } | |
| 1719 | } | |
| 1720 | int intintLCGQuadraticOpenCompactCLHash_InnerInsert(__global char *tableData, | |
| 1721 | unsigned int numEntries, | |
| 1722 | __global int *keys, | |
| 1723 | __global int *values) { | |
| 1724 | __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets = | |
| 1725 | (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) & | |
| 1726 | tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)]; | |
| 1727 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1728 | int key; | |
| 1729 | int value; | |
| 1730 | int index; | |
| 1731 | int exitCode; | |
| 1732 | uint i; | |
| 1733 | for (i = 0; i < numEntries; i++) { | |
| 1734 | key = keys[i]; | |
| 1735 | __global intintLCGQuadraticOpenCompactCLHash_TableData | |
| 1736 | *mytableData = | |
| 1737 | (__global intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1738 | tableData; | |
| 1739 | intintHash_CompressLCGData compressFuncData = | |
| 1740 | mytableData->compressFuncData; | |
| 1741 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1742 | unsigned long int iteration = 0; | |
| 1743 | for (;;) { | |
| 1744 | index = | |
| 1745 | ((1 * iteration * iteration + 0 * iteration + | |
| 1746 | c) % | |
| 1747 | ((__global | |
| 1748 | intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1749 | tableData)->numBuckets); | |
| 1750 | if ((atomic_cmpxchg | |
| 1751 | (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY, | |
| 1752 | key)) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1753 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1754 | break; | |
| 1755 | } else if (key == buckets[index].key) { | |
| 1756 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1757 | break; | |
| 1758 | } else | |
| 1759 | if ((iteration > | |
| 1760 | ((__global | |
| 1761 | intintLCGQuadraticOpenCompactCLHash_TableData | |
| 1762 | *) tableData)->numBuckets)) { | |
| 1763 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1764 | break; | |
| 1765 | } | |
| 1766 | iteration++; | |
| 1767 | } | |
| 1768 | switch (exitCode) { | |
| 1769 | case HASH_SEARCH_CODE_MATCH: | |
| 1770 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1771 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 1772 | case HASH_SEARCH_CODE_EMPTY: | |
| 1773 | buckets[index].value = values[i]; | |
| 1774 | break; | |
| 1775 | default: | |
| 1776 | return exitCode; | |
| 1777 | } | |
| 1778 | } | |
| 1779 | return resultExitCode; | |
| 1780 | } | |
| 1781 | int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global | |
| 1782 | char | |
| 1783 | *tableData, | |
| 1784 | int key, | |
| 1785 | int value) | |
| 1786 | { | |
| 1787 | __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets = | |
| 1788 | (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) & | |
| 1789 | tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)]; | |
| 1790 | int index; | |
| 1791 | int exitCode; | |
| 1792 | __global intintLCGQuadraticOpenCompactCLHash_TableData *mytableData = | |
| 1793 | (__global intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1794 | tableData; | |
| 1795 | intintHash_CompressLCGData compressFuncData = | |
| 1796 | mytableData->compressFuncData; | |
| 1797 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1798 | unsigned long int iteration = 0; | |
| 1799 | for (;;) { | |
| 1800 | index = | |
| 1801 | ((1 * iteration * iteration + 0 * iteration + | |
| 1802 | c) % | |
| 1803 | ((__global intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1804 | tableData)->numBuckets); | |
| 1805 | if ((atomic_cmpxchg | |
| 1806 | (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY, | |
| 1807 | key)) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1808 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1809 | break; | |
| 1810 | } else if (key == buckets[index].key) { | |
| 1811 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1812 | break; | |
| 1813 | } else | |
| 1814 | if ((iteration > | |
| 1815 | ((__global | |
| 1816 | intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1817 | tableData)->numBuckets)) { | |
| 1818 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1819 | break; | |
| 1820 | } | |
| 1821 | iteration++; | |
| 1822 | } | |
| 1823 | switch (exitCode) { | |
| 1824 | case HASH_SEARCH_CODE_MATCH: | |
| 1825 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1826 | return HASH_EXIT_CODE_OVERWRITE; | |
| 1827 | case HASH_SEARCH_CODE_EMPTY: | |
| 1828 | buckets[index].value = value; | |
| 1829 | return HASH_EXIT_CODE_NORMAL; | |
| 1830 | default: | |
| 1831 | return exitCode; | |
| 1832 | } | |
| 1833 | } | |
| 1834 | int intintLCGQuadraticOpenCompactCLHash_InnerInsertNoOverwrite(__global char | |
| 1835 | *tableData, | |
| 1836 | unsigned int | |
| 1837 | numEntries, | |
| 1838 | __global int | |
| 1839 | *keys, | |
| 1840 | __global int | |
| 1841 | *values) { | |
| 1842 | __global intintLCGQuadraticOpenCompactCLHash_Bucket *buckets = | |
| 1843 | (__global intintLCGQuadraticOpenCompactCLHash_Bucket *) & | |
| 1844 | tableData[sizeof(intintLCGQuadraticOpenCompactCLHash_TableData)]; | |
| 1845 | int resultExitCode = HASH_EXIT_CODE_NORMAL; | |
| 1846 | int key; | |
| 1847 | int value; | |
| 1848 | int index; | |
| 1849 | int exitCode; | |
| 1850 | uint i; | |
| 1851 | for (i = 0; i < numEntries; i++) { | |
| 1852 | key = keys[i]; | |
| 1853 | __global intintLCGQuadraticOpenCompactCLHash_TableData | |
| 1854 | *mytableData = | |
| 1855 | (__global intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1856 | tableData; | |
| 1857 | intintHash_CompressLCGData compressFuncData = | |
| 1858 | mytableData->compressFuncData; | |
| 1859 | unsigned int c = intintHash_CompressLCG(compressFuncData, key); | |
| 1860 | unsigned long int iteration = 0; | |
| 1861 | for (;;) { | |
| 1862 | index = | |
| 1863 | ((1 * iteration * iteration + 0 * iteration + | |
| 1864 | c) % | |
| 1865 | ((__global | |
| 1866 | intintLCGQuadraticOpenCompactCLHash_TableData *) | |
| 1867 | tableData)->numBuckets); | |
| 1868 | if ((atomic_cmpxchg | |
| 1869 | (&(buckets[index].key), HASH_BUCKET_STATUS_EMPTY, | |
| 1870 | key)) == HASH_BUCKET_STATUS_EMPTY) { | |
| 1871 | exitCode = HASH_SEARCH_CODE_EMPTY; | |
| 1872 | break; | |
| 1873 | } else if (key == buckets[index].key) { | |
| 1874 | exitCode = HASH_SEARCH_CODE_MATCH; | |
| 1875 | break; | |
| 1876 | } else | |
| 1877 | if ((iteration > | |
| 1878 | ((__global | |
| 1879 | intintLCGQuadraticOpenCompactCLHash_TableData | |
| 1880 | *) tableData)->numBuckets)) { | |
| 1881 | exitCode = HASH_EXIT_CODE_CYCLE; | |
| 1882 | break; | |
| 1883 | } | |
| 1884 | iteration++; | |
| 1885 | } | |
| 1886 | switch (exitCode) { | |
| 1887 | case HASH_SEARCH_CODE_MATCH: | |
| 1888 | case HASH_SEARCH_CODE_MISMATCH: | |
| 1889 | resultExitCode = HASH_EXIT_CODE_OVERWRITE; | |
| 1890 | break; | |
| 1891 | case HASH_SEARCH_CODE_EMPTY: | |
| 1892 | buckets[index].value = values[i]; | |
| 1893 | break; | |
| 1894 | default: | |
| 1895 | return exitCode; | |
| 1896 | } | |
| 1897 | } | |
| 1898 | return resultExitCode; | |
| 1899 | } | |
| 1900 | int intintLCGQuadraticOpenCompactCLHash_QuerySingle(__global char *tableData, | |
| 1901 | int key, | |
| 1902 | __global int *valueOutput) { | |
| 1903 | return intintLCGQuadraticOpenCompactCLHash_InnerQuerySingle(tableData, | |
| 1904 | key, | |
| 1905 | valueOutput); | |
| 1906 | } | |
| 1907 | int intintLCGQuadraticOpenCompactCLHash_Query(__global char *tableData, | |
| 1908 | size_t numKeys, | |
| 1909 | __global int *keys, | |
| 1910 | __global int *valuesOutput) { | |
| 1911 | return intintLCGQuadraticOpenCompactCLHash_InnerQuery(tableData, | |
| 1912 | numKeys, keys, | |
| 1913 | valuesOutput); | |
| 1914 | } | |
| 1915 | int intintLCGQuadraticOpenCompactCLHash_InsertSingle(__global char *tableData, | |
| 1916 | int key, int value) { | |
| 1917 | return intintLCGQuadraticOpenCompactCLHash_InnerInsertSingle(tableData, | |
| 1918 | key, | |
| 1919 | value); | |
| 1920 | } | |
| 1921 | int intintLCGQuadraticOpenCompactCLHash_Insert(__global char *tableData, | |
| 1922 | size_t numEntries, | |
| 1923 | __global int *keys, | |
| 1924 | __global int *values) { | |
| 1925 | return intintLCGQuadraticOpenCompactCLHash_InnerInsert(tableData, | |
| 1926 | numEntries, keys, | |
| 1927 | values); | |
| 1928 | } | |
| 1929 | int intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite(__global char | |
| 1930 | *tableData, | |
| 1931 | int key, | |
| 1932 | int value) { | |
| 1933 | return | |
| 1934 | intintLCGQuadraticOpenCompactCLHash_InnerInsertSingleNoOverwrite | |
| 1935 | (tableData, key, value); | |
| 1936 | } | |
| 1937 | int intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite(__global char | |
| 1938 | *tableData, | |
| 1939 | size_t numEntries, | |
| 1940 | __global int *keys, | |
| 1941 | __global int *values) | |
| 1942 | { | |
| 1943 | return | |
| 1944 | intintLCGQuadraticOpenCompactCLHash_InnerInsertNoOverwrite | |
| 1945 | (tableData, numEntries, keys, values); | |
| 1946 | } | |
| 1947 | __kernel void intintLCGQuadraticOpenCompactCLHash_RangeQuerySingle(__global char | |
| 1948 | *tableData, | |
| 1949 | unsigned int | |
| 1950 | numQueries, | |
| 1951 | __global int | |
| 1952 | *keys, | |
| 1953 | __global int | |
| 1954 | *valuesOutput) | |
| 1955 | { | |
| 1956 | uint i = get_global_id(0); | |
| 1957 | if (i >= numQueries) { | |
| 1958 | return; | |
| 1959 | } | |
| 1960 | intintLCGQuadraticOpenCompactCLHash_InnerQuerySingle(tableData, keys[i], | |
| 1961 | valuesOutput + i); | |
| 1962 | } | |
| 1963 | __kernel void intintLCGQuadraticOpenCompactCLHash_RangeQuery(__global char | |
| 1964 | *tableData, | |
| 1965 | unsigned int | |
| 1966 | numQueries, | |
| 1967 | unsigned int | |
| 1968 | numKeys, | |
| 1969 | __global int *keys, | |
| 1970 | __global int | |
| 1971 | *valuesOutput) { | |
| 1972 | uint i = get_global_id(0); | |
| 1973 | if (i >= numQueries) { | |
| 1974 | return; | |
| 1975 | } | |
| 1976 | intintLCGQuadraticOpenCompactCLHash_InnerQuery(tableData, numKeys, | |
| 1977 | keys + (i * numKeys), | |
| 1978 | valuesOutput + | |
| 1979 | (i * numKeys)); | |
| 1980 | } | |
| 1981 | __kernel void intintLCGQuadraticOpenCompactCLHash_RangeInsertSingle(__global | |
| 1982 | char | |
| 1983 | *tableData, | |
| 1984 | unsigned int | |
| 1985 | numInsertions, | |
| 1986 | __global int | |
| 1987 | *keys, | |
| 1988 | __global int | |
| 1989 | *values) { | |
| 1990 | uint i = get_global_id(0); | |
| 1991 | if (i >= numInsertions) { | |
| 1992 | return; | |
| 1993 | } | |
| 1994 | intintLCGQuadraticOpenCompactCLHash_InnerInsertSingle(tableData, | |
| 1995 | keys[i], | |
| 1996 | values[i]); | |
| 1997 | } | |
| 1998 | __kernel void intintLCGQuadraticOpenCompactCLHash_RangeInsert(__global char | |
| 1999 | *tableData, | |
| 2000 | unsigned int | |
| 2001 | numInsertions, | |
| 2002 | unsigned int | |
| 2003 | numEntries, | |
| 2004 | __global int | |
| 2005 | *keys, | |
| 2006 | __global int | |
| 2007 | *values) { | |
| 2008 | uint i = get_global_id(0); | |
| 2009 | if (i >= numInsertions) { | |
| 2010 | return; | |
| 2011 | } | |
| 2012 | intintLCGQuadraticOpenCompactCLHash_InnerInsert(tableData, numEntries, | |
| 2013 | keys + (i * numEntries), | |
| 2014 | values + | |
| 2015 | (i * numEntries)); | |
| 2016 | } | |
| 2017 | __kernel void | |
| 2018 | intintLCGQuadraticOpenCompactCLHash_RangeInsertSingleNoOverwrite(__global char | |
| 2019 | *tableData, | |
| 2020 | unsigned int | |
| 2021 | numInsertions, | |
| 2022 | __global int | |
| 2023 | *keys, | |
| 2024 | __global int | |
| 2025 | *values) { | |
| 2026 | uint i = get_global_id(0); | |
| 2027 | if (i >= numInsertions) { | |
| 2028 | return; | |
| 2029 | } | |
| 2030 | intintLCGQuadraticOpenCompactCLHash_InnerInsertSingleNoOverwrite | |
| 2031 | (tableData, keys[i], values[i]); | |
| 2032 | } | |
| 2033 | __kernel void | |
| 2034 | intintLCGQuadraticOpenCompactCLHash_RangeInsertNoOverwrite(__global char | |
| 2035 | *tableData, | |
| 2036 | unsigned int | |
| 2037 | numInsertions, | |
| 2038 | unsigned int | |
| 2039 | numEntries, | |
| 2040 | __global int *keys, | |
| 2041 | __global int | |
| 2042 | *values) { | |
| 2043 | uint i = get_global_id(0); | |
| 2044 | if (i >= numInsertions) { | |
| 2045 | return; | |
| 2046 | } | |
| 2047 | intintLCGQuadraticOpenCompactCLHash_InnerInsertNoOverwrite(tableData, | |
| 2048 | numEntries, | |
| 2049 | keys + | |
| 2050 | (i * | |
| 2051 | numEntries), | |
| 2052 | values + | |
| 2053 | (i * | |
| 2054 | numEntries)); | |
| 2055 | } | |
| 2056 | __kernel void intintHash_RangeQuery(__global char *tableData, | |
| 2057 | unsigned int numQueries, | |
| 2058 | unsigned int numKeys, __global int *keys, | |
| 2059 | __global int *valuesOutput) { | |
| 2060 | switch (((__global int *)tableData)[0]) { | |
| 2061 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2062 | return intintIdentityPerfectCLHash_RangeQuery(tableData, | |
| 2063 | numQueries, | |
| 2064 | numKeys, keys, | |
| 2065 | valuesOutput); | |
| 2066 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2067 | return intintIdentitySentinelPerfectCLHash_RangeQuery(tableData, | |
| 2068 | numQueries, | |
| 2069 | numKeys, | |
| 2070 | keys, | |
| 2071 | valuesOutput); | |
| 2072 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2073 | return intintLCGLinearOpenCompactCLHash_RangeQuery(tableData, | |
| 2074 | numQueries, | |
| 2075 | numKeys, | |
| 2076 | keys, | |
| 2077 | valuesOutput); | |
| 2078 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2079 | return intintLCGQuadraticOpenCompactCLHash_RangeQuery(tableData, | |
| 2080 | numQueries, | |
| 2081 | numKeys, | |
| 2082 | keys, | |
| 2083 | valuesOutput); | |
| 2084 | } | |
| 2085 | } | |
| 2086 | __kernel void intintHash_RangeQuerySingle(__global char *tableData, | |
| 2087 | unsigned int numQueries, | |
| 2088 | __global int *keys, | |
| 2089 | __global int *valueOutput) { | |
| 2090 | switch (((__global int *)tableData)[0]) { | |
| 2091 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2092 | return intintIdentityPerfectCLHash_RangeQuerySingle(tableData, | |
| 2093 | numQueries, | |
| 2094 | keys, | |
| 2095 | valueOutput); | |
| 2096 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2097 | return | |
| 2098 | intintIdentitySentinelPerfectCLHash_RangeQuerySingle | |
| 2099 | (tableData, numQueries, keys, valueOutput); | |
| 2100 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2101 | return | |
| 2102 | intintLCGLinearOpenCompactCLHash_RangeQuerySingle(tableData, | |
| 2103 | numQueries, | |
| 2104 | keys, | |
| 2105 | valueOutput); | |
| 2106 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2107 | return | |
| 2108 | intintLCGQuadraticOpenCompactCLHash_RangeQuerySingle | |
| 2109 | (tableData, numQueries, keys, valueOutput); | |
| 2110 | } | |
| 2111 | } | |
| 2112 | __kernel void intintHash_RangeInsert(__global char *tableData, | |
| 2113 | unsigned int numInsertions, | |
| 2114 | unsigned int numEntries, | |
| 2115 | __global int *keys, __global int *values) { | |
| 2116 | switch (((__global int *)tableData)[0]) { | |
| 2117 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2118 | return intintIdentityPerfectCLHash_RangeInsert(tableData, | |
| 2119 | numInsertions, | |
| 2120 | numEntries, keys, | |
| 2121 | values); | |
| 2122 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2123 | return | |
| 2124 | intintIdentitySentinelPerfectCLHash_RangeInsert(tableData, | |
| 2125 | numInsertions, | |
| 2126 | numEntries, | |
| 2127 | keys, | |
| 2128 | values); | |
| 2129 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2130 | return intintLCGLinearOpenCompactCLHash_RangeInsert(tableData, | |
| 2131 | numInsertions, | |
| 2132 | numEntries, | |
| 2133 | keys, | |
| 2134 | values); | |
| 2135 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2136 | return | |
| 2137 | intintLCGQuadraticOpenCompactCLHash_RangeInsert(tableData, | |
| 2138 | numInsertions, | |
| 2139 | numEntries, | |
| 2140 | keys, | |
| 2141 | values); | |
| 2142 | } | |
| 2143 | } | |
| 2144 | __kernel void intintHash_RangeInsertSingle(__global char *tableData, | |
| 2145 | unsigned int numInsertions, | |
| 2146 | __global int *keys, | |
| 2147 | __global int *values) { | |
| 2148 | switch (((__global int *)tableData)[0]) { | |
| 2149 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2150 | return intintIdentityPerfectCLHash_RangeInsertSingle(tableData, | |
| 2151 | numInsertions, | |
| 2152 | keys, | |
| 2153 | values); | |
| 2154 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2155 | return | |
| 2156 | intintIdentitySentinelPerfectCLHash_RangeInsertSingle | |
| 2157 | (tableData, numInsertions, keys, values); | |
| 2158 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2159 | return | |
| 2160 | intintLCGLinearOpenCompactCLHash_RangeInsertSingle | |
| 2161 | (tableData, numInsertions, keys, values); | |
| 2162 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2163 | return | |
| 2164 | intintLCGQuadraticOpenCompactCLHash_RangeInsertSingle | |
| 2165 | (tableData, numInsertions, keys, values); | |
| 2166 | } | |
| 2167 | } | |
| 2168 | __kernel void intintHash_RangeInsertNoOverwrite(__global char *tableData, | |
| 2169 | unsigned int numInsertions, | |
| 2170 | unsigned int numEntries, | |
| 2171 | __global int *keys, | |
| 2172 | __global int *values) { | |
| 2173 | switch (((__global int *)tableData)[0]) { | |
| 2174 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2175 | return | |
| 2176 | intintIdentityPerfectCLHash_RangeInsertNoOverwrite | |
| 2177 | (tableData, numInsertions, numEntries, keys, values); | |
| 2178 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2179 | return | |
| 2180 | intintIdentitySentinelPerfectCLHash_RangeInsertNoOverwrite | |
| 2181 | (tableData, numInsertions, numEntries, keys, values); | |
| 2182 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2183 | return | |
| 2184 | intintLCGLinearOpenCompactCLHash_RangeInsertNoOverwrite | |
| 2185 | (tableData, numInsertions, numEntries, keys, values); | |
| 2186 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2187 | return | |
| 2188 | intintLCGQuadraticOpenCompactCLHash_RangeInsertNoOverwrite | |
| 2189 | (tableData, numInsertions, numEntries, keys, values); | |
| 2190 | } | |
| 2191 | } | |
| 2192 | __kernel void intintHash_RangeInsertSingleNoOverwrite(__global char *tableData, | |
| 2193 | unsigned int | |
| 2194 | numInsertions, | |
| 2195 | __global int *keys, | |
| 2196 | __global int *values) { | |
| 2197 | switch (((__global int *)tableData)[0]) { | |
| 2198 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2199 | return | |
| 2200 | intintIdentityPerfectCLHash_RangeInsertSingleNoOverwrite | |
| 2201 | (tableData, numInsertions, keys, values); | |
| 2202 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2203 | return | |
| 2204 | intintIdentitySentinelPerfectCLHash_RangeInsertSingleNoOverwrite | |
| 2205 | (tableData, numInsertions, keys, values); | |
| 2206 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2207 | return | |
| 2208 | intintLCGLinearOpenCompactCLHash_RangeInsertSingleNoOverwrite | |
| 2209 | (tableData, numInsertions, keys, values); | |
| 2210 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2211 | return | |
| 2212 | intintLCGQuadraticOpenCompactCLHash_RangeInsertSingleNoOverwrite | |
| 2213 | (tableData, numInsertions, keys, values); | |
| 2214 | } | |
| 2215 | } | |
| 2216 | int intintHash_Query(__global char *tableData, unsigned int numKeys, | |
| 2217 | __global int *keys, __global int *valuesOutput) { | |
| 2218 | switch (((__global int *)tableData)[0]) { | |
| 2219 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2220 | return intintIdentityPerfectCLHash_Query(tableData, numKeys, | |
| 2221 | keys, valuesOutput); | |
| 2222 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2223 | return intintIdentitySentinelPerfectCLHash_Query(tableData, | |
| 2224 | numKeys, keys, | |
| 2225 | valuesOutput); | |
| 2226 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2227 | return intintLCGLinearOpenCompactCLHash_Query(tableData, | |
| 2228 | numKeys, keys, | |
| 2229 | valuesOutput); | |
| 2230 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2231 | return intintLCGQuadraticOpenCompactCLHash_Query(tableData, | |
| 2232 | numKeys, keys, | |
| 2233 | valuesOutput); | |
| 2234 | } | |
| 2235 | return HASH_EXIT_CODE_ERROR; | |
| 2236 | } | |
| 2237 | int intintHash_QuerySingle(__global char *tableData, int key, | |
| 2238 | __global int *valueOutput) { | |
| 2239 | switch (((__global int *)tableData)[0]) { | |
| 2240 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2241 | return intintIdentityPerfectCLHash_QuerySingle(tableData, key, | |
| 2242 | valueOutput); | |
| 2243 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2244 | return | |
| 2245 | intintIdentitySentinelPerfectCLHash_QuerySingle(tableData, | |
| 2246 | key, | |
| 2247 | valueOutput); | |
| 2248 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2249 | return intintLCGLinearOpenCompactCLHash_QuerySingle(tableData, | |
| 2250 | key, | |
| 2251 | valueOutput); | |
| 2252 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2253 | return | |
| 2254 | intintLCGQuadraticOpenCompactCLHash_QuerySingle(tableData, | |
| 2255 | key, | |
| 2256 | valueOutput); | |
| 2257 | } | |
| 2258 | return HASH_EXIT_CODE_ERROR; | |
| 2259 | } | |
| 2260 | int intintHash_Insert(__global char *tableData, unsigned int numEntries, | |
| 2261 | __global int *keys, __global int *values) { | |
| 2262 | switch (((__global int *)tableData)[0]) { | |
| 2263 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2264 | return intintIdentityPerfectCLHash_Insert(tableData, numEntries, | |
| 2265 | keys, values); | |
| 2266 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2267 | return intintIdentitySentinelPerfectCLHash_Insert(tableData, | |
| 2268 | numEntries, | |
| 2269 | keys, values); | |
| 2270 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2271 | return intintLCGLinearOpenCompactCLHash_Insert(tableData, | |
| 2272 | numEntries, keys, | |
| 2273 | values); | |
| 2274 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2275 | return intintLCGQuadraticOpenCompactCLHash_Insert(tableData, | |
| 2276 | numEntries, | |
| 2277 | keys, values); | |
| 2278 | } | |
| 2279 | return HASH_EXIT_CODE_ERROR; | |
| 2280 | } | |
| 2281 | int intintHash_InsertSingle(__global char *tableData, int key, int value) { | |
| 2282 | switch (((__global int *)tableData)[0]) { | |
| 2283 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2284 | return intintIdentityPerfectCLHash_InsertSingle(tableData, key, | |
| 2285 | value); | |
| 2286 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2287 | return | |
| 2288 | intintIdentitySentinelPerfectCLHash_InsertSingle(tableData, | |
| 2289 | key, | |
| 2290 | value); | |
| 2291 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2292 | return intintLCGLinearOpenCompactCLHash_InsertSingle(tableData, | |
| 2293 | key, | |
| 2294 | value); | |
| 2295 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2296 | return | |
| 2297 | intintLCGQuadraticOpenCompactCLHash_InsertSingle(tableData, | |
| 2298 | key, | |
| 2299 | value); | |
| 2300 | } | |
| 2301 | return HASH_EXIT_CODE_ERROR; | |
| 2302 | } | |
| 2303 | int intintHash_InsertNoOverwrite(__global char *tableData, | |
| 2304 | unsigned int numEntries, __global int *keys, | |
| 2305 | __global int *values) { | |
| 2306 | switch (((__global int *)tableData)[0]) { | |
| 2307 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2308 | return intintIdentityPerfectCLHash_InsertNoOverwrite(tableData, | |
| 2309 | numEntries, | |
| 2310 | keys, | |
| 2311 | values); | |
| 2312 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2313 | return | |
| 2314 | intintIdentitySentinelPerfectCLHash_InsertNoOverwrite | |
| 2315 | (tableData, numEntries, keys, values); | |
| 2316 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2317 | return | |
| 2318 | intintLCGLinearOpenCompactCLHash_InsertNoOverwrite | |
| 2319 | (tableData, numEntries, keys, values); | |
| 2320 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2321 | return | |
| 2322 | intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite | |
| 2323 | (tableData, numEntries, keys, values); | |
| 2324 | } | |
| 2325 | return HASH_EXIT_CODE_ERROR; | |
| 2326 | } | |
| 2327 | int intintHash_InsertSingleNoOverwrite(__global char *tableData, int key, | |
| 2328 | int value) { | |
| 2329 | switch (((__global int *)tableData)[0]) { | |
| 2330 | case IDENTITY_PERFECT_CL_HASH_ID: | |
| 2331 | return | |
| 2332 | intintIdentityPerfectCLHash_InsertSingleNoOverwrite | |
| 2333 | (tableData, key, value); | |
| 2334 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: | |
| 2335 | return | |
| 2336 | intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite | |
| 2337 | (tableData, key, value); | |
| 2338 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: | |
| 2339 | return | |
| 2340 | intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite | |
| 2341 | (tableData, key, value); | |
| 2342 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: | |
| 2343 | return | |
| 2344 | intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite | |
| 2345 | (tableData, key, value); | |
| 2346 | } | |
| 2347 | return HASH_EXIT_CODE_ERROR; | |
| 2348 | } |
| … | … | @@ -1,230 +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 | #define GLOBAL __global | |
| 34 | ||
| 35 | int intintIdentityPerfectCLHash_InsertSingle(__global char *tableData, | |
| 36 | int key, int value); | |
| 37 | int intintIdentityPerfectCLHash_InnerInsertSingle(__global char *tableData, | |
| 38 | int key, int value); | |
| 39 | int intintHash_InsertSingle(__global char *tableData, int key, int value); | |
| 40 | int intintIdentityPerfectCLHash_InnerQuery(__global char *tableData, | |
| 41 | unsigned int numKeys, | |
| 42 | __global int *keys, | |
| 43 | __global int *valuesOutput); | |
| 44 | int intintIdentityPerfectCLHash_InnerQuerySingle(__global char *tableData, | |
| 45 | int key, | |
| 46 | __global int *valueOutput); | |
| 47 | int intintIdentityPerfectCLHash_InnerInsert(__global char *tableData, | |
| 48 | unsigned int numEntries, | |
| 49 | __global int *keys, | |
| 50 | __global int *values); | |
| 51 | int intintIdentityPerfectCLHash_InnerInsertSingleNoOverwrite(__global char | |
| 52 | *tableData, | |
| 53 | int key, | |
| 54 | int value); | |
| 55 | int intintIdentityPerfectCLHash_InnerInsertNoOverwrite(__global char *tableData, | |
| 56 | unsigned int numEntries, | |
| 57 | __global int *keys, | |
| 58 | __global int *values); | |
| 59 | int intintIdentityPerfectCLHash_QuerySingle(__global char *tableData, int key, | |
| 60 | __global int *valueOutput); | |
| 61 | int intintIdentityPerfectCLHash_QuerySingle(__global char *tableData, int key, | |
| 62 | __global int *valueOutput); | |
| 63 | int intintIdentityPerfectCLHash_Query(__global char *tableData, size_t numKeys, | |
| 64 | __global int *keys, | |
| 65 | __global int *valuesOutput); | |
| 66 | int intintIdentityPerfectCLHash_Insert(__global char *tableData, | |
| 67 | size_t numEntries, __global int *keys, | |
| 68 | __global int *values); | |
| 69 | int intintIdentityPerfectCLHash_InsertSingleNoOverwrite(__global char | |
| 70 | *tableData, int key, | |
| 71 | int value); | |
| 72 | int intintIdentityPerfectCLHash_InsertNoOverwrite(__global char *tableData, | |
| 73 | size_t numEntries, | |
| 74 | __global int *keys, | |
| 75 | __global int *values); | |
| 76 | int intintIdentitySentinelPerfectCLHash_InnerInsertNoOverwrite(__global char *tableData, | |
| 77 | unsigned int numEntries, | |
| 78 | __global int *keys, | |
| 79 | __global int *values); | |
| 80 | int intintIdentitySentinelPerfectCLHash_InnerQuerySingle(__global char *tableData, int key, | |
| 81 | __global int *valueOutput); | |
| 82 | int intintIdentitySentinelPerfectCLHash_InnerQuery(__global char *tableData, | |
| 83 | unsigned int numKeys, | |
| 84 | __global int *keys, | |
| 85 | __global int *valuesOutput); | |
| 86 | int intintIdentitySentinelPerfectCLHash_InnerInsertSingle(__global char *tableData, int key, | |
| 87 | int value); | |
| 88 | int intintIdentitySentinelPerfectCLHash_InnerInsert(__global char *tableData, | |
| 89 | unsigned int numEntries, | |
| 90 | __global int *keys, | |
| 91 | __global int *values); | |
| 92 | int intintIdentitySentinelPerfectCLHash_InnerInsertSingleNoOverwrite(__global char *tableData, | |
| 93 | int key, | |
| 94 | int value); | |
| 95 | int intintIdentitySentinelPerfectCLHash_QuerySingle(__global char *tableData, | |
| 96 | int key, | |
| 97 | __global int *valueOutput); | |
| 98 | int intintIdentitySentinelPerfectCLHash_Query(__global char *tableData, | |
| 99 | size_t numKeys, | |
| 100 | __global int *keys, | |
| 101 | __global int *valuesOutput); | |
| 102 | int intintIdentitySentinelPerfectCLHash_InsertSingle(__global char *tableData, | |
| 103 | int key, int value); | |
| 104 | int intintIdentitySentinelPerfectCLHash_Insert(__global char *tableData, | |
| 105 | size_t numEntries, | |
| 106 | __global int *keys, | |
| 107 | __global int *values); | |
| 108 | int intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite(__global char | |
| 109 | *tableData, | |
| 110 | int key, | |
| 111 | int value); | |
| 112 | int intintIdentitySentinelPerfectCLHash_InsertNoOverwrite(__global char *tableData, | |
| 113 | size_t numEntries, | |
| 114 | __global int *keys, | |
| 115 | __global int *values); | |
| 116 | int intintLCGLinearOpenCompactCLHash_InnerQuerySingle(__global char *tableData, | |
| 117 | int key, | |
| 118 | __global int *valueOutput); | |
| 119 | int intintLCGLinearOpenCompactCLHash_QuerySingle(__global char *tableData, | |
| 120 | int key, | |
| 121 | __global int *valueOutput); | |
| 122 | int intintLCGLinearOpenCompactCLHash_Query(__global char *tableData, | |
| 123 | size_t numKeys, __global int *keys, | |
| 124 | __global int *valuesOutput); | |
| 125 | int intintLCGLinearOpenCompactCLHash_InsertSingle(__global char *tableData, | |
| 126 | int key, int value); | |
| 127 | int intintLCGLinearOpenCompactCLHash_Insert(__global char *tableData, | |
| 128 | size_t numEntries, | |
| 129 | __global int *keys, | |
| 130 | __global int *values); | |
| 131 | int intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite(__global char | |
| 132 | *tableData, | |
| 133 | int key, | |
| 134 | int value); | |
| 135 | int intintLCGLinearOpenCompactCLHash_InsertNoOverwrite(__global char *tableData, | |
| 136 | size_t numEntries, | |
| 137 | __global int *keys, | |
| 138 | __global int *values); | |
| 139 | int intintLCGLinearOpenCompactCLHash_InnerQuery(__global char *tableData, | |
| 140 | unsigned int numKeys, | |
| 141 | __global int *keys, | |
| 142 | __global int *valuesOutput); | |
| 143 | int intintLCGLinearOpenCompactCLHash_InnerInsertNoOverwrite(__global char *tableData, | |
| 144 | unsigned int numEntries, | |
| 145 | __global int *keys, | |
| 146 | __global int *values); | |
| 147 | int intintLCGLinearOpenCompactCLHash_InnerInsertSingle(__global char *tableData, | |
| 148 | int key, int value); | |
| 149 | int intintLCGLinearOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global char *tableData, | |
| 150 | int key, int value); | |
| 151 | int intintLCGLinearOpenCompactCLHash_InnerInsert(__global char *tableData, | |
| 152 | unsigned int numEntries, | |
| 153 | __global int *keys, | |
| 154 | __global int *values); | |
| 155 | int intintLCGQuadraticOpenCompactCLHash_InnerQuerySingle(__global char *tableData, int key, | |
| 156 | __global int *valueOutput); | |
| 157 | int intintLCGQuadraticOpenCompactCLHash_InnerQuery(__global char *tableData, | |
| 158 | unsigned int numKeys, | |
| 159 | __global int *keys, | |
| 160 | __global int *valuesOutput); | |
| 161 | int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingle(__global char *tableData, int key, | |
| 162 | int value); | |
| 163 | int intintLCGQuadraticOpenCompactCLHash_InnerInsert(__global char *tableData, | |
| 164 | unsigned int numEntries, | |
| 165 | __global int *keys, | |
| 166 | __global int *values); | |
| 167 | int intintLCGQuadraticOpenCompactCLHash_InnerInsertSingleNoOverwrite(__global char *tableData, | |
| 168 | int key, int value); | |
| 169 | int intintLCGQuadraticOpenCompactCLHash_InnerInsertNoOverwrite(__global char *tableData, | |
| 170 | unsigned int numEntries, | |
| 171 | __global int *keys, | |
| 172 | __global int *values); | |
| 173 | int intintLCGQuadraticOpenCompactCLHash_QuerySingle(__global char *tableData, | |
| 174 | int key, | |
| 175 | __global int *valueOutput); | |
| 176 | int intintLCGQuadraticOpenCompactCLHash_Query(__global char *tableData, | |
| 177 | size_t numKeys, | |
| 178 | __global int *keys, | |
| 179 | __global int *valuesOutput); | |
| 180 | int intintLCGQuadraticOpenCompactCLHash_InsertSingle(__global char *tableData, | |
| 181 | int key, int value); | |
| 182 | int intintLCGQuadraticOpenCompactCLHash_Insert(__global char *tableData, | |
| 183 | size_t numEntries, | |
| 184 | __global int *keys, | |
| 185 | __global int *values); | |
| 186 | int intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite(__global char | |
| 187 | *tableData, | |
| 188 | int key, | |
| 189 | int value); | |
| 190 | int intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite(__global char *tableData, | |
| 191 | size_t numEntries, | |
| 192 | __global int *keys, | |
| 193 | __global int *values); | |
| 194 | int intintHash_Query(__global char *tableData, unsigned int numKeys, | |
| 195 | __global int *keys, __global int *valuesOutput); | |
| 196 | int intintHash_QuerySingle(__global char *tableData, int key, | |
| 197 | __global int *valueOutput); | |
| 198 | int intintHash_Insert(__global char *tableData, unsigned int numEntries, | |
| 199 | __global int *keys, __global int *values); | |
| 200 | int intintHash_InsertNoOverwrite(__global char *tableData, | |
| 201 | unsigned int numEntries, __global int *keys, | |
| 202 | __global int *values); | |
| 203 | int intintHash_InsertSingleNoOverwrite(__global char *tableData, int key, | |
| 204 | int value); | |
| 205 | #define DELAY(X) X | |
| 206 | DELAY(#define HASH_REPORT_NEVER /**/ 0) | |
| 207 | DELAY(#define HASH_REPORT_CYCLE /**/ 1) | |
| 208 | DELAY(#define HASH_REPORT_END /****/ 2) | |
| 209 | // | |
| 210 | DELAY(#define HASH_EXIT_CODE_NORMAL /****************/ -1) | |
| 211 | DELAY(#define HASH_EXIT_CODE_ERROR /*****************/ -2) | |
| 212 | DELAY(#define HASH_EXIT_CODE_OVERWRITE /*************/ -3) | |
| 213 | DELAY(#define HASH_EXIT_CODE_KEY_DNE /***************/ -4) | |
| 214 | DELAY(#define HASH_EXIT_CODE_CYCLE /*****************/ -5) | |
| 215 | DELAY(#define HASH_EXIT_CODE_MAX_ENTRIES_EXCEEDED /**/ -6) | |
| 216 | DELAY(#define HASH_EXIT_CODE_BUCKET_INDEX_OOB /******/ -7) | |
| 217 | // | |
| 218 | DELAY(#define HASH_SEARCH_CODE_MATCH /*****/ 0) | |
| 219 | DELAY(#define HASH_SEARCH_CODE_MISMATCH /**/ 1) | |
| 220 | DELAY(#define HASH_SEARCH_CODE_EMPTY /*****/ 2) | |
| 221 | // | |
| 222 | DELAY(#define LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID /**/ 8) | |
| 223 | DELAY(#define LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID /**/ 4) | |
| 224 | DELAY(#define IDENTITY_SENTINEL_PERFECT_CL_HASH_ID /*******/ 2) | |
| 225 | DELAY(#define IDENTITY_PERFECT_CL_HASH_ID /*******/ 1) | |
| 226 | // | |
| 227 | DELAY(#define HASH_BUCKET_STATUS_EMPTY /**/ -1) | |
| 228 | DELAY(#define HASH_BUCKET_STATUS_FULL /***/ -2) | |
| 229 | DELAY(#define HASH_BUCKET_STATUS_LOCK /***/ -3) | |
| 230 | HASH_KERN_DEFINE(intint, int, int) |
| … | … | @@ -1,372 +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 "perfectHash.cm" | |
| 34 | #include "compactHash.cm" | |
| 35 | #include "hash.hm" | |
| 36 | ||
| 37 | #define HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE) \ | |
| 38 | \ | |
| 39 | struct NAME##Hash_Table_{\ | |
| 40 | char* tableData;\ | |
| 41 | cl_mem tableDataBuffer;\ | |
| 42 | int (*destroyFunc)(NAME##Hash_Table*);\ | |
| 43 | int (*emptyFunc)(NAME##Hash_Table*);\ | |
| 44 | int (*queryFunc)(NAME##Hash_Table*, size_t, KEY_TYPE*, VALUE_TYPE*);\ | |
| 45 | int (*querySingleFunc)(NAME##Hash_Table*, KEY_TYPE, VALUE_TYPE*);\ | |
| 46 | int (*insertFunc)(NAME##Hash_Table*, size_t, KEY_TYPE*, VALUE_TYPE*);\ | |
| 47 | int (*insertSingleFunc)(NAME##Hash_Table*, KEY_TYPE, VALUE_TYPE);\ | |
| 48 | int (*insertNoOverwriteFunc)(NAME##Hash_Table*, size_t, KEY_TYPE*, VALUE_TYPE*);\ | |
| 49 | int (*insertSingleNoOverwriteFunc)(NAME##Hash_Table*, KEY_TYPE, VALUE_TYPE);\ | |
| 50 | int (*bufferQueryFunc)(NAME##Hash_Table*, size_t, cl_mem, cl_mem);\ | |
| 51 | int (*bufferInsertFunc)(NAME##Hash_Table*, size_t, cl_mem, cl_mem);\ | |
| 52 | int (*bufferInsertNoOverwriteFunc)(NAME##Hash_Table*, size_t, cl_mem, cl_mem);\ | |
| 53 | cl_context context;\ | |
| 54 | cl_command_queue queue;\ | |
| 55 | cl_program utilProgram;\ | |
| 56 | cl_kernel emptyKernel;\ | |
| 57 | size_t emptyKernelLocalWorkSize;\ | |
| 58 | cl_program program;\ | |
| 59 | cl_kernel querySingleKernel;\ | |
| 60 | cl_kernel insertSingleKernel;\ | |
| 61 | cl_kernel insertSingleNoOverwriteKernel;\ | |
| 62 | size_t localWorkSize;\ | |
| 63 | };\ | |
| 64 | \ | |
| 65 | struct NAME##Hash_Factory_{\ | |
| 66 | cl_context context;\ | |
| 67 | cl_program program;\ | |
| 68 | cl_command_queue queue;\ | |
| 69 | int hashTypesAvailable;\ | |
| 70 | cl_program utilProgram[HASH_NUM_CL_HASHES];\ | |
| 71 | cl_kernel emptyKernel[HASH_NUM_CL_HASHES];\ | |
| 72 | size_t emptyKernelLocalWorkSize[HASH_NUM_CL_HASHES];\ | |
| 73 | cl_kernel querySingleKernel[HASH_NUM_CL_HASHES];\ | |
| 74 | cl_kernel insertSingleKernel[HASH_NUM_CL_HASHES];\ | |
| 75 | cl_kernel insertSingleNoOverwriteKernel[HASH_NUM_CL_HASHES];\ | |
| 76 | VALUE_TYPE emptyValue;\ | |
| 77 | size_t localWorkSize;\ | |
| 78 | NAME##Hash_Table* (*createFunc[HASH_NUM_HASHES])(NAME##Hash_Factory*, int hashIndex, size_t keyRange, size_t numEntries, float loadFactor);\ | |
| 79 | int (*destroyFunc[HASH_NUM_HASHES])(NAME##Hash_Factory*, int hashIndex);\ | |
| 80 | };\ | |
| 81 | \ | |
| 82 | NAME##Hash_Factory* NAME##Hash_CreateFactory(int hashTypes, VALUE_TYPE *emptyValue, size_t localWorkSize, cl_context *context, cl_command_queue *queue){\ | |
| 83 | if(hashTypes == 0){\ | |
| 84 | hashTypes = HASH_ALL_C_HASHES;\ | |
| 85 | }\ | |
| 86 | if(!(hashTypes & HASH_ALL_HASHES)){\ | |
| 87 | printf("Please specify a valid hash type to create.\n");\ | |
| 88 | exit(1);\ | |
| 89 | }\ | |
| 90 | hashTypes &= HASH_ALL_HASHES;\ | |
| 91 | if((hashTypes & HASH_SENTINEL_PERFECT_HASHES) == hashTypes && emptyValue == NULL){\ | |
| 92 | printf("emptyValue must be valid if a sentinel perfect hash is the only option available.\n");\ | |
| 93 | exit(1);\ | |
| 94 | }\ | |
| 95 | NAME##Hash_Factory *factory = (NAME##Hash_Factory*)malloc(sizeof(NAME##Hash_Factory));\ | |
| 96 | if(emptyValue == NULL){\ | |
| 97 | hashTypes &= !HASH_SENTINEL_PERFECT_HASHES;\ | |
| 98 | }else{\ | |
| 99 | factory->emptyValue = *emptyValue;\ | |
| 100 | }\ | |
| 101 | factory->hashTypesAvailable = hashTypes;\ | |
| 102 | if(hashTypes & HASH_ALL_CL_HASHES){\ | |
| 103 | if(localWorkSize == 0){\ | |
| 104 | factory->localWorkSize = HASH_DEFAULT_LOCAL_WORK_SIZE;\ | |
| 105 | }else{\ | |
| 106 | factory->localWorkSize = 1 << intLog2(localWorkSize);\ | |
| 107 | }\ | |
| 108 | if(context == NULL){\ | |
| 109 | CLHash_Utilities_CreateContext(&factory->context, &factory->queue);\ | |
| 110 | }else{\ | |
| 111 | factory->context = *context;\ | |
| 112 | clRetainContext(*context);\ | |
| 113 | if(queue == NULL){\ | |
| 114 | printf("Please specify a command queue for your context.\n");\ | |
| 115 | exit(-1);\ | |
| 116 | }\ | |
| 117 | factory->queue = *queue;\ | |
| 118 | clRetainCommandQueue(*queue);\ | |
| 119 | }\ | |
| 120 | cl_int error;\ | |
| 121 | cl_device_id device;\ | |
| 122 | error = clGetContextInfo(factory->context, CL_CONTEXT_DEVICES, sizeof(device), &device, NULL);\ | |
| 123 | CLHash_Utilities_HandleError(error, STRINGIFY(NAME##Hash_CreateFactory), "clGetContextInfo");\ | |
| 124 | factory->program = CLHash_Utilities_BuildProgramString(factory->context, device, Hash_GetKernelSourceString());\ | |
| 125 | }\ | |
| 126 | int hashType=1;\ | |
| 127 | for(int hashIndex = 0; hashIndex < HASH_NUM_HASHES; hashIndex++){\ | |
| 128 | hashType = 1 << hashIndex;\ | |
| 129 | switch(hashType & hashTypes){\ | |
| 130 | case IDENTITY_PERFECT_HASH_ID: NAME##IdentityPerfectHash_CreateFactory(factory, hashIndex); break;\ | |
| 131 | case IDENTITY_PERFECT_CL_HASH_ID: NAME##IdentityPerfectCLHash_CreateFactory(factory, hashIndex); break;\ | |
| 132 | case IDENTITY_SENTINEL_PERFECT_HASH_ID: NAME##IdentitySentinelPerfectHash_CreateFactory(factory, hashIndex); break;\ | |
| 133 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: NAME##IdentitySentinelPerfectCLHash_CreateFactory(factory, hashIndex); break;\ | |
| 134 | case LCG_LINEAR_OPEN_COMPACT_HASH_ID: NAME##LCGLinearOpenCompactHash_CreateFactory(factory, hashIndex); break;\ | |
| 135 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: NAME##LCGLinearOpenCompactCLHash_CreateFactory(factory, hashIndex); break;\ | |
| 136 | case LCG_QUADRATIC_OPEN_COMPACT_HASH_ID: NAME##LCGQuadraticOpenCompactHash_CreateFactory(factory, hashIndex); break;\ | |
| 137 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: NAME##LCGQuadraticOpenCompactCLHash_CreateFactory(factory, hashIndex); break;\ | |
| 138 | }\ | |
| 139 | }\ | |
| 140 | return factory;\ | |
| 141 | }\ | |
| 142 | \ | |
| 143 | int NAME##Hash_DestroyFactory(NAME##Hash_Factory *factory){\ | |
| 144 | int hashType;\ | |
| 145 | for(int hashIndex = 0; hashIndex < HASH_NUM_HASHES; hashType = 1 << hashIndex){\ | |
| 146 | switch(hashType & factory->hashTypesAvailable){\ | |
| 147 | case IDENTITY_PERFECT_HASH_ID: NAME##IdentityPerfectHash_DestroyFactory(factory, hashIndex); break;\ | |
| 148 | case IDENTITY_PERFECT_CL_HASH_ID: NAME##IdentityPerfectCLHash_DestroyFactory(factory, hashIndex); break;\ | |
| 149 | case IDENTITY_SENTINEL_PERFECT_HASH_ID: NAME##IdentitySentinelPerfectHash_DestroyFactory(factory, hashIndex); break;\ | |
| 150 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: NAME##IdentitySentinelPerfectCLHash_DestroyFactory(factory, hashIndex); break;\ | |
| 151 | case LCG_LINEAR_OPEN_COMPACT_HASH_ID: NAME##LCGLinearOpenCompactHash_DestroyFactory(factory, hashIndex); break;\ | |
| 152 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: NAME##LCGLinearOpenCompactCLHash_DestroyFactory(factory, hashIndex); break;\ | |
| 153 | case LCG_QUADRATIC_OPEN_COMPACT_HASH_ID: NAME##LCGQuadraticOpenCompactHash_DestroyFactory(factory, hashIndex); break;\ | |
| 154 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: NAME##LCGQuadraticOpenCompactCLHash_DestroyFactory(factory, hashIndex); break;\ | |
| 155 | }\ | |
| 156 | hashIndex++;\ | |
| 157 | }\ | |
| 158 | if(factory->hashTypesAvailable & HASH_ALL_CL_HASHES){\ | |
| 159 | clReleaseContext(factory->context);\ | |
| 160 | clReleaseCommandQueue(factory->queue);\ | |
| 161 | clReleaseProgram(factory->program);\ | |
| 162 | }\ | |
| 163 | free(factory);\ | |
| 164 | return(0);\ | |
| 165 | }\ | |
| 166 | \ | |
| 167 | NAME##Hash_Table* NAME##Hash_CreateTable(NAME##Hash_Factory* factory, int hashTypes, size_t keyRange, size_t numEntries, float loadFactor){\ | |
| 168 | if(loadFactor > 1.0 || loadFactor < HASH_MIN_LOAD_FACTOR){\ | |
| 169 | loadFactor = HASH_DEFAULT_LOAD_FACTOR;\ | |
| 170 | }\ | |
| 171 | if(hashTypes == 0){\ | |
| 172 | hashTypes = factory->hashTypesAvailable;\ | |
| 173 | if((hashTypes & HASH_ALL_CL_HASHES) && (hashTypes & HASH_ALL_C_HASHES)){\ | |
| 174 | hashTypes &= HASH_ALL_C_HASHES;\ | |
| 175 | }\ | |
| 176 | }\ | |
| 177 | if(!(hashTypes & factory->hashTypesAvailable)){\ | |
| 178 | printf("None of the selected hash types are supported by this factory.\n");\ | |
| 179 | exit(1);\ | |
| 180 | }\ | |
| 181 | hashTypes &= factory->hashTypesAvailable;\ | |
| 182 | if((hashTypes & HASH_ALL_CL_HASHES) && (hashTypes & HASH_ALL_C_HASHES)){\ | |
| 183 | printf("Please decide between OpenCL or C hash.\n");\ | |
| 184 | exit(1);\ | |
| 185 | }\ | |
| 186 | if((hashTypes & HASH_PERFECT_HASHES) == hashTypes && keyRange == 0){\ | |
| 187 | printf("keyRange must be set if a perfect hash is the only option available.\n");\ | |
| 188 | exit(1);\ | |
| 189 | }\ | |
| 190 | if((hashTypes & HASH_COMPACT_HASHES) == hashTypes && numEntries == 0){\ | |
| 191 | printf("numEntries must be set if a compact hash is the only option available.\n");\ | |
| 192 | exit(1);\ | |
| 193 | }\ | |
| 194 | if(numEntries == 0 && keyRange == 0){\ | |
| 195 | printf("either numEntries or keyRange must be set.\n");\ | |
| 196 | exit(1);\ | |
| 197 | }\ | |
| 198 | size_t perfectNumBuckets = keyRange;\ | |
| 199 | size_t compactNumBuckets = (size_t)(numEntries/loadFactor);\ | |
| 200 | int hashIndex;\ | |
| 201 | if((hashTypes & HASH_SENTINEL_PERFECT_HASHES) && ((hashTypes == (hashTypes & HASH_SENTINEL_PERFECT_HASHES)) || (compactNumBuckets == 0 || (perfectNumBuckets/compactNumBuckets < HASH_PERFECT_COMPACT_SWITCH_FACTOR)))){\ | |
| 202 | hashIndex = intLog2(hashTypes & HASH_SENTINEL_PERFECT_HASHES);\ | |
| 203 | }else if((hashTypes & HASH_NOSENTINEL_PERFECT_HASHES) && ((hashTypes == (hashTypes & HASH_PERFECT_HASHES)) || (compactNumBuckets == 0 || (perfectNumBuckets/compactNumBuckets < HASH_PERFECT_COMPACT_SWITCH_FACTOR)))){\ | |
| 204 | hashIndex = intLog2(hashTypes & HASH_NOSENTINEL_PERFECT_HASHES);\ | |
| 205 | }else if((hashTypes & HASH_LINEAR_COMPACT_HASHES) && ((hashTypes == (hashTypes & (HASH_PERFECT_HASHES | HASH_LINEAR_COMPACT_HASHES))) || ((hashTypes & HASH_COMPACT_HASHES & HASH_LINEAR_COMPACT_HASHES) == (hashTypes & HASH_COMPACT_HASHES) || loadFactor > 0.5))){\ | |
| 206 | hashIndex = intLog2(hashTypes & HASH_LINEAR_COMPACT_HASHES);\ | |
| 207 | }else{\ | |
| 208 | hashIndex = intLog2(hashTypes & HASH_QUADRATIC_COMPACT_HASHES);\ | |
| 209 | }\ | |
| 210 | NAME##Hash_Table *table = factory->createFunc[hashIndex](factory, hashIndex, keyRange, numEntries, loadFactor);\ | |
| 211 | return table;\ | |
| 212 | }\ | |
| 213 | \ | |
| 214 | int NAME##Hash_EmptyTable(NAME##Hash_Table *table){\ | |
| 215 | table->emptyFunc(table);\ | |
| 216 | return(0);\ | |
| 217 | }\ | |
| 218 | \ | |
| 219 | int NAME##Hash_DestroyTable(NAME##Hash_Table *table){\ | |
| 220 | table->destroyFunc(table);\ | |
| 221 | return(0);\ | |
| 222 | }\ | |
| 223 | \ | |
| 224 | cl_mem NAME##Hash_GetTableDataBuffer(NAME##Hash_Table *table){\ | |
| 225 | return table->tableDataBuffer;\ | |
| 226 | }\ | |
| 227 | \ | |
| 228 | cl_mem *NAME##Hash_GetTableDataBufferPtr(NAME##Hash_Table *table){\ | |
| 229 | return &table->tableDataBuffer;\ | |
| 230 | }\ | |
| 231 | \ | |
| 232 | int NAME##Hash_GetTableType(NAME##Hash_Table *table){\ | |
| 233 | return ((int*)table->tableData)[0];\ | |
| 234 | }\ | |
| 235 | \ | |
| 236 | int NAME##Hash_Query(NAME##Hash_Table *table, size_t numKeys, KEY_TYPE *keys, VALUE_TYPE *valuesOutput){\ | |
| 237 | table->queryFunc(table, numKeys, keys, valuesOutput);\ | |
| 238 | return(0);\ | |
| 239 | }\ | |
| 240 | \ | |
| 241 | int NAME##Hash_QuerySingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE *valueOutput){\ | |
| 242 | table->querySingleFunc(table, key, valueOutput);\ | |
| 243 | return(0);\ | |
| 244 | }\ | |
| 245 | \ | |
| 246 | int NAME##Hash_Insert(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values){\ | |
| 247 | table->insertFunc(table, numEntries, keys, values);\ | |
| 248 | return(0);\ | |
| 249 | }\ | |
| 250 | \ | |
| 251 | int NAME##Hash_InsertSingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value){\ | |
| 252 | table->insertSingleFunc(table, key, value);\ | |
| 253 | return(0);\ | |
| 254 | }\ | |
| 255 | \ | |
| 256 | int NAME##Hash_InsertNoOverwrite(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values){\ | |
| 257 | table->insertNoOverwriteFunc(table, numEntries, keys, values);\ | |
| 258 | return(0);\ | |
| 259 | }\ | |
| 260 | \ | |
| 261 | int NAME##Hash_InsertSingleNoOverwrite(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value){\ | |
| 262 | table->insertSingleNoOverwriteFunc(table, key, value);\ | |
| 263 | return(0);\ | |
| 264 | }\ | |
| 265 | int NAME##Hash_BufferQuery(NAME##Hash_Table *table, size_t numKeys, cl_mem keys, cl_mem valuesOutput){\ | |
| 266 | table->bufferQueryFunc(table, numKeys, keys, valuesOutput);\ | |
| 267 | return(0);\ | |
| 268 | }\ | |
| 269 | \ | |
| 270 | int NAME##Hash_BufferInsert(NAME##Hash_Table *table, size_t numEntries, cl_mem keys, cl_mem values){\ | |
| 271 | table->bufferInsertFunc(table, numEntries, keys, values);\ | |
| 272 | return(0);\ | |
| 273 | }\ | |
| 274 | \ | |
| 275 | int NAME##Hash_BufferInsertNoOverwrite(NAME##Hash_Table *table, size_t numEntries, cl_mem keys, cl_mem values){\ | |
| 276 | table->bufferInsertNoOverwriteFunc(table, numEntries, keys, values);\ | |
| 277 | return(0);\ | |
| 278 | }\ | |
| 279 | \ | |
| 280 | IDENTITY_PERFECT_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 281 | \ | |
| 282 | IDENTITY_PERFECT_CL_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 283 | \ | |
| 284 | IDENTITY_SENTINEL_PERFECT_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 285 | \ | |
| 286 | IDENTITY_SENTINEL_PERFECT_CL_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 287 | \ | |
| 288 | LCG_LINEAR_OPEN_COMPACT_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE, 1)\ | |
| 289 | \ | |
| 290 | LCG_LINEAR_OPEN_COMPACT_CL_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 291 | \ | |
| 292 | LCG_QUADRATIC_OPEN_COMPACT_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE, 1, 0)\ | |
| 293 | \ | |
| 294 | LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 295 | \ | |
| 296 | ||
| 297 | #define KERN_SWITCH_LOOKUP_EXP(NAME, FUNCTION_NAME, ...)\ | |
| 298 | switch(((__global int*)tableData)[0]){\ | |
| 299 | case IDENTITY_PERFECT_CL_HASH_ID: return NAME##IdentityPerfectCLHash_##FUNCTION_NAME(__VA_ARGS__);\ | |
| 300 | case IDENTITY_SENTINEL_PERFECT_CL_HASH_ID: return NAME##IdentitySentinelPerfectCLHash_##FUNCTION_NAME(__VA_ARGS__);\ | |
| 301 | case LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID: return NAME##LCGLinearOpenCompactCLHash_##FUNCTION_NAME(__VA_ARGS__);\ | |
| 302 | case LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID: return NAME##LCGQuadraticOpenCompactCLHash_##FUNCTION_NAME(__VA_ARGS__);\ | |
| 303 | }\ | |
| 304 | \ | |
| 305 | ||
| 306 | #define HASH_KERN_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 307 | \ | |
| 308 | HASH_H_TYPES_DECLARE(NAME, KEY_TYPE)\ | |
| 309 | \ | |
| 310 | IDENTITY_PERFECT_CL_HASH_KERN_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 311 | \ | |
| 312 | IDENTITY_SENTINEL_PERFECT_CL_HASH_KERN_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 313 | \ | |
| 314 | LCG_LINEAR_OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, KEY_TYPE, VALUE_TYPE, 1)\ | |
| 315 | \ | |
| 316 | LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_KERN_DEFINE(NAME, KEY_TYPE, VALUE_TYPE, 1, 0)\ | |
| 317 | \ | |
| 318 | __kernel void NAME##Hash_RangeQuery(__global char *tableData, unsigned int numQueries, unsigned int numKeys, __global KEY_TYPE *keys, __global VALUE_TYPE *valuesOutput){\ | |
| 319 | KERN_SWITCH_LOOKUP_EXP(NAME, RangeQuery, tableData, numQueries, numKeys, keys, valuesOutput)\ | |
| 320 | }\ | |
| 321 | \ | |
| 322 | __kernel void NAME##Hash_RangeQuerySingle(__global char *tableData, unsigned int numQueries, __global KEY_TYPE *keys, __global VALUE_TYPE *valueOutput){\ | |
| 323 | KERN_SWITCH_LOOKUP_EXP(NAME, RangeQuerySingle, tableData, numQueries, keys, valueOutput)\ | |
| 324 | }\ | |
| 325 | \ | |
| 326 | __kernel void NAME##Hash_RangeInsert(__global char *tableData, unsigned int numInsertions, unsigned int numEntries, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 327 | KERN_SWITCH_LOOKUP_EXP(NAME, RangeInsert, tableData, numInsertions, numEntries, keys, values)\ | |
| 328 | }\ | |
| 329 | \ | |
| 330 | __kernel void NAME##Hash_RangeInsertSingle(__global char *tableData, unsigned int numInsertions, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 331 | KERN_SWITCH_LOOKUP_EXP(NAME, RangeInsertSingle, tableData, numInsertions, keys, values)\ | |
| 332 | }\ | |
| 333 | \ | |
| 334 | __kernel void NAME##Hash_RangeInsertNoOverwrite(__global char *tableData, unsigned int numInsertions, unsigned int numEntries, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 335 | KERN_SWITCH_LOOKUP_EXP(NAME, RangeInsertNoOverwrite, tableData, numInsertions, numEntries, keys, values)\ | |
| 336 | }\ | |
| 337 | \ | |
| 338 | __kernel void NAME##Hash_RangeInsertSingleNoOverwrite(__global char *tableData, unsigned int numInsertions, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 339 | KERN_SWITCH_LOOKUP_EXP(NAME, RangeInsertSingleNoOverwrite, tableData, numInsertions, keys, values)\ | |
| 340 | }\ | |
| 341 | \ | |
| 342 | int NAME##Hash_Query(__global char *tableData, unsigned int numKeys, __global KEY_TYPE *keys, __global VALUE_TYPE *valuesOutput){\ | |
| 343 | KERN_SWITCH_LOOKUP_EXP(NAME, Query, tableData, numKeys, keys, valuesOutput)\ | |
| 344 | return HASH_EXIT_CODE_ERROR;\ | |
| 345 | }\ | |
| 346 | \ | |
| 347 | int NAME##Hash_QuerySingle(__global char *tableData, KEY_TYPE key, __global VALUE_TYPE *valueOutput){\ | |
| 348 | KERN_SWITCH_LOOKUP_EXP(NAME, QuerySingle, tableData, key, valueOutput)\ | |
| 349 | return HASH_EXIT_CODE_ERROR;\ | |
| 350 | }\ | |
| 351 | \ | |
| 352 | int NAME##Hash_Insert(__global char *tableData, unsigned int numEntries, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 353 | KERN_SWITCH_LOOKUP_EXP(NAME, Insert, tableData, numEntries, keys, values)\ | |
| 354 | return HASH_EXIT_CODE_ERROR;\ | |
| 355 | }\ | |
| 356 | \ | |
| 357 | int NAME##Hash_InsertSingle(__global char *tableData, KEY_TYPE key, VALUE_TYPE value){\ | |
| 358 | KERN_SWITCH_LOOKUP_EXP(NAME, InsertSingle, tableData, key, value)\ | |
| 359 | return HASH_EXIT_CODE_ERROR;\ | |
| 360 | }\ | |
| 361 | \ | |
| 362 | int NAME##Hash_InsertNoOverwrite(__global char *tableData, unsigned int numEntries, __global KEY_TYPE *keys, __global VALUE_TYPE *values){\ | |
| 363 | KERN_SWITCH_LOOKUP_EXP(NAME, InsertNoOverwrite, tableData, numEntries, keys, values)\ | |
| 364 | return HASH_EXIT_CODE_ERROR;\ | |
| 365 | }\ | |
| 366 | \ | |
| 367 | int NAME##Hash_InsertSingleNoOverwrite(__global char *tableData, KEY_TYPE key, VALUE_TYPE value){\ | |
| 368 | KERN_SWITCH_LOOKUP_EXP(NAME, InsertSingleNoOverwrite, tableData, key, value)\ | |
| 369 | return HASH_EXIT_CODE_ERROR;\ | |
| 370 | }\ | |
| 371 | \ | |
| 372 |
| … | … | @@ -1,225 +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 | #define GLOBAL | |
| 34 | ||
| 35 | #undef UNDEFINED | |
| 36 | #ifdef UNDEFINED | |
| 37 | /** | |
| 38 | * @file hash.cp | |
| 39 | * @author Peter Ahrens | |
| 40 | * @date Thu Jun 6 2013 | |
| 41 | */ | |
| 42 | #endif | |
| 43 | /** | |
| 44 | * @file hash.c | |
| 45 | * @author Peter Ahrens | |
| 46 | * @date Thu Jun 6 2013 | |
| 47 | */ | |
| 48 | // | |
| 49 | #define DELAY(x) x | |
| 50 | #define STRINGIFY_(x) #x | |
| 51 | #define STRINGIFY(x) STRINGIFY_(x) | |
| 52 | DELAY(#include "hash.h") | |
| 53 | DELAY(#ifdef HAVE_OPENCL) | |
| 54 | DELAY(#ifdef __APPLE_CC__) | |
| 55 | DELAY(#include <OpenCL/OpenCL.h>) | |
| 56 | DELAY(#else) | |
| 57 | DELAY(#include <CL/cl.h>) | |
| 58 | DELAY(#endif) | |
| 59 | DELAY(#else) | |
| 60 | typedef int cl_kernel; | |
| 61 | DELAY(#define CL_CONTEXT_DEVICES 0) | |
| 62 | DELAY(#define CL_MEM_READ_WRITE 0) | |
| 63 | DELAY(#define CL_TRUE 1) | |
| 64 | DELAY(#define CL_MEM_READ_ONLY 0) | |
| 65 | DELAY(#define CL_MEM_COPY_HOST_PTR 0) | |
| 66 | DELAY(#define CL_MEM_WRITE_ONLY 0) | |
| 67 | DELAY(#define CL_KERNEL_WORK_GROUP_SIZE 128) | |
| 68 | int clRetainContext(int context) { return context; } | |
| 69 | int clRetainCommandQueue(int command_queue) { return command_queue; } | |
| 70 | int clGetContextInfo(int context, int param, size_t size, void *value, size_t *size_ret) { return 0; } | |
| 71 | int clReleaseContext(int context) { return context; } | |
| 72 | int clReleaseCommandQueue(int command_queue) { return command_queue; } | |
| 73 | int clReleaseProgram(int program) { return program; } | |
| 74 | int clRetainKernel(int kernel) { return kernel; } | |
| 75 | int clRetainProgram(int program) { return program; } | |
| 76 | cl_mem clCreateBuffer(int context, int flags, size_t size, void *value, int *size_ret) { return 0; } | |
| 77 | int clEnqueueWriteBuffer(int command_queue, void *buffer, int blocking_write, size_t offset, size_t cb, const void * ptr, | |
| 78 | uint nevents, const int *wait_list, int *event) { return 0; } | |
| 79 | int clEnqueueReadBuffer(int command_queue, void *buffer, int blocking_write, size_t offset, size_t cb, const void * ptr, | |
| 80 | uint nevents, const int *wait_list, int *event) { return 0; } | |
| 81 | int clCreateKernel(int program, const char *kernel_name, int *errcode_ret) { return 0; } | |
| 82 | int clReleaseKernel(int kernel) { return kernel; } | |
| 83 | int clReleaseMemObject(void * memobj) { return 0; } | |
| 84 | int clSetKernelArg(int kernel, uint arg_index, size_t arg_size, const void *arg_value) { return 0; } | |
| 85 | int clGetKernelWorkGroupInfo(int kernel, int device, int param_name, size_t size, void *value, size_t *size_ret) { return 0; } | |
| 86 | int clEnqueueNDRangeKernel(int command_queue, int kernel, uint work_dim, const size_t *offset, const size_t *size, const size_t *local_size, | |
| 87 | uint nevents, const int *wait_list, int *event) { return 0; } | |
| 88 | int clFinish(int command_queue) { return 0; } | |
| 89 | DELAY(#endif) | |
| 90 | DELAY(#define PRIME_NUM_CHECKS 20) | |
| 91 | typedef unsigned int uint; | |
| 92 | ||
| 93 | ||
| 94 | DELAY(#include <math.h>) | |
| 95 | #include "hash.cm" | |
| 96 | ||
| 97 | #ifdef __cplusplus | |
| 98 | extern "C" | |
| 99 | { | |
| 100 | #endif | |
| 101 | ||
| 102 | static int reportLevel = 0; | |
| 103 | ||
| 104 | const char* hash_source; | |
| 105 | ||
| 106 | const char* Hash_GetKernelSourceString(){ | |
| 107 | return hash_source; | |
| 108 | } | |
| 109 | ||
| 110 | size_t roundUpToNearest(size_t x, size_t r){ | |
| 111 | return (((x - 1) / r) + 1) * r; | |
| 112 | } | |
| 113 | ||
| 114 | int modularPow(int base, int exponent, int modulus){ | |
| 115 | int result = 1; | |
| 116 | while (exponent){ | |
| 117 | if (exponent & 1) | |
| 118 | result = ((long long int)result * base) % modulus; | |
| 119 | exponent >>= 1; | |
| 120 | base = ((long long int)base * base) % modulus; | |
| 121 | } | |
| 122 | return result; | |
| 123 | } | |
| 124 | ||
| 125 | int largestProthPrimeUnder(int N){ | |
| 126 | if(N < 4){ | |
| 127 | return N; | |
| 128 | } | |
| 129 | //determine the nearest proth number | |
| 130 | int n; | |
| 131 | int m; | |
| 132 | frexp((double)N, &n); | |
| 133 | n /= 2; | |
| 134 | int s = 1 << n; | |
| 135 | int p = s * ((N - 1) / s) + 1; | |
| 136 | int i; | |
| 137 | int a; | |
| 138 | srand(p); | |
| 139 | while(p > 3){ | |
| 140 | //check if a proth number is prime | |
| 141 | for(i = 0; i < PRIME_NUM_CHECKS; i++){ | |
| 142 | a = rand(); | |
| 143 | if(modularPow(a, (p - 1) / 2, p) == p - 1){ | |
| 144 | return p; | |
| 145 | } | |
| 146 | } | |
| 147 | //determine the next proth number | |
| 148 | if(p - 1 == s * s / 4){ | |
| 149 | s /= 2; | |
| 150 | } | |
| 151 | p -= s; | |
| 152 | } | |
| 153 | return 3; | |
| 154 | } | |
| 155 | ||
| 156 | int smallestProthPrimeAbove(int N){ | |
| 157 | if(N < 4){ | |
| 158 | return N; | |
| 159 | } | |
| 160 | //determine the nearest proth number | |
| 161 | int n; | |
| 162 | int m; | |
| 163 | frexp((double)N, &n); | |
| 164 | n /= 2; | |
| 165 | int s = 1 << n; | |
| 166 | int p = s * ((N - 1) / s) + 1; | |
| 167 | int i; | |
| 168 | int a; | |
| 169 | srand(p); | |
| 170 | while(1){ | |
| 171 | //determine the next proth number | |
| 172 | if(p - 1 == s * s){ | |
| 173 | s *= 2; | |
| 174 | } | |
| 175 | p += s; | |
| 176 | //check if a proth number is prime | |
| 177 | for(i = 0; i < PRIME_NUM_CHECKS; i++){ | |
| 178 | a = rand(); | |
| 179 | if(modularPow(a, (p - 1) / 2, p) == p - 1){ | |
| 180 | return p; | |
| 181 | } | |
| 182 | } | |
| 183 | } | |
| 184 | return 3; | |
| 185 | } | |
| 186 | ||
| 187 | int intLog2(int n){ | |
| 188 | int result = 0; | |
| 189 | while(n >>= 1){ | |
| 190 | result++; | |
| 191 | } | |
| 192 | return result; | |
| 193 | } | |
| 194 | ||
| 195 | void Hash_SetReportLevel(int level){ | |
| 196 | reportLevel = level; | |
| 197 | } | |
| 198 | ||
| 199 | int Hash_GetReportLevel(){ | |
| 200 | return reportLevel; | |
| 201 | } | |
| 202 | ||
| 203 | char* Hash_ExitCodeString(int exitCode){ | |
| 204 | switch(exitCode){ | |
| 205 | case HASH_EXIT_CODE_NORMAL: return "Normal"; | |
| 206 | case HASH_EXIT_CODE_ERROR: return "Error"; | |
| 207 | case HASH_EXIT_CODE_OVERWRITE: return "Overwrite"; | |
| 208 | case HASH_EXIT_CODE_KEY_DNE: return "Key Does Not Exist"; | |
| 209 | case HASH_EXIT_CODE_CYCLE: return "Cycle"; | |
| 210 | case HASH_EXIT_CODE_MAX_ENTRIES_EXCEEDED: return "Maximum Number Of Entries Exceeded"; | |
| 211 | default: return "Unknown"; | |
| 212 | } | |
| 213 | } | |
| 214 | ||
| 215 | void Hash_ExitCodeDebug(int exitCode){ | |
| 216 | if(exitCode != HASH_EXIT_CODE_NORMAL){ | |
| 217 | printf("HashExitCode: %s\n", Hash_ExitCodeString(exitCode)); | |
| 218 | } | |
| 219 | } | |
| 220 | ||
| 221 | HASH_DEFINE(intint, int, int) | |
| 222 | ||
| 223 | #ifdef __cplusplus | |
| 224 | } | |
| 225 | #endif |
| … | … | @@ -1,573 +0,0 @@ |
| 1 | ||
| 2 | /* Copyright 2013-14. Los Alamos National Security, LLC. This material was produced | |
| 3 | * under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | |
| 4 | * Laboratory (LANL), which is operated by Los Alamos National Security, LLC | |
| 5 | * for the U.S. Department of Energy. The U.S. Government has rights to use, | |
| 6 | * reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | |
| 7 | * ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | |
| 8 | * ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified | |
| 9 | * to produce derivative works, such modified software should be clearly marked, | |
| 10 | * so as not to confuse it with the version available from LANL. | |
| 11 | * | |
| 12 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 13 | * use this file except in compliance with the License. You may obtain a copy | |
| 14 | * of the License at | |
| 15 | * | |
| 16 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 17 | * | |
| 18 | * Unless required by applicable law or agreed to in writing, software distributed | |
| 19 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| 20 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 21 | * specific language governing permissions and limitations under the License. | |
| 22 | * | |
| 23 | * Under this license, it is required to include a reference to this work. We | |
| 24 | * request that each derivative work contain a reference to LANL Copyright | |
| 25 | * Disclosure C14043/LA-CC-14-003 so that this work's impact can be roughly | |
| 26 | * measured. In addition, it is requested that a modifier is included as in | |
| 27 | * the following example: | |
| 28 | * | |
| 29 | * //<Uses | improves on | modified from> LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 30 | * | |
| 31 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 | |
| 32 | */ | |
| 33 | /** | |
| 34 | * @file hash.h | |
| 35 | * @author Peter Ahrens | |
| 36 | * @date Thu Jun 6 2013 | |
| 37 | */ | |
| 38 | // | |
| 39 | #ifndef HASH_H | |
| 40 | #define HASH_H | |
| 41 | // | |
| 42 | #include <stdlib.h> | |
| 43 | #include <stdio.h> | |
| 44 | #include <stdarg.h> | |
| 45 | #include <string.h> | |
| 46 | // | |
| 47 | #ifdef HAVE_OPENCL | |
| 48 | #ifdef __APPLE_CC__ | |
| 49 | #include <OpenCL/OpenCL.h> | |
| 50 | #else | |
| 51 | #include <CL/cl.h> | |
| 52 | #endif | |
| 53 | #else | |
| 54 | typedef void *cl_mem; | |
| 55 | typedef int cl_context; | |
| 56 | typedef int cl_command_queue; | |
| 57 | typedef int cl_program; | |
| 58 | typedef int cl_device_id; | |
| 59 | typedef int cl_int; | |
| 60 | int clRetainContext(int context); | |
| 61 | int clRetainCommandQueue(int command_queue); | |
| 62 | int clGetContextInfo(int context, int param, size_t size, void *value, | |
| 63 | size_t * size_ret); | |
| 64 | int clReleaseContext(int context); | |
| 65 | int clReleaseCommandQueue(int command_queue); | |
| 66 | int clReleaseProgram(int program); | |
| 67 | int clRetainProgram(int program); | |
| 68 | int clRetainKernel(int kernel); | |
| 69 | cl_mem clCreateBuffer(int context, int flags, size_t size, void *value, | |
| 70 | int *size_ret); | |
| 71 | int clEnqueueWriteBuffer(int command_queue, void *buffer, int blocking_write, | |
| 72 | size_t offset, size_t cb, const void *ptr, | |
| 73 | uint nevents, const int *wait_list, int *event); | |
| 74 | int clEnqueueReadBuffer(int command_queue, void *buffer, int blocking_write, | |
| 75 | size_t offset, size_t cb, const void *ptr, uint nevents, | |
| 76 | const int *wait_list, int *event); | |
| 77 | int clCreateKernel(int program, const char *kernel_name, int *errcode_ret); | |
| 78 | int clReleaseKernel(int kernel); | |
| 79 | int clReleaseMemObject(void *memobj); | |
| 80 | int clSetKernelArg(int kernel, uint arg_index, size_t arg_size, | |
| 81 | const void *arg_value); | |
| 82 | int clGetKernelWorkGroupInfo(int kernel, int device, int param_name, | |
| 83 | size_t size, void *value, size_t * size_ret); | |
| 84 | int clEnqueueNDRangeKernel(int command_queue, int kernel, uint work_dim, | |
| 85 | const size_t * offset, const size_t * size, | |
| 86 | const size_t * local_size, uint nevents, | |
| 87 | const int *wait_list, int *event); | |
| 88 | int clFinish(int command_queue); | |
| 89 | #endif | |
| 90 | // | |
| 91 | #include "CLHash_Utilities.h" | |
| 92 | // | |
| 93 | // | |
| 94 | #include "hash.hm" | |
| 95 | #include "hash.cm" | |
| 96 | // | |
| 97 | #define HASH_REPORT_NEVER /**/ 0 | |
| 98 | #define HASH_REPORT_CYCLE /**/ 1 | |
| 99 | #define HASH_REPORT_END /****/ 2 | |
| 100 | // | |
| 101 | #define HASH_EXIT_CODE_NORMAL /****************/ -1 | |
| 102 | #define HASH_EXIT_CODE_ERROR /*****************/ -2 | |
| 103 | #define HASH_EXIT_CODE_OVERWRITE /*************/ -3 | |
| 104 | #define HASH_EXIT_CODE_KEY_DNE /***************/ -4 | |
| 105 | #define HASH_EXIT_CODE_CYCLE /*****************/ -5 | |
| 106 | #define HASH_EXIT_CODE_MAX_ENTRIES_EXCEEDED /**/ -6 | |
| 107 | #define HASH_EXIT_CODE_BUCKET_INDEX_OOB /******/ -7 | |
| 108 | // | |
| 109 | #define HASH_SEARCH_CODE_MATCH /*****/ 0 | |
| 110 | #define HASH_SEARCH_CODE_MISMATCH /**/ 1 | |
| 111 | #define HASH_SEARCH_CODE_EMPTY /*****/ 2 | |
| 112 | // | |
| 113 | #define HASH_NUM_HASHES /**/ 8 | |
| 114 | #define HASH_NUM_CL_HASHES /**/ 4 | |
| 115 | // | |
| 116 | #define LCG_QUADRATIC_OPEN_COMPACT_HASH_ID 128 | |
| 117 | #define LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID 8 | |
| 118 | #define LCG_LINEAR_OPEN_COMPACT_HASH_ID 64 | |
| 119 | #define LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID 4 | |
| 120 | #define IDENTITY_SENTINEL_PERFECT_HASH_ID 32 | |
| 121 | #define IDENTITY_SENTINEL_PERFECT_CL_HASH_ID 2 | |
| 122 | #define IDENTITY_PERFECT_HASH_ID 16 | |
| 123 | #define IDENTITY_PERFECT_CL_HASH_ID 1 | |
| 124 | // | |
| 125 | /** | |
| 126 | * HASH_ALL_CL_HASHES hash table types that run in an OpenCL context. | |
| 127 | */ | |
| 128 | #define HASH_ALL_CL_HASHES (IDENTITY_PERFECT_CL_HASH_ID | IDENTITY_SENTINEL_PERFECT_CL_HASH_ID | LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID | LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID) | |
| 129 | /** | |
| 130 | * HASH_ALL_C_HASHES hash table types that run on the host. | |
| 131 | */ | |
| 132 | #define HASH_ALL_C_HASHES (IDENTITY_PERFECT_HASH_ID | IDENTITY_SENTINEL_PERFECT_HASH_ID | LCG_LINEAR_OPEN_COMPACT_HASH_ID | LCG_QUADRATIC_OPEN_COMPACT_HASH_ID) | |
| 133 | /** | |
| 134 | * HASH_ALL_HASHES all hash table types. | |
| 135 | */ | |
| 136 | #define HASH_ALL_HASHES (HASH_ALL_CL_HASHES | HASH_ALL_C_HASHES) | |
| 137 | /** | |
| 138 | * HASH_NOSENTINEL_PERFECT_HASHES perfect hash table types that do not use a sentinel value to mark empty buckets. | |
| 139 | */ | |
| 140 | #define HASH_NOSENTINEL_PERFECT_HASHES (IDENTITY_PERFECT_HASH_ID | IDENTITY_PERFECT_CL_HASH_ID) | |
| 141 | /** | |
| 142 | * HASH_SENTINEL_PERFECT_HASHES perfect hash table types that use a sentinel value to mark empty buckets. | |
| 143 | */ | |
| 144 | #define HASH_SENTINEL_PERFECT_HASHES (IDENTITY_SENTINEL_PERFECT_HASH_ID | IDENTITY_SENTINEL_PERFECT_CL_HASH_ID) | |
| 145 | /** | |
| 146 | * HASH_PERFECT_HASHES perfect hash table types. | |
| 147 | */ | |
| 148 | #define HASH_PERFECT_HASHES (HASH_NOSENTINEL_PERFECT_HASHES | HASH_SENTINEL_PERFECT_HASHES) | |
| 149 | /** | |
| 150 | * HASH_QUADRATIC_COMPACT_HASHES compact hash table types that use a quadratic probe sequence. | |
| 151 | */ | |
| 152 | #define HASH_QUADRATIC_COMPACT_HASHES (LCG_QUADRATIC_OPEN_COMPACT_HASH_ID | LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID) | |
| 153 | /** | |
| 154 | * HASH_LINEAR_COMPACT_HASHES compact hash table types that use a linear probe sequence. | |
| 155 | */ | |
| 156 | #define HASH_LINEAR_COMPACT_HASHES (LCG_LINEAR_OPEN_COMPACT_HASH_ID | LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID) | |
| 157 | /** | |
| 158 | * HASH_COMPACT_HASHES compact hash table types that use a linear probe sequence. | |
| 159 | */ | |
| 160 | #define HASH_COMPACT_HASHES (HASH_QUADRATIC_COMPACT_HASHES | HASH_LINEAR_COMPACT_HASHES) | |
| 161 | // | |
| 162 | #define HASH_DEFAULT_LOCAL_WORK_SIZE /*******/ 64 | |
| 163 | #define HASH_DEFAULT_LOAD_FACTOR /*******/ 0.3 | |
| 164 | #define HASH_MIN_LOAD_FACTOR /*******/ 0.0009 | |
| 165 | #define HASH_PERFECT_COMPACT_SWITCH_FACTOR /*******/ 20 | |
| 166 | #define HASH_LCG_A /*******/ 2147483629 | |
| 167 | #define HASH_LCG_C /*******/ 2147483587 | |
| 168 | #define HASH_LCG_M /*******/ 2147483647 | |
| 169 | // | |
| 170 | #define HASH_BUCKET_STATUS_EMPTY /**/ -1 | |
| 171 | #define HASH_BUCKET_STATUS_FULL /***/ -2 | |
| 172 | #define HASH_BUCKET_STATUS_LOCK /***/ -3 | |
| 173 | /** | |
| 174 | * Hash_ExitCodeString will return a string representation of the given exit | |
| 175 | * code. | |
| 176 | * | |
| 177 | * @param exitCode | |
| 178 | * | |
| 179 | * @return A string representation of that exit code. | |
| 180 | */ | |
| 181 | char *Hash_ExitCodeString(int exitCode); | |
| 182 | /** | |
| 183 | * Hash_ExitCodeDebug will print a string representation of the given exit code | |
| 184 | * if it is not EXIT_CODE_NORMAL. | |
| 185 | * | |
| 186 | * @param exitCode | |
| 187 | */ | |
| 188 | void Hash_ExitCodeDebug(int exitCode); | |
| 189 | /** | |
| 190 | * Hash_SetReportLevel sets a static report level variable in hash.c. It should | |
| 191 | * be called before hash tables are created. | |
| 192 | * | |
| 193 | * @param level The level of data collection desired. | |
| 194 | */ | |
| 195 | void Hash_SetReportLevel(int level); | |
| 196 | /** | |
| 197 | * Hash_GetReportLevel gets this variable. | |
| 198 | * | |
| 199 | * @return The current report level. | |
| 200 | * Special Values: Meaning | |
| 201 | * HASH_REPORT_NEVER: The hash table will not collect data. This is the | |
| 202 | * default. A call to Hash_Report will return an empty | |
| 203 | * string. | |
| 204 | * HASH_REPORT_END: The hash table will collect data and calls to | |
| 205 | * Hash_Report will return summary information. | |
| 206 | * HASH_REPORT_CYCLE: The hash table will collect data and calls to | |
| 207 | * Hash_Report will return information related to the | |
| 208 | * last important call. | |
| 209 | */ | |
| 210 | int Hash_GetReportLevel(); | |
| 211 | const char *Hash_GetKernelSourceString(); | |
| 212 | int smallestProthPrimeAbove(int N); | |
| 213 | int largestProthPrimeUnder(int N); | |
| 214 | typedef struct intintHash_Table_ intintHash_Table; | |
| 215 | typedef struct intintCLHash_Table_ intintCLHash_Table; | |
| 216 | typedef struct intintHash_Factory_ intintHash_Factory; | |
| 217 | typedef struct intintCLHash_Factory_ intintCLHash_Factory; | |
| 218 | intintHash_Factory *intintHash_CreateFactory(int HashTypes, int *emptyValue, | |
| 219 | size_t localWorkSize, | |
| 220 | cl_context * context, | |
| 221 | cl_command_queue * queue); | |
| 222 | int intintHash_DestroyFactory(intintHash_Factory * factory); | |
| 223 | intintHash_Table *intintHash_CreateTable(intintHash_Factory * factory, | |
| 224 | int hashTypes, size_t keyRange, | |
| 225 | size_t numEntries, float loadFactor); | |
| 226 | int intintHash_EmptyTable(intintHash_Table * table); | |
| 227 | int intintHash_DestroyTable(intintHash_Table * table); | |
| 228 | cl_mem intintHash_GetTableDataBuffer(intintHash_Table * table); | |
| 229 | cl_mem *intintHash_GetTableDataBufferPtr(intintHash_Table * table); | |
| 230 | int intintHash_GetTableType(intintHash_Table * table); | |
| 231 | int intintHash_Query(intintHash_Table * table, size_t numKeys, int *keys, | |
| 232 | int *valuesOutput); | |
| 233 | int intintHash_QuerySingle(intintHash_Table * table, int key, int *valueOutput); | |
| 234 | int intintHash_Insert(intintHash_Table * table, size_t numEntries, int *keys, | |
| 235 | int *values); | |
| 236 | int intintHash_InsertSingle(intintHash_Table * table, int key, int value); | |
| 237 | int intintHash_InsertNoOverwrite(intintHash_Table * table, size_t numEntries, | |
| 238 | int *keys, int *values); | |
| 239 | int intintHash_InsertSingleNoOverwrite(intintHash_Table * table, int key, | |
| 240 | int value); | |
| 241 | int intintHash_BufferQuery(intintHash_Table * table, size_t numKeys, | |
| 242 | cl_mem keys, cl_mem valuesOutput); | |
| 243 | int intintHash_BufferInsert(intintHash_Table * table, size_t numEntries, | |
| 244 | cl_mem keys, cl_mem values); | |
| 245 | int intintHash_BufferInsertNoOverwrite(intintHash_Table * table, | |
| 246 | size_t numEntries, cl_mem keys, | |
| 247 | cl_mem values); | |
| 248 | static inline unsigned int intintHash_CompressIdentity(char data, int hashCode) { | |
| 249 | return hashCode; | |
| 250 | } | |
| 251 | ||
| 252 | typedef struct intintHash_CompressLCGData { | |
| 253 | long unsigned int a; | |
| 254 | long unsigned int c; | |
| 255 | unsigned int m; | |
| 256 | unsigned int n; | |
| 257 | } intintHash_CompressLCGData; | |
| 258 | static inline unsigned int intintHash_CompressLCG(intintHash_CompressLCGData | |
| 259 | compressLCGData, | |
| 260 | int hashCode) { | |
| 261 | return ((compressLCGData.a * hashCode + | |
| 262 | compressLCGData.c) % compressLCGData.m) % compressLCGData.n; | |
| 263 | } | |
| 264 | ||
| 265 | int intintIdentityPerfectHash_CreateFactory(intintHash_Factory * factory, | |
| 266 | int hashIndex); | |
| 267 | int intintIdentityPerfectHash_DestroyFactory(intintHash_Factory * factory, | |
| 268 | int hashIndex); | |
| 269 | intintHash_Table *intintIdentityPerfectHash_CreateTable(intintHash_Factory * | |
| 270 | factory, int hashIndex, | |
| 271 | size_t keyRange, | |
| 272 | size_t numEntries, | |
| 273 | float loadFactor); | |
| 274 | int intintIdentityPerfectHash_InitTable(intintHash_Table * table, va_list args); | |
| 275 | int intintIdentityPerfectHash_DestroyTable(intintHash_Table * table); | |
| 276 | char *intintIdentityPerfectHash_Report(intintHash_Table * table); | |
| 277 | int intintIdentityPerfectHash_EmptyTable(intintHash_Table * table); | |
| 278 | int intintIdentityPerfectHash_Query(intintHash_Table * table, size_t numKeys, | |
| 279 | int *keys, int *valuesOutput); | |
| 280 | int intintIdentityPerfectHash_QuerySingle(intintHash_Table * table, int key, | |
| 281 | int *valueOutput); | |
| 282 | int intintIdentityPerfectHash_Insert(intintHash_Table * table, | |
| 283 | size_t numEntries, int *keys, int *values); | |
| 284 | int intintIdentityPerfectHash_InsertSingle(intintHash_Table * table, int key, | |
| 285 | int value); | |
| 286 | int intintIdentityPerfectHash_InsertNoOverwrite(intintHash_Table * table, | |
| 287 | size_t numEntries, int *keys, | |
| 288 | int *values); | |
| 289 | int intintIdentityPerfectHash_InsertSingleNoOverwrite(intintHash_Table * table, | |
| 290 | int key, int value); | |
| 291 | int intintIdentityPerfectCLHash_CreateFactory(intintHash_Factory * factory, | |
| 292 | int hashIndex); | |
| 293 | int intintIdentityPerfectCLHash_DestroyFactory(intintHash_Factory * factory, | |
| 294 | int hashIndex); | |
| 295 | intintHash_Table *intintIdentityPerfectCLHash_CreateTable(intintHash_Factory * | |
| 296 | factory, | |
| 297 | int hashIndex, | |
| 298 | size_t keyRange, | |
| 299 | size_t numEntries, | |
| 300 | float loadFactor); | |
| 301 | int intintIdentityPerfectCLHash_InitTable(intintHash_Table * table, | |
| 302 | va_list args); | |
| 303 | int intintIdentityPerfectCLHash_DestroyTable(intintHash_Table * table); | |
| 304 | char *intintIdentityPerfectCLHash_Report(intintHash_Table * table); | |
| 305 | int intintIdentityPerfectCLHash_EmptyTable(intintHash_Table * table); | |
| 306 | int intintIdentityPerfectCLHash_Query(intintHash_Table * table, size_t numKeys, | |
| 307 | int *keys, int *valuesOutput); | |
| 308 | int intintIdentityPerfectCLHash_QuerySingle(intintHash_Table * table, int key, | |
| 309 | int *valueOutput); | |
| 310 | int intintIdentityPerfectCLHash_Insert(intintHash_Table * table, | |
| 311 | size_t numEntries, int *keys, | |
| 312 | int *values); | |
| 313 | int intintIdentityPerfectCLHash_InsertSingle(intintHash_Table * table, int key, | |
| 314 | int value); | |
| 315 | int intintIdentityPerfectCLHash_InsertNoOverwrite(intintHash_Table * table, | |
| 316 | size_t numEntries, int *keys, | |
| 317 | int *values); | |
| 318 | int intintIdentityPerfectCLHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 319 | table, int key, | |
| 320 | int value); | |
| 321 | int intintIdentityPerfectCLHash_BufferQuery(intintHash_Table * table, | |
| 322 | size_t numKeys, cl_mem keysBuffer, | |
| 323 | cl_mem valuesOutputBuffer); | |
| 324 | int intintIdentityPerfectCLHash_BufferInsert(intintHash_Table * table, | |
| 325 | size_t numEntries, | |
| 326 | cl_mem keysBuffer, | |
| 327 | cl_mem valuesBuffer); | |
| 328 | int intintIdentityPerfectCLHash_BufferInsertNoOverwrite(intintHash_Table * | |
| 329 | table, | |
| 330 | size_t numEntries, | |
| 331 | cl_mem keysBuffer, | |
| 332 | cl_mem valuesBuffer); | |
| 333 | int intintIdentitySentinelPerfectHash_CreateFactory(intintHash_Factory * | |
| 334 | factory, int hashIndex); | |
| 335 | int intintIdentitySentinelPerfectHash_DestroyFactory(intintHash_Factory * | |
| 336 | factory, int hashIndex); | |
| 337 | intintHash_Table | |
| 338 | *intintIdentitySentinelPerfectHash_CreateTable(intintHash_Factory * factory, | |
| 339 | int hashIndex, | |
| 340 | size_t keyRange, | |
| 341 | size_t numEntries, | |
| 342 | float loadFactor); | |
| 343 | int intintIdentitySentinelPerfectHash_InitTable(intintHash_Table * table, | |
| 344 | va_list args); | |
| 345 | int intintIdentitySentinelPerfectHash_DestroyTable(intintHash_Table * table); | |
| 346 | char *intintIdentitySentinelPerfectHash_Report(intintHash_Table * table); | |
| 347 | int intintIdentitySentinelPerfectHash_EmptyTable(intintHash_Table * table); | |
| 348 | int intintIdentitySentinelPerfectHash_Query(intintHash_Table * table, | |
| 349 | size_t numKeys, int *keys, | |
| 350 | int *valuesOutput); | |
| 351 | int intintIdentitySentinelPerfectHash_QuerySingle(intintHash_Table * table, | |
| 352 | int key, int *valueOutput); | |
| 353 | int intintIdentitySentinelPerfectHash_Insert(intintHash_Table * table, | |
| 354 | size_t numEntries, int *keys, | |
| 355 | int *values); | |
| 356 | int intintIdentitySentinelPerfectHash_InsertSingle(intintHash_Table * table, | |
| 357 | int key, int value); | |
| 358 | int intintIdentitySentinelPerfectHash_InsertNoOverwrite(intintHash_Table * | |
| 359 | table, | |
| 360 | size_t numEntries, | |
| 361 | int *keys, int *values); | |
| 362 | int intintIdentitySentinelPerfectHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 363 | table, int key, | |
| 364 | int value); | |
| 365 | int intintIdentitySentinelPerfectCLHash_CreateFactory(intintHash_Factory * | |
| 366 | factory, int hashIndex); | |
| 367 | int intintIdentitySentinelPerfectCLHash_DestroyFactory(intintHash_Factory * | |
| 368 | factory, int hashIndex); | |
| 369 | intintHash_Table | |
| 370 | *intintIdentitySentinelPerfectCLHash_CreateTable(intintHash_Factory * | |
| 371 | factory, int hashIndex, | |
| 372 | size_t keyRange, | |
| 373 | size_t numEntries, | |
| 374 | float loadFactor); | |
| 375 | int intintIdentitySentinelPerfectCLHash_InitTable(intintHash_Table * table, | |
| 376 | va_list args); | |
| 377 | int intintIdentitySentinelPerfectCLHash_DestroyTable(intintHash_Table * table); | |
| 378 | char *intintIdentitySentinelPerfectCLHash_Report(intintHash_Table * table); | |
| 379 | int intintIdentitySentinelPerfectCLHash_EmptyTable(intintHash_Table * table); | |
| 380 | int intintIdentitySentinelPerfectCLHash_Query(intintHash_Table * table, | |
| 381 | size_t numKeys, int *keys, | |
| 382 | int *valuesOutput); | |
| 383 | int intintIdentitySentinelPerfectCLHash_QuerySingle(intintHash_Table * table, | |
| 384 | int key, int *valueOutput); | |
| 385 | int intintIdentitySentinelPerfectCLHash_Insert(intintHash_Table * table, | |
| 386 | size_t numEntries, int *keys, | |
| 387 | int *values); | |
| 388 | int intintIdentitySentinelPerfectCLHash_InsertSingle(intintHash_Table * table, | |
| 389 | int key, int value); | |
| 390 | int intintIdentitySentinelPerfectCLHash_InsertNoOverwrite(intintHash_Table * | |
| 391 | table, | |
| 392 | size_t numEntries, | |
| 393 | int *keys, | |
| 394 | int *values); | |
| 395 | int intintIdentitySentinelPerfectCLHash_InsertSingleNoOverwrite(intintHash_Table | |
| 396 | * table, | |
| 397 | int key, | |
| 398 | int value); | |
| 399 | int intintIdentitySentinelPerfectCLHash_BufferQuery(intintHash_Table * table, | |
| 400 | size_t numKeys, | |
| 401 | cl_mem keysBuffer, | |
| 402 | cl_mem valuesOutputBuffer); | |
| 403 | int intintIdentitySentinelPerfectCLHash_BufferInsert(intintHash_Table * table, | |
| 404 | size_t numEntries, | |
| 405 | cl_mem keysBuffer, | |
| 406 | cl_mem valuesBuffer); | |
| 407 | int intintIdentitySentinelPerfectCLHash_BufferInsertNoOverwrite(intintHash_Table | |
| 408 | * table, | |
| 409 | size_t | |
| 410 | numEntries, | |
| 411 | cl_mem | |
| 412 | keysBuffer, | |
| 413 | cl_mem | |
| 414 | valuesBuffer); | |
| 415 | int intintLCGLinearOpenCompactHash_CreateFactory(intintHash_Factory * factory, | |
| 416 | int hashIndex); | |
| 417 | int intintLCGLinearOpenCompactHash_DestroyFactory(intintHash_Factory * factory, | |
| 418 | int hashIndex); | |
| 419 | intintHash_Table *intintLCGLinearOpenCompactHash_CreateTable(intintHash_Factory | |
| 420 | * factory, | |
| 421 | int hashIndex, | |
| 422 | size_t keyRange, | |
| 423 | size_t numEntries, | |
| 424 | float loadFactor); | |
| 425 | int intintLCGLinearOpenCompactHash_InitTable(intintHash_Table * table, | |
| 426 | va_list args); | |
| 427 | int intintLCGLinearOpenCompactHash_DestroyTable(intintHash_Table * table); | |
| 428 | char *intintLCGLinearOpenCompactHash_Report(intintHash_Table * table); | |
| 429 | int intintLCGLinearOpenCompactHash_EmptyTable(intintHash_Table * table); | |
| 430 | int intintLCGLinearOpenCompactHash_Query(intintHash_Table * table, | |
| 431 | size_t numKeys, int *keys, | |
| 432 | int *valuesOutput); | |
| 433 | int intintLCGLinearOpenCompactHash_QuerySingle(intintHash_Table * table, | |
| 434 | int key, int *valueOutput); | |
| 435 | int intintLCGLinearOpenCompactHash_Insert(intintHash_Table * table, | |
| 436 | size_t numEntries, int *keys, | |
| 437 | int *values); | |
| 438 | int intintLCGLinearOpenCompactHash_InsertSingle(intintHash_Table * table, | |
| 439 | int key, int value); | |
| 440 | int intintLCGLinearOpenCompactHash_InsertNoOverwrite(intintHash_Table * table, | |
| 441 | size_t numEntries, | |
| 442 | int *keys, int *values); | |
| 443 | int intintLCGLinearOpenCompactHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 444 | table, int key, | |
| 445 | int value); | |
| 446 | int intintLCGLinearOpenCompactCLHash_CreateFactory(intintHash_Factory * factory, | |
| 447 | int hashIndex); | |
| 448 | int intintLCGLinearOpenCompactCLHash_DestroyFactory(intintHash_Factory * | |
| 449 | factory, int hashIndex); | |
| 450 | intintHash_Table | |
| 451 | *intintLCGLinearOpenCompactCLHash_CreateTable(intintHash_Factory * factory, | |
| 452 | int hashIndex, | |
| 453 | size_t keyRange, | |
| 454 | size_t numEntries, | |
| 455 | float loadFactor); | |
| 456 | int intintLCGLinearOpenCompactCLHash_InitTable(intintHash_Table * table, | |
| 457 | va_list args); | |
| 458 | int intintLCGLinearOpenCompactCLHash_DestroyTable(intintHash_Table * table); | |
| 459 | char *intintLCGLinearOpenCompactCLHash_Report(intintHash_Table * table); | |
| 460 | int intintLCGLinearOpenCompactCLHash_EmptyTable(intintHash_Table * table); | |
| 461 | int intintLCGLinearOpenCompactCLHash_Query(intintHash_Table * table, | |
| 462 | size_t numKeys, int *keys, | |
| 463 | int *valuesOutput); | |
| 464 | int intintLCGLinearOpenCompactCLHash_QuerySingle(intintHash_Table * table, | |
| 465 | int key, int *valueOutput); | |
| 466 | int intintLCGLinearOpenCompactCLHash_Insert(intintHash_Table * table, | |
| 467 | size_t numEntries, int *keys, | |
| 468 | int *values); | |
| 469 | int intintLCGLinearOpenCompactCLHash_InsertSingle(intintHash_Table * table, | |
| 470 | int key, int value); | |
| 471 | int intintLCGLinearOpenCompactCLHash_InsertNoOverwrite(intintHash_Table * table, | |
| 472 | size_t numEntries, | |
| 473 | int *keys, int *values); | |
| 474 | int intintLCGLinearOpenCompactCLHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 475 | table, int key, | |
| 476 | int value); | |
| 477 | int intintLCGLinearOpenCompactCLHash_BufferQuery(intintHash_Table * table, | |
| 478 | size_t numKeys, | |
| 479 | cl_mem keysBuffer, | |
| 480 | cl_mem valuesOutputBuffer); | |
| 481 | int intintLCGLinearOpenCompactCLHash_BufferInsert(intintHash_Table * table, | |
| 482 | size_t numEntries, | |
| 483 | cl_mem keysBuffer, | |
| 484 | cl_mem valuesBuffer); | |
| 485 | int intintLCGLinearOpenCompactCLHash_BufferInsertNoOverwrite(intintHash_Table * | |
| 486 | table, | |
| 487 | size_t numEntries, | |
| 488 | cl_mem keysBuffer, | |
| 489 | cl_mem | |
| 490 | valuesBuffer); | |
| 491 | int intintLCGQuadraticOpenCompactHash_CreateFactory(intintHash_Factory * | |
| 492 | factory, int hashIndex); | |
| 493 | int intintLCGQuadraticOpenCompactHash_DestroyFactory(intintHash_Factory * | |
| 494 | factory, int hashIndex); | |
| 495 | intintHash_Table | |
| 496 | *intintLCGQuadraticOpenCompactHash_CreateTable(intintHash_Factory * factory, | |
| 497 | int hashIndex, | |
| 498 | size_t keyRange, | |
| 499 | size_t numEntries, | |
| 500 | float loadFactor); | |
| 501 | int intintLCGQuadraticOpenCompactHash_InitTable(intintHash_Table * table, | |
| 502 | va_list args); | |
| 503 | int intintLCGQuadraticOpenCompactHash_DestroyTable(intintHash_Table * table); | |
| 504 | char *intintLCGQuadraticOpenCompactHash_Report(intintHash_Table * table); | |
| 505 | int intintLCGQuadraticOpenCompactHash_EmptyTable(intintHash_Table * table); | |
| 506 | int intintLCGQuadraticOpenCompactHash_Query(intintHash_Table * table, | |
| 507 | size_t numKeys, int *keys, | |
| 508 | int *valuesOutput); | |
| 509 | int intintLCGQuadraticOpenCompactHash_QuerySingle(intintHash_Table * table, | |
| 510 | int key, int *valueOutput); | |
| 511 | int intintLCGQuadraticOpenCompactHash_Insert(intintHash_Table * table, | |
| 512 | size_t numEntries, int *keys, | |
| 513 | int *values); | |
| 514 | int intintLCGQuadraticOpenCompactHash_InsertSingle(intintHash_Table * table, | |
| 515 | int key, int value); | |
| 516 | int intintLCGQuadraticOpenCompactHash_InsertNoOverwrite(intintHash_Table * | |
| 517 | table, | |
| 518 | size_t numEntries, | |
| 519 | int *keys, int *values); | |
| 520 | int intintLCGQuadraticOpenCompactHash_InsertSingleNoOverwrite(intintHash_Table * | |
| 521 | table, int key, | |
| 522 | int value); | |
| 523 | int intintLCGQuadraticOpenCompactCLHash_CreateFactory(intintHash_Factory * | |
| 524 | factory, int hashIndex); | |
| 525 | int intintLCGQuadraticOpenCompactCLHash_DestroyFactory(intintHash_Factory * | |
| 526 | factory, int hashIndex); | |
| 527 | intintHash_Table | |
| 528 | *intintLCGQuadraticOpenCompactCLHash_CreateTable(intintHash_Factory * | |
| 529 | factory, int hashIndex, | |
| 530 | size_t keyRange, | |
| 531 | size_t numEntries, | |
| 532 | float loadFactor); | |
| 533 | int intintLCGQuadraticOpenCompactCLHash_InitTable(intintHash_Table * table, | |
| 534 | va_list args); | |
| 535 | int intintLCGQuadraticOpenCompactCLHash_DestroyTable(intintHash_Table * table); | |
| 536 | char *intintLCGQuadraticOpenCompactCLHash_Report(intintHash_Table * table); | |
| 537 | int intintLCGQuadraticOpenCompactCLHash_EmptyTable(intintHash_Table * table); | |
| 538 | int intintLCGQuadraticOpenCompactCLHash_Query(intintHash_Table * table, | |
| 539 | size_t numKeys, int *keys, | |
| 540 | int *valuesOutput); | |
| 541 | int intintLCGQuadraticOpenCompactCLHash_QuerySingle(intintHash_Table * table, | |
| 542 | int key, int *valueOutput); | |
| 543 | int intintLCGQuadraticOpenCompactCLHash_Insert(intintHash_Table * table, | |
| 544 | size_t numEntries, int *keys, | |
| 545 | int *values); | |
| 546 | int intintLCGQuadraticOpenCompactCLHash_InsertSingle(intintHash_Table * table, | |
| 547 | int key, int value); | |
| 548 | int intintLCGQuadraticOpenCompactCLHash_InsertNoOverwrite(intintHash_Table * | |
| 549 | table, | |
| 550 | size_t numEntries, | |
| 551 | int *keys, | |
| 552 | int *values); | |
| 553 | int intintLCGQuadraticOpenCompactCLHash_InsertSingleNoOverwrite(intintHash_Table | |
| 554 | * table, | |
| 555 | int key, | |
| 556 | int value); | |
| 557 | int intintLCGQuadraticOpenCompactCLHash_BufferQuery(intintHash_Table * table, | |
| 558 | size_t numKeys, | |
| 559 | cl_mem keysBuffer, | |
| 560 | cl_mem valuesOutputBuffer); | |
| 561 | int intintLCGQuadraticOpenCompactCLHash_BufferInsert(intintHash_Table * table, | |
| 562 | size_t numEntries, | |
| 563 | cl_mem keysBuffer, | |
| 564 | cl_mem valuesBuffer); | |
| 565 | int intintLCGQuadraticOpenCompactCLHash_BufferInsertNoOverwrite(intintHash_Table | |
| 566 | * table, | |
| 567 | size_t | |
| 568 | numEntries, | |
| 569 | cl_mem | |
| 570 | keysBuffer, | |
| 571 | cl_mem | |
| 572 | valuesBuffer); | |
| 573 | #endif |
| … | … | @@ -1,116 +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 "perfectHash.hm" | |
| 34 | #include "compactHash.hm" | |
| 35 | ||
| 36 | #define HASH_H_TYPES_DECLARE(NAME, KEY_TYPE)\ | |
| 37 | \ | |
| 38 | static inline unsigned int NAME##Hash_CompressIdentity(char data, int hashCode){\ | |
| 39 | return hashCode;\ | |
| 40 | }\ | |
| 41 | \ | |
| 42 | typedef struct NAME##Hash_CompressLCGData{\ | |
| 43 | long unsigned int a;\ | |
| 44 | long unsigned int c;\ | |
| 45 | unsigned int m;\ | |
| 46 | unsigned int n;\ | |
| 47 | }NAME##Hash_CompressLCGData;\ | |
| 48 | \ | |
| 49 | static inline unsigned int NAME##Hash_CompressLCG(NAME##Hash_CompressLCGData compressLCGData, int hashCode){\ | |
| 50 | return ((compressLCGData.a * hashCode + compressLCGData.c) % compressLCGData.m) % compressLCGData.n;\ | |
| 51 | }\ | |
| 52 | \ | |
| 53 | ||
| 54 | #define HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 55 | \ | |
| 56 | typedef struct NAME##Hash_Table_ NAME##Hash_Table;\ | |
| 57 | \ | |
| 58 | typedef struct NAME##CLHash_Table_ NAME##CLHash_Table;\ | |
| 59 | \ | |
| 60 | typedef struct NAME##Hash_Factory_ NAME##Hash_Factory;\ | |
| 61 | \ | |
| 62 | typedef struct NAME##CLHash_Factory_ NAME##CLHash_Factory;\ | |
| 63 | \ | |
| 64 | NAME##Hash_Factory* NAME##Hash_CreateFactory(int HashTypes, VALUE_TYPE *emptyValue, size_t localWorkSize, cl_context *context, cl_command_queue *queue);\ | |
| 65 | \ | |
| 66 | int NAME##Hash_DestroyFactory(NAME##Hash_Factory *factory);\ | |
| 67 | \ | |
| 68 | NAME##Hash_Table* NAME##Hash_CreateTable(NAME##Hash_Factory* factory, int hashTypes, size_t keyRange, size_t numEntries, float loadFactor);\ | |
| 69 | \ | |
| 70 | int NAME##Hash_EmptyTable(NAME##Hash_Table *table);\ | |
| 71 | \ | |
| 72 | int NAME##Hash_DestroyTable(NAME##Hash_Table *table);\ | |
| 73 | \ | |
| 74 | cl_mem NAME##Hash_GetTableDataBuffer(NAME##Hash_Table *table);\ | |
| 75 | \ | |
| 76 | cl_mem *NAME##Hash_GetTableDataBufferPtr(NAME##Hash_Table *table);\ | |
| 77 | \ | |
| 78 | int NAME##Hash_GetTableType(NAME##Hash_Table *table);\ | |
| 79 | \ | |
| 80 | int NAME##Hash_Query(NAME##Hash_Table *table, size_t numKeys, KEY_TYPE *keys, VALUE_TYPE *valuesOutput);\ | |
| 81 | \ | |
| 82 | int NAME##Hash_QuerySingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE *valueOutput);\ | |
| 83 | \ | |
| 84 | int NAME##Hash_Insert(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values);\ | |
| 85 | \ | |
| 86 | int NAME##Hash_InsertSingle(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value);\ | |
| 87 | \ | |
| 88 | int NAME##Hash_InsertNoOverwrite(NAME##Hash_Table *table, size_t numEntries, KEY_TYPE *keys, VALUE_TYPE *values);\ | |
| 89 | \ | |
| 90 | int NAME##Hash_InsertSingleNoOverwrite(NAME##Hash_Table *table, KEY_TYPE key, VALUE_TYPE value);\ | |
| 91 | \ | |
| 92 | int NAME##Hash_BufferQuery(NAME##Hash_Table *table, size_t numKeys, cl_mem keys, cl_mem valuesOutput);\ | |
| 93 | \ | |
| 94 | int NAME##Hash_BufferInsert(NAME##Hash_Table *table, size_t numEntries, cl_mem keys, cl_mem values);\ | |
| 95 | \ | |
| 96 | int NAME##Hash_BufferInsertNoOverwrite(NAME##Hash_Table *table, size_t numEntries, cl_mem keys, cl_mem values);\ | |
| 97 | \ | |
| 98 | HASH_H_TYPES_DECLARE(NAME, KEY_TYPE)\ | |
| 99 | \ | |
| 100 | IDENTITY_PERFECT_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 101 | \ | |
| 102 | IDENTITY_PERFECT_CL_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 103 | \ | |
| 104 | IDENTITY_SENTINEL_PERFECT_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 105 | \ | |
| 106 | IDENTITY_SENTINEL_PERFECT_CL_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 107 | \ | |
| 108 | LCG_LINEAR_OPEN_COMPACT_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 109 | \ | |
| 110 | LCG_LINEAR_OPEN_COMPACT_CL_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 111 | \ | |
| 112 | LCG_QUADRATIC_OPEN_COMPACT_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 113 | \ | |
| 114 | LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 115 | \ | |
| 116 |
| … | … | @@ -1,233 +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 | #undef UNDEFINED | |
| 34 | #ifdef UNDEFINED | |
| 35 | /** | |
| 36 | * @file hash.hp | |
| 37 | * @author Peter Ahrens | |
| 38 | * @date Thu Jun 6 2013 | |
| 39 | */ | |
| 40 | #endif | |
| 41 | /** | |
| 42 | * @file hash.h | |
| 43 | * @author Peter Ahrens | |
| 44 | * @date Thu Jun 6 2013 | |
| 45 | */ | |
| 46 | // | |
| 47 | #define DELAY(x) x | |
| 48 | #define STRINGIFY_(x) #x | |
| 49 | #define STRINGIFY(x) STRINGIFY_(x) | |
| 50 | DELAY(#ifndef HASH_H) | |
| 51 | DELAY(#define HASH_H) | |
| 52 | // | |
| 53 | DELAY(#include <stdlib.h>) | |
| 54 | DELAY(#include <stdio.h>) | |
| 55 | DELAY(#include <stdarg.h>) | |
| 56 | DELAY(#include <string.h>) | |
| 57 | // | |
| 58 | DELAY(#ifdef HAVE_OPENCL) | |
| 59 | DELAY(#ifdef __APPLE_CC__) | |
| 60 | DELAY(#include <OpenCL/OpenCL.h>) | |
| 61 | DELAY(#else) | |
| 62 | DELAY(#include <CL/cl.h>) | |
| 63 | DELAY(#endif) | |
| 64 | DELAY(#else) | |
| 65 | typedef void * cl_mem; | |
| 66 | typedef int cl_context; | |
| 67 | typedef int cl_command_queue; | |
| 68 | typedef int cl_program; | |
| 69 | typedef int cl_device_id; | |
| 70 | typedef int cl_int; | |
| 71 | int clRetainContext(int context); | |
| 72 | int clRetainCommandQueue(int command_queue); | |
| 73 | int clGetContextInfo(int context, int param, size_t size, void *value, size_t *size_ret); | |
| 74 | int clReleaseContext(int context); | |
| 75 | int clReleaseCommandQueue(int command_queue); | |
| 76 | int clReleaseProgram(int program); | |
| 77 | int clRetainProgram(int program); | |
| 78 | int clRetainKernel(int kernel); | |
| 79 | cl_mem clCreateBuffer(int context, int flags, size_t size, void *value, int *size_ret); | |
| 80 | int clEnqueueWriteBuffer(int command_queue, void *buffer, int blocking_write, size_t offset, size_t cb, const void * ptr, | |
| 81 | uint nevents, const int *wait_list, int *event); | |
| 82 | int clEnqueueReadBuffer(int command_queue, void *buffer, int blocking_write, size_t offset, size_t cb, const void * ptr, | |
| 83 | uint nevents, const int *wait_list, int *event); | |
| 84 | int clCreateKernel(int program, const char *kernel_name, int *errcode_ret); | |
| 85 | int clReleaseKernel(int kernel); | |
| 86 | int clReleaseMemObject(void * memobj); | |
| 87 | int clSetKernelArg(int kernel, uint arg_index, size_t arg_size, const void *arg_value); | |
| 88 | int clGetKernelWorkGroupInfo(int kernel, int device, int param_name, size_t size, void *value, size_t *size_ret); | |
| 89 | int clEnqueueNDRangeKernel(int command_queue, int kernel, uint work_dim, const size_t *offset, const size_t *size, const size_t *local_size, | |
| 90 | uint nevents, const int *wait_list, int *event); | |
| 91 | int clFinish(int command_queue); | |
| 92 | DELAY(#endif) | |
| 93 | // | |
| 94 | DELAY(#include "CLHash_Utilities.h") | |
| 95 | // | |
| 96 | // | |
| 97 | DELAY(#include "hash.hm") | |
| 98 | DELAY(#include "hash.cm") | |
| 99 | // | |
| 100 | DELAY(#define HASH_REPORT_NEVER /**/ 0) | |
| 101 | DELAY(#define HASH_REPORT_CYCLE /**/ 1) | |
| 102 | DELAY(#define HASH_REPORT_END /****/ 2) | |
| 103 | // | |
| 104 | DELAY(#define HASH_EXIT_CODE_NORMAL /****************/ -1) | |
| 105 | DELAY(#define HASH_EXIT_CODE_ERROR /*****************/ -2) | |
| 106 | DELAY(#define HASH_EXIT_CODE_OVERWRITE /*************/ -3) | |
| 107 | DELAY(#define HASH_EXIT_CODE_KEY_DNE /***************/ -4) | |
| 108 | DELAY(#define HASH_EXIT_CODE_CYCLE /*****************/ -5) | |
| 109 | DELAY(#define HASH_EXIT_CODE_MAX_ENTRIES_EXCEEDED /**/ -6) | |
| 110 | DELAY(#define HASH_EXIT_CODE_BUCKET_INDEX_OOB /******/ -7) | |
| 111 | // | |
| 112 | DELAY(#define HASH_SEARCH_CODE_MATCH /*****/ 0) | |
| 113 | DELAY(#define HASH_SEARCH_CODE_MISMATCH /**/ 1) | |
| 114 | DELAY(#define HASH_SEARCH_CODE_EMPTY /*****/ 2) | |
| 115 | // | |
| 116 | DELAY(#define HASH_NUM_HASHES /**/ 8) | |
| 117 | DELAY(#define HASH_NUM_CL_HASHES /**/ 4) | |
| 118 | // | |
| 119 | DELAY(#define LCG_QUADRATIC_OPEN_COMPACT_HASH_ID 128) | |
| 120 | DELAY(#define LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID 8) | |
| 121 | DELAY(#define LCG_LINEAR_OPEN_COMPACT_HASH_ID 64) | |
| 122 | DELAY(#define LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID 4) | |
| 123 | DELAY(#define IDENTITY_SENTINEL_PERFECT_HASH_ID 32) | |
| 124 | DELAY(#define IDENTITY_SENTINEL_PERFECT_CL_HASH_ID 2) | |
| 125 | DELAY(#define IDENTITY_PERFECT_HASH_ID 16) | |
| 126 | DELAY(#define IDENTITY_PERFECT_CL_HASH_ID 1) | |
| 127 | // | |
| 128 | /** | |
| 129 | * HASH_ALL_CL_HASHES hash table types that run in an OpenCL context. | |
| 130 | */ | |
| 131 | DELAY(#define HASH_ALL_CL_HASHES (IDENTITY_PERFECT_CL_HASH_ID | IDENTITY_SENTINEL_PERFECT_CL_HASH_ID | LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID | LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID)) | |
| 132 | /** | |
| 133 | * HASH_ALL_C_HASHES hash table types that run on the host. | |
| 134 | */ | |
| 135 | DELAY(#define HASH_ALL_C_HASHES (IDENTITY_PERFECT_HASH_ID | IDENTITY_SENTINEL_PERFECT_HASH_ID | LCG_LINEAR_OPEN_COMPACT_HASH_ID | LCG_QUADRATIC_OPEN_COMPACT_HASH_ID)) | |
| 136 | /** | |
| 137 | * HASH_ALL_HASHES all hash table types. | |
| 138 | */ | |
| 139 | DELAY(#define HASH_ALL_HASHES (HASH_ALL_CL_HASHES | HASH_ALL_C_HASHES)) | |
| 140 | /** | |
| 141 | * HASH_NOSENTINEL_PERFECT_HASHES perfect hash table types that do not use a sentinel value to mark empty buckets. | |
| 142 | */ | |
| 143 | DELAY(#define HASH_NOSENTINEL_PERFECT_HASHES (IDENTITY_PERFECT_HASH_ID | IDENTITY_PERFECT_CL_HASH_ID)) | |
| 144 | /** | |
| 145 | * HASH_SENTINEL_PERFECT_HASHES perfect hash table types that use a sentinel value to mark empty buckets. | |
| 146 | */ | |
| 147 | DELAY(#define HASH_SENTINEL_PERFECT_HASHES (IDENTITY_SENTINEL_PERFECT_HASH_ID | IDENTITY_SENTINEL_PERFECT_CL_HASH_ID)) | |
| 148 | /** | |
| 149 | * HASH_PERFECT_HASHES perfect hash table types. | |
| 150 | */ | |
| 151 | DELAY(#define HASH_PERFECT_HASHES (HASH_NOSENTINEL_PERFECT_HASHES | HASH_SENTINEL_PERFECT_HASHES)) | |
| 152 | /** | |
| 153 | * HASH_QUADRATIC_COMPACT_HASHES compact hash table types that use a quadratic probe sequence. | |
| 154 | */ | |
| 155 | DELAY(#define HASH_QUADRATIC_COMPACT_HASHES (LCG_QUADRATIC_OPEN_COMPACT_HASH_ID | LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID)) | |
| 156 | /** | |
| 157 | * HASH_LINEAR_COMPACT_HASHES compact hash table types that use a linear probe sequence. | |
| 158 | */ | |
| 159 | DELAY(#define HASH_LINEAR_COMPACT_HASHES (LCG_LINEAR_OPEN_COMPACT_HASH_ID | LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID)) | |
| 160 | /** | |
| 161 | * HASH_COMPACT_HASHES compact hash table types that use a linear probe sequence. | |
| 162 | */ | |
| 163 | DELAY(#define HASH_COMPACT_HASHES (HASH_QUADRATIC_COMPACT_HASHES | HASH_LINEAR_COMPACT_HASHES)) | |
| 164 | // | |
| 165 | DELAY(#define HASH_DEFAULT_LOCAL_WORK_SIZE /*******/ 64) | |
| 166 | DELAY(#define HASH_DEFAULT_LOAD_FACTOR /*******/ 0.3) | |
| 167 | DELAY(#define HASH_MIN_LOAD_FACTOR /*******/ 0.0009) | |
| 168 | DELAY(#define HASH_PERFECT_COMPACT_SWITCH_FACTOR /*******/ 20) | |
| 169 | DELAY(#define HASH_LCG_A /*******/ 2147483629) | |
| 170 | DELAY(#define HASH_LCG_C /*******/ 2147483587) | |
| 171 | DELAY(#define HASH_LCG_M /*******/ 2147483647) | |
| 172 | // | |
| 173 | DELAY(#define HASH_BUCKET_STATUS_EMPTY /**/ -1) | |
| 174 | DELAY(#define HASH_BUCKET_STATUS_FULL /***/ -2) | |
| 175 | DELAY(#define HASH_BUCKET_STATUS_LOCK /***/ -3) | |
| 176 | ||
| 177 | #ifdef __cplusplus | |
| 178 | extern "C" | |
| 179 | { | |
| 180 | #endif | |
| 181 | ||
| 182 | /** | |
| 183 | * Hash_ExitCodeString will return a string representation of the given exit | |
| 184 | * code. | |
| 185 | * | |
| 186 | * @param exitCode | |
| 187 | * | |
| 188 | * @return A string representation of that exit code. | |
| 189 | */ | |
| 190 | char* Hash_ExitCodeString(int exitCode); | |
| 191 | ||
| 192 | /** | |
| 193 | * Hash_ExitCodeDebug will print a string representation of the given exit code | |
| 194 | * if it is not EXIT_CODE_NORMAL. | |
| 195 | * | |
| 196 | * @param exitCode | |
| 197 | */ | |
| 198 | void Hash_ExitCodeDebug(int exitCode); | |
| 199 | ||
| 200 | /** | |
| 201 | * Hash_SetReportLevel sets a static report level variable in hash.c. It should | |
| 202 | * be called before hash tables are created. | |
| 203 | * | |
| 204 | * @param level The level of data collection desired. | |
| 205 | */ | |
| 206 | void Hash_SetReportLevel(int level); | |
| 207 | ||
| 208 | /** | |
| 209 | * Hash_GetReportLevel gets this variable. | |
| 210 | * | |
| 211 | * @return The current report level. | |
| 212 | * Special Values: Meaning | |
| 213 | * HASH_REPORT_NEVER: The hash table will not collect data. This is the | |
| 214 | * default. A call to Hash_Report will return an empty | |
| 215 | * string. | |
| 216 | * HASH_REPORT_END: The hash table will collect data and calls to | |
| 217 | * Hash_Report will return summary information. | |
| 218 | * HASH_REPORT_CYCLE: The hash table will collect data and calls to | |
| 219 | * Hash_Report will return information related to the | |
| 220 | * last important call. | |
| 221 | */ | |
| 222 | int Hash_GetReportLevel(); | |
| 223 | ||
| 224 | const char *Hash_GetKernelSourceString(); | |
| 225 | int smallestProthPrimeAbove(int N); | |
| 226 | int largestProthPrimeUnder(int N); | |
| 227 | ||
| 228 | HASH_DECLARE(intint, int, int) | |
| 229 | ||
| 230 | #ifdef __cplusplus | |
| 231 | } | |
| 232 | #endif | |
| 233 | DELAY(#endif) |
| … | … | @@ -1,106 +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 | /** | |
| 34 | * @file hashTest.c | |
| 35 | * @author Peter Ahrens | |
| 36 | * @date Fri Jun 7 2013 | |
| 37 | */ | |
| 38 | ||
| 39 | #include "testHelper.h" | |
| 40 | #include "hash.h" | |
| 41 | ||
| 42 | void sanityTest(int hashType, TestData *metaTest, char* subTestName){ | |
| 43 | TestData *sanityTestData = Test_CreateTest(subTestName); | |
| 44 | int emptyValue = -1; | |
| 45 | intintHash_Factory *sanityFactory = intintHash_CreateFactory(hashType, &emptyValue, 128, NULL, NULL); | |
| 46 | intintHash_Table *sanityTable = intintHash_CreateTable(sanityFactory, hashType, 21, 7, 0.5); | |
| 47 | Test_IntEquality(sanityTestData, "Correct Hash Type Check", hashType, intintHash_GetTableType(sanityTable), NULL); | |
| 48 | intintHash_EmptyTable(sanityTable); | |
| 49 | int keys[] = {6, 6, 9, 12, 15, 18, 21}; | |
| 50 | int values[] = {101, 101, 102, 103, 104, 105, 106}; | |
| 51 | int keys1[] = {6, 9, 12, 15, 18, 21}; | |
| 52 | int values1[] = {101, 102, 103, 104, 105, 106}; | |
| 53 | int values2[] = {201, 202, 203, 204, 205, 206}; | |
| 54 | int valuesOut[6]; | |
| 55 | intintHash_Insert(sanityTable, 7, keys, values); | |
| 56 | int sanityInt; | |
| 57 | intintHash_QuerySingle(sanityTable, 6, &sanityInt); | |
| 58 | Test_IntEquality(sanityTestData, "QuerySingle after Insert Check 1", 101, sanityInt, NULL); | |
| 59 | intintHash_QuerySingle(sanityTable, 9, &sanityInt); | |
| 60 | Test_IntEquality(sanityTestData, "QuerySingle after Insert Check 2", 102, sanityInt, NULL); | |
| 61 | intintHash_QuerySingle(sanityTable, 12, &sanityInt); | |
| 62 | Test_IntEquality(sanityTestData, "QuerySingle after Insert Check 3", 103, sanityInt, NULL); | |
| 63 | intintHash_QuerySingle(sanityTable, 15, &sanityInt); | |
| 64 | Test_IntEquality(sanityTestData, "QuerySingle after Insert Check 4", 104, sanityInt, NULL); | |
| 65 | intintHash_QuerySingle(sanityTable, 18, &sanityInt); | |
| 66 | Test_IntEquality(sanityTestData, "QuerySingle after Insert Check 5", 105, sanityInt, NULL); | |
| 67 | intintHash_QuerySingle(sanityTable, 21, &sanityInt); | |
| 68 | Test_IntEquality(sanityTestData, "QuerySingle after Insert Check 6", 106, sanityInt, NULL); | |
| 69 | intintHash_InsertSingleNoOverwrite(sanityTable, 6, 201); | |
| 70 | intintHash_InsertSingleNoOverwrite(sanityTable, 9, 202); | |
| 71 | intintHash_InsertSingleNoOverwrite(sanityTable, 12, 203); | |
| 72 | intintHash_InsertSingleNoOverwrite(sanityTable, 15, 204); | |
| 73 | intintHash_InsertSingleNoOverwrite(sanityTable, 18, 205); | |
| 74 | intintHash_InsertSingleNoOverwrite(sanityTable, 21, 206); | |
| 75 | intintHash_Query(sanityTable, 6, keys1, &valuesOut[0]); | |
| 76 | Test_IntArrayEquality(sanityTestData, "Query after InsertSingleNoOverwrite Check", 6, values1, valuesOut, NULL); | |
| 77 | intintHash_InsertSingle(sanityTable, 6, 201); | |
| 78 | intintHash_InsertSingle(sanityTable, 9, 202); | |
| 79 | intintHash_InsertSingle(sanityTable, 12, 203); | |
| 80 | intintHash_InsertSingle(sanityTable, 15, 204); | |
| 81 | intintHash_InsertSingle(sanityTable, 18, 205); | |
| 82 | intintHash_InsertSingle(sanityTable, 21, 206); | |
| 83 | intintHash_Query(sanityTable, 6, keys1, valuesOut); | |
| 84 | Test_IntArrayEquality(sanityTestData, "Query after InsertSingle Check", 6, values2, valuesOut, NULL); | |
| 85 | intintHash_InsertNoOverwrite(sanityTable, 6, keys1, values1); | |
| 86 | intintHash_Query(sanityTable, 6, keys1, valuesOut); | |
| 87 | Test_IntArrayEquality(sanityTestData, "Query after InsertNoOverwrite Check", 6, values2, valuesOut, NULL); | |
| 88 | intintHash_DestroyTable(sanityTable); | |
| 89 | intintHash_DestroyFactory(sanityFactory); | |
| 90 | Test_FinishSubTest(metaTest, sanityTestData); | |
| 91 | } | |
| 92 | ||
| 93 | int main(int argc, char *argv[]){ | |
| 94 | CLHash_Init(argv[0]); | |
| 95 | TestData *allHashTestsData = Test_CreateTest("HashTest"); | |
| 96 | sanityTest(IDENTITY_PERFECT_HASH_ID, allHashTestsData, "intintIdentityPerfectHash Test"); | |
| 97 | sanityTest(IDENTITY_SENTINEL_PERFECT_HASH_ID, allHashTestsData, "intintIdentitySentinelPerfectHash Test"); | |
| 98 | sanityTest(LCG_LINEAR_OPEN_COMPACT_HASH_ID, allHashTestsData, "intintLCGLinearOpenCompactHash Test"); | |
| 99 | sanityTest(LCG_QUADRATIC_OPEN_COMPACT_HASH_ID, allHashTestsData, "intintLCGQuadraticOpenCompactHash Test"); | |
| 100 | sanityTest(IDENTITY_PERFECT_CL_HASH_ID, allHashTestsData, "intintIdentityPerfectCLHash Test"); | |
| 101 | sanityTest(IDENTITY_SENTINEL_PERFECT_CL_HASH_ID, allHashTestsData, "intintIdentitySentinelPerfectCLHash Test"); | |
| 102 | sanityTest(LCG_LINEAR_OPEN_COMPACT_CL_HASH_ID, allHashTestsData, "intintLCGLinearOpenCompactCLHash Test"); | |
| 103 | sanityTest(LCG_QUADRATIC_OPEN_COMPACT_CL_HASH_ID, allHashTestsData, "intintLCGQuadraticOpenCompactCLHash Test"); | |
| 104 | Test_FinishTest(allHashTestsData); | |
| 105 | return 0; | |
| 106 | } |
| … | … | @@ -1,133 +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 | #undef UNDEFINED | |
| 34 | #ifdef UNDEFINED | |
| 35 | /** | |
| 36 | * @file perfectHash.cm | |
| 37 | * @author Peter Ahrens | |
| 38 | * @date Thu Jun 6 2013 | |
| 39 | */ | |
| 40 | #endif | |
| 41 | #include "baseHash.cm" | |
| 42 | ||
| 43 | #define PERFECT_HASH_SEARCH_EXP(NAME, MODIFIER, COMPRESS_FUNC, COMPRESS_FUNC_DATA, READ_KEY_EXP, CL_GLOBAL) \ | |
| 44 | index = COMPRESS_FUNC(((CL_GLOBAL NAME##MODIFIER##Hash_TableData*)tableData)->compressFuncData, key);\ | |
| 45 | if(READ_KEY_EXP != HASH_BUCKET_STATUS_EMPTY){\ | |
| 46 | if(key == buckets[index].key){\ | |
| 47 | exitCode = HASH_SEARCH_CODE_MATCH;\ | |
| 48 | }else{\ | |
| 49 | exitCode = HASH_SEARCH_CODE_MISMATCH;\ | |
| 50 | }\ | |
| 51 | }else{\ | |
| 52 | exitCode = HASH_SEARCH_CODE_EMPTY;\ | |
| 53 | }\ | |
| 54 | ||
| 55 | #define SENTINEL_PERFECT_HASH_SEARCH_EXP(NAME, MODIFIER, COMPRESS_FUNC, COMPRESS_FUNC_DATA, READ_KEY_EXP, CL_GLOBAL) \ | |
| 56 | index = COMPRESS_FUNC(((CL_GLOBAL NAME##MODIFIER##Hash_TableData*)tableData)->compressFuncData, key);\ | |
| 57 | if(buckets[index].value != ((CL_GLOBAL NAME##MODIFIER##Hash_TableData*)tableData)->emptyValue){\ | |
| 58 | exitCode = HASH_SEARCH_CODE_MATCH;\ | |
| 59 | }else{\ | |
| 60 | exitCode = HASH_SEARCH_CODE_EMPTY;\ | |
| 61 | }\ | |
| 62 | ||
| 63 | #define PERFECT_HASH_INIT_EXP(NAME, MODIFIER, INIT_EXP, COMPRESS_FUNC, COMPRESS_FUNC_DATA, KEY_TYPE) \ | |
| 64 | INIT_EXP\ | |
| 65 | ((NAME##MODIFIER##Hash_TableData*)table->tableData)->numBuckets = keyRange + 1;\ | |
| 66 | ||
| 67 | #define SENTINEL_PERFECT_HASH_INIT_EXP(NAME, MODIFIER, INIT_EXP, COMPRESS_FUNC, COMPRESS_FUNC_DATA, KEY_TYPE) \ | |
| 68 | \ | |
| 69 | ((NAME##MODIFIER##Hash_TableData*)table->tableData)->emptyValue = factory->emptyValue;\ | |
| 70 | \ | |
| 71 | PERFECT_HASH_INIT_EXP(NAME, MODIFIER, INIT_EXP, COMPRESS_FUNC, COMPRESS_FUNC_DATA, KEY_TYPE) \ | |
| 72 | \ | |
| 73 | ||
| 74 | #define PERFECT_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP)\ | |
| 75 | \ | |
| 76 | BASE_HASH_DEFINE(NAME, MODIFIER##Perfect, HASH_ID, KEY_TYPE, VALUE_TYPE, KEY_VALUE_BASE_HASH_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA,,, PERFECT_HASH_INIT_EXP(NAME, MODIFIER##Perfect, INIT_EXP, COMPRESS_FUNC, COMPRESS_FUNC_DATA, KEY_TYPE), PERFECT_HASH_SEARCH_EXP, KEY_VALUE_HASH_INNER_EMPTY_EXP)\ | |
| 77 | \ | |
| 78 | ||
| 79 | #define PERFECT_CL_HASH_KERN_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA)\ | |
| 80 | \ | |
| 81 | CL_HASH_KERN_DEFINE(NAME, MODIFIER##Perfect, KEY_TYPE, VALUE_TYPE, KEY_VALUE_BASE_HASH_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, CMPXCHG_HASH_READ_KEY_EXP, PERFECT_HASH_SEARCH_EXP)\ | |
| 82 | \ | |
| 83 | ||
| 84 | #define PERFECT_CL_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP)\ | |
| 85 | \ | |
| 86 | CL_BASE_HASH_DEFINE(NAME, MODIFIER##Perfect, HASH_ID, KEY_TYPE, VALUE_TYPE, KEY_VALUE_BASE_HASH_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA,,, PERFECT_HASH_INIT_EXP(NAME, MODIFIER##PerfectCL, INIT_EXP, COMPRESS_FUNC, COMPRESS_FUNC_DATA, KEY_TYPE), KEY_VALUE_CL_HASH_INNER_EMPTY_EXP)\ | |
| 87 | \ | |
| 88 | ||
| 89 | #define SENTINEL_PERFECT_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP)\ | |
| 90 | \ | |
| 91 | BASE_HASH_DEFINE(NAME, MODIFIER##SentinelPerfect, HASH_ID, KEY_TYPE, VALUE_TYPE, SENTINEL_VALUE_BASE_HASH_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA,,, SENTINEL_PERFECT_HASH_INIT_EXP(NAME, MODIFIER##SentinelPerfect, INIT_EXP, COMPRESS_FUNC, COMPRESS_FUNC_DATA, KEY_TYPE), SENTINEL_PERFECT_HASH_SEARCH_EXP, SENTINEL_VALUE_HASH_INNER_EMPTY_EXP(NAME, MODIFIER##SentinelPerfect))\ | |
| 92 | \ | |
| 93 | ||
| 94 | #define SENTINEL_PERFECT_CL_HASH_KERN_DEFINE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA)\ | |
| 95 | \ | |
| 96 | CL_HASH_KERN_DEFINE(NAME, MODIFIER##SentinelPerfect, KEY_TYPE, VALUE_TYPE, SENTINEL_VALUE_BASE_HASH_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, CMPXCHG_HASH_READ_KEY_EXP, SENTINEL_PERFECT_HASH_SEARCH_EXP)\ | |
| 97 | \ | |
| 98 | ||
| 99 | #define SENTINEL_PERFECT_CL_HASH_DEFINE(NAME, MODIFIER, HASH_ID, KEY_TYPE, VALUE_TYPE, COMPRESS_FUNC, COMPRESS_FUNC_DATA, INIT_EXP)\ | |
| 100 | \ | |
| 101 | CL_BASE_HASH_DEFINE(NAME, MODIFIER##SentinelPerfect, HASH_ID, KEY_TYPE, VALUE_TYPE, SENTINEL_VALUE_BASE_HASH_TYPES_DEFINE, COMPRESS_FUNC, COMPRESS_FUNC_DATA,,, SENTINEL_PERFECT_HASH_INIT_EXP(NAME, MODIFIER##SentinelPerfectCL, INIT_EXP, COMPRESS_FUNC, COMPRESS_FUNC_DATA, KEY_TYPE), SENTINEL_VALUE_CL_HASH_INNER_EMPTY_EXP(NAME, MODIFIER##SentinelPerfectCL))\ | |
| 102 | \ | |
| 103 | ||
| 104 | #define IDENTITY_PERFECT_CL_HASH_KERN_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 105 | \ | |
| 106 | PERFECT_CL_HASH_KERN_DEFINE(NAME, Identity, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressIdentity, char)\ | |
| 107 | \ | |
| 108 | ||
| 109 | #define IDENTITY_PERFECT_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 110 | \ | |
| 111 | PERFECT_HASH_DEFINE(NAME, Identity, IDENTITY_PERFECT_HASH_ID, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressIdentity, char, )\ | |
| 112 | \ | |
| 113 | ||
| 114 | #define IDENTITY_PERFECT_CL_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 115 | \ | |
| 116 | PERFECT_CL_HASH_DEFINE(NAME, Identity, IDENTITY_PERFECT_CL_HASH_ID, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressIdentity, char, )\ | |
| 117 | \ | |
| 118 | ||
| 119 | #define IDENTITY_SENTINEL_PERFECT_CL_HASH_KERN_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 120 | \ | |
| 121 | SENTINEL_PERFECT_CL_HASH_KERN_DEFINE(NAME, Identity, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressIdentity, char)\ | |
| 122 | \ | |
| 123 | ||
| 124 | #define IDENTITY_SENTINEL_PERFECT_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 125 | \ | |
| 126 | SENTINEL_PERFECT_HASH_DEFINE(NAME, Identity, IDENTITY_SENTINEL_PERFECT_HASH_ID, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressIdentity, char, )\ | |
| 127 | \ | |
| 128 | ||
| 129 | #define IDENTITY_SENTINEL_PERFECT_CL_HASH_DEFINE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 130 | \ | |
| 131 | SENTINEL_PERFECT_CL_HASH_DEFINE(NAME, Identity, IDENTITY_SENTINEL_PERFECT_CL_HASH_ID, KEY_TYPE, VALUE_TYPE, NAME##Hash_CompressIdentity, char, )\ | |
| 132 | \ | |
| 133 |
| … | … | @@ -1,82 +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 | #undef UNDECLARED | |
| 34 | #ifdef UNDECLARED | |
| 35 | /** | |
| 36 | * @file perfectHash.hm | |
| 37 | * @author Peter Ahrens | |
| 38 | * @date Thu Jun 6 2013 | |
| 39 | */ | |
| 40 | #endif | |
| 41 | #include "baseHash.hm" | |
| 42 | ||
| 43 | #define PERFECT_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 44 | \ | |
| 45 | BASE_HASH_DECLARE(NAME, MODIFIER##Perfect, KEY_TYPE, VALUE_TYPE)\ | |
| 46 | \ | |
| 47 | ||
| 48 | #define IDENTITY_PERFECT_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 49 | \ | |
| 50 | PERFECT_HASH_DECLARE(NAME, Identity, KEY_TYPE, VALUE_TYPE)\ | |
| 51 | \ | |
| 52 | ||
| 53 | #define PERFECT_CL_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 54 | \ | |
| 55 | CL_HASH_DECLARE(NAME, MODIFIER##Perfect, KEY_TYPE, VALUE_TYPE)\ | |
| 56 | \ | |
| 57 | ||
| 58 | #define IDENTITY_PERFECT_CL_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 59 | \ | |
| 60 | PERFECT_CL_HASH_DECLARE(NAME, Identity, KEY_TYPE, VALUE_TYPE)\ | |
| 61 | \ | |
| 62 | ||
| 63 | #define SENTINEL_PERFECT_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 64 | \ | |
| 65 | BASE_HASH_DECLARE(NAME, MODIFIER##SentinelPerfect, KEY_TYPE, VALUE_TYPE)\ | |
| 66 | \ | |
| 67 | ||
| 68 | #define IDENTITY_SENTINEL_PERFECT_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 69 | \ | |
| 70 | SENTINEL_PERFECT_HASH_DECLARE(NAME, Identity, KEY_TYPE, VALUE_TYPE)\ | |
| 71 | \ | |
| 72 | ||
| 73 | #define SENTINEL_PERFECT_CL_HASH_DECLARE(NAME, MODIFIER, KEY_TYPE, VALUE_TYPE)\ | |
| 74 | \ | |
| 75 | CL_HASH_DECLARE(NAME, MODIFIER##SentinelPerfect, KEY_TYPE, VALUE_TYPE)\ | |
| 76 | \ | |
| 77 | ||
| 78 | #define IDENTITY_SENTINEL_PERFECT_CL_HASH_DECLARE(NAME, KEY_TYPE, VALUE_TYPE)\ | |
| 79 | \ | |
| 80 | SENTINEL_PERFECT_CL_HASH_DECLARE(NAME, Identity, KEY_TYPE, VALUE_TYPE)\ | |
| 81 | \ | |
| 82 |
| … | … | @@ -1,142 +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 <math.h> | |
| 34 | #include <stdio.h> | |
| 35 | #define LCG_A 2147483629 | |
| 36 | #define LCG_C 2147483587 | |
| 37 | #define LCG_M 2147483647 | |
| 38 | #define PRIME_NUM_CHECKS 20 | |
| 39 | ||
| 40 | int modularPow(int base, int exponent, int modulus){ | |
| 41 | int result = 1; | |
| 42 | while (exponent){ | |
| 43 | if (exponent & 1) | |
| 44 | result = ((long long int)result * base) % modulus; | |
| 45 | exponent >>= 1; | |
| 46 | base = ((long long int)base * base) % modulus; | |
| 47 | } | |
| 48 | return result; | |
| 49 | } | |
| 50 | ||
| 51 | int largestProthPrimeUnder(int N){ | |
| 52 | if(N < 4){ | |
| 53 | return N; | |
| 54 | } | |
| 55 | //determine the nearest proth number | |
| 56 | int n; | |
| 57 | int m; | |
| 58 | frexp((double)N, &n); | |
| 59 | n /= 2; | |
| 60 | int s = 1 << n; | |
| 61 | int p = s * ((N - 1) / s) + 1; | |
| 62 | int i; | |
| 63 | int a; | |
| 64 | srand(p); | |
| 65 | while(p > 3){ | |
| 66 | //check if a proth number is prime | |
| 67 | for(i = 0; i < PRIME_NUM_CHECKS; i++){ | |
| 68 | a = rand(); | |
| 69 | if(modularPow(a, (p - 1) / 2, p) == p - 1){ | |
| 70 | return p; | |
| 71 | } | |
| 72 | } | |
| 73 | //determine the next proth number | |
| 74 | if(p - 1 == s * s / 4){ | |
| 75 | s /= 2; | |
| 76 | } | |
| 77 | p -= s; | |
| 78 | } | |
| 79 | return 3; | |
| 80 | } | |
| 81 | ||
| 82 | int smallestProthPrimeAbove(int N){ | |
| 83 | if(N < 4){ | |
| 84 | return N; | |
| 85 | } | |
| 86 | //determine the nearest proth number | |
| 87 | int n; | |
| 88 | int m; | |
| 89 | frexp((double)N, &n); | |
| 90 | n /= 2; | |
| 91 | int s = 1 << n; | |
| 92 | int p = s * ((N - 1) / s) + 1; | |
| 93 | int i; | |
| 94 | int a; | |
| 95 | srand(p); | |
| 96 | while(1){ | |
| 97 | //determine the next proth number | |
| 98 | if(p - 1 == s * s){ | |
| 99 | s *= 2; | |
| 100 | } | |
| 101 | p += s; | |
| 102 | //check if a proth number is prime | |
| 103 | for(i = 0; i < PRIME_NUM_CHECKS; i++){ | |
| 104 | a = rand(); | |
| 105 | if(modularPow(a, (p - 1) / 2, p) == p - 1){ | |
| 106 | return p; | |
| 107 | } | |
| 108 | } | |
| 109 | } | |
| 110 | return 3; | |
| 111 | } | |
| 112 | ||
| 113 | int main(){ | |
| 114 | printf("%d\n", largestProthPrimeUnder(2)); | |
| 115 | printf("%d\n", smallestProthPrimeAbove(2)); | |
| 116 | printf("%d\n", largestProthPrimeUnder(3)); | |
| 117 | printf("%d\n", smallestProthPrimeAbove(3)); | |
| 118 | printf("%d\n", largestProthPrimeUnder(4)); | |
| 119 | printf("%d\n", smallestProthPrimeAbove(4)); | |
| 120 | printf("%d\n", largestProthPrimeUnder(5)); | |
| 121 | printf("%d\n", smallestProthPrimeAbove(5)); | |
| 122 | printf("%d\n", largestProthPrimeUnder(11)); | |
| 123 | printf("%d\n", smallestProthPrimeAbove(11)); | |
| 124 | printf("%d\n", largestProthPrimeUnder(13)); | |
| 125 | printf("%d\n", smallestProthPrimeAbove(13)); | |
| 126 | printf("%d\n", largestProthPrimeUnder(2000024)); | |
| 127 | printf("%d\n", smallestProthPrimeAbove(1993728)); | |
| 128 | int p = 3; | |
| 129 | int m = 2; | |
| 130 | int c = 1; | |
| 131 | int i; | |
| 132 | for(i = 0; i < 0; i++){ | |
| 133 | printf("%d %d\n", i, p); | |
| 134 | if(c == 0){ | |
| 135 | m *= 2; | |
| 136 | c = i + 2; | |
| 137 | } | |
| 138 | p += m; | |
| 139 | c--; | |
| 140 | } | |
| 141 | return 0; | |
| 142 | } |
| … | … | @@ -1,186 +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 | /** | |
| 34 | * @file test.c | |
| 35 | * @author Peter Ahrens | |
| 36 | * @date Fri Jun 7 2013 | |
| 37 | */ | |
| 38 | ||
| 39 | #include "testHelper.h" | |
| 40 | ||
| 41 | void Test_StartTry(char *nameOfTest){ | |
| 42 | printf("TRYING %s: ", nameOfTest); | |
| 43 | fflush(stdout); | |
| 44 | } | |
| 45 | ||
| 46 | void Test_EndTry(TestData *currentTest){ | |
| 47 | printf("PASSED\n"); | |
| 48 | currentTest->numPassed++; | |
| 49 | } | |
| 50 | ||
| 51 | void Test_PointerEquality(TestData *currentTest, char *nameOfTest, void *expected, void *observed, char *failMessage){ | |
| 52 | if(expected == observed){ | |
| 53 | printf("%s: PASSED\n", nameOfTest); | |
| 54 | currentTest->numPassed++; | |
| 55 | }else{ | |
| 56 | printf("%s: FAILED\n", nameOfTest); | |
| 57 | printf(" POINTERS DO NOT MATCH"); | |
| 58 | if(failMessage != NULL){ | |
| 59 | printf(" ADDITIONAL INFO: %s\n", failMessage); | |
| 60 | } | |
| 61 | currentTest->numFailed++; | |
| 62 | printf("\n"); | |
| 63 | } | |
| 64 | } | |
| 65 | ||
| 66 | void Test_PointerInequality(TestData *currentTest, char *nameOfTest, void *notExpected, void *observed, char *failMessage){ | |
| 67 | if(notExpected != observed){ | |
| 68 | printf("%s: PASSED\n", nameOfTest); | |
| 69 | currentTest->numPassed++; | |
| 70 | }else{ | |
| 71 | printf("%s: FAILED\n", nameOfTest); | |
| 72 | printf(" POINTERS SHOULD NOT MATCH"); | |
| 73 | if(failMessage != NULL){ | |
| 74 | printf(" ADDITIONAL INFO: %s\n", failMessage); | |
| 75 | } | |
| 76 | currentTest->numFailed++; | |
| 77 | printf("\n"); | |
| 78 | } | |
| 79 | } | |
| 80 | ||
| 81 | void Test_IntEquality(TestData *currentTest, char *nameOfTest, int expected, int observed, char *failMessage){ | |
| 82 | if(expected == observed){ | |
| 83 | printf("%s: PASSED\n", nameOfTest); | |
| 84 | currentTest->numPassed++; | |
| 85 | }else{ | |
| 86 | printf("%s: FAILED\n", nameOfTest); | |
| 87 | printf(" EXPECTED: %d\n", expected); | |
| 88 | printf(" OBSERVED: %d\n", observed); | |
| 89 | if(failMessage != NULL){ | |
| 90 | printf(" ADDITIONAL INFO: %s\n", failMessage); | |
| 91 | } | |
| 92 | currentTest->numFailed++; | |
| 93 | printf("\n"); | |
| 94 | } | |
| 95 | } | |
| 96 | ||
| 97 | void Test_IntArrayEquality(TestData *currentTest, char *nameOfTest, unsigned int size, int *expected, int *observed, char *failMessage){ | |
| 98 | int result = 0; | |
| 99 | int i; | |
| 100 | for(i = 0; i < size; i++){ | |
| 101 | if(expected[i] != observed[i]){ | |
| 102 | result = 1; | |
| 103 | } | |
| 104 | } | |
| 105 | if(result == 0){ | |
| 106 | printf("%s: PASSED\n", nameOfTest); | |
| 107 | currentTest->numPassed++; | |
| 108 | }else{ | |
| 109 | printf("%s: FAILED\n", nameOfTest); | |
| 110 | printf(" EXPECTED: {"); | |
| 111 | for(i = 0; i < size; i++){ | |
| 112 | printf("%d, ", expected[i]); | |
| 113 | } | |
| 114 | printf("}\n"); | |
| 115 | printf(" OBSERVED: {"); | |
| 116 | for(i = 0; i < size; i++){ | |
| 117 | printf("%d, ", observed[i]); | |
| 118 | } | |
| 119 | printf("}\n"); | |
| 120 | if(failMessage != NULL){ | |
| 121 | printf(" ADDITIONAL INFO: %s\n", failMessage); | |
| 122 | } | |
| 123 | currentTest->numFailed++; | |
| 124 | printf("\n"); | |
| 125 | } | |
| 126 | } | |
| 127 | ||
| 128 | void Test_IntLessThan(TestData *currentTest, char *nameOfTest, int expectedAbove, int observed, char *failMessage){ | |
| 129 | if(expectedAbove > observed){ | |
| 130 | printf("%s: PASSED\n", nameOfTest); | |
| 131 | currentTest->numPassed++; | |
| 132 | }else{ | |
| 133 | printf("%s: FAILED\n", nameOfTest); | |
| 134 | printf(" EXPECTED OBSERVED VALUE TO BE LESS THAN: %d\n", expectedAbove); | |
| 135 | printf(" OBSERVED: %d\n", observed); | |
| 136 | if(failMessage != NULL){ | |
| 137 | printf(" ADDITIONAL INFO: %s\n", failMessage); | |
| 138 | } | |
| 139 | currentTest->numFailed++; | |
| 140 | printf("\n"); | |
| 141 | } | |
| 142 | } | |
| 143 | ||
| 144 | void Test_IntGreaterThan(TestData *currentTest, char *nameOfTest, int expectedBelow, int observed, char *failMessage){ | |
| 145 | if(expectedBelow < observed){ | |
| 146 | printf("%s: PASSED\n", nameOfTest); | |
| 147 | currentTest->numPassed++; | |
| 148 | }else{ | |
| 149 | printf("%s: FAILED\n", nameOfTest); | |
| 150 | printf(" EXPECTED OBSERVED VALUE TO BE GREATER THAN: %d\n", expectedBelow); | |
| 151 | printf(" OBSERVED: %d\n", observed); | |
| 152 | if(failMessage != NULL){ | |
| 153 | printf(" ADDITIONAL INFO: %s\n", failMessage); | |
| 154 | } | |
| 155 | currentTest->numFailed++; | |
| 156 | printf("\n"); | |
| 157 | } | |
| 158 | } | |
| 159 | ||
| 160 | void Test_FinishSubTest(TestData *currentTest, TestData *subTest){ | |
| 161 | if(subTest->numFailed == 0){ | |
| 162 | currentTest->numPassed++; | |
| 163 | }else{ | |
| 164 | currentTest->numFailed++; | |
| 165 | } | |
| 166 | Test_FinishTest(subTest); | |
| 167 | } | |
| 168 | ||
| 169 | ||
| 170 | TestData *Test_CreateTest(char *nameOfTestGroup){ | |
| 171 | TestData *newTest = (TestData*)malloc(sizeof(TestData)); | |
| 172 | newTest->nameOfTestGroup = nameOfTestGroup; | |
| 173 | newTest->numPassed = 0; | |
| 174 | newTest->numFailed = 0; | |
| 175 | printf("%s STARTED\n", nameOfTestGroup); | |
| 176 | return newTest; | |
| 177 | } | |
| 178 | ||
| 179 | void Test_FinishTest(TestData *currentTest){ | |
| 180 | printf("%s FINISHED\n", currentTest->nameOfTestGroup); | |
| 181 | printf("%d%% (%d/%d) TESTS PASSED\n\n", | |
| 182 | ((currentTest->numPassed * 100) / (currentTest->numPassed + currentTest->numFailed)), | |
| 183 | currentTest->numPassed, | |
| 184 | currentTest->numPassed + currentTest->numFailed); | |
| 185 | free(currentTest); | |
| 186 | } |
| … | … | @@ -1,62 +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 | /** | |
| 34 | * @file test.h | |
| 35 | * @author Peter Ahrens | |
| 36 | * @date Fri Jun 7 2013 | |
| 37 | */ | |
| 38 | ||
| 39 | #include <stdio.h> | |
| 40 | #include <stdlib.h> | |
| 41 | #ifndef TEST_H | |
| 42 | #define TEST_H | |
| 43 | ||
| 44 | typedef struct TestData{ | |
| 45 | char* nameOfTestGroup; | |
| 46 | unsigned int numPassed; | |
| 47 | unsigned int numFailed; | |
| 48 | } TestData; | |
| 49 | ||
| 50 | void Test_StartTry(char *nameOfTest); | |
| 51 | void Test_EndTry(TestData *currentTest); | |
| 52 | void Test_PointerEquality(TestData *currentTest, char *nameOfTest, void *expected, void *observed, char *failMessage); | |
| 53 | void Test_PointerInequality(TestData *currentTest, char *nameOfTest, void *notExpected, void *observed, char *failMessage); | |
| 54 | void Test_IntGreaterThan(TestData *currentTest, char *nameOfTest, int expectedBelow, int observed, char *failMessage); | |
| 55 | void Test_IntLessThan(TestData *currentTest, char *nameOfTest, int expectedAbove, int observed, char *failMessage); | |
| 56 | void Test_IntEquality(TestData *currentTest, char *nameOfTest, int expected, int observed, char *failMessage); | |
| 57 | void Test_IntArrayEquality(TestData *currentTest, char *nameOfTest, unsigned int size, int *expected, int *observed, char *failMessage); | |
| 58 | void Test_FinishSubTest(TestData *currentTest, TestData *subTest); | |
| 59 | TestData *Test_CreateTest(char *nameOfTestGroup); | |
| 60 | void Test_FinishTest(TestData *currentTest); | |
| 61 | ||
| 62 | #endif |
| … | … | @@ -49,7 +49,7 @@ |
| 49 | 49 | #include <sys/stat.h> |
| 50 | 50 | #include "kdtree/KDTree2d.h" |
| 51 | 51 | #include "gpu.h" |
| 52 | #include "hash/hash.h" | |
| 52 | #include "HashFactory/HashFactory.h" | |
| 53 | 53 | #include "simplehash/simplehash.h" |
| 54 | 54 | #include "simplehash/simplehashlib.h" |
| 55 | 55 | #include "timer/timer.h" |