|
GGEMS
1.1
GPU GEant4-based Monte Carlo Simulations
|
Go to the documentation of this file. 1 #ifndef GUARD_GGEMS_GLOBAL_GGEMSOPENCLMANAGER_HH
2 #define GUARD_GGEMS_GLOBAL_GGEMSOPENCLMANAGER_HH
34 #include <unordered_map>
38 #pragma warning(disable: 4251) // Deleting warning exporting STL members!!!
42 #pragma GCC diagnostic ignored "-Wignored-attributes"
45 typedef std::unordered_map<std::string, std::string>
VendorUMap;
47 #define KERNEL_NOT_COMPILED 0x100000000
53 class GGEMS_EXPORT GGEMSOpenCLManager
113 void CheckOpenCLError(
GGint const& error, std::string
const& class_name, std::string
const& method_name)
const;
119 void PrintPlatformInfos(
void)
const;
125 void PrintDeviceInfos(
void)
const;
131 void PrintBuildOptions(
void)
const;
137 void PrintActivatedDevices(
void)
const;
153 inline cl_device_type
GetDeviceType(
GGsize const& device_index)
const {
return device_type_[device_index];}
206 GGsize GetBestWorkItem(
GGsize const& number_of_elements)
const;
214 inline cl::Context*
GetContext(
GGsize const& thread_index)
const {
return contexts_[thread_index];}
230 inline cl::Event*
GetEvent(
GGsize const& thread_index)
const {
return events_[thread_index];}
237 void DeviceToActivate(
GGsize const& device_id);
245 void DeviceToActivate(std::string
const& device_type, std::string
const& device_vendor =
"");
253 void DeviceBalancing(std::string
const& device_balancing);
275 inline bool IsReady(
void)
const {
return !device_indices_.empty();}
292 void CompileKernel(std::string
const& kernel_filename, std::string
const& kernel_name, cl::Kernel** kernel_list,
char*
const custom_options =
nullptr,
char*
const additional_options =
nullptr);
302 template <
typename T>
303 T* GetDeviceBuffer(cl::Buffer* device_ptr,
GGsize const& size,
GGsize const& thread_index);
312 template <
typename T>
313 void ReleaseDeviceBuffer(cl::Buffer*
const device_ptr,
T* host_ptr,
GGsize const& thread_index);
325 cl::Buffer* Allocate(
void* host_ptr,
GGsize const& size,
GGsize const& thread_index, cl_mem_flags flags, std::string
const& class_name =
"Undefined");
335 void Deallocate(cl::Buffer* buffer,
GGsize size,
GGsize const& thread_index, std::string
const& class_name =
"Undefined");
344 void CleanBuffer(cl::Buffer* buffer,
GGsize const& size,
GGsize const& thread_index);
352 bool IsDoublePrecisionAtomicAddition(
GGsize const& device_index)
const;
361 std::string ErrorType(
GGint const& error)
const;
370 GGsize CheckKernel(std::string
const& kernel_name, std::string
const& compilation_options)
const;
378 bool IsDoublePrecision(
GGsize const& device_index)
const;
479 template <
typename T>
482 GGcout(
"GGEMSOpenCLManager",
"GetDeviceBuffer", 4) <<
"Getting mapped memory buffer on OpenCL device..." <<
GGendl;
485 T* ptr =
static_cast<T*
>(
queues_[thread_index]->enqueueMapBuffer(*device_ptr, CL_TRUE, CL_MAP_WRITE | CL_MAP_READ, 0, size,
nullptr,
nullptr, &err));
494 template <
typename T>
497 GGcout(
"GGEMSOpenCLManager",
"ReleaseDeviceBuffer", 4) <<
"Releasing mapped memory buffer on OpenCL device..." <<
GGendl;
500 CheckOpenCLError(
queues_[thread_index]->enqueueUnmapMemObject(*device_ptr, host_ptr),
"GGEMSOpenCLManager",
"ReleaseDeviceBuffer");
549 #endif // GUARD_GGEMS_GLOBAL_GGEMSOpenCLManager_HH
GGfloat GetDeviceBalancing(GGsize const &thread_index) const
return the device load for a device
std::vector< GGuint > device_preferred_vector_width_int_
std::vector< cl_device_affinity_domain > device_partition_affinity_domain_
bool IsReady(void) const
check if an OpenCL device is activated
std::vector< GGuint > device_native_vector_width_char_
std::vector< std::string > platform_extensions_
std::vector< GGbool > device_host_unified_memory_
GGsize GetNumberOfActivatedDevice(void) const
get the number of activated devices
void set_device_balancing_opencl_manager(GGEMSOpenCLManager *opencl_manager, char const *device_balancing)
change the device balancing, by default device balancing is the same for each device
void print_infos_opencl_manager(GGEMSOpenCLManager *opencl_manager)
Print information about OpenCL.
std::vector< GGuint > device_max_samplers_
std::vector< GGuint > device_preferred_vector_width_half_
std::unordered_map< std::string, std::string > VendorUMap
GGsize GetRAMMemory(GGsize const &device_index) const
Get the RAM in bytes on OpenCL device.
GGEMSOpenCLManager & operator=(GGEMSOpenCLManager const &opencl_manager)=delete
Avoid assignement of the singleton by reference.
std::vector< cl::Device * > devices_
std::vector< GGulong > device_max_mem_alloc_size_
std::vector< GGuint > device_preferred_vector_width_char_
cl_device_type GetDeviceType(GGsize const &device_index) const
Get the type of the activated device.
std::vector< GGuint > device_native_vector_width_float_
GGsize GetMaxBufferAllocationSize(GGsize const &device_index) const
Get the max buffer size in bytes on activated OpenCL device.
std::vector< GGsize > device_image_max_array_size_
std::vector< GGuint > device_native_vector_width_long_
void CheckOpenCLError(GGint const &error, std::string const &class_name, std::string const &method_name) const
check the OpenCL error
std::vector< GGuint > device_native_vector_width_int_
std::vector< GGuint > device_preferred_vector_width_long_
cl::Event * GetEvent(GGsize const &thread_index) const
return an event to activated context
std::vector< GGbool > device_error_correction_support_
void ReleaseDeviceBuffer(cl::Buffer *const device_ptr, T *host_ptr, GGsize const &thread_index)
Get the device pointer on host to write on it. Mandatory after a GetDeviceBufferWrite ou GetDeviceBuf...
std::vector< cl_device_fp_config > device_double_fp_config_
std::vector< GGuint > device_max_work_item_dimensions_
std::vector< std::string > device_profile_
std::vector< GGuint > device_address_bits_
std::vector< GGulong > device_max_constant_buffer_size_
std::vector< GGbool > device_compiler_available_
std::vector< cl_device_fp_config > device_single_fp_config_
std::vector< cl_device_fp_config > device_half_fp_config_
std::vector< cl_device_type > device_type_
std::vector< GGuint > device_max_read_image_args_
std::vector< std::string > platform_version_
std::vector< GGulong > device_global_mem_size_
std::vector< GGuint > device_native_vector_width_short_
void set_device_index_ggems_opencl_manager(GGEMSOpenCLManager *opencl_manager, GGsize const device_id)
Set the device index to activate.
std::vector< GGuint > device_vendor_id_
std::vector< std::string > device_opencl_c_version_
std::vector< std::string > device_vendor_
std::vector< GGuint > device_max_compute_units_
std::vector< GGuint > device_preferred_vector_width_double_
GGEMSOpenCLManager(GGEMSOpenCLManager const &opencl_manager)=delete
Avoid copy of the singleton by reference.
GGEMSOpenCLManager * get_instance_ggems_opencl_manager(void)
Get the GGEMSOpenCLManager pointer for python user.
std::vector< GGsize > device_printf_buffer_size_
GGsize GetWorkGroupSize(void) const
Get the work group size defined in GGEMS on activated OpenCL context.
std::vector< GGuint > device_max_constant_args_
std::vector< GGsize > device_max_work_item_sizes_
std::vector< GGsize > device_indices_
std::vector< GGulong > device_global_mem_cache_size_
std::vector< GGbool > device_image_support_
std::vector< cl::CommandQueue * > queues_
std::vector< std::string > platform_vendor_
std::vector< GGuint > device_preferred_vector_width_short_
std::vector< GGbool > device_endian_little_
std::vector< GGsize > device_max_parameter_size_
std::vector< cl::Kernel * > kernels_
std::vector< GGuint > device_native_vector_width_half_
std::vector< GGuint > device_max_clock_frequency_
std::vector< GGuint > device_preferred_vector_width_float_
std::vector< GGsize > device_image3D_max_width_
std::vector< GGbool > device_available_
cl::Context * GetContext(GGsize const &thread_index) const
return the activated context
std::vector< GGsize > device_image3D_max_depth_
std::string build_options_
std::vector< GGuint > device_global_mem_cacheline_size_
std::vector< GGuint > device_native_vector_width_double_
std::vector< GGsize > device_profiling_timer_resolution_
std::vector< GGuint > device_partition_max_sub_devices_
T * GetDeviceBuffer(cl::Buffer *device_ptr, GGsize const &size, GGsize const &thread_index)
Get the device pointer on host to write on it. ReleaseDeviceBuffer must be used after this method!...
GGsize GetNumberOfDetectedDevice(void) const
get the number of detected devices
std::vector< cl::Platform > platforms_
std::vector< cl_device_exec_capabilities > device_execution_capabilities_
#define GGendl
overload C++ std::endl
std::vector< GGsize > device_image2D_max_width_
std::vector< GGulong > device_local_mem_size_
Singleton class storing all informations about OpenCL and managing GPU/CPU devices,...
std::vector< std::string > platform_profile_
void clean_opencl_manager(GGEMSOpenCLManager *opencl_manager)
Clean OpenCL manager for python user.
std::vector< std::string > device_version_
Print a custom std::cout end std::cerr handling verbosity.
std::vector< cl::Context * > contexts_
std::vector< GGuint > device_mem_base_addr_align_
std::vector< std::string > device_driver_version_
std::vector< cl_device_mem_cache_type > device_global_mem_cache_type_
std::vector< std::string > device_name_
std::vector< GGfloat > device_balancing_
std::string GetDeviceName(GGsize const &device_index) const
Get the name of the activated device.
std::vector< GGsize > device_image3D_max_height_
void set_device_to_activate_opencl_manager(GGEMSOpenCLManager *opencl_manager, char const *device_type, char const *device_vendor="")
Set the device index to activate.
GGEMSOpenCLManager(GGEMSOpenCLManager const &&opencl_manager)=delete
Avoid copy of the singleton by rvalue reference.
GGsize GetNumberDeviceLoads(void) const
return the size of device load vector
std::vector< cl::Event * > events_
std::vector< std::string > device_extensions_
GGsize GetIndexOfActivatedDevice(GGsize const &thread_index) const
get the index of activated device
std::vector< std::string > platform_name_
std::vector< GGsize > device_image_max_buffer_size_
std::vector< GGsize > device_max_work_group_size_
std::vector< std::string > kernel_compilation_options_
cl::CommandQueue * GetCommandQueue(GGsize const &thread_index) const
Return the command queue to activated context.
GGEMSOpenCLManager & operator=(GGEMSOpenCLManager const &&opencl_manager)=delete
Avoid copy of the singleton by rvalue reference.
std::vector< GGuint > device_max_write_image_args_
std::vector< GGsize > device_image2D_max_height_
static GGEMSOpenCLManager & GetInstance(void)
Create at first time the Singleton.
std::vector< cl_device_local_mem_type > device_local_mem_type_