在OpenCL和Fortran中传递两个选项作为参数(CLFORTRAN) [英] Passing two options as arguments in OpenCL with Fortran (CLFORTRAN)

查看:247
本文介绍了在OpenCL和Fortran中传递两个选项作为参数(CLFORTRAN)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的主机程序使用C语言时,我可以传递两个选项作为OpenCL函数的参数。例如,我可以像这样将两个
标志传递给 clCreateBuffer 函数:

 
clCreateBuffer(context,CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
sizeof(main_data),main_data,&err)

然而,我尝试在用Fortran编写的主机程序中执行相同的操作:

main_data = clCreateBuffer(context,CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,&
sizeof(main_data),C_NULL_PTR,err)

我得到一个错误:

 & | CL_MEM_COPY_HOST_PTR,size_in_bytes,C_NULL_PTR,ierr)
1
错误:参数列表中的语法错误(1)

我已经用CLFORTRAN成功编译了一些其他程序,但是每当我尝试传递两个标志,例如 CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR 我得到上述错误。

解决方案

C按位或 不能在Fortran中使用。你必须使用 + ior()函数也可能工作,但我会使用 + *。它的工作原理是因为常量的值通常设计为只有一个 1 位,并且每次都位于不同位置。



*如果您使用 + ,您可能不会添加同一个标志两次,它的标志会被错误地计算。 b

When my host program is in C language I can pass two options as an argument of an OpenCL function. For example, I can pass two flags to the clCreateBuffer function like this:

clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
                            sizeof(main_data), main_data, &err)

However, when I try to do the same in a host program written in Fortran:

main_data=clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, &
                               sizeof(main_data), C_NULL_PTR, err)

I get an error:

 &     |CL_MEM_COPY_HOST_PTR, size_in_bytes,C_NULL_PTR,ierr)        
       1
Error: Syntax error in argument list at (1)

I have successfully compiled some other programs with CLFORTRAN, but whenever I try to pass two flags like CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR I get the above error.

解决方案

The C bitwise or | cannot be used in Fortran. You have to use +. The ior() function would probably also work, but I would use +*. It works because the valued of the constants are normally designed in such a way that they have only one 1 bit and every time at a different position.

*If you do use + you may not add the same flag twice, it flags would be computed incorrectly.

这篇关于在OpenCL和Fortran中传递两个选项作为参数(CLFORTRAN)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆