我想将一个字符串传递给我的GPU并从GPU中取回来打印它.这是为了理解目的 - 我知道,这个想法听起来毫无意义.
我试过了:
OpenCL的:
__kernel void same_in_same_out_char(__global uchar * out, __constant uchar * in){
for (unsigned int ui=0; ui<3; ui++) out[ui]=in[ui];
}
Run Code Online (Sandbox Code Playgroud)
C++:
#define __CL_ENABLE_EXCEPTIONS
#include <fstream>
#include <iostream>
#include <iterator>
#include <CL/cl.hpp>
#include <CL/opencl.h>
using namespace std;
int main () {
vector<cl::Platform> platforms;
vector<cl::Device> devices;
vector<cl::Kernel> kernels;
try {
// create platform
cl::Platform::get(&platforms);
platforms[0].getDevices(CL_DEVICE_TYPE_GPU, &devices);
// create context
cl::Context context(devices);
// create command queue
cl::CommandQueue queue(context, devices[0]);
// load opencl source
ifstream cl_file("inout.cl");
string cl_string(istreambuf_iterator<char>(cl_file), (istreambuf_iterator<char>()));
cl::Program::Sources source(1, …Run Code Online (Sandbox Code Playgroud)