Octave + CUDA

I was wondering if there is a way to add custom CUDA kernels to Octave, similar to the way one can do for Matlab?

Octave has an external code interface:


Although I haven’t tried it, I’m reasonably sure it could be used to run CUDA code that was usable by Octave, after a fashion, that is to say, roughly analogous to the matlab mex interface.

If you’re looking for functionality like the Matlab PTX interface, or else matlab gpuArray, you won’t find it in Octave.

There are some other possible strategies for accelerating Octave code using GPUs, such as the library method discussed here:


You can use the mex interface ( there should be a whitepaper floating around the web I wrote years ago before Matlab supported GPUs).

You will need to change the makefile, Octave uses different command from Matlab to generate mex.
This is an example from a CUDA accelerated project on Jetson that uses Octave since Matlab is not available on that platform:

# Define installation location for CUDA and compilation flags compatible
# with the CUDA include files.
INCLUDELIB  = -L$(CUDAHOME)/lib -lcudart -lcufft
COPTIMFLAGS = -O3  -Xcompiler -fPIC
NVCC=nvcc -m32 -arch sm_32 --ptxas-options=-v

# Define installation location for Octave
MKOCTFILE = mkoctfile
OCTAVE_INC = -I /usr/include/octave-3.8.1/octave
MEXEXT        = .mex

MEXFILES = mf.mex

all: $(MEXFILES)

        rm -f $(MEXFILES) 

.SUFFIXES: .cu .o .mex

%.o : %.m


        $(MKOCTFILE) --mex  $< \