Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the role of cudaDeviceReset() in Cuda

Tags:

cuda

#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
__global__ void funct(void){
      printf("Hello from GPU!\n");
}

int main(void){
         funct << < 2, 4 >> >();

for (int i = 0; i < 10; i++){
    cudaDeviceReset();
    //cudaDeviceSynchronize();
    printf("Hello, World from CPU!\n");

    }
return 0;
}

I thought the role of cudaDeviceReset is cudamemcpy. this case we didn't have the result of number. So we were not able to use cudamemcpy. But We used cudaDeviceReset for returning four "Hello from GPU!" result from kernel.

Is that right?

and I replaced cudaDeviceRest() with cudaDeviceSynchronize(). I saw the same result. but I couldn't know the difference between them.

like image 892
최우석 Avatar asked Mar 15 '16 13:03

최우석


People also ask

For what purpose cudaMalloc function is used?

cudaMalloc is a function that can be called from the host or the device to allocate memory on the device, much like malloc for the host.

What is function of _global_ qualifier in CUDA program?

__global__ : 1. A qualifier added to standard C. This alerts the compiler that a function should be compiled to run on a device (GPU) instead of host (CPU).

Which functions are used in CUDA to allocate de allocate and free the memory in CUDA?

allocate and free memory dynamically from a fixed-size heap in global memory. The CUDA in-kernel malloc() function allocates at least size bytes from the device heap and returns a pointer to the allocated memory or NULL if insufficient memory exists to fulfill the request.

What is kernel function in CUDA?

Figure 1 shows that the CUDA kernel is a function that gets executed on GPU. The parallel portion of your applications is executed K times in parallel by K different CUDA threads, as opposed to only one time like regular C/C++ functions. Figure 1. The kernel is a function executed on the GPU.

What is the use of it () function in CUDA?

It is used to destroy a CUDA context, which means that all device allocations are removed. I agree that it appears to have a synchronizing effect. However since the documentation states: Note that this function will reset the device immediately.

When to call cudadevicereset ()?

call cudaDeviceReset () as part of application shut-down. Note that calling cudaDeviceReset () as part of application shut-down should not be considered mandatory. Many applications will work fine without such an idiom.

Should cudadevicereset () be called as part of application shut-down?

Note that calling cudaDeviceReset () as part of application shut-down should not be considered mandatory. Many applications will work fine without such an idiom. This answer may also be of interest.

What are the advantages of having more CUDA cores?

1 More number of CUDA cores means more data can be processed parallelly. 2 More clock speed means that a single core can perform much faster. 3 The GPUs get better with new generations and architectures, so a graphic card with more number of CUDA cores is not necessarily more powerful than the one with lesser CUDA ...


1 Answers

The role of cudaDeviceReset() is documented here

It is used to destroy a CUDA context, which means that all device allocations are removed.

I agree that it appears to have a synchronizing effect. However since the documentation states:

Note that this function will reset the device immediately.

I believe it is unsafe to rely on this behavior. Furthermore, the documentation also calls out the hazard of using this function in a multi-threaded app. Therefore, safe coding would dictate:

  1. Use of device synchronization (e.g. cudaDeviceSynchronize(), or cudaMemcpy(), etc.)

  2. Retrieve whatever data your application would like to preserve that may be in a device allocation, or that a recently running kernel may have updated (in device memory).

  3. Make sure that any host threads that may also have device activity associated with them, are also terminated

  4. Make sure that any C++ objects that may have device activity in their destructors are properly destroyed or out-of-scope

  5. call cudaDeviceReset() as part of application shut-down.

Note that calling cudaDeviceReset() as part of application shut-down should not be considered mandatory. Many applications will work fine without such an idiom.

This answer may also be of interest.

like image 122
Robert Crovella Avatar answered Sep 19 '22 14:09

Robert Crovella