gpt4 book ai didi

c - GT540M 上的低性能 CUDA 代码

转载 作者:行者123 更新时间:2023-12-02 05:19:06 24 4
gpt4 key购买 nike

在 GeForce GT540M 上执行以下代码示例需要大约 750 毫秒,而在 GT330M 上执行相同的代码需要大约 250 毫秒。

将 dev_a 和 dev_b 复制到 CUDA 设备内存在 GT540M 上需要大约 350 毫秒,而在 GT540M 上需要大约 250 毫秒。 “addCuda”的执行和复制回主机在 GT540M 上又花费了约 400 毫秒,在 GT330M 上又花费了约 0 毫秒。

这不是我所期望的,所以我检查了设备的属性,发现 GT540M 设备在各方面都超过或等于 GT330M,除了多处理器数量 - GT540M 有 2 个,GT330M 有 6 个。这真的是真的吗?如果是这样,它真的会对执行时间产生如此大的影响吗?

#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

#define T 512
#define N 60000*T

__global__ void addCuda(double *a, double *b, double *c) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
if(tid < N) {
c[tid] = sqrt(fabs(a[tid] * b[tid] / 12.34567)) * cos(a[tid]);
}
}

int main() {
double *dev_a, *dev_b, *dev_c;

double* a = (double*)malloc(N*sizeof(double));
double* b = (double*)malloc(N*sizeof(double));
double* c = (double*)malloc(N*sizeof(double));

printf("Filling arrays (CPU)...\n\n");
int i;
for(i = 0; i < N; i++) {
a[i] = (double)-i;
b[i] = (double)i;
}

int timer = clock();
cudaMalloc((void**) &dev_a, N*sizeof(double));
cudaMalloc((void**) &dev_b, N*sizeof(double));
cudaMalloc((void**) &dev_c, N*sizeof(double));
cudaMemcpy(dev_a, a, N*sizeof(double), cudaMemcpyHostToDevice);
cudaMemcpy(dev_b, b, N*sizeof(double), cudaMemcpyHostToDevice);

printf("Memcpy time: %d\n", clock() - timer);
addCuda<<<(N+T-1)/T,T>>>(dev_a, dev_b, dev_c);
cudaMemcpy(c, dev_c, N*sizeof(double), cudaMemcpyDeviceToHost);

printf("Time elapsed: %d\n", clock() - timer);

cudaFree(dev_a);
cudaFree(dev_b);
cudaFree(dev_c);
free(a);
free(b);
free(c);

return 0;
}

设备的设备属性:

GT540M:

Major revision number:         2
Minor revision number: 1
Name: GeForce GT 540M
Total global memory: 1073741824
Total shared memory per block: 49152
Total registers per block: 32768
Warp size: 32
Maximum memory pitch: 2147483647
Maximum threads per block: 1024
Maximum dimension 0 of block: 1024
Maximum dimension 1 of block: 1024
Maximum dimension 2 of block: 64
Maximum dimension 0 of grid: 65535
Maximum dimension 1 of grid: 65535
Maximum dimension 2 of grid: 65535
Clock rate: 1344000
Total constant memory: 65536
Texture alignment: 512
Concurrent copy and execution: Yes
Number of multiprocessors: 2
Kernel execution timeout: Yes

GT330M

Major revision number:         1
Minor revision number: 2
Name: GeForce GT 330M
Total global memory: 268435456
Total shared memory per block: 16384
Total registers per block: 16384
Warp size: 32
Maximum memory pitch: 2147483647
Maximum threads per block: 512
Maximum dimension 0 of block: 512
Maximum dimension 1 of block: 512
Maximum dimension 2 of block: 64
Maximum dimension 0 of grid: 65535
Maximum dimension 1 of grid: 65535
Maximum dimension 2 of grid: 1
Clock rate: 1100000
Total constant memory: 65536
Texture alignment: 256
Concurrent copy and execution: Yes
Number of multiprocessors: 6
Kernel execution timeout: Yes

最佳答案

我认为从设备到主机的复制不可能是~0ms。我建议检查该副本是否有 stg 错误

关于c - GT540M 上的低性能 CUDA 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9258755/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com