성능 테스트를 위해 간단한 CUDA 프로그램을 작성하고 있습니다.
이것은 벡터 계산과 관련이 없지만 단순한 (병렬) 문자열 변환의 경우에만 해당됩니다. 내가 2에서 1000 BLOCK_SIZE 값을 변경할 때CUDA 성능 테스트
#include <stdio.h>
#include <string.h>
#include <cuda_runtime.h>
#define UCHAR unsigned char
#define UINT32 unsigned long int
#define CTX_SIZE sizeof(aes_context)
#define DOCU_SIZE 4096
#define TOTAL 100000
#define BBLOCK_SIZE 500
UCHAR pH_TXT[DOCU_SIZE * TOTAL];
UCHAR pH_ENC[DOCU_SIZE * TOTAL];
UCHAR* pD_TXT;
UCHAR* pD_ENC;
__global__
void TEST_Encode(UCHAR *a_input, UCHAR *a_output)
{
UCHAR *input;
UCHAR *output;
input = &(a_input[threadIdx.x * DOCU_SIZE]);
output = &(a_output[threadIdx.x * DOCU_SIZE]);
for (int i = 0 ; i < 30 ; i++) {
if ((input[i] >= 'a') && (input[i] <= 'z')) {
output[i] = input[i] - 'a' + 'A';
}
else {
output[i] = input[i];
}
}
}
int main(int argc, char** argv)
{
struct cudaDeviceProp xCUDEV;
cudaGetDeviceProperties(&xCUDEV, 0);
// Prepare Source
memset(pH_TXT, 0x00, DOCU_SIZE * TOTAL);
for (int i = 0 ; i < TOTAL ; i++) {
strcpy((char*)pH_TXT + (i * DOCU_SIZE), "hello world, i need an apple.");
}
// Allocate vectors in device memory
cudaMalloc((void**)&pD_TXT, DOCU_SIZE * TOTAL);
cudaMalloc((void**)&pD_ENC, DOCU_SIZE * TOTAL);
// Copy vectors from host memory to device memory
cudaMemcpy(pD_TXT, pH_TXT, DOCU_SIZE * TOTAL, cudaMemcpyHostToDevice);
// Invoke kernel
int threadsPerBlock = BLOCK_SIZE;
int blocksPerGrid = (TOTAL + threadsPerBlock - 1)/threadsPerBlock;
printf("Total Task is %d\n", TOTAL);
printf("block size is %d\n", threadsPerBlock);
printf("repeat cnt is %d\n", blocksPerGrid);
TEST_Encode<<<blocksPerGrid, threadsPerBlock>>>(pD_TXT, pD_ENC);
cudaMemcpy(pH_ENC, pD_ENC, DOCU_SIZE * TOTAL, cudaMemcpyDeviceToHost);
// Free device memory
if (pD_TXT) cudaFree(pD_TXT);
if (pD_ENC) cudaFree(pD_ENC);
cudaDeviceReset();
}
는, 나는 그렇게 (NVIDIA 비주얼 프로파일 러에서)는 다음과 같은 지속 시간
TOTAL BLOCKS BLOCK_SIZE Duration(ms)
100000 50000 2 28.22
100000 10000 10 22.223
100000 2000 50 12.3
100000 1000 100 9.624
100000 500 200 10.755
100000 250 400 29.824
100000 200 500 39.67
100000 100 1000 81.268
내 GPU는 지포스 GT520 및 최대 threadsPerBlock 값은 1024입니다있어 나는 BLOCK이 1000 일 때 최상의 성능을 얻을 것이라고 예측했지만 위 표는 다른 결과를 보여줍니다.
왜 지속 시간이 선형이 아닌지 이해할 수 없으며이 문제를 어떻게 해결할 수 있습니까? (또는 나는 (mimimum 기간 시간) 자사의 디자인은 훨씬 더 많은 스레드를 시작하는 것입니다 때문에