本文整理汇总了C++中cl::Program::getInfo方法的典型用法代码示例。如果您正苦于以下问题:C++ Program::getInfo方法的具体用法?C++ Program::getInfo怎么用?C++ Program::getInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cl::Program
的用法示例。
在下文中一共展示了Program::getInfo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runtime_error
CL_helper(const char *kernelFileName, std::vector<std::string> kernelNames, bool loadBinary, bool writeBinary,
bool usePreProcArgs = false, std::map<std::string, std::string> preProcArgs = std::map<std::string, std::string>()){
cl::Platform::get(&platforms);
if(platforms.size()==0)
throw std::runtime_error("No OpenCL platforms found.\n");
int selectedPlatform=0;
platform=platforms.at(selectedPlatform);
platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);
if(devices.size()==0)
throw std::runtime_error("No opencl devices found.\n");
int selectedDevice=0;
device=devices.at(selectedDevice);
context = cl::Context(devices);
try{
if(loadBinary){
std::string vendor=platform.getInfo<CL_PLATFORM_VENDOR>();
size_t found = vendor.find("NVIDIA");
if(found != std::string::npos){
FILE* fp;
fp = fopen("src/kernels/julia_filter.ptx", "r");
if (!fp) {
std::cerr << "Error loading kernel binary" << std::endl;
std::cerr << "Building kernel from .cl file" << std::endl;
loadBinary = false;
} else {
fseek(fp, 0, SEEK_END);
size_t kernel_sz = ftell(fp);
rewind(fp);
char* kernel_str = (char*)malloc(kernel_sz);
unsigned bytes = fread(kernel_str, 1, kernel_sz, fp);
fclose(fp);
binaries.push_back(std::make_pair((void*)kernel_str,kernel_sz+1));
program = cl::Program(context, devices, binaries);
program.build(devices);
}
} else{
std::cerr << "Vendor not NVIDIA, cannot load .ptx binary" << std::endl;
std::cerr << "Building kernel from .cl file" << std::endl;
loadBinary = false;
}
}
if(!loadBinary){
std::string kernelSource=CL_helper::LoadSource(kernelFileName);
sources.push_back(std::make_pair(kernelSource.c_str(), kernelSource.size()+1));
program = cl::Program(context, sources);
if(usePreProcArgs && !preProcArgs.empty()){
std::string preProcArgsString;
for(auto& arg : preProcArgs) {
preProcArgsString += "-D" + arg.first + "=" + arg.second + " ";
}
program.build(devices, preProcArgsString.c_str());
} else {
//std::string params = "-cl-unsafe-math-optimizations";
program.build(devices);
}
}
}catch (cl::Error er) {
for(unsigned i=0;i<devices.size();i++){
std::cerr <<"Log for device " << devices[i].getInfo<CL_DEVICE_NAME>().c_str()<<std::endl;
std::cerr << program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(devices[i]).c_str() <<std::endl;
}
std::cerr << "ERROR:" << er.what() << " Code " << er.err()<<std::endl;
throw;
}
for(unsigned i=0; i<kernelNames.size();i++){
kernels.push_back( cl::Kernel(program, kernelNames.at(i).c_str()) );
}
queue = cl::CommandQueue(context, device);
if(writeBinary){
size_t bin_sz;
program.getInfo( CL_PROGRAM_BINARY_SIZES, &bin_sz);
unsigned char *bin = (unsigned char *)malloc(bin_sz);
program.getInfo(CL_PROGRAM_BINARIES, &bin);
//.........这里部分代码省略.........