How to program in kernel mode Some question about program under kernel

there are two kind of mode in linux we can program, user mode and kernel mode.

I think CUDA give us a user mode interface to let’s work on user mode. But when i want to program some kernel model which only can be programmed in kernel mode and couldn’t call the API in CUDA which is user mode, i don’t know how to work.

Should i call the driver layer’s api? Is there any instruction about that? OR the linux version of CUDA included the kernel mode API already?


yanbin at tsinghua university(CHINA)

Hi !

I am not sure to understand what you mean by the driver API, but both CUDA API are intended to be used in user-mode as far as i know. Driver only meaning it is a low-level approach, but nothing to do with the kernel.

Provided we do not have the actual (kernel) driver sources, this seems very unlikely that we may access the gpu within the linux kernel.

Just a matter of curiosity, why would you use something like CUDA from the kernel ? This really seems to belong to the userland.



thanks for your reply, we know that CUDA is a user level SDK which can help us developing user level software. But some kind of program such as kernel module, file system etc. If we want to use the GPU to help us improving the kernel module effeciency, we can’t use CUDA.

So , i want to know how to enjoy the benifit and power this new architecture bring us in kernel developing :)

am i clear? hope to get more help from everyone

Maybe it is smart to take a look at things like FUSE, where they have moved kernel modules to userspace. That should give you some idea of how to use userspace from the kernel. My guess is that a lot of code that is necessary for CUDA (cubin -> machine code, loading kernels to GPU, etc) is running in userspace

I was actually about to write the exact same thing !

Now assuming you really want to do it within the kernel, you would have a hard time without the card specs. First rewriting the code that actually performs some code on the CUDA device would mean simply reverse-enginering the driver and the user-space side of CUDA since there must certainly be some OS-bypass as Denis suggested it … that’s very unlikely it is worth it (or doable). Then you might have a bad time with security issues and many others (imagine that the X server reclaims memory so that it kills your cuda apps, this could be somehow painful)

Eventually, that sounds like a nightmare.