t_map_entry *ft_map_get_p(t_map map, void *key, t_simple_hash_func h_f) { t_map_entry *entry; t_uint64 hash; hash = h_f(key); entry = get(map[hash % MAP_TREE_SIZE], hash); return (entry); }
Image<float> transfer(Image<float> &image, TransferFunction &f) { Image<float> h_f(f.size); memcpy(h_f.data(),&f.values[0], f.size*sizeof(float)); Image<float> output(image.width(), image.height()); hl_transfer_histogram(image, h_f, f.source_mini, f.source_maxi, f.target_mini, f.target_maxi, output); return output; }
Image<float> transfer(Image<float> &image, vector<TransferFunction> &fs) { Image<float> h_f(fs[0].size+4,3); float *pData = h_f.data(); int idx = 0; for (size_t i = 0; i < fs.size(); ++i) { pData[idx++] = fs[i].source_mini; pData[idx++] = fs[i].source_maxi; pData[idx++] = fs[i].target_mini; pData[idx++] = fs[i].target_maxi; memcpy(pData+idx,&fs[i].values[0], fs[i].size*sizeof(float)); idx += fs[i].size; } Image<float> output(image.width(), image.height(),3); hl_transfer_histogram_color_float(image, h_f, output); return output; }
int main(void) { std::vector<float> h_a(LENGTH); // a vector std::vector<float> h_b(LENGTH); // b vector std::vector<float> h_c (LENGTH, 0xdeadbeef); // c vector (result) std::vector<float> h_d (LENGTH, 0xdeadbeef); // d vector (result) std::vector<float> h_e (LENGTH); // e vector std::vector<float> h_f (LENGTH, 0xdeadbeef); // f vector (result) std::vector<float> h_g (LENGTH); // g vector cl::Buffer d_a; // device memory used for the input a vector cl::Buffer d_b; // device memory used for the input b vector cl::Buffer d_c; // device memory used for the output c vector cl::Buffer d_d; // device memory used for the output d vector cl::Buffer d_e; // device memory used for the input e vector cl::Buffer d_f; // device memory used for the output f vector cl::Buffer d_g; // device memory used for the input g vector // Fill vectors a and b with random float values int count = LENGTH; for(int i = 0; i < count; i++) { h_a[i] = rand() / (float)RAND_MAX; h_b[i] = rand() / (float)RAND_MAX; h_e[i] = rand() / (float)RAND_MAX; h_g[i] = rand() / (float)RAND_MAX; } try { // Create a context cl::Context context(DEVICE); // Load in kernel source, creating a program object for the context cl::Program program(context, util::loadProgram("vadd.cl"), true); // Get the command queue cl::CommandQueue queue(context); // Create the kernel functor auto vadd = cl::make_kernel<cl::Buffer, cl::Buffer, cl::Buffer>(program, "vadd"); d_a = cl::Buffer(context, begin(h_a), end(h_a), true); d_b = cl::Buffer(context, begin(h_b), end(h_b), true); d_e = cl::Buffer(context, begin(h_e), end(h_e), true); d_g = cl::Buffer(context, begin(h_g), end(h_g), true); d_c = cl::Buffer(context, CL_MEM_READ_WRITE, sizeof(float) * LENGTH); d_d = cl::Buffer(context, CL_MEM_READ_WRITE, sizeof(float) * LENGTH); d_f = cl::Buffer(context, CL_MEM_WRITE_ONLY, sizeof(float) * LENGTH); vadd( cl::EnqueueArgs( queue, cl::NDRange(count)), d_a, d_b, d_c); vadd( cl::EnqueueArgs( queue, cl::NDRange(count)), d_e, d_c, d_d); vadd( cl::EnqueueArgs( queue, cl::NDRange(count)), d_g, d_d, d_f); cl::copy(queue, d_f, begin(h_f), end(h_f)); // Test the results int correct = 0; float tmp; for(int i = 0; i < count; i++) { tmp = h_a[i] + h_b[i] + h_e[i] + h_g[i]; // assign element i of a+b+e+g to tmp tmp -= h_f[i]; // compute deviation of expected and output result if(tmp*tmp < TOL*TOL) // correct if square deviation is less than tolerance squared correct++; else { printf(" tmp %f h_a %f h_b %f h_e %f h_g %f h_f %f\n",tmp, h_a[i], h_b[i], h_e[i], h_g[i], h_f[i]); } } // summarize results printf("C = A+B+E+G: %d out of %d results were correct.\n", correct, count); } catch (cl::Error err) { std::cout << "Exception\n"; std::cerr << "ERROR: " << err.what() << std::endl; } }