MATRIX_SIZE not defined

Hi ,
Just installed pycuda and tried to run matrixmul code from <a href=""target=_blank>here. Got error in the phase where we compile kernel code . When i copy this in file, it runs well. But when i execute step by step it gives error. After this, i might write some code on graph algorithm and get same error. so wanted to clean it now.

#!/usr/bin/env python
… #-- coding: utf-8 --
… import numpy as np

from pycuda import driver, compiler, gpuarray, tools

– initialize the device

import pycuda.autoinit
kernel_code_template = “”"
global void MatrixMulKernel (float *a, float *b, float *c)
… {
… int tx = threadIdx.x;
… int ty = threadIdx.y;
… float Pvalue=0;
… for (int k=0;k<(MATRIX_SIZE)s;++k){
… float Aelement = a[ty * %(MATRIX_SIZE)s + k];
… float Belement = b[k * %(MATRIX_SIZE)s + tx];
… Pvalue += Aelement + Belement;
… }
… c[ty * %(MATRIX_SIZE)s + tx] = Pvalue;
… }
… “”"

a_cpu = np.random.randn(MATRIX_SIZE,MATRIX_SIZE).astype(np.float32)
b_cpu = np.random.randn(MATRIX_SIZE, MATRIX_SIZE).astype(np.float32)
c_cpu =, b_cpu)
a_gpu = gpuarray.to_gpu(a_cpu)
b_gpu = gpuarray.to_gpu(b_cpu)
c_gpu = gpuarray.empty((MATRIX_SIZE,MATRIX_SIZE),np.float32)
kernel_code = kernel_code_template %{
… }

mod = compiler.SourceModule(kernel_code)

[i]Traceback (most recent call last):
File “”, line 1, in
File “/usr/local/lib/python2.7/dist-packages/pycuda-2011.2.2-py2.7-linux-x86_64.egg/pycuda/”, line 283, in init
arch, code, cache_dir, include_dirs)
File “/usr/local/lib/python2.7/dist-packages/pycuda-2011.2.2-py2.7-linux-x86_64.egg/pycuda/”, line 273, in compile
return compile_plain(source, options, keep, nvcc, cache_dir)
File “/usr/local/lib/python2.7/dist-packages/pycuda-2011.2.2-py2.7-linux-x86_64.egg/pycuda/”, line 129, in compile_plain
cmdline, stdout=stdout, stderr=stderr)
pycuda.driver.CompileError: nvcc compilation of /tmp/tmpGuRUsm/ failed
[command: nvcc --cubin -arch sm_11 -I/usr/local/lib/python2.7/dist-packages/pycuda-2011.2.2-py2.7-linux-x86_64.egg/pycuda/…/include/pycuda]
[stderr: error: identifier “MATRIX_SIZE” is undefined error: expected a “;”

2 errors detected in the compilation of “/tmp/tmpxft_00007bbf_00000000-4_kernel.cpp4.ii”.


could it be some indent error which i don’t see or don’t know ?


Perhaps, would do you forget to define MATRIX_SIZE in debug mode?

Thanks for response. I never imported pdb, so what you meant by debug mode ?