chsasank / llama.lisp

Lisp dialect designed for HPC and AI
GNU Lesser General Public License v2.1
15 stars 6 forks source link

Running C-Lisp code on Nvidia GPUs #71

Closed GlowingScrewdriver closed 4 months ago

GlowingScrewdriver commented 4 months ago

This PR introduces a small framework for compiling and launching kernels written in C-Lisp on an Nvidia GPU

Documentation on this issue can be found here: https://outline.von-neumann.ai/s/d0cd5eb9-2e15-4fa4-bd17-c3911f305008/doc/attacking-ptx-kKZJzn5Uem

GlowingScrewdriver commented 4 months ago

Address space markers have been implemented in C-Lisp. Test kernels in vecadd.sexp and matmul.sexp now specify address space 1 for pointers passed from the caller.

chsasank commented 4 months ago

Do we also need addrspace for alloc? It looks like so:

from docs:

‘alloca’ Instruction Syntax: = alloca [inalloca] [, ] [, align ] [, addrspace()] ; yields type addrspace(num)*:result The ‘alloca’ instruction allocates memory on the stack frame of the currently executing function, to be automatically released when this function returns to its caller. If the address space is not explicitly specified, the object is allocated in the alloca address space from the datalayout string.

But llvmlite doesn't seem to support it. May be we don't need to implement at this point of time.

GlowingScrewdriver commented 4 months ago

Do we also need addrspace for alloc? It looks like so:

I don't think we need it as of now. Using alloca in the kernel without specifying addrspace works, and yet doesn't cause llc to insert address space casts.

On the other hand, I got an error from the CUDA driver API when I specified addrspace on a stack allocation. This is what I tried:

The error reported by the driver: cuCtxSynchronize() returned non-zero status 717. Result code 717 (CUDA_ERROR_INVALID_ADDRESS_SPACE in CUDA terms) indicates that an instruction was used on data in the wrong address space, as per Nvidia documentation