Hi 金陆,

The "\n\n" in your code correspond to two actual newlines in the .cu
file being compiled, not to a "\n\n" string, because they are resolved
by the Python interpreter at the parsing stage. See the kernel.cu you
quoted for the result, you have 'CUPRINTF("' commented and an
unmatched quote and parenthesis out of the comment — that's why the
compiler is complaining. You could actually just "print
my_kernel_code" inside the Python program and see that the result is
not valid C code.

In order to make "\n\n" appear in the C code, you can either prefix
the my_kernel_code literal with 'r' (my_kernel_code = r""" ... your
code here ... """), preventing the interpreter from resolving
character codes, or prefix each backslash with another backslash, so
that it gets resolved as a single backslash (my_kernel_code = """ ...
CUPRINTF("\\n\\n"); """).


On Sun, Mar 16, 2014 at 3:17 PM, 金陆 <[email protected]> wrote:
> Hi, everyone
> There is a simple code, but I found if I use "//CUPRINTF("\n\n");" in
> test.py, the yielded kernel.cu file is invalid. That is so strange, because
> 1."//unsigned int y=threadIdx.y; " dose not ruin the yielded kernel.cu; 2.
> if I use "/*CUPRINTF("\n\n");*/", there is no problem
>
> I am using  pycuda-2013.1.1.win32-py2.7.exe from
> http://www.lfd.uci.edu/~gohlke/pythonlibs/ on Winxp
>
> Thanks in advance
>
> [test.py starts]
>
> #coding=utf-8
>
> import pycuda.driver as drv
> import pycuda.autoinit
> from pycuda.compiler import SourceModule
>
> def compile_kernel(kernel_code, kernel_name):
>   mod = SourceModule(kernel_code)
>   func = mod.get_function(kernel_name)
>   return func
>
> my_kernel_code = """
> #include "math.h"
> #include "stdio.h"
>
> __global__ void my_kernel()
> {
>     unsigned int x=threadIdx.x;
>     //unsigned int y=threadIdx.y;
>
>     //CUPRINTF("\n\n");
>
> }
> """
> kernel = compile_kernel(my_kernel_code, 'my_kernel')
>
> if __name__ == '__main__':
>     pass
>
>  [test.py ends]
>
>
> [kernel.cu starts]
>
> extern "C" {
>
> #include "math.h"
> #include "stdio.h"
>
> __global__ void my_kernel()
> {
>     unsigned int x=threadIdx.x;
>     //unsigned int y=threadIdx.y;
>
>     //CUPRINTF("
>
> ");
>
> }
>
> }
> [kernel.cu ends]
>
>
> _______________________________________________
> PyCUDA mailing list
> [email protected]
> http://lists.tiker.net/listinfo/pycuda
>

_______________________________________________
PyCUDA mailing list
[email protected]
http://lists.tiker.net/listinfo/pycuda

Reply via email to