From 427bb6baae94b19b8ea641958221d94bf5ba5386 Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Mon, 14 Sep 2020 13:45:13 +0300 Subject: [PATCH 1/5] Modify cpu_queues, gpu_queues and active_queues to functions. --- backends/source/dppl_sycl_queue_interface.cpp | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/backends/source/dppl_sycl_queue_interface.cpp b/backends/source/dppl_sycl_queue_interface.cpp index 2c359c6abe..d0d5d023a5 100644 --- a/backends/source/dppl_sycl_queue_interface.cpp +++ b/backends/source/dppl_sycl_queue_interface.cpp @@ -103,9 +103,21 @@ void error_reporter (const std::string & msg) class QMgrHelper { public: - static std::vector cpu_queues; - static std::vector gpu_queues; - static thread_local std::vector active_queues; + static std::vector& cpu_queues_() + { + static std::vector cpu_queues = QMgrHelper::init_queues(info::device_type::cpu); + return cpu_queues; + } + static std::vector& gpu_queues_() + { + static std::vector gpu_queues = QMgrHelper::init_queues(info::device_type::gpu); + return gpu_queues; + } + static std::vector& active_queues_() + { + thread_local static std::vector active_queues = {default_selector()}; + return active_queues; + } static __dppl_give DPPLSyclQueueRef getQueue (DPPLSyclDeviceType DeviceTy, size_t DNum); @@ -132,15 +144,19 @@ class QMgrHelper } }; +#define active_queues active_queues_() +#define cpu_queues cpu_queues_() +#define gpu_queues gpu_queues_() + // Initialize the active_queue with the default queue -thread_local std::vector QMgrHelper::active_queues - = {default_selector()}; +// thread_local std::vector QMgrHelper::active_queues +// = {default_selector()}; -std::vector QMgrHelper::cpu_queues - = QMgrHelper::init_queues(info::device_type::cpu); +// std::vector QMgrHelper::cpu_queues +// = QMgrHelper::init_queues(info::device_type::cpu); -std::vector QMgrHelper::gpu_queues - = QMgrHelper::init_queues(info::device_type::gpu); +// std::vector QMgrHelper::gpu_queues +// = QMgrHelper::init_queues(info::device_type::gpu); /*! * Allocates a new copy of the present top of stack queue, which can be the From 394c8ce209c5c98333216e9d9dcf459d5be156c7 Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Mon, 14 Sep 2020 13:56:57 +0300 Subject: [PATCH 2/5] Change static vectors to static pointers to verctors. It disables call for destructors. Destructors are also call in undefined order. --- backends/source/dppl_sycl_queue_interface.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/backends/source/dppl_sycl_queue_interface.cpp b/backends/source/dppl_sycl_queue_interface.cpp index d0d5d023a5..93f0c211be 100644 --- a/backends/source/dppl_sycl_queue_interface.cpp +++ b/backends/source/dppl_sycl_queue_interface.cpp @@ -105,18 +105,18 @@ class QMgrHelper public: static std::vector& cpu_queues_() { - static std::vector cpu_queues = QMgrHelper::init_queues(info::device_type::cpu); - return cpu_queues; + static std::vector* cpu_queues = QMgrHelper::init_queues(info::device_type::cpu); + return *cpu_queues; } static std::vector& gpu_queues_() { - static std::vector gpu_queues = QMgrHelper::init_queues(info::device_type::gpu); - return gpu_queues; + static std::vector* gpu_queues = QMgrHelper::init_queues(info::device_type::gpu); + return *gpu_queues; } static std::vector& active_queues_() { - thread_local static std::vector active_queues = {default_selector()}; - return active_queues; + thread_local static std::vector* active_queues = new std::vector({default_selector()}); + return *active_queues; } static __dppl_give DPPLSyclQueueRef @@ -134,12 +134,12 @@ class QMgrHelper static void popSyclQueue (); - static cl::sycl::vector_class + static cl::sycl::vector_class* init_queues (info::device_type device_ty) { - std::vector queues; + std::vector* queues = new std::vector(); for(auto d : device::get_devices(device_ty)) - queues.emplace_back(d); + queues->emplace_back(d); return queues; } }; From 72d6bea6747b98aeb9a6d7c474c881d106fa30df Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Mon, 14 Sep 2020 14:06:03 +0300 Subject: [PATCH 3/5] Clean commented code --- backends/source/dppl_sycl_queue_interface.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/backends/source/dppl_sycl_queue_interface.cpp b/backends/source/dppl_sycl_queue_interface.cpp index 93f0c211be..eb95631b45 100644 --- a/backends/source/dppl_sycl_queue_interface.cpp +++ b/backends/source/dppl_sycl_queue_interface.cpp @@ -148,16 +148,6 @@ class QMgrHelper #define cpu_queues cpu_queues_() #define gpu_queues gpu_queues_() -// Initialize the active_queue with the default queue -// thread_local std::vector QMgrHelper::active_queues -// = {default_selector()}; - -// std::vector QMgrHelper::cpu_queues -// = QMgrHelper::init_queues(info::device_type::cpu); - -// std::vector QMgrHelper::gpu_queues -// = QMgrHelper::init_queues(info::device_type::gpu); - /*! * Allocates a new copy of the present top of stack queue, which can be the * default queue and returns to caller. The caller owns the pointer and is From 923ed5f3149fba7ca65fd54bc8d7d5f0d0a2190b Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Mon, 14 Sep 2020 14:07:20 +0300 Subject: [PATCH 4/5] Format code to fit line width --- backends/source/dppl_sycl_queue_interface.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/backends/source/dppl_sycl_queue_interface.cpp b/backends/source/dppl_sycl_queue_interface.cpp index eb95631b45..675d2900da 100644 --- a/backends/source/dppl_sycl_queue_interface.cpp +++ b/backends/source/dppl_sycl_queue_interface.cpp @@ -105,17 +105,20 @@ class QMgrHelper public: static std::vector& cpu_queues_() { - static std::vector* cpu_queues = QMgrHelper::init_queues(info::device_type::cpu); + static std::vector* cpu_queues = + QMgrHelper::init_queues(info::device_type::cpu); return *cpu_queues; } static std::vector& gpu_queues_() { - static std::vector* gpu_queues = QMgrHelper::init_queues(info::device_type::gpu); + static std::vector* gpu_queues = + QMgrHelper::init_queues(info::device_type::gpu); return *gpu_queues; } static std::vector& active_queues_() { - thread_local static std::vector* active_queues = new std::vector({default_selector()}); + thread_local static std::vector* active_queues = + new std::vector({default_selector()}); return *active_queues; } @@ -137,7 +140,7 @@ class QMgrHelper static cl::sycl::vector_class* init_queues (info::device_type device_ty) { - std::vector* queues = new std::vector(); + auto queues = new std::vector(); for(auto d : device::get_devices(device_ty)) queues->emplace_back(d); return queues; From 05ae66fe361ed41b6e8a2d125e3d978a921a37de Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Tue, 15 Sep 2020 08:34:50 +0300 Subject: [PATCH 5/5] Fix for code style --- backends/source/dppl_sycl_queue_interface.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/backends/source/dppl_sycl_queue_interface.cpp b/backends/source/dppl_sycl_queue_interface.cpp index 675d2900da..cf215c6795 100644 --- a/backends/source/dppl_sycl_queue_interface.cpp +++ b/backends/source/dppl_sycl_queue_interface.cpp @@ -103,19 +103,24 @@ void error_reporter (const std::string & msg) class QMgrHelper { public: - static std::vector& cpu_queues_() + static std::vector& + cpu_queues_ () { static std::vector* cpu_queues = QMgrHelper::init_queues(info::device_type::cpu); return *cpu_queues; } - static std::vector& gpu_queues_() + + static std::vector& + gpu_queues_ () { static std::vector* gpu_queues = QMgrHelper::init_queues(info::device_type::gpu); return *gpu_queues; } - static std::vector& active_queues_() + + static std::vector& + active_queues_ () { thread_local static std::vector* active_queues = new std::vector({default_selector()}); @@ -147,9 +152,13 @@ class QMgrHelper } }; +// make function call like access to variable +// it is for minimizing code changes during replacing static vars with functions +// it could be refactored by replacing variable with function call +// scope of this variables is only this file +#define cpu_queues cpu_queues_() +#define gpu_queues gpu_queues_() #define active_queues active_queues_() -#define cpu_queues cpu_queues_() -#define gpu_queues gpu_queues_() /*! * Allocates a new copy of the present top of stack queue, which can be the