Programming/openCL & CUDA2011. 1. 2. 21:51
deviceQuery 예문은 말그대로 장치에 질의의 던져 어떤 스펙인지
몇개의 thread가 존재하는지를 파악하는 프로그램이다.

아무튼 NVIDIA_CUDA_C_ProgrammingGuide.pdf 문서를 보면 아래의 내용이 나오니 참고를 해서 보자면,


Geforce 8800GT(이하 8800GT)는 14개의 멀티 프로세서를 가졌고 112개의 코어를 지녔다.
Grid는 Block을 포함하고, Block은 Thread를 포함한다.

단순 계산으로는 하나의 프로세서별로 8개의 코어가 존재하며
멀티프로세서는 14개 코어는 총 112개가 존재한다.

그리드(Grid)는 블럭의 2차원 배열로 존재하고,
블럭(Block)은 쓰레드의 2차원 배열로 존재한다.
쓰레드(Thread)는 일을하는 최소단위이다.

한번에 묶이는 최소 쓰레드의 숫자(Warp size)는 32개 이며
하나의 블럭으로 묶을수 있는 최대 쓰레드는 512개 이다.

블럭의 최대 차원은 3차원 512x512x64 이며
그리드의 최대 차원은 2차원 65535x65535x1 이다.

라고 이해하면 되려나?

A multithreaded program is partitioned into blocks of threads that execute independently from each
other, so that a GPU with more cores will automatically execute the program in less time than a GPU
with fewer cores.
=> 멀티쓰레드화된 프로그램은 서로 독립적으로 실행되는 쓰레드의 블럭으로 나누어지며, 그러한 이유로 더욱 많은 코어를 포함하는 CPU는 적은 코어를 지닌 GPU보다 짧은 시간에 프로그램을 실행할 수 있다.

Host는 일반적인 CPU 환경이고, Device는 GPU 환경이다.
컴파일시에 Device 코드만 nvcc에서 처리하고, 나머지는 일반적인 컴파일러에서 처리하는 이원화된 구조이다.

아래는 커널이다. 디바이스 코드를 생성하는 부분이며
MatAdd 함수는 __global__ 선언을 앞에 붙여 device 코드임을 명시해야 한다.
MatAdd<<<numBlocks, threadsPerBlock>>>(A, B, C);
그리고 커널 안에는 int형이나 dim3 형으로 선언이 되어야 한다.

아래는 dim3 형으로 선언된 녀석으로,
dim3 threadsPerBlock(16, 16);
dim3 numBlocks(N / threadsPerBlock.x, N / threadsPerBlock.y);
MatAdd<<<numBlocks, threadsPerBlock>>>(A, B, C);
블럭당 쓰레디의 크기를 16x16 thread로, 그리드를 N/16개로 분할하는 예제이다.

물론 2차원은 1차원과 같이 사용이 가능하므로 int형도 허용하는 듯?

B.15  Execution Configuration
Any call to a __global__ function must specify the execution configuration for that call. The execution configuration defines the dimension of the grid and blocks that will be used to execute the function on the device, as well as the associated stream (see Section 3.3.10.1 for a description of streams).
When using the driver API, the execution configuration is specified through a series of driver function calls as detailed in Section 3.3.3.
When using the runtime API (Section 3.2), the execution configuration is specified by inserting an expression of the form <<< Dg, Db, Ns, S >>> between the function name and the parenthesized argument list, where:
  Dg is of type dim3 (see Section B.3.2) and specifies the dimension and size of the grid,
     such that Dg.x * Dg.y equals the number of blocks being launched; Dg.z must be equal to 1;
  Db is of type dim3 (see Section B.3.2) and specifies the dimension and size of each block,
     such that Db.x * Db.y * Db.z equals the number of threads per block;
  Ns is of type size_t and specifies the number of bytes in shared memory that is dynamically allocated per block for this call in addition to the statically allocated memory; this dynamically allocated memory is used by any of the variables declared as an external array as mentioned in Section B.2.3; Ns is an optional argument which defaults to 0;
  S is of type cudaStream_t and specifies the associated stream; S is an optional argument which defaults to 0.
As an example, a function declared as
__global__ void Func(float* parameter);
must be called like this:
Func<<< Dg, Db, Ns >>>(parameter);
The arguments to the execution configuration are evaluated before the actual function arguments and like the function arguments, are currently passed via shared memory to the device. The function call will fail if Dg or Db are greater than the maximum sizes allowed for the device as specified in Appendix G, or if Ns is greater than the maximum
amount of shared memory available on the device, minus the amount of shared memory required for static allocation, functions arguments (for devices of compute capability 1.x), and execution configuration. 

아무튼 원래는 아래의 예제 내용을 분석하기 위한 내용인데
점점 미궁으로 빠지는 느낌 -_-

CUDA deviceQuery


OpenCL DeviceQuery

'Programming > openCL & CUDA' 카테고리의 다른 글

Visual Studio 2008 에서 CUDA 프로젝트 만들기  (2) 2011.01.04
CUDA Toolkit 3.2  (0) 2011.01.02
CUDA on Linux  (0) 2010.12.07
CUDA 예제 컴파일시 오류  (0) 2010.12.05
CUDA / Visual Studio 2008  (2) 2010.12.05
Posted by 구차니