cudaDeviceSynchronize()仅在当前CUDA上下文中或在所有上下文中等待完成?

问题描述 投票:4回答:1

我使用CUDA 6.54 x GPU开普勒

我使用多线程,CUDA运行时API,并从不同的CPU线程访问CUDA上下文(通过使用OpenMP,但这并不重要)。>>

  1. [当我调用cudaDeviceSynchronize();时,它将仅在最新调用cudaSetDevice()选择的当前CUDA上下文中或在所有CUDA上下文中等待内核完成?

  2. 如果将在所有CUDA上下文中等待内核完成,则它将在当前CPU线程中使用的所有CUDA上下文中等待(在示例中CPU线程_0将等待GPU:0和1

  3. )或通常所有的CUDA上下文(CPU线程_0将等待GPU:0、1、2和3)?

    以下代码:

// For using OpenMP requires to set:
// MSVS option: -Xcompiler "/openmp"
// GCC option: –Xcompiler –fopenmp
#include <omp.h>

int main() {

    // execute two threads with different: omp_get_thread_num() = 0 and 1
    #pragma omp parallel num_threads(2)
    {
        int omp_threadId = omp_get_thread_num();

        // CPU thread 0
        if(omp_threadId == 0) {

            cudaSetDevice(0);
            kernel_0<<<...>>>(...);
            cudaSetDevice(1);
            kernel_1<<<...>>>(...);

            cudaDeviceSynchronize(); // what kernel<>() will wait?

        // CPU thread 1
        } else if(omp_threadId == 1) {

            cudaSetDevice(2);
            kernel_2<<<...>>>(...);
            cudaSetDevice(3);
            kernel_3<<<...>>>(...);

            cudaDeviceSynchronize(); // what kernel<>() will wait?

        }
    }

    return 0;
}

我使用CUDA 6.5和4 x GPU开普勒。我使用多线程,CUDA运行时API,并从不同的CPU线程访问CUDA上下文(通过使用OpenMP,但这并不重要)。当我打电话时...

multithreading cuda gpgpu nvidia
1个回答
7
投票

当我调用cudaDeviceSynchronize();它会等待内核仅在最新呼叫选择的当前CUDA上下文中完成cudaSetDevice(),还是在所有CUDA上下文中?

© www.soinside.com 2019 - 2024. All rights reserved.