About Open MP and cudaSetDevice()
About Open MP and cudaSetDevice()
有人知道以下cudaSetDevice
的用法是否正确吗?我想在任何时间、任何主机线程中重复调用在不同设备上创建的资源;在CUDA有办法做到这一点吗?
cudaSetDevice(0);
/...create cuda streams and do some memory allocation on gpu.../
cudaSetDevice(1);
/...create cuda streams and do some memory allocation on gpu.../
#pragma omp parallel num_threads(2)
{
int omp_threadID=omp_get_thread_num();
....
if (omp_threadID==0)
{
cudaSetDevice(0);
/...calling streams/memory created on device 0.../
}
else
{
cudaSetDevice(1);
/...calling streams/memory created on device 1.../
};
};
是的,这样的东西应该可以工作。请确保您在设备0上创建的所有东西都只在OpenMP线程0中使用,设备1和线程1也是如此。
您可能还想查看CUDA OpenMP示例代码,该代码演示了如何使用OpenMP线程分别管理单个设备。
相关文章:
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- 为什么C++逐位AND运算符在不同大小的操作数中表现为这样
- 为什么 Clang 不允许"and"作为函数名称?
- 位阵列上的快速AND运算
- 是否可以在 C++03 中定义'move-and-swap idiom'等效项
- BoostPython and CMake
- OpenSSL BIO and SSL_read
- Gurobi GRBModel and GRBmodel in C++
- std::visit and std::variant usage
- SHBrowseForFolder with BIF_BROWSEFORCOMPUTER and SHGetPathFr
- Directx12 and keystrokes
- different between int **arr =new int [ n]; and int a[i][j]?
- C++ getenv and setenv
- Inference pytorch C++ with alexnet and cv::imread image
- Visual Studio 2019 C++ and std::filesystem
- 保证逻辑 AND 表达式中的函数调用
- python ctypes and C++ pointers
- C++ const char with .begin() and .end()
- Threads with Classes and std::packaged_task
- About Open MP and cudaSetDevice()