在“Classifying ImageNet: using the C++ API”教程(http://caffe.berkeleyvision.org/gathered/examples/cpp_classification.html)的结尾,我发现了这样的短语:
Use multiple classification threads to ensure the GPU is always fully utilized and not waiting for an I/O blocked CPU thread.
这是什么意思? 我理解正确,有一种方法可以在一个 GPU 上运行时为 CPU 层使用多个线程吗?
谢谢
最佳答案
您可以使用 CUDA 在一个 GPU 上使用多个线程和 CUDNN .
以下代码将两个大小为 NxN 的矩阵 A 和 B 相加,并将结果存储到矩阵 C 中:
// Kernel definition
__global__ void MatAdd(float A[N][N], float B[N][N],
float C[N][N])
{
int i = threadIdx.x;
int j = threadIdx.y;
C[i][j] = A[i][j] + B[i][j];
}
int main()
{
...
// Kernel invocation with one block of N * N * 1 threads
int numBlocks = 1;
dim3 threadsPerBlock(N, N);
MatAdd<<<numBlocks, threadsPerBlock>>>(A, B, C);
...
}
关于multithreading - 咖啡文档 :"Use multiple classification threads to ensure the GPU is always fully utilized"。如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36991270/