need to cache function values
I want to use image as cache for function values in some range.
I create image in such way:
float* cache = (float*) malloc(8192 * sizeof(cl_float));
for (int i = 0; i < 8192; ++i) {
double chisqr = 1.0 + (double) i / 8192.0 * 10.0;
cache[ i ] = (float)lcgf(0.5*gauss_dof,std::max(chisqr*0.5*gauss_bins,0.5*gauss_dof+1));
}
cl_image_format image_format;
image_format.image_channel_data_type = CL_FLOAT;
image_format.image_channel_order = CL_R;
gpu_gauss_dof_lcgf_cache=clCreateImage2D(context,
CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,&image_format,8192,1,0,&cache,&err);
Then I use it in kernel in such way:
__constant sampler_t read_sampler = CLK_NORMALIZED_COORDS_TRUE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR;
float calc_GaussFit_score_cached(float chisqr, float null_chisqr,float score_offset,image2d_t gauss_cache,image2d_t null_cache) { // <- gauss_pot_length constant across whole package
float chisqr_cache = (chisqr - 1.0f) / 10.f; //R: normalized coords clamped to the edge
float null_chisqr_cache = (null_chisqr - 1.0f) / 10.f;
return score_offset+
(read_imagef(gauss_cache, read_sampler, (int2)(chisqr_cache, 1))).x+
(read_imagef(null_cache, read_sampler, (int2)(chisqr_cache, 1))).x;
}
App crashed when reach corresponding kernel.
What is wrong? Should I use float4 in CPU array? I see that read_imagef always return float4, but I need only one float value per image element...