本文整理汇总了C++中opencldevice::pointer::createProgramFromSource方法的典型用法代码示例。如果您正苦于以下问题:C++ pointer::createProgramFromSource方法的具体用法?C++ pointer::createProgramFromSource怎么用?C++ pointer::createProgramFromSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opencldevice::pointer
的用法示例。
在下文中一共展示了pointer::createProgramFromSource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: recompileOpenCLCode
void SeededRegionGrowing::recompileOpenCLCode(Image::pointer input) {
// Check if there is a need to recompile OpenCL code
if(input->getDimensions() == mDimensionCLCodeCompiledFor &&
input->getDataType() == mTypeCLCodeCompiledFor)
return;
OpenCLDevice::pointer device = getMainDevice();
std::string buildOptions = "";
if(input->getDataType() == TYPE_FLOAT) {
buildOptions = "-DTYPE_FLOAT";
} else if(input->getDataType() == TYPE_INT8 || input->getDataType() == TYPE_INT16) {
buildOptions = "-DTYPE_INT";
} else {
buildOptions = "-DTYPE_UINT";
}
std::string filename;
if(input->getDimensions() == 2) {
filename = "Algorithms/SeededRegionGrowing/SeededRegionGrowing2D.cl";
} else {
filename = "Algorithms/SeededRegionGrowing/SeededRegionGrowing3D.cl";
}
int programNr = device->createProgramFromSource(std::string(FAST_SOURCE_DIR) + filename, buildOptions);
mKernel = cl::Kernel(device->getProgram(programNr), "seededRegionGrowing");
mDimensionCLCodeCompiledFor = input->getDimensions();
mTypeCLCodeCompiledFor = input->getDataType();
}
示例2: execute
void DoubleFilter::execute() {
if(!mInput.isValid()) {
throw Exception("No input supplied to GaussianSmoothingFilter");
}
Image::pointer input = mInput;
Image::pointer output = mOutput;
// Initialize output image
output->createFromImage(input, mDevice);
if(mDevice->isHost()) {
// Execution device is Host, use the executeAlgorithmOnHost function with the given data type
switch(input->getDataType()) {
// This macro creates a case statement for each data type and sets FAST_TYPE to the correct C++ data type
fastSwitchTypeMacro(executeAlgorithmOnHost<FAST_TYPE>(input, output));
}
} else {
// Execution device is an OpenCL device
OpenCLDevice::pointer device = boost::static_pointer_cast<OpenCLDevice>(mDevice);
// Set build options based on the data type of the data
std::string buildOptions = "";
switch(input->getDataType()) {
case TYPE_FLOAT:
buildOptions = "-DTYPE=float";
break;
case TYPE_INT8:
buildOptions = "-DTYPE=char";
break;
case TYPE_UINT8:
buildOptions = "-DTYPE=uchar";
break;
case TYPE_INT16:
buildOptions = "-DTYPE=short";
break;
case TYPE_UINT16:
buildOptions = "-DTYPE=ushort";
break;
}
// Compile the code
int programNr = device->createProgramFromSource(std::string(FAST_SOURCE_DIR) + "Tests/Algorithms/DoubleFilter.cl", buildOptions);
cl::Kernel kernel = cl::Kernel(device->getProgram(programNr), "doubleFilter");
// Get global size for the kernel
cl::NDRange globalSize(input->getWidth()*input->getHeight()*input->getDepth()*input->getNrOfComponents());
// Set the arguments for the kernel
OpenCLBufferAccess inputAccess = input->getOpenCLBufferAccess(ACCESS_READ, device);
OpenCLBufferAccess outputAccess = output->getOpenCLBufferAccess(ACCESS_READ_WRITE, device);
kernel.setArg(0, *inputAccess.get());
kernel.setArg(1, *outputAccess.get());
// Execute the kernel
device->getCommandQueue().enqueueNDRangeKernel(
kernel,
cl::NullRange,
globalSize,
cl::NullRange
);
}
// Update timestamp of the output data
output->updateModifiedTimestamp();
}