ATI OpenCL printf 扩展问题,将 char* 参数传递给函数
我在启用了 printf 扩展的 ATI 卡上使用 OpenCL。我编写了一个函数来打印变量:
void printVar(constant char* name, float var)
{
printf("%s: %f\r\n", name, var);
}
此代码在编译为纯 C 时按预期工作,但如果我在 OpenCL 中调用它,
printVar("foo", 0.123);
结果始终是一些随机字符,后跟 0.123 而不是“foo: 0.123”。我猜编译器在识别 char* 字符串时遇到问题,是否有解决方法或修复程序,以便我可以使该函数正常工作?
I use OpenCL on an ATI card with the printf extension enabled. I've written a function to print out variables:
void printVar(constant char* name, float var)
{
printf("%s: %f\r\n", name, var);
}
This code works as expected when compiled as plain C, but if i invoke it in OpenCL with
printVar("foo", 0.123);
the result is always some random char followed by 0.123 instead of "foo: 0.123". I guess the compiler has problems with recognizing the char* string, is there a workaround or a fix so i can get the function working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我在评论中提到的,我也得到了相同的行为,但是我可以为您展示的用例建议一个简单的解决方法,即当字符串在编译时已知时,我们可以只使用定义语句:
As I mentioned in my comment I also get the same behavior, however I can suggest a simple workaround for the use case you showed, I.e. when the string is known at compile time we could just use a define statement instead: