I have a CUDA code which I have compiled and have the executable of it. Now I want to call this executable from a R script and pass it arguments also from the R script itself? Is it possible? If yes, please explain how?
2
-
Surely calling a CUDA executable from R is no different from calling any other compiled executable from R?talonmies– talonmies2012-11-23 06:56:37 +00:00Commented Nov 23, 2012 at 6:56
-
more details are usually good - operating system, in particular, is handy when asking questions like this.Spacedman– Spacedman2012-11-23 07:58:41 +00:00Commented Nov 23, 2012 at 7:58
Add a comment
|
2 Answers
To call any external executables you can use the system function:
system("cuda_exe arg1 arg2")
where cuda_exe is the cuda executable, and arg* are the command line arguments passed to the script.
2 Comments
Spacedman
To pass arguments from R, you might have to construct the string to system by using "paste". Note that passing entire R objects to C code is a different problem altogether, and can't be easily done to a standalone executable.
Spacedman
I always use
paste and forget about sprintf - I should try to remember, it will save me wearing out my comma and quote keys.A more cross-platform alternative than system is system2. It'll work on Windows and other systems without a /bin/sh.
system2("cuda_exe", c("arg1", "arg2"))
It requires no shell, but shell syntax like the * glob won't work, and you'll have to learn the R way of doing things, such as list.files(pattern = ".*.csv") instead of just "*.csv". The upside is that you won't have to fiddle with paste() to construct the command line.