This section describes the procedure for writing a simple "Hello, PyCUDA!" program using PyCUDA. It will demonstrate the workflow for writing any PyCUDA programs. As Python is an interpreted language, the code can also be run line by line from the Python terminal, or it can be saved with the .py extension and executed as a file.
The program for displaying a simple string from the kernel using PyCUDA is shown as follows:
import pycuda.driver as drv
import pycuda.autoinit
from pycuda.compiler import SourceModule
mod = SourceModule("""
#include <stdio.h>
__global__ void myfirst_kernel()
{
printf("Hello,PyCUDA!!!");
}
""")
function = mod.get_function("myfirst_kernel")
function(block=(1,1,1))
The first step while developing PyCUDA code is to include all libraries needed for the...