c++ - 在 OpenCL 内核中使用 printf 的问题
问题描述
我OpenCL 2.0
使用AMD
. 代码非常简单。如果我使用 1 printf
,工作就很好。但是如果我添加第二个printf
,那么就会有弯曲的数据。我在主机 C++ 中的代码:
cl_int errcode;
// Get available platforms
vector<Platform> platforms;
Platform::get(&platforms);
// Select the default platform and create a context using this platform and the GPU
cl_context_properties cps[3] = {
CL_CONTEXT_PLATFORM,
(cl_context_properties)(platforms[0])(),
0
};
Context context(CL_DEVICE_TYPE_GPU, cps);
vector<Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();
CommandQueue queue = CommandQueue(context, devices[0]);
// Read source file
string name;
name += "CalcN.cl";
std::ifstream sourceFile(name);
std::string sourceCode(
std::istreambuf_iterator<char>(sourceFile),
(std::istreambuf_iterator<char>()));
Program::Sources source(1, std::make_pair(sourceCode.c_str(), sourceCode.length() + 1));
Program program = Program(context, source);
errcode = program.build(devices);
if (errcode != CL_SUCCESS)
{
cout << "There were error during build kernel code. Please, check program code. Errcode = " << errcode << "\n";
cout << "BUILD LOG: " + program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(devices[0]) + "\n";
getchar();
}
// Make kernel
Kernel kernel(program, "Optimization");
NDRange global(1);
queue.enqueueNDRangeKernel(kernel, 0, global);
我在内核中的代码:
__kernel void Optimization()
{
for(int i = 0;i<100;i++)
{
printf("%d",i);
printf("%d",i);
}
}
带有 One printf 的控制台
并使用两个 printf 进行控制台:
我已经不止一次地询问过这个问题,但没有人知道。
解决方案
您的输出在每个 printf 之后打印新行,而您的代码中没有 \n。我的系统不会那样做;它会在一行中打印 112233...。你可以试试 printf("%i\n",i);。
推荐阅读
- oracle - 在 Toad 中解析查询/过程
- kubernetes - Logstash 输出来自另一个输入
- node.js - 要求模块以防止 eslint 错误的正确方法
- flutter - Flutter 编译 apk 失败:Finished with error: Gradle task assembleDebug failed with exit code 1
- python - 用beautifulsoup抓取时如何在html日期选择器中输入日期范围?
- amazon-web-services - Create AWS Access Policy to Only 1 S3 Bucket
- google-cloud-platform - BigQuery 加载作业不会插入所有数据
- javascript - 尝试使用带有 JSON 的点表示法从 Stripe API 获取特定键值时遇到问题
- c# - 使用两个参数之一的 LINQ 语句
- react-native - 如何在 react-native 中更改兄弟组件中的文本?