diff --git a/nntrainer/cl_buffer_manager.cpp b/nntrainer/cl_buffer_manager.cpp index c2af78ca5..df5009dcc 100644 --- a/nntrainer/cl_buffer_manager.cpp +++ b/nntrainer/cl_buffer_manager.cpp @@ -21,7 +21,7 @@ ClBufferManager &ClBufferManager::getInstance() { // to-do: Implementation to be updated with array of Buffer objects if required // fp16 Buffer objects to be added in future -ClBufferManager::ClBufferManager() { +void ClBufferManager::initBuffers() { readBufferA = new opencl::Buffer(context_inst_, buffer_size_bytes, true); readBufferB = new opencl::Buffer(context_inst_, buffer_size_bytes, true); readBufferC = new opencl::Buffer(context_inst_, buffer_size_bytes, true); @@ -36,6 +36,7 @@ ClBufferManager::~ClBufferManager() { delete readBufferC; delete writeBufferA; delete writeBufferB; + ml_logi("ClBufferManager: Buffers destroyed"); } } // namespace nntrainer diff --git a/nntrainer/cl_buffer_manager.h b/nntrainer/cl_buffer_manager.h index 875e7e9bc..99b79ef4c 100644 --- a/nntrainer/cl_buffer_manager.h +++ b/nntrainer/cl_buffer_manager.h @@ -34,7 +34,7 @@ class ClBufferManager { * @brief Private constructor to prevent object creation * */ - ClBufferManager(); + ClBufferManager(){}; /** * @brief OpenCl context global instance @@ -61,6 +61,11 @@ class ClBufferManager { opencl::Buffer *writeBufferA; opencl::Buffer *writeBufferB; + /** + * @brief Initialize Buffer objects. + */ + void initBuffers(); + /** * @brief Destroy Buffer pointers. * diff --git a/nntrainer/cl_context.h b/nntrainer/cl_context.h index 025365546..e0b720900 100644 --- a/nntrainer/cl_context.h +++ b/nntrainer/cl_context.h @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -79,12 +80,14 @@ class ClContext { template using FactoryMap = std::tuple...>; - // getting static instance of commandqueue and opencl context + // getting static instance of commandqueue, opencl context and buffermanager opencl::CommandQueueManager &command_queue_inst_ = opencl::CommandQueueManager::GetInstance(); opencl::ContextManager &context_inst_ = opencl::ContextManager::GetInstance(); + ClBufferManager &clbuffInstance = ClBufferManager::getInstance(); + /** * @brief Default constructor */ @@ -272,6 +275,9 @@ class ClContext { // getContext() called inside createCommandQueue which creates clContext bool result = command_queue_inst_.CreateCommandQueue(); + // initialize device buffers + clbuffInstance.initBuffers(); + cl_initialized = result; return cl_initialized; };