[英]boost compute (opencl wrapper), initial setup problems (qt, g++)
Been trying to compile this sample code: https://github.com/boostorg/compute/blob/master/README.md 一直在尝试编译此示例代码: https : //github.com/boostorg/compute/blob/master/README.md
I installed QT Creator 5.7 using mingw530 我使用mingw530安装了QT Creator 5.7
I compiled the boost libraries using 我使用编译了boost库
bootstrap.bat gcc
b2 install --prefix="C:\Boostbuild" --toolset=gcc
bjam --build-dir=c:/Dev/Boost/Boost_lib toolset=gcc stage
I installed AMD SDK 3.0, 2.9.1, and 2.9 我安装了AMD SDK 3.0、2.9.1和2.9
I even downloaded opencl 1.1, 1.2, and 2.1 cl.hpp and tried to include that. 我什至下载了opencl 1.1、1.2和2.1 cl.hpp,并尝试包含其中。
The compile starts, but I get a slew of errors 编译开始,但是出现了很多错误
C:\\Dev\\Boost\\compute-master\\include\\boost\\compute\\device.hpp:80: error: undefined reference to `clRetainDevice@4' C:\\ Dev \\ Boost \\ compute-master \\ include \\ boost \\ compute \\ device.hpp:80:错误:未定义对`clRetainDevice @ 4'的引用
C:\\Users\\User\\Documents\\Projects\\build-console-test-Desktop_Qt_5_7_0_MinGW_32bit-Debug\\debug\\main.o:-1: In function `ZN5boost7compute6deviceaSERKS1_': C:\\ Users \\ User \\ Documents \\ Projects \\ build-console-test-Desktop_Qt_5_7_0_MinGW_32bit-Debug \\ debug \\ main.o:-1:在功能`ZN5boost7compute6deviceaSERKS1_'中:
I tried a simple qt console app, using the code supplied by boost compute 我尝试了一个简单的qt控制台应用程序,使用boost boost提供的代码
Note: this isn't specific to qt, I've also tried compiling this using 注意:这不是qt特有的,我也尝试过使用
g++ -I/path/to/compute/include sort.cpp -lOpenCL
doing an -I to each of the include's in the main.cpp (see below) 对main.cpp中的每个include都执行-I(请参见下文)
Ideally, I'd like to know how to compile the example given on their page, with includes and all (and relevant amd sdk and/or opencl versions) along with the necessary included libraries. 理想情况下,我想知道如何编译包含在页面上的示例,包括include和所有(以及相关的amd sdk和/或opencl版本)以及必需的包含库。
My qt project file libraries 我的QT项目文件库
INCLUDEPATH += C:\Dev\Boost\compute-master\include
INCLUDEPATH += C:/Users/User/Downloads/dev/boost_1_61_0
INCLUDEPATH += "C:\Program Files (x86)\AMD APP SDK\2.9-1\include"
My main.cpp 我的main.cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <boost/compute.hpp>
//#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
//#undef CL_VERSION_1_2
//#include <C:\Dev\OpenCL\2.1\cl.hpp>
namespace compute = boost::compute;
int main()
{
// get the default compute device
compute::device gpu = compute::system::default_device();
// create a compute context and command queue
compute::context ctx(gpu);
compute::command_queue queue(ctx, gpu);
// generate random numbers on the host
std::vector<float> host_vector(1000000);
std::generate(host_vector.begin(), host_vector.end(), rand);
// create vector on the device
compute::vector<float> device_vector(1000000, ctx);
// copy data to the device
compute::copy(
host_vector.begin(), host_vector.end(), device_vector.begin(), queue
);
// sort data on the device
compute::sort(
device_vector.begin(), device_vector.end(), queue
);
// copy data back to the host
compute::copy(
device_vector.begin(), device_vector.end(), host_vector.begin(), queue
);
return 0;
}
if I uncomment out the include cl.hpp, I get further 如果我取消注释include cl.hpp,我会更进一步
C:/Dev/Boost/compute-master/include/boost/compute/allocator/buffer_allocator.hpp:91: undefined reference to `clReleaseMemObject@4'
The "slew of errors" are link errors because the location of the AMP APP SDK
libraries ( libOpenCL.a
in this case) is missing. “大量错误”是链接错误,因为缺少
AMP APP SDK
库(在本例中为libOpenCL.a
)的位置。
Eg to link to the 32 bit version for MinGw
, -lOpenCL
becomes: 例如,链接到
MinGw
的32位版本, -lOpenCL
变为:
-L"C:\\Program Files (x86)\\AMD APP SDK\\2.9-1\\lib\\x86" -lOpenCL
Or you could add the following to your qt .pro
file: 或者,您可以将以下内容添加到您的qt
.pro
文件中:
# Ensure that the AMDAPPSDKROOT environment variable has been set
OPENCL_ROOT = $$(AMDAPPSDKROOT)
isEmpty(OPENCL_ROOT) {
error("Please set AMDAPPSDKROOT to the location of the AMD APP SDK")
} else {
message(Using Boost from: $$OPENCL_ROOT)
}
INCLUDEPATH += $$OPENCL_ROOT/include
LIBS += -L$${OPENCL_ROOT}/lib/x86
LIBS += -lOpenCL
Note: the AMDAPPSDKROOT
environment variable is normally created when you install the AMD APP SDK. 注意:通常,在安装AMD APP SDK时会创建
AMDAPPSDKROOT
环境变量。 In your case it should be set to: 在您的情况下,应将其设置为:
C:\Program Files (x86)\AMD APP SDK\2.9-1\
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.