To run shell command in the device

Hi all,

I am presently working on image processing. I came to know about the command “system” which can be used to run shell command within a C file. I would like to know if there exists a command in CUDA C similar to “system” in C which is used to run shell commands. I am actually asking whether I can call a shell command in the device …

Million Thanks,


No, you can’t. And it would be completely against the idea of CUDA.

Hello Tera,

Can you explain me in a more detailed way so that I can explain my friends why we can’t do it


Hi Swaroop,

Since CUDA works on SIMT(Single Instruction Multiple Threads) architecture, If calling system(“commandName”) is permitted, each thread running in the kernel will try to invoke the shell command, that will lead to memory outage or system will hang depending on the called program size.

I think, that’s why ‘system’ function is not supported inside CUDA kernel.

Hi new,

I have another question. Suppose we know a the maximum number of times a bash shell command can be called then is it possible to incorporate “system” command into device manually.

The reason behind me asking this question is I have to run simulations on a big database of 2400 images to find out the best settings of the jpegxr image encoder which provides the best matching performance for various bio-metric systems like iris and fingerprint. I have the jpegxr software in the form of a shell command. Of course I have the c files too but I don’t have any idea how it was compiled i.e. I got the compiled software from a colleague. Till now I have been using shell script to run these simulations but it takes one hour for one bit-rate. When I calculated I found it takes 204 days to run the total simulations. I know I can use cloud computing for stuff of this kind but I am checking if I can use CUDA which I have learned before for fun.

Greetings, Swaroop

Even though Nvidia tries to make CUDA look as similar to C(++) as possible to ease programming, it still remains an acceleration technology for special suitable algorithms and workloads. CUDA has only few of library routines and none of the operating system calls available on the CPU. And even if Nvidia went through the trouble of implementing them all, the resulting performance would be disappointing in comparison the the CPU.

So there is no way around looking at the source code of the application and adapting the most time-consuming computations to CUDA manually.

Shell commands are NOT related to C language in anyway.

You have libraries that enable you to launch process, or shell interpreters (that is just a generic process), and these libraries are available depending on the context (ie: on Linux using libc) but not on other (ie: on CUDA code or some embedded OS).

The CUDA execution context is clearly separated from the main OS context. So if you want to launch command-line commands while on a CUDA context, you have to communicate with main OS context (using Pinned Mapped Memory if available or by finishing execution of CUDA code) for it to launche the process.