参考博客:
OpenCL 环境适配流程 : vs环境搭建 + 最简单的设备信息输出,代码。
OpenCL环境搭建、获取平台设备信息 : 上面类似的博客, 补充作用。
OpenCL开发环境搭建 : 主要是AMD SDK 的安装。
opencl编程指南 : 简单的概述,没有代码和图,只是说明相关概念
**OpenCL快速入门教程: 【好】很好的文章,部分代码,但是简单介绍了各个流程的核心函数的基本使用方法 **
资源:
OpenCL 2.0 异构计算 [第三版] (Heterogeneous Computing with OpenCL 2.0) : 【重要】 gitbook , 中文版 ,系统的。
intel-profiling-opencl-applications-with-system-analyzer-and-platform-analyzer-520639.pdf : 电子书, 英文版,
OpenCL Optimization - 1068_GTC09.pdf ppt , 英文版
遇到的问题解决方法:
OpenCL 性能非常差 : 内存拷贝-》映射
主要流程:
具体实现:
vs2017 + cuda11.5 + 最简单demo
OpenCL 环境适配流程 :
cuda 的 opencl 库
G:\thirdcode\CUDA_Data\Development\include
G:\thirdcode\CUDA_Data\Development\lib\x64
OpenCL.lib
# include <stdio.h>
# include <stdlib.h>
# include <malloc.h>
# ifdef APPLE
# include <OpenCL/cl.h>
# else
# include <CL/cl.h>
# endif
void displayPlatformInfo(cl_platform_id id,
cl_platform_info param_name,
const char* paramNameAsStr) {
cl_int error = 0;
size_t paramSize = 0;
error = clGetPlatformInfo(id, param_name, 0, NULL, ¶mSize);
char* moreInfo = (char*)malloc(sizeof(char) * paramSize);
error = clGetPlatformInfo(id, param_name, paramSize, moreInfo, NULL);
if (error != CL_SUCCESS) {
perror("Unable to find any OpenCL platform information");
return;
}
printf("%s: %s\n", paramNameAsStr, moreInfo);
}
int main() {
/* OpenCL 1.1 data structures */
cl_platform_id* platforms;
/* OpenCL 1.1 scalar data types */
cl_uint numOfPlatforms;
cl_int error;
/*
Get the number of platforms
Remember that for each vendor's SDK installed on the computer,
the number of available platform also increased.
*/
error = clGetPlatformIDs(0, NULL, &numOfPlatforms);
if (error != CL_SUCCESS) {
perror("Unable to find any OpenCL platforms");
exit(1);
}
// Allocate memory for the number of installed platforms.
// alloca(...) occupies some stack space but is automatically freed on return
platforms = (cl_platform_id*)alloca(sizeof(cl_platform_id) * numOfPlatforms);
printf("Number of OpenCL platforms found: %d\n", numOfPlatforms);
error = clGetPlatformIDs(numOfPlatforms, platforms, NULL);
if (error != CL_SUCCESS) {
perror("Unable to find any OpenCL platforms");
exit(1);
}
// We invoke the API 'clPlatformInfo' twice for each parameter we're trying to extract
// and we use the return value to create temporary data structures (on the stack) to store
// the returned information on the second invocation.
for (cl_uint i = 0; i < numOfPlatforms; ++i) {
displayPlatformInfo(platforms[i], CL_PLATFORM_PROFILE, "CL_PLATFORM_PROFILE");
displayPlatformInfo(platforms[i], CL_PLATFORM_VERSION, "CL_PLATFORM_VERSION");
displayPlatformInfo(platforms[i], CL_PLATFORM_NAME, "CL_PLATFORM_NAME");
displayPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, "CL_PLATFORM_VENDOR");
displayPlatformInfo(platforms[i], CL_PLATFORM_EXTENSIONS, "CL_PLATFORM_EXTENSIONS");
}
return 0;
}
vs2017: 内存写入和内存读出,向量相加demo
**OpenCL快速入门教程: 很好的文章,部分代码,但是简单介绍了各个流程的核心函数的基本使用方法 **
OpenCL demo : 这篇博客中的对demo的基础封装还是可以的,简单的讲解demo , 不适合系统学习,只适合入门。