43 _build_opts.emplace(std::move(option));
79 return _build_opts == other._build_opts;
82 Program::Program() : _context(), _device(), _is_binary(false), _name(), _source(), _binary()
90 _name(std::move(
name)),
91 _source(std::move(source)),
98 _device(std::move(device)),
100 _name(std::move(
name)),
102 _binary(std::move(binary))
106 Program::operator cl::Program()
const
110 return cl::Program(_context, {_device}, {_binary});
114 return cl::Program(_context, _source,
false);
124 catch (
const cl::Error &e)
126 cl_int err = CL_SUCCESS;
127 const auto build_info = program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(&err);
129 for (
auto &pair : build_info)
131 std::cerr << pair.second << std::endl;
140 cl::Program cl_program =
static_cast<cl::Program
>(*this);
150 : _name(std::move(
name)), _kernel(
cl::
Kernel(program, _name.c_str()))
154 : _context(), _device(), _programs_map(), _built_programs_map(), _is_wbsm_supported()
159 : _context(), _device(), _programs_map(), _built_programs_map(), _is_wbsm_supported()
167 const std::string &program_name,
168 const std::string &program_source,
169 const std::string &kernel_path,
170 const StringSet &build_options_set,
171 bool is_binary)
const
173 const std::string
build_options = generate_build_options(build_options_set, kernel_path);
174 const std::string built_program_name = program_name +
"_" +
build_options;
175 auto built_program_it = _built_programs_map.find(built_program_name);
176 cl::Program cl_program;
178 if (_built_programs_map.end() != built_program_it)
181 cl_program = built_program_it->second;
185 Program program = load_program(program_name, program_source, is_binary);
191 _built_programs_map.emplace(built_program_name, cl_program);
199 CLCompileContext::load_program(
const std::string &program_name,
const std::string &program_source,
bool is_binary)
const
201 const auto program_it = _programs_map.find(program_name);
203 if (program_it != _programs_map.end())
205 return program_it->second;
210 #ifdef EMBEDDED_KERNELS
212 program = Program(_context, program_name, program_source);
216 program = Program(_context, _device.
cl_device(), program_name,
217 std::vector<unsigned char>(program_source.begin(), program_source.end()));
221 program = Program(_context, program_name, program_source);
226 const auto new_program = _programs_map.emplace(program_name, std::move(program));
228 return new_program.first->second;
234 if (_context.get() !=
nullptr)
236 const auto cl_devices = _context.getInfo<CL_CONTEXT_DEVICES>();
238 if (!cl_devices.empty())
245 std::string CLCompileContext::generate_build_options(
const StringSet &build_options_set,
246 const std::string &kernel_path)
const
248 std::string concat_str;
249 bool ext_supported =
false;
250 std::string ext_buildopts;
252 #if defined(ARM_COMPUTE_DEBUG_ENABLED)
254 concat_str +=
" -DARM_COMPUTE_DEBUG_ENABLED";
255 #endif // defined(ARM_COMPUTE_DEBUG_ENABLED)
263 concat_str +=
" -DARM_COMPUTE_OPENCL_FP16_ENABLED=1 ";
266 if (_device.
supported(
"cl_arm_integer_dot_product_int8") || _device.
supported(
"cl_khr_integer_dot_product"))
268 concat_str +=
" -DARM_COMPUTE_OPENCL_DOT8_ENABLED=1 ";
271 if (_device.
supported(
"cl_arm_integer_dot_product_accumulate_int8"))
273 concat_str +=
" -DARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED=1 ";
280 concat_str += ext_buildopts;
289 concat_str +=
" -DUNROLL_WITH_PRAGMA ";
292 std::string
build_options = stringify_set(build_options_set, kernel_path) + concat_str;
302 std::string CLCompileContext::stringify_set(
const StringSet &s,
const std::string &kernel_path)
const
304 std::string concat_set;
305 #ifndef EMBEDDED_KERNELS
306 concat_set +=
"-I" + kernel_path +
" ";
312 for (
const auto &el : s)
314 concat_set +=
" " + el;
322 _built_programs_map.emplace(built_program_name, program);
327 _programs_map.clear();
328 _built_programs_map.clear();
333 return _built_programs_map;
349 _device = std::move(device);
355 cl::NDRange default_range;
363 default_range = cl::NDRange(128u, 1);
366 default_range = cl::NullRange;
369 return default_range;
374 return _device.
supported(
"cl_khr_int64_base_atomics");
379 return _is_wbsm_supported;
386 size_t err = kernel.getWorkGroupInfo(_device.
cl_device(), CL_KERNEL_WORK_GROUP_SIZE, &result);
388 "clGetKernelWorkGroupInfo failed to return the maximum workgroup size for the kernel");
407 const std::regex ddk_regex(
"r([0-9]*)p[0-9]");
408 std::smatch ddk_match;
410 if (std::regex_search(device_version, ddk_match, ddk_regex))