std::vector<T> AdiosCheckpointInput::retrieveVector(const std::string& var_name) { /* Retrieve one of the buffers that we have read from the file system. */ void* buff_to_return; int buff_size; bool buff_found = false; for (int i = 0; i < read_queue.size(); i++) { if (read_queue[i] == var_name) { buff_found = true; buff_to_return = buffers[i]; buff_size = sizes[i]; //delete this value from the queues buffers.erase(buffers.begin() + i); sizes.erase(sizes.begin() + i); read_queue.erase(read_queue.begin() + i); break; } } if (!buff_found) { qmcplusplus::app_error() << "Checkpoint file does not contain: " << var_name << std::endl; APP_ABORT("qmcapp"); return ; } T* raw_buff = static_cast<T*>(buff_to_return); vector<T> vec_buff(raw_buff, raw_buff + buff_size); //free some memory free(raw_buff); return vec_buff; }
int OpenCL_Manager::execute_kernel() { // setup data & buffers float mat[16], vec[4], result[4]; for (int i=0; i<16; i++) { mat[i] = i; } for (int i=0; i<4; i++) { vec[i] = i * 3.0f; } cl::Buffer mat_buff(m_context,CL_MEM_READ_WRITE,sizeof(float)*16); cl::Buffer vec_buff(m_context,CL_MEM_READ_WRITE,sizeof(float)*4); cl::Buffer res_buff(m_context,CL_MEM_READ_WRITE,sizeof(float)*4); // create command queue m_queue = cl::CommandQueue(m_context,m_device); // set kernel arguments m_queue.enqueueWriteBuffer(mat_buff,CL_TRUE,0,sizeof(float)*16,mat); m_queue.enqueueWriteBuffer(vec_buff,CL_TRUE,0,sizeof(float)*4,vec); m_kernel.setArg(0,mat_buff); m_kernel.setArg(1,vec_buff); m_kernel.setArg(2,res_buff); m_queue.enqueueNDRangeKernel(m_kernel, // kernel cl::NullRange, // offset cl::NDRange(4), // global work size cl::NullRange); // local work size // blocks program until done m_queue.finish(); m_queue.enqueueReadBuffer(res_buff,CL_TRUE,0,sizeof(float)*4,result); return 0; }