-4

I was wondering whether this is possible? Could someone please point out if I'm wrong anywhere? I'm a complete newbie to CUDA.

__global__ void run_multiple_cpp(int *n, int *result){
    int i = blockDim.x*blockIdx.x + threadIdx.x;
    if (i < n){
        result[i] = system("//path to a.out" -parameters[i])
    }
}

int main(void){
    // Get input here,
    // kernel call which splits the input as shown above
    return 0;
}

My question is whether this is possible without requiring to write the CPP file CUDA friendly. I've tried using __device__ and __host__ flags but my application is too big to be modified to support CUDA.

The operation above is always based on different set of inputs - I've tried CPU multithreading but I need to run this application for a large set of inputs. Hence I asked.

Darknorth
  • 3
  • 4
  • Why a negative reputation? I'm simply asking whether is this possible. – Darknorth Oct 23 '18 at 17:14
  • didnt downvote, though questions along the line "Does X work?" are usually best answered by simply trying it out. Did you maybe actually wanted to ask "Why does it not work?" ? In that case i guess much more information would be required to help you – 463035818_is_not_an_ai Oct 23 '18 at 17:42
  • My question is how to use "system" in the kernel. Look at the first answer here. https://stackoverflow.com/questions/17703721/how-to-execute-another-exe-from-a-c-program-in-windows - I wanted to ask whether that works on GPU as well. – Darknorth Oct 23 '18 at 18:27
  • thats not really clear from your question and even then you should show what you tried (see also [mcve]). The code you posted here will fail to reasons completely unrelated to calling `system`. you got the arguments wrong, `"//path to a.out" -parameters[i]` ... there is no autoconcatenation of strings and `//path to a.out"` is of course not a valid path... – 463035818_is_not_an_ai Oct 23 '18 at 18:31

1 Answers1

1

The main reason GPUs are fast is they contain many small and simple processors so can perform many simple tasks in parallel. High level operations like calling system are completely unavailable on the GPU. In order to take advantage of the power of the GPU you will need to rewrite your code for CUDA/OpenCL/Metal etc.

If you can't modify your program to run on the GPU you might be able to take advantage of the CPU's SIMD features and still achieve a (smaller) speedup, this may also be a stepping stone to GPU processing as making your code CPU SIMD friendly will also likely make porting to the GPU easier.

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
  • https://stackoverflow.com/questions/486087/how-to-call-an-external-program-with-parameters ---- So basically I cannot implement the high level operation "system", like in the mentioned example, on GPU. – Darknorth Oct 30 '18 at 05:18
  • No you can't, simple operations only on the gpu – Alan Birtles Oct 30 '18 at 07:05