[英]boost compute (opencl wrapper), initial setup problems (qt, g++)
一直在嘗試編譯此示例代碼: https : //github.com/boostorg/compute/blob/master/README.md
我使用mingw530安裝了QT Creator 5.7
我使用編譯了boost庫
bootstrap.bat gcc
b2 install --prefix="C:\Boostbuild" --toolset=gcc
bjam --build-dir=c:/Dev/Boost/Boost_lib toolset=gcc stage
我安裝了AMD SDK 3.0、2.9.1和2.9
我什至下載了opencl 1.1、1.2和2.1 cl.hpp,並嘗試包含其中。
編譯開始,但是出現了很多錯誤
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:在功能`ZN5boost7compute6deviceaSERKS1_'中:
我嘗試了一個簡單的qt控制台應用程序,使用boost boost提供的代碼
注意:這不是qt特有的,我也嘗試過使用
g++ -I/path/to/compute/include sort.cpp -lOpenCL
對main.cpp中的每個include都執行-I(請參見下文)
理想情況下,我想知道如何編譯包含在頁面上的示例,包括include和所有(以及相關的amd sdk和/或opencl版本)以及必需的包含庫。
我的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"
我的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;
}
如果我取消注釋include cl.hpp,我會更進一步
C:/Dev/Boost/compute-master/include/boost/compute/allocator/buffer_allocator.hpp:91: undefined reference to `clReleaseMemObject@4'
“大量錯誤”是鏈接錯誤,因為缺少AMP APP SDK
庫(在本例中為libOpenCL.a
)的位置。
例如,鏈接到MinGw
的32位版本, -lOpenCL
變為:
-L"C:\\Program Files (x86)\\AMD APP SDK\\2.9-1\\lib\\x86" -lOpenCL
或者,您可以將以下內容添加到您的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
注意:通常,在安裝AMD APP SDK時會創建AMDAPPSDKROOT
環境變量。 在您的情況下,應將其設置為:
C:\Program Files (x86)\AMD APP SDK\2.9-1\
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.