28
28
29
29
#include " image.hpp"
30
30
#include < fstream>
31
+ #include < mutex>
31
32
#include < random>
32
33
33
34
namespace dpct {
@@ -493,6 +494,7 @@ class kernel_launcher {
493
494
static_cast <sycl::range<3 >>(local_range));
494
495
_local_mem_size = local_mem_size;
495
496
};
497
+ static inline std::mutex kernel_function_ptr_map_mutex;
496
498
497
499
public:
498
500
// / Variables for storing execution configuration.
@@ -513,6 +515,7 @@ class kernel_launcher {
513
515
const void *func,
514
516
std::function<void (dim3, dim3, void **, unsigned int , queue_ptr)>
515
517
launcher) {
518
+ std::lock_guard<std::mutex> lock (kernel_function_ptr_map_mutex);
516
519
kernel_function_ptr_map[func] = std::move (launcher);
517
520
}
518
521
// / Launches a kernel function with arguments provided directly through
@@ -543,8 +546,13 @@ class kernel_launcher {
543
546
// / \param [in] que SYCL queue used to execute kernel.
544
547
static void launch (const void *func, dim3 group_range, dim3 local_range,
545
548
void **args, unsigned int local_mem_size, queue_ptr que) {
546
- kernel_function_ptr_map[func](group_range, local_range, args,
547
- local_mem_size, que);
549
+ std::lock_guard<std::mutex> lock (kernel_function_ptr_map_mutex);
550
+ auto Iter = kernel_function_ptr_map.find (func);
551
+ if (Iter == kernel_function_ptr_map.end ()) {
552
+ throw std::runtime_error (
553
+ " dpct::launch() : no registered kernel function wrapper found." );
554
+ }
555
+ (Iter->second )(group_range, local_range, args, local_mem_size, que);
548
556
}
549
557
// / Launches a kernel function with packed arguments through kernel
550
558
// / function wrapper.
0 commit comments