2017-08-01 14:30:58 +02:00
|
|
|
#include "b3FillCL.h"
|
|
|
|
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
|
|
|
|
#include "b3BufferInfoCL.h"
|
|
|
|
#include "b3LauncherCL.h"
|
|
|
|
|
|
|
|
#define FILL_CL_PROGRAM_PATH "src/Bullet3OpenCL/ParallelPrimitives/kernels/FillKernels.cl"
|
|
|
|
|
|
|
|
#include "kernels/FillKernelsCL.h"
|
|
|
|
|
|
|
|
b3FillCL::b3FillCL(cl_context ctx, cl_device_id device, cl_command_queue queue)
|
2019-01-03 14:26:51 +01:00
|
|
|
: m_commandQueue(queue)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
const char* kernelSource = fillKernelsCL;
|
|
|
|
cl_int pErrNum;
|
|
|
|
const char* additionalMacros = "";
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
cl_program fillProg = b3OpenCLUtils::compileCLProgramFromString(ctx, device, kernelSource, &pErrNum, additionalMacros, FILL_CL_PROGRAM_PATH);
|
2017-08-01 14:30:58 +02:00
|
|
|
b3Assert(fillProg);
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
m_fillIntKernel = b3OpenCLUtils::compileCLKernelFromString(ctx, device, kernelSource, "FillIntKernel", &pErrNum, fillProg, additionalMacros);
|
2017-08-01 14:30:58 +02:00
|
|
|
b3Assert(m_fillIntKernel);
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
m_fillUnsignedIntKernel = b3OpenCLUtils::compileCLKernelFromString(ctx, device, kernelSource, "FillUnsignedIntKernel", &pErrNum, fillProg, additionalMacros);
|
2017-08-01 14:30:58 +02:00
|
|
|
b3Assert(m_fillIntKernel);
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
m_fillFloatKernel = b3OpenCLUtils::compileCLKernelFromString(ctx, device, kernelSource, "FillFloatKernel", &pErrNum, fillProg, additionalMacros);
|
2017-08-01 14:30:58 +02:00
|
|
|
b3Assert(m_fillFloatKernel);
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
m_fillKernelInt2 = b3OpenCLUtils::compileCLKernelFromString(ctx, device, kernelSource, "FillInt2Kernel", &pErrNum, fillProg, additionalMacros);
|
2017-08-01 14:30:58 +02:00
|
|
|
b3Assert(m_fillKernelInt2);
|
|
|
|
}
|
|
|
|
|
|
|
|
b3FillCL::~b3FillCL()
|
|
|
|
{
|
|
|
|
clReleaseKernel(m_fillKernelInt2);
|
|
|
|
clReleaseKernel(m_fillIntKernel);
|
|
|
|
clReleaseKernel(m_fillUnsignedIntKernel);
|
|
|
|
clReleaseKernel(m_fillFloatKernel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void b3FillCL::execute(b3OpenCLArray<float>& src, const float value, int n, int offset)
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3Assert(n > 0);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3LauncherCL launcher(m_commandQueue, m_fillFloatKernel, "m_fillFloatKernel");
|
|
|
|
launcher.setBuffer(src.getBufferCL());
|
|
|
|
launcher.setConst(n);
|
|
|
|
launcher.setConst(value);
|
|
|
|
launcher.setConst(offset);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
launcher.launch1D(n);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void b3FillCL::execute(b3OpenCLArray<int>& src, const int value, int n, int offset)
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3Assert(n > 0);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3LauncherCL launcher(m_commandQueue, m_fillIntKernel, "m_fillIntKernel");
|
2017-08-01 14:30:58 +02:00
|
|
|
launcher.setBuffer(src.getBufferCL());
|
2019-01-03 14:26:51 +01:00
|
|
|
launcher.setConst(n);
|
|
|
|
launcher.setConst(value);
|
|
|
|
launcher.setConst(offset);
|
|
|
|
launcher.launch1D(n);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void b3FillCL::execute(b3OpenCLArray<unsigned int>& src, const unsigned int value, int n, int offset)
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3Assert(n > 0);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3BufferInfoCL bInfo[] = {b3BufferInfoCL(src.getBufferCL())};
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
b3LauncherCL launcher(m_commandQueue, m_fillUnsignedIntKernel, "m_fillUnsignedIntKernel");
|
|
|
|
launcher.setBuffers(bInfo, sizeof(bInfo) / sizeof(b3BufferInfoCL));
|
|
|
|
launcher.setConst(n);
|
|
|
|
launcher.setConst(value);
|
2017-08-01 14:30:58 +02:00
|
|
|
launcher.setConst(offset);
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
launcher.launch1D(n);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
void b3FillCL::executeHost(b3AlignedObjectArray<b3Int2>& src, const b3Int2& value, int n, int offset)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < n; i++)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
src[i + offset] = value;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
void b3FillCL::executeHost(b3AlignedObjectArray<int>& src, const int value, int n, int offset)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < n; i++)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
src[i + offset] = value;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
void b3FillCL::execute(b3OpenCLArray<b3Int2>& src, const b3Int2& value, int n, int offset)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3Assert(n > 0);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3BufferInfoCL bInfo[] = {b3BufferInfoCL(src.getBufferCL())};
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
b3LauncherCL launcher(m_commandQueue, m_fillKernelInt2, "m_fillKernelInt2");
|
|
|
|
launcher.setBuffers(bInfo, sizeof(bInfo) / sizeof(b3BufferInfoCL));
|
2017-08-01 14:30:58 +02:00
|
|
|
launcher.setConst(n);
|
|
|
|
launcher.setConst(value);
|
|
|
|
launcher.setConst(offset);
|
|
|
|
|
|
|
|
//( constBuffer );
|
2019-01-03 14:26:51 +01:00
|
|
|
launcher.launch1D(n);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|