I am new to python and PYCUDA.
In many PYCUDA examples I can find codes like this:
import pycuda.driver as cuda
cuda.mem_alloc(a.nbytes)
But when I take a look into pycuda/driver.py, I can't find where mem_alloc is defined.
I can only find mem_alloc_like, which calls mem_alloc():
def mem_alloc_like(ary):
return mem_alloc(ary.nbytes)
which tells me that mem_alloc must be somewhere in the libraries driver.py imports.
However, the following are the imports I find in driver.py, and none of six, numpy, or sys has a function named as "mem_alloc()"
from __future__ import absolute_import
from __future__ import print_function
import six
try:
from pycuda._driver import * # noqa
except ImportError as e:
if "_v2" in str(e):
from warnings import warn
warn("Failed to import the CUDA driver interface, with an error "
"message indicating that the version of your CUDA header "
"does not match the version of your CUDA driver.")
raise
import numpy as np
import sys
pyCUDA is wrapper around CUDA driver API. This is how pyCUDA exposes those APIs
write wrapper around driver API in C / C++
Expose those function to python using Boost::python because python's interpreter is implemented in C(Cpython)
Compile those wrapper into a shared library that is _driver.so
import the shared library that is the from pycuda._driver import *
.
But when I take a look into pycuda/driver.py, I can't find where mem_alloc is defined.
It is defined in pycuda/src/cpp/cuda.hpp