void init_ocl_ldchecker(void) { struct callback_s callbacks = {ocl_getBufferContent, ocl_setParameterValue, ocl_getAndReleaseParameterValue, ocl_triggerKernelExecution}; #if ENABLE_KERNEL_PROFILING == 1 pthread_mutex_init(&stats_lock, NULL); signal(SIGUSR1, sig_handler); #endif init_ldchecker(callbacks, ocl_bindings); create_ocl_buffer(NULL); ocl_init_helper(); }
cl_mem clCreateBuffer (cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_int *errcode_ret) { struct ld_mem_s *buffer; if (flags & CL_MEM_ALLOC_HOST_PTR) { goto unhandled; } buffer = create_ocl_buffer(real_clCreateBuffer(context, flags, size, host_ptr, errcode_ret)); buffer->size = size; buffer->flags = ocl_buffer_flags_to_ld(flags); buffer_created_event(buffer); return buffer->handle; unhandled: return real_clCreateBuffer(context, flags, size, host_ptr, errcode_ret); }
/** Initialization of data buffers on OpenCL device * @param position_cpp * initial position buffer * @param velocity_cpp * initial velocity buffer * @param config * Contain information about simulating configuration * @param elasticConnectionData_cpp * buffer with info about elastic connections * @param membraneData_cpp * buffer with info about membranes * @param particleMembranesList_cpp * buffer with info about sets of membranes in which particular particle is including */ void owOpenCLSolver::initializeBuffers(const float * position_cpp, const float * velocity_cpp, owConfigProperty * config, const float * elasticConnectionsData_cpp, const int * membraneData_cpp, const int * particleMembranesList_cpp){ // Needed for sortin stuff _particleIndex = new int[ 2 * config->getParticleCount() ]; gridNextNonEmptyCellBuffer = new int[config->gridCellCount+1]; create_ocl_buffer( "acceleration", acceleration, CL_MEM_READ_WRITE, ( config->getParticleCount() * sizeof( float ) * 4 * 3 ) );// 4*2-->4*3; third part is to store acceleration[t], while first to are for acceleration[t+delta_t] create_ocl_buffer( "gridCellIndex", gridCellIndex, CL_MEM_READ_WRITE, ( ( config->gridCellCount + 1 ) * sizeof( unsigned int ) * 1 ) ); create_ocl_buffer( "gridCellIndexFixedUp", gridCellIndexFixedUp, CL_MEM_READ_WRITE, ( ( config->gridCellCount + 1 ) * sizeof( unsigned int ) * 1 ) ); create_ocl_buffer( "neighborMap", neighborMap, CL_MEM_READ_WRITE, ( MAX_NEIGHBOR_COUNT * config->getParticleCount() * sizeof( float ) * 2 ) ); create_ocl_buffer( "particleIndex", particleIndex, CL_MEM_READ_WRITE, ( config->getParticleCount() * sizeof( unsigned int ) * 2 ) ); create_ocl_buffer( "particleIndexBack", particleIndexBack, CL_MEM_READ_WRITE, ( config->getParticleCount() * sizeof( unsigned int ) ) ); create_ocl_buffer( "position", position, CL_MEM_READ_WRITE, ( config->getParticleCount() * sizeof( float ) * 4 * (1 + 1/*1 extra, for membrane handling*/)) ); create_ocl_buffer( "pressure", pressure, CL_MEM_READ_WRITE, ( config->getParticleCount() * sizeof( float ) * 1 ) ); create_ocl_buffer( "rho", rho, CL_MEM_READ_WRITE, ( config->getParticleCount() * sizeof( float ) * 2 ) ); create_ocl_buffer( "sortedPosition", sortedPosition, CL_MEM_READ_WRITE, ( config->getParticleCount() * sizeof( float ) * 4 * 2 ) ); create_ocl_buffer( "sortedVelocity", sortedVelocity, CL_MEM_READ_WRITE, ( config->getParticleCount() * sizeof( float ) * 4 ) ); create_ocl_buffer( "velocity", velocity, CL_MEM_READ_WRITE, ( config->getParticleCount() * sizeof( float ) * 4 * (1 + 1/*1 extra, for membrane handling*/) ) ); create_ocl_buffer( "muscle_activation_signal", muscle_activation_signal, CL_MEM_READ_WRITE, ( config->MUSCLE_COUNT * sizeof( float ) ) ); if(membraneData_cpp != NULL && particleMembranesList_cpp != NULL) { create_ocl_buffer( "membraneData", membraneData, CL_MEM_READ_WRITE, ( config->numOfMembranes * sizeof( int ) * 3 ) ); create_ocl_buffer("particleMembranesList", particleMembranesList,CL_MEM_READ_WRITE, config->numOfElasticP * MAX_MEMBRANES_INCLUDING_SAME_PARTICLE * sizeof(int) ); } if(elasticConnectionsData_cpp != NULL){ create_ocl_buffer("elasticConnectionsData", elasticConnectionsData,CL_MEM_READ_WRITE, config->numOfElasticP * MAX_NEIGHBOR_COUNT * sizeof(float) * 4); } // Copy initial position_cpp and velocity_cpp to the OpenCL Device copy_buffer_to_device( position_cpp, position, config->getParticleCount() * sizeof( float ) * 4 ); copy_buffer_to_device( velocity_cpp, velocity, config->getParticleCount() * sizeof( float ) * 4 ); // Copy membrane data to device memory elastic connections if(membraneData_cpp != NULL && particleMembranesList_cpp != NULL) { copy_buffer_to_device( membraneData_cpp, membraneData, config->numOfMembranes * sizeof( int ) * 3 ); copy_buffer_to_device( particleMembranesList_cpp, particleMembranesList, config->numOfElasticP * MAX_MEMBRANES_INCLUDING_SAME_PARTICLE * sizeof( int ) ); } // Copy elastic connectiondate to device memory elastic connections if(elasticConnectionsData_cpp != NULL){ copy_buffer_to_device(elasticConnectionsData_cpp, elasticConnectionsData, config->numOfElasticP * MAX_NEIGHBOR_COUNT * sizeof(float) * 4); } }