/workspaces/astro/sol3-sdk/cpp/sol3/opencl/opencl_manager.h Source File

Space-ng SDK: /workspaces/astro/sol3-sdk/cpp/sol3/opencl/opencl_manager.h Source File
Space-ng SDK
opencl_manager.h
Go to the documentation of this file.
1 // Copyright (c) Space-ng, inc. All rights reserved.
2 
3 #pragma once
4 
6 #include "sol3/cpp/filesystem.h"
9 
10 #include <map>
11 #include <string>
12 #include <vector>
13 
14 namespace sol3::opencl {
15 
21  public:
24 
26  cl::Context const& context() const { return context_; }
27 
29  cl::Device const& device() const { return device_; }
30 
32  std::vector<cl::Device> const& devices() const { return devices_; }
33 
34  // Creates a command queue to use for a kernel instance.
35  cl::CommandQueue createCommandQueue() const {
36  return cl::CommandQueue(context_, device_);
37  }
38 
42  cl::Kernel createKernel(
43  cpp::fs::path const& source_cl_file,
44  std::string const& kernel_name,
45  std::string const& compiler_opts = "");
46 
51  cpp::fs::path const& source_cl_file,
52  std::string const& compiler_opts = "");
53 
60  std::string const& name,
61  std::string const& source,
62  std::string const& compiler_opts = "");
63 
85 
86  private:
87  OpenClManager();
88  ~OpenClManager() = default;
89 
90  // Non-copyable, non-movable
91  OpenClManager(OpenClManager const&) = delete;
92  OpenClManager& operator=(OpenClManager const&) = delete;
93  OpenClManager(OpenClManager&&) = delete;
94  OpenClManager& operator=(OpenClManager&&) = delete;
95 
98  template <typename TGetSourceFn>
99  cl::Program getOrCompileImpl(
100  std::string const& key,
101  std::string const& compiler_opts,
102  TGetSourceFn&& get_source);
103 
104  std::vector<cl::Platform> platforms_;
105  std::vector<cl::Device> devices_;
106  cl::Device device_;
107  cl::Context context_;
109 };
110 
111 } // namespace sol3::opencl
112 
113 namespace sol3 {
117 }
118 } // namespace sol3
table Buffer
Definition: buffer.fbs:31
A view of an immutable shared-memory buffer.
Definition: shmem_buffer.h:74
Mutable view of shared memory buffer.
Definition: shmem_buffer.h:90
Small helper for read/write access to a value guarded by a shared mutex.
Definition: thread_safe_value.h:13
Definition: opencl_manager.h:20
cl::Kernel createKernel(cpp::fs::path const &source_cl_file, std::string const &kernel_name, std::string const &compiler_opts="")
cl::Context const & context() const
Get OpenCL context.
Definition: opencl_manager.h:26
cl::Program getOrCompileProgramFile(cpp::fs::path const &source_cl_file, std::string const &compiler_opts="")
cl::CommandQueue createCommandQueue() const
Definition: opencl_manager.h:35
cl::Device const & device() const
Get OpenCL device.
Definition: opencl_manager.h:29
std::vector< cl::Device > const & devices() const
Get list of all devices.
Definition: opencl_manager.h:32
cl::Buffer mapBufferToGpu(core::IBufferConst const &buffer)
cl::Buffer mapBufferToGpu(core::IBufferMutable &buffer)
static OpenClManager & instance()
Get singleton instance (thread-safe)
cl::Program getOrCompileProgramSource(std::string const &name, std::string const &source, std::string const &compiler_opts="")
Definition: opencl_manager.h:14
Definition: carrier_board_msg_spec.h:10
opencl::OpenClManager & openclMgr()
Convenience accessor for OpenCL manager singleton.
Definition: opencl_manager.h:115