我是一个关于OpenCL编程的新手,我想运行一个简单的程序,该程序位于" OpenCL并行编程开发手册"中。 实际上,我想通过这个简单的编程来查询OpenCl平台:
#include <stdio.h>
#include <stdlib.h>
#include <CL/cl.h>
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.2 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
*/
error = clGetPlatformIDs(0, NULL, &numOfPlatforms);
if(error < 0) {
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*) malloc(sizeof(cl_platform_id)
* numOfPlatforms);
printf("Number of OpenCL platforms found: %d\n",
numOfPlatforms);
// 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;
}
我在Qt Creator上,关于视频我的电脑配置是:NVIDIA GEFORCE GT 635M&amp; Windows 8.1下的英特尔(R)HD Graphics 4000
我的.pro文件是:
SOURCES += \
main.cpp
QMAKE_CXXFLAGS += -std=c++0x
INCLUDEPATH += \
$$quote(C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v6.5/include)
LIBS += \
$$quote(C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v6.5/lib/x64/OpenCL.lib)
由于文件路径中的空格。所以,我的问题是:为什么,当我编译我的项目时,问题&#34;未定义引用clGetPlatformInfo@20'" appear? There's 2 others errors (one which exactly the same, the other is "undefined reference to
clGetPlatformIDs @ 12&#39;&#34;)
我在网上搜索了很多天,但我无法找到答案(这些问题已在Linux或Mac上得到答案。)
提前致谢!
马修
答案 0 :(得分:1)
看起来您正在尝试构建32位应用程序,同时使用64位版本的OpenCL.lib进行链接:
C:/ Program Files / NVIDIA GPU Computing Toolkit / CUDA / v6.5 / lib / x64 /OpenCL.lib
因此,要么以64位模式构建应用程序,要么修复路径以指向32位版本的OpenCL.lib。
答案 1 :(得分:-1)
感谢您的回答。你是对的,但我正在尝试构建64位版本,而使用32位版本,它可以工作!
再次感谢,它已经解决了!