static void HGPU_PRNG_RANMAR_init_GPU(HGPU_GPU_context* context,void* PRNG_state,HGPU_PRNG_parameters* PRNG_parameters){ HGPU_PRNG_RANMAR_state_t* state = (HGPU_PRNG_RANMAR_state_t*) PRNG_state; size_t seeds_size = HGPU_GPU_context_buffer_size_align(context,PRNG_parameters->instances * 2); size_t seed_table_size = HGPU_GPU_context_buffer_size_align(context,PRNG_parameters->instances * 2 * (97+1)); // 97 - size of seed table, 1 - size of indices size_t randoms_size = HGPU_GPU_context_buffer_size_align(context,PRNG_parameters->instances * PRNG_parameters->samples); cl_uint4* PRNG_seeds = (cl_uint4*) calloc(seeds_size,sizeof(cl_uint4)); cl_float4* PRNG_seed_table_float4= (cl_float4*) calloc(seed_table_size,sizeof(cl_float4)); cl_float4* PRNG_randoms = NULL; cl_double4* PRNG_randoms_double = NULL; if (PRNG_parameters->precision==HGPU_precision_double) PRNG_randoms_double = (cl_double4*) calloc(randoms_size,sizeof(cl_double4)); else PRNG_randoms = (cl_float4*) calloc(randoms_size,sizeof(cl_float4)); if ((!PRNG_seeds) || (!PRNG_seed_table_float4) || ((!PRNG_randoms_double) && (!PRNG_randoms))) HGPU_error_message(HGPU_ERROR_NO_MEMORY,"could not allocate memory for randoms"); for (unsigned int i=0; i<(seeds_size>>1); i++) { PRNG_seeds[i].s[0] = HGPU_PRNG_rand32bit() % HGPU_PRNG_RANMAR_init_1; PRNG_seeds[i].s[1] = HGPU_PRNG_rand32bit() % HGPU_PRNG_RANMAR_init_1; PRNG_seeds[i].s[2] = HGPU_PRNG_rand32bit() % HGPU_PRNG_RANMAR_init_1; PRNG_seeds[i].s[3] = HGPU_PRNG_rand32bit() % HGPU_PRNG_RANMAR_init_1; } for (unsigned int i=(seeds_size>>1); i<seeds_size; i++) { PRNG_seeds[i].s[0] = HGPU_PRNG_rand32bit() % HGPU_PRNG_RANMAR_init_2; PRNG_seeds[i].s[1] = HGPU_PRNG_rand32bit() % HGPU_PRNG_RANMAR_init_2; PRNG_seeds[i].s[2] = HGPU_PRNG_rand32bit() % HGPU_PRNG_RANMAR_init_2; PRNG_seeds[i].s[3] = HGPU_PRNG_rand32bit() % HGPU_PRNG_RANMAR_init_2; } PRNG_seeds[0].s[0] = state->seed1; // setup first thread as CPU PRNG_seeds[PRNG_parameters->instances].s[0] = state->seed2; // setup first thread as CPU unsigned int seeds_id = 0; unsigned int seed_table_id = 0; unsigned int randoms_id = 0; seeds_id = HGPU_GPU_context_buffer_init(context,PRNG_seeds,HGPU_GPU_buffer_type_io,seeds_size,sizeof(cl_uint4)); HGPU_GPU_context_buffer_set_name(context,seeds_id,(char*) "(RANMAR) PRNG_input_seeds"); seed_table_id = HGPU_GPU_context_buffer_init(context,PRNG_seed_table_float4,HGPU_GPU_buffer_type_io,seed_table_size,sizeof(cl_float4)); HGPU_GPU_context_buffer_set_name(context,seed_table_id,(char*) "(RANMAR) PRNG_seed_table"); if (PRNG_parameters->precision==HGPU_precision_double) randoms_id = HGPU_GPU_context_buffer_init(context,PRNG_randoms_double,HGPU_GPU_buffer_type_io,randoms_size,sizeof(cl_double4)); else randoms_id = HGPU_GPU_context_buffer_init(context,PRNG_randoms,HGPU_GPU_buffer_type_io,randoms_size,sizeof(cl_float4)); HGPU_GPU_context_buffer_set_name(context,randoms_id,(char*) "(RANMAR) PRNG_randoms"); PRNG_parameters->id_buffer_input_seeds = seeds_id; PRNG_parameters->id_buffer_seeds = seed_table_id; PRNG_parameters->id_buffer_randoms = randoms_id; }
static void HGPU_PRNG_CONSTANT_init_GPU(HGPU_GPU_context* context,void*,HGPU_PRNG_parameters* PRNG_parameters){ size_t randoms_size = HGPU_GPU_context_buffer_size_align(context,PRNG_parameters->instances * PRNG_parameters->samples); cl_float4* PRNG_randoms = NULL; cl_double4* PRNG_randoms_double = NULL; if (PRNG_parameters->precision==HGPU_precision_double) PRNG_randoms_double = (cl_double4*) calloc(randoms_size,sizeof(cl_double4)); else PRNG_randoms = (cl_float4*) calloc(randoms_size,sizeof(cl_float4)); if ((!PRNG_randoms_double) && (!PRNG_randoms)) HGPU_error_message(HGPU_ERROR_NO_MEMORY,"could not allocate memory for randoms"); unsigned int randoms_id = 0; if (PRNG_parameters->precision==HGPU_precision_double) randoms_id = HGPU_GPU_context_buffer_init(context,PRNG_randoms_double,HGPU_GPU_buffer_type_io,randoms_size,sizeof(cl_double4)); else randoms_id = HGPU_GPU_context_buffer_init(context,PRNG_randoms,HGPU_GPU_buffer_type_io,randoms_size,sizeof(cl_float4)); HGPU_GPU_context_buffer_set_name(context,randoms_id,(char*) "(CONSTANT) PRNG_randoms"); PRNG_parameters->id_buffer_input_seeds = HGPU_GPU_MAX_BUFFERS; PRNG_parameters->id_buffer_seeds = HGPU_GPU_MAX_BUFFERS; PRNG_parameters->id_buffer_randoms = randoms_id; }