MCPcopy Create free account
hub / github.com/AdaptiveCpp/AdaptiveCpp / register_hcf_object

Method register_hcf_object

src/runtime/kernel_cache.cpp:268–372  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

266}
267
268hcf_object_id hcf_cache::register_hcf_object(const common::hcf_container &obj) {
269
270 std::lock_guard<std::mutex> lock{_mutex};
271
272 if (!obj.root_node()->has_key("object-id")) {
273 HIPSYCL_DEBUG_ERROR
274 << "hcf_cache: Invalid hcf object (missing object id)" << std::endl;
275 }
276 const std::string *data = obj.root_node()->get_value("object-id");
277
278 assert(data);
279 hcf_object_id id = std::stoull(*data);
280 HIPSYCL_DEBUG_INFO << "hcf_cache: Registering HCF object " << id << "..." << std::endl;
281
282 if (_hcf_objects.count(id) > 0) {
283 HIPSYCL_DEBUG_ERROR
284 << "hcf_cache: Detected hcf object id collision " << id
285 << ", this should not happen. Some kernels might be unavailable."
286 << std::endl;
287 } else {
288 common::hcf_container* stored_obj = new common::hcf_container{obj};
289 _hcf_objects[id] = std::unique_ptr<common::hcf_container>{stored_obj};
290 // Check if the HCF exports some symbols
291 for_each_exported_symbol_list(
292 // Don't use obj here, since we have copied it into the cache, and need
293 // to ensure that the pointers to image nodes are stable
294 *stored_obj,
295 [&](const common::hcf_container::node *image_node,
296 const std::vector<std::string> &exported_symbols) {
297
298 for (const auto &symbol : exported_symbols) {
299
300 _exported_symbol_providers[symbol].push_back(
301 device_image_id{id, image_node});
302
303 HIPSYCL_DEBUG_INFO << "hcf_cache: Symbol " << symbol
304 << " is registered as exported by object " << id
305 << " and image " << image_node->node_id
306 << " @" << image_node << std::endl;
307 }
308 });
309 // See if stored object has kernel nodes that we can parse
310 if(auto* kernels_node = stored_obj->root_node()->get_subnode("kernels")) {
311 for(const auto& kernel_name : kernels_node->get_subnodes()) {
312 std::unique_ptr<hcf_kernel_info> kernel_info{
313 new hcf_kernel_info{id, kernels_node->get_subnode(kernel_name)}};
314 if(kernel_info->is_valid()) {
315 HIPSYCL_DEBUG_INFO << "hcf_cache: Registering kernel info for kernel "
316 << kernel_name << " from HCF object " << id
317 << std::endl;
318 HIPSYCL_DEBUG_INFO << " kernel_info: hcf object id = "
319 << kernel_info->get_hcf_object_id() << std::endl;
320 for(int i = 0; i < kernel_info->get_num_parameters(); ++i) {
321 HIPSYCL_DEBUG_INFO
322 << " kernel_info: parameter " << i
323 << ": offset = " << kernel_info->get_argument_offset(i)
324 << " size = " << kernel_info->get_argument_size(i)
325 << " original index = "

Callers 1

__acpp_register_hcfFunction · 0.80

Calls 15

to_stringFunction · 0.85
has_keyMethod · 0.80
root_nodeMethod · 0.80
get_valueMethod · 0.80
countMethod · 0.80
push_backMethod · 0.80
get_subnodeMethod · 0.80
get_subnodesMethod · 0.80
is_validMethod · 0.80
get_hcf_object_idMethod · 0.80
get_num_parametersMethod · 0.80

Tested by

no test coverage detected