3

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? Commented Nov 23, 2012 at 6:56
  • more details are usually good - operating system, in particular, is handy when asking questions like this. Commented Nov 23, 2012 at 7:58

2 Answers 2

10

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
I always use paste and forget about sprintf - I should try to remember, it will save me wearing out my comma and quote keys.
2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.