-1

I want to allow users to define functions to be used in CUDA kernels (or be called by CUDA kernels).

I don't want to expose CUDA API to the users. The functions should look like typical c++/lua functions.

I've checked pyCUDA, but it seems to only be wrapper around .cu code.

I'd rather have a .lua or .cc file and use function pointers. Is it remotely possible?

Mikel
  • 466
  • 3
  • 16
  • 1
    Q: What exactly do you mean by "user defined function"? Could you give an example? Q: If you're not providing your own API, and if you're using CUDA, then why don't you want to "expose CUDA API to users"? Could you elaborate? – paulsm4 Dec 05 '15 at 21:30
  • @paulsm4 The application can be run either on GPU or CPU. CUDA is just one of variants. The defined functions should be able to run on CPU too. – Mikel Dec 05 '15 at 21:32
  • You still haven't explained what you mean by "user defined function"? Will they be writing in Lua (for example), and will your "library" give them functions that you've written; functions that can be executed on either a CPU or a GPU? Or do you want them to be able to write raw Lua code and somehow have it executed on either a CPU or GPU? – paulsm4 Dec 05 '15 at 21:52
  • Functions defined by a user would be executed by the library. The functions could be defined in either lua (and imported via LuaJIT) or c++. – Mikel Dec 05 '15 at 22:01
  • 2
    For an example using a user provided function in a text file that conforms to c++, take a look [here](http://stackoverflow.com/questions/22824897/online-compilation-of-single-cuda-function/24498416#24498416). – Robert Crovella Dec 05 '15 at 22:41
  • The CUDA 7.0 added runtime compilation (which is subject to change however), so I guess it would be a viable solution, but the reason I asked this question is because I wanted to skip the compilation step somehow. – Mikel Dec 05 '15 at 22:46

1 Answers1

1

No, it is not remotely possible.

CUDA kernels, by design, execute on the GPU. They are compiled into (NVIDIA) GPU-specific machine language and executed in an execution environment that is utterly alien to anything a C++ function operates in, let alone Lua. They cannot simply call arbitrary code.

The absolute most that you might do is write a compiler to compile from C++/Lua into a CUDA library. But that would be a substantial undertaking for either language.

Community
  • 1
  • 1
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • I thought so, but wanted to be sure. Thanks. – Mikel Dec 05 '15 at 21:33
  • I have no idea what CUDA is, so excuse my stupidity if I look like an idiot, but is there a function like loadstring that one could parse a Lua function to? – warspyking Dec 05 '15 at 22:29