Passing two options as arguments in OpenCL with Fo

2019-03-02 06:37发布

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条回答
2楼-- · 2019-03-02 07:12

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.

查看更多
登录 后发表回答