livoxGen1: Add OpenClSplittingEngine
This commit is contained in:
@@ -9,26 +9,33 @@ if(ENABLE_STIMBUFFAPI_livoxGen1)
|
|||||||
# Find liburing using pkg-config
|
# Find liburing using pkg-config
|
||||||
pkg_check_modules(URING REQUIRED liburing)
|
pkg_check_modules(URING REQUIRED liburing)
|
||||||
|
|
||||||
|
# Find OpenCL using pkg-config
|
||||||
|
pkg_check_modules(OPENCL REQUIRED OpenCL)
|
||||||
|
|
||||||
add_library(livoxGen1 SHARED
|
add_library(livoxGen1 SHARED
|
||||||
livoxGen1.cpp
|
livoxGen1.cpp
|
||||||
stagingBuffer.cpp
|
stagingBuffer.cpp
|
||||||
pcloudStimulusBuffer.cpp
|
pcloudStimulusBuffer.cpp
|
||||||
ioUringAssemblyEngine.cpp
|
ioUringAssemblyEngine.cpp
|
||||||
|
openClSplittingEngine.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(livoxGen1 PUBLIC
|
target_include_directories(livoxGen1 PUBLIC
|
||||||
${Boost_INCLUDE_DIRS}
|
${Boost_INCLUDE_DIRS}
|
||||||
${CMAKE_SOURCE_DIR}/commonLibs
|
${CMAKE_SOURCE_DIR}/commonLibs
|
||||||
${URING_INCLUDE_DIRS}
|
${URING_INCLUDE_DIRS}
|
||||||
|
${OPENCL_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
target_link_libraries(livoxGen1 PUBLIC
|
target_link_libraries(livoxGen1 PUBLIC
|
||||||
Boost::system
|
Boost::system
|
||||||
Boost::log
|
Boost::log
|
||||||
${URING_LIBRARIES}
|
${URING_LIBRARIES}
|
||||||
|
${OPENCL_LIBRARIES}
|
||||||
attachmentSupport
|
attachmentSupport
|
||||||
)
|
)
|
||||||
target_link_directories(livoxGen1 PUBLIC
|
target_link_directories(livoxGen1 PUBLIC
|
||||||
${URING_LIBRARY_DIRS}
|
${URING_LIBRARY_DIRS}
|
||||||
|
${OPENCL_LIBRARY_DIRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Verify Boost dynamic dependencies after build
|
# Verify Boost dynamic dependencies after build
|
||||||
|
|||||||
@@ -0,0 +1,119 @@
|
|||||||
|
#include <stdexcept>
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstring>
|
||||||
|
#include "openClSplittingEngine.h"
|
||||||
|
#include "pcloudStimulusBuffer.h"
|
||||||
|
|
||||||
|
namespace smo {
|
||||||
|
namespace stim_buff {
|
||||||
|
|
||||||
|
OpenClSplittingEngine::OpenClSplittingEngine(PcloudStimulusBuffer& parent_)
|
||||||
|
: parent(parent_),
|
||||||
|
platform(nullptr),
|
||||||
|
device(nullptr),
|
||||||
|
context(nullptr),
|
||||||
|
commandQueue(nullptr),
|
||||||
|
program(nullptr),
|
||||||
|
kernel(nullptr),
|
||||||
|
isSetup(false),
|
||||||
|
assemblyBuffer(nullptr),
|
||||||
|
xyzBuffer(nullptr),
|
||||||
|
intensityBuffer(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
OpenClSplittingEngine::~OpenClSplittingEngine()
|
||||||
|
{
|
||||||
|
finalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OpenClSplittingEngine::setup()
|
||||||
|
{
|
||||||
|
if (isSetup) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
cl_int err;
|
||||||
|
|
||||||
|
// Get platform
|
||||||
|
cl_uint numPlatforms;
|
||||||
|
err = clGetPlatformIDs(1, &platform, &numPlatforms);
|
||||||
|
if (err != CL_SUCCESS || numPlatforms == 0) {
|
||||||
|
std::cerr << __func__ << ": failed to get OpenCL platform: "
|
||||||
|
<< err << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get device
|
||||||
|
err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, nullptr);
|
||||||
|
if (err != CL_SUCCESS) {
|
||||||
|
std::cerr << __func__ << ": failed to get GPU device: "
|
||||||
|
<< err << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create context
|
||||||
|
context = clCreateContext(nullptr, 1, &device, nullptr, nullptr, &err);
|
||||||
|
if (err != CL_SUCCESS || !context) {
|
||||||
|
std::cerr << __func__ << ": failed to create OpenCL context: "
|
||||||
|
<< err << std::endl;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create command queue
|
||||||
|
commandQueue = clCreateCommandQueue(context, device, 0, &err);
|
||||||
|
if (err != CL_SUCCESS || !commandQueue) {
|
||||||
|
std::cerr << __func__ << ": failed to create command queue: "
|
||||||
|
<< err << std::endl;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Create program and kernel
|
||||||
|
// TODO: Create buffers
|
||||||
|
|
||||||
|
isSetup = true;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
finalize();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenClSplittingEngine::finalize()
|
||||||
|
{
|
||||||
|
if (intensityBuffer) {
|
||||||
|
clReleaseMemObject(intensityBuffer);
|
||||||
|
intensityBuffer = nullptr;
|
||||||
|
}
|
||||||
|
if (xyzBuffer) {
|
||||||
|
clReleaseMemObject(xyzBuffer);
|
||||||
|
xyzBuffer = nullptr;
|
||||||
|
}
|
||||||
|
if (assemblyBuffer) {
|
||||||
|
clReleaseMemObject(assemblyBuffer);
|
||||||
|
assemblyBuffer = nullptr;
|
||||||
|
}
|
||||||
|
if (kernel) {
|
||||||
|
clReleaseKernel(kernel);
|
||||||
|
kernel = nullptr;
|
||||||
|
}
|
||||||
|
if (program) {
|
||||||
|
clReleaseProgram(program);
|
||||||
|
program = nullptr;
|
||||||
|
}
|
||||||
|
if (commandQueue) {
|
||||||
|
clReleaseCommandQueue(commandQueue);
|
||||||
|
commandQueue = nullptr;
|
||||||
|
}
|
||||||
|
if (context) {
|
||||||
|
clReleaseContext(context);
|
||||||
|
context = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
device = nullptr;
|
||||||
|
platform = nullptr;
|
||||||
|
isSetup = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace stim_buff
|
||||||
|
} // namespace smo
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
#ifndef _LIVOX_GEN1_OPENCL_SPLITTING_ENGINE_H
|
||||||
|
#define _LIVOX_GEN1_OPENCL_SPLITTING_ENGINE_H
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <memory>
|
||||||
|
#include <CL/cl.h>
|
||||||
|
|
||||||
|
namespace smo {
|
||||||
|
namespace stim_buff {
|
||||||
|
|
||||||
|
class PcloudStimulusBuffer;
|
||||||
|
|
||||||
|
class OpenClSplittingEngine
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit OpenClSplittingEngine(PcloudStimulusBuffer& parent);
|
||||||
|
~OpenClSplittingEngine();
|
||||||
|
|
||||||
|
// Non-copyable, movable
|
||||||
|
OpenClSplittingEngine(const OpenClSplittingEngine&) = delete;
|
||||||
|
OpenClSplittingEngine& operator=(const OpenClSplittingEngine&) = delete;
|
||||||
|
OpenClSplittingEngine(OpenClSplittingEngine&&) = default;
|
||||||
|
OpenClSplittingEngine& operator=(OpenClSplittingEngine&&) = default;
|
||||||
|
|
||||||
|
bool setup();
|
||||||
|
void finalize();
|
||||||
|
|
||||||
|
private:
|
||||||
|
PcloudStimulusBuffer& parent;
|
||||||
|
|
||||||
|
// OpenCL infrastructure
|
||||||
|
cl_platform_id platform;
|
||||||
|
cl_device_id device;
|
||||||
|
cl_context context;
|
||||||
|
cl_command_queue commandQueue;
|
||||||
|
cl_program program;
|
||||||
|
cl_kernel kernel;
|
||||||
|
bool isSetup;
|
||||||
|
|
||||||
|
// OpenCL buffers
|
||||||
|
cl_mem assemblyBuffer;
|
||||||
|
cl_mem xyzBuffer;
|
||||||
|
cl_mem intensityBuffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace stim_buff
|
||||||
|
} // namespace smo
|
||||||
|
|
||||||
|
#endif // _LIVOX_GEN1_OPENCL_SPLITTING_ENGINE_H
|
||||||
Reference in New Issue
Block a user