linux opencl(AMD) Example
? ? 當(dāng)然,首先要安裝AMD-APP-SDK和AMD的顯卡驅(qū)動(dòng)。我的是linux系統(tǒng)加AMD顯卡。我下APP的地址:http://developer.amd.com/Downloads/AMD-APP-SDK-v2.7-lnx64.tgz。
? ? 搞定以后就可以開始寫程序了。找到apple的一個(gè)例程:http://developer.apple.com/library/mac/#samplecode/OpenCL_Hello_World_Example/Listings/hello_c.html。
? ? 當(dāng)然,我這非蘋果的系統(tǒng)直接用這個(gè)是不行的。需要把#include <OpenCL/opencl.h>改為#include <CL/opencl.h>。apple的頭文件目錄和其他的平臺(tái)有區(qū)別的。
? ? 好了,開始編譯:
? ? ? ? ? g++ -L/opt/AMDAPP/lib/x86_64 -lOpenCL -I/opt/AMDAPP/include /home/delat2/mac_square.cpp -o /home/delat2/mac_square.cpp.o
? ? 編譯成功,運(yùn)行看看。居然提示:Error: Failed to create a device group!看看代碼,可以發(fā)現(xiàn)是clGetDeviceIDs這個(gè)函數(shù)返回了錯(cuò)誤。google一下,得知
clGetDeviceIDs returns CL_SUCCESS if the function is executed successfully. Otherwise it returns the following:
CL_INVALID_PLATFORM if platform is not a valid platform.
CL_INVALID_DEVICE_TYPE if device_type is not a valid value.
CL_INVALID_VALUE if num_entries is equal to zero and device_type is not NULL or if both num_devices and device_type are NULL.
CL_DEVICE_NOT_FOUND if no OpenCL devices that matched device_type were found.
?
? ? 用switch case判斷一下錯(cuò)誤,說(shuō)是CL_INVALID_PLATFORM。莫非我的APP-SDK還沒裝好?用/opt/AMDAPP/samples/opencl/bin/x86_64下的例程測(cè)試一下是可以的。google一下CL_INVALID_PLATFORM,找到了AMD的說(shuō)明(http://developer.amd.com/support/KnowledgeBase/Lists/KnowledgeBase/DispForm.aspx?ID=71)。原來(lái)是新版本的SDK有幾處修改。按照說(shuō)明,clGetDeviceIDs的cl_platform_id參數(shù)不能為NULL。而獲取platform_id的方法
? ? cl_platform_id platform_id=NULL;
? ? err=clGetPlatformIDs(1,&platform_id,NULL);
相應(yīng)的clGetDeviceIDs改為
? ? ?err = clGetDeviceIDs(platform_id, gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU, 1, &device_id, NULL);
重新編譯,運(yùn)行就沒出錯(cuò)了。
?
總結(jié)
以上是生活随笔為你收集整理的linux opencl(AMD) Example的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android—OkHttp同步异步请求
- 下一篇: 最佳Linux服务器发行版