the use of stream Could the "stream management" only be used in '.cu' fi

I defined a cudaStream_t variable in ‘.h’ file, and call cudaStreamCreate with the variable in ‘.c’ file.
But it cannot be passed in the compile, and the error is “… was not declared in this scope”.
Could the cudaStream_t variable and function of stream only be used in the ‘.cu’ file?

1 Like

Why did you define your own cudaStream_t variable? It is defined in driver_types.h which is included when you include cuda_runtime.h

I am writing a .cpp file where I need to use cudaStream_t, but getting the same error: ‘cudaStream_t’ was not declared in this scope. I need to do this since I am converting a backward() function in a .cu file to its corresponding version for the .cpp file.

I need to run the code on CPU, and I am using the cpu version of libtorch-1.6.0.
I also looked for the cuda_runtime.h file in the system but could not find it out.

Please suggest how to solve this issue… Thanks in advance!!

“I need to run the code on CPU”

That won’t work. You’ll need to find another way to do what you want. If you have a proper CUDA install and a CUDA-capable GPU, you can certainly access cudaStream_t from a .cpp file:

$ cat t51.cpp
#include <cuda_runtime.h>

int main(){

        cudaStream_t str;
        cudaError_t err = cudaStreamCreate(&str);
        assert(err == cudaSuccess);
$ g++ t51.cpp -o t51 -I/usr/local/cuda/include  -L/usr/local/cuda/lib64 -lcudart
$ ./t51