Passing two options as arguments in OpenCL with Fortran (CLFORTRAN)

孤街浪徒 提交于 2019-12-02 09:51:10

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/42449181/passing-two-options-as-arguments-in-opencl-with-fortran-clfortran

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!