void hash_lib_init(void){ cl_context context = ezcl_get_context(); cl_program program = ezcl_create_program_wsource(context, hashlib_kern_source); kernel_hash_init = ezcl_create_kernel_wprogram(program, "hash_init_cl"); ezcl_program_release(program); }
void *MallocPlus::memory_malloc(size_t nelem, size_t elsize, const char *name, int flags){ malloc_plus_memory_entry *memory_item = (malloc_plus_memory_entry *)malloc(sizeof(malloc_plus_memory_entry)); memory_item->mem_nelem = (size_t *)malloc(1*sizeof(size_t)); memory_item->mem_nelem[0] = nelem; memory_item->mem_ndims = 1; memory_item->mem_elsize = elsize; memory_item->mem_flags = flags; // allocate memory on the accelerator if flag is set if ((flags & DEVICE_REGULAR_MEMORY) != 0){ #ifdef HAVE_OPENCL cl_context context = ezcl_get_context(); memory_item->mem_capacity = nelem; memory_item->mem_ptr = ezcl_device_memory_malloc(context, NULL, name, nelem, elsize, CL_MEM_READ_WRITE, 0); #endif } // Managed memory allocates extra space and expands as necessary to reduce allocations else if ((flags & HOST_MANAGED_MEMORY) != 0){ memory_item->mem_capacity = 2 * nelem; memory_item->mem_ptr = malloc(2* nelem*elsize); } #ifdef HAVE_J7 // experimental shared memory allocation else if (flags & LOAD_BALANCE_MEMORY) { memory_item->mem_capacity = nelem; memory_item->mem_ptr = j7->memAlloc(nelem * elsize); } #endif // Just regular memory allocation else { memory_item->mem_capacity = nelem; memory_item->mem_ptr = malloc(nelem*elsize); } memory_item->mem_name = strdup(name); // Mallocs memory for copy //printf("MALLOC_PLUS_MEMORY_MALLOC: DEBUG -- malloc plus memory pointer for :%s: is %p nelements %ld elsize is %ld flags %d\n",memory_item->mem_name,memory_item->mem_ptr,memory_item->mem_nelem[0],memory_item->mem_elsize,memory_item->mem_flags); // Insert entry into dictionary -- two versions, one by name and another by pointer address memory_name_dict.insert(std::pair<const char*, malloc_plus_memory_entry*>(name, memory_item) ); memory_ptr_dict.insert(std::pair<void*, malloc_plus_memory_entry*>(memory_item->mem_ptr, memory_item) ); if (DEBUG) printf("MALLOC_PLUS_MEMORY_MALLOC: DEBUG -- malloc plus memory pointer for :%s: is %p nelements %ld elsize is %ld\n",memory_item->mem_name,memory_item->mem_ptr,memory_item->mem_nelem[0],memory_item->mem_elsize); // return the pointer for use by the calling routine return(memory_item->mem_ptr); }
void *MallocPlus::memory_malloc(size_t nelem, size_t elsize, int flags, const char *name){ malloc_plus_memory_entry memory_item; memory_item.mem_nelem = nelem; memory_item.mem_elsize = elsize; memory_item.mem_flags = flags; if ((flags & DEVICE_REGULAR_MEMORY) != 0){ #ifdef HAVE_OPENCL cl_context context = ezcl_get_context(); memory_item.mem_capacity = nelem; memory_item.mem_ptr = ezcl_device_memory_malloc(context, NULL, name, nelem, elsize, CL_MEM_READ_WRITE, 0); #endif } else if ((flags & HOST_MANAGED_MEMORY) != 0){ memory_item.mem_capacity = 2 * nelem; memory_item.mem_ptr = malloc(2* nelem*elsize); } #ifdef HAVE_J7 else if (flags & LOAD_BALANCE_MEMORY) { memory_item.mem_capacity = nelem; memory_item.mem_ptr = j7->memAlloc(nelem * elsize); } #endif else { memory_item.mem_capacity = nelem; memory_item.mem_ptr = malloc(nelem*elsize); } char *mem_name = (char *)malloc(MIN(strlen(name)+1,20)); strncpy(mem_name,name,MIN(strlen(name),19)); mem_name[strlen(name)]='\0'; memory_item.mem_name = mem_name; memory_list.push_back(memory_item); if (DEBUG) printf("MALLOC_PLUS_MEMORY_MALLOC: DEBUG -- malloc plus memory pointer for %s is %p nelements %ld elsize is %ld\n",mem_name,memory_item.mem_ptr,memory_item.mem_nelem,memory_item.mem_elsize); return(memory_item.mem_ptr); }