Вы находитесь на странице: 1из 57

. ..

CUDA.
GPU. CUDA C
..

GPGPU
GPU?
GPU

UDA

. , 2011 .

CUDA. GPU. CUDA C

GPGPU

. , 2011 .

CUDA. GPU. CUDA C

GPGPU

GPGPU (general-purpose computing on GPU)


.

, ,

(,
).
,
,
.

. , 2011 .

CUDA. GPU. CUDA C

GPGPU

.
.
.
, .

CUDA:
http://www.nvidia.com/object/cuda_showcase_html.html

. , 2011 .

CUDA. GPU. CUDA C


(heterogeneous computing)

.
:
(CPU);
APU
(GPU);
(, DSP);
;
.

CPU + GPU.
, GPGPU , .

. , 2011 .

CUDA. GPU. CUDA C

GPU

GPU:

:
HLSL
GLSL
Cg

. , 2011 .


:
NVIDIA CUDA
AMD Stream
(
)

CUDA. GPU. CUDA C

:
OpenCL
C++ AMP
()

NVIDIA CUDA

CUDA Compute Unified Device Architecture.


-
NVIDIA.
GPU
.
.

. , 2011 .

CUDA. GPU. CUDA C

NVIDIA CUDA

: NVIDIA CUDA C Programming Guide v. 4.0


. , 2011 .

CUDA. GPU. CUDA C

CUDA

4.0:
http://developer.nvidia.com/cuda-toolkit-40
CUDA driver.
CUDA toolkit.
;
;
;
.
GPU Computing SDK.
.

. , 2011 .

CUDA. GPU. CUDA C

10

GPU?

. , 2011 .

CUDA. GPU. CUDA C

11

CPU GPU

: NVIDIA CUDA C Programming Guide v. 4.0


. , 2011 .

CUDA. GPU. CUDA C

12

CPU GPU

: NVIDIA CUDA C Programming Guide v. 4.0


. , 2011 .

CUDA. GPU. CUDA C

13

GPU

3 5
TOP500 2011
GPU:

: top500.org
. , 2011 .

CUDA. GPU. CUDA C

14

GPU

3 5
Green500 2011
GPU:

: green500.org
. , 2011 .

CUDA. GPU. CUDA C

15

GPU

. , 2011 .

CUDA. GPU. CUDA C

16

CPU GPU

CPU
cache-oriented

GPU
cache-miss oriented

: NVIDIA CUDA C Programming Guide v. 3.2


. , 2011 .

CUDA. GPU. CUDA C

17

CPU GPU
GPU ,
:
,

.


.

.
GPU .

. , 2011 .

CUDA. GPU. CUDA C

18

GPU:

GPU - .
(streaming multiprocessor,
MP), CUDA-
(CUDA core) .
Fermi CUDA-
(scalar
processor, SP).
CUDA-
SIMD.
,
.

. , 2011 .

CUDA. GPU. CUDA C

19

Tesla 8/10

: .. , ..
-
. , 2011 .

CUDA. GPU. CUDA C

20

Tesla 8

: .. , ..
-
. , 2011 .

CUDA. GPU. CUDA C

21

Tesla 10

: .. , ..
-
. , 2011 .

CUDA. GPU. CUDA C

22

Tesla 10

(device/global) .
(shared) SP MP.
(constant cache) ,
SP MP).
(texture cache) ,
SP MP).
(register) () SP.
(local) () SP.

. , 2011 .

CUDA. GPU. CUDA C

23

Fermi

: .. , ..
-
. , 2011 .

CUDA. GPU. CUDA C

24

Fermi
NVIDIA.
L2- .
L1-
.
,
L1- 48kB/16kB.

.

SFU.
C++.
ECC.

. , 2011 .

CUDA. GPU. CUDA C

25

(compute capability)

.
,
(major)
(minor) , major.minor.
, 1.3.
(
CUDA-)
Appendix A NVIDIA CUDA C Programming Guide.
Fermi 2
( 2.x),
1 ( 1.x).
. , 2011 .

CUDA. GPU. CUDA C

26


Appendix G NVIDIA CUDA C
Programming Guide.
1.0.

, 1.3.
(C++), 2.0.
++ 2.0
, CUDA 4.0.



.
. , 2011 .

CUDA. GPU. CUDA C

27

. , 2011 .

CUDA. GPU. CUDA C

28


(thread)
(kernel).
Fermi 4
.
(thread blocks).
,
CUDA- .
/ (grid).
.

.

. , 2011 .

CUDA. GPU. CUDA C

29



( ) ,
.
Block ID (1D, 2D 3D).
CUDA 4.0.
Thread ID (1D, 2D 3D).

.
: ,
.
, , x y-
.

. , 2011 .

CUDA. GPU. CUDA C

30

: NVIDIA CUDA C Programming Guide v. 4.0


. , 2011 .

CUDA. GPU. CUDA C

31


,
:
;
.

.

.

. , 2011 .

CUDA. GPU. CUDA C

32


.

.
,

.


.

. , 2011 .

CUDA. GPU. CUDA C

33

: NVIDIA CUDA C Programming Guide v. 4.0


. , 2011 .

CUDA. GPU. CUDA C

34


.


,


.
: .. , ..
-
. , 2011 .

CUDA. GPU. CUDA C

35

CUDA C

. , 2011 .

CUDA. GPU. CUDA C

36

CUDA C

CUDA C /C++,
;
;
.
C++. C++
CUDA.
:
(host) = CPU;
(device) = GPU;
(kernel) ,
GPU.
. , 2011 .

CUDA. GPU. CUDA C

37

__host__
__global__

host
device

host
host

__device__

device

device

__host__ ( ) ,
.
__global__ ,
().
__device__ , ( )
.

. , 2011 .

CUDA. GPU. CUDA C

38

__global__

void.
/
.
.
.
.
__global__
.

. , 2011 .

CUDA. GPU. CUDA C

39

__device__

__device__ __host__,
2 .
.
.

2.0 .
__device__

2.0 ,
.

1.x.
. , 2011 .

CUDA. GPU. CUDA C

40


__device__ ,
:
;

;

, ,
.
__constant__ ,

.

. , 2011 .

CUDA. GPU. CUDA C

41

__shared__ ,

,
;

;

, .

. , 2011 .

CUDA. GPU. CUDA C

42

[u]char[1..4], [u]int[1..4], [u]long[1..4], float[1..4], double2


, .x, .y, .z, .w.
, make_<type name>.
.
dim3 = uint3 + ; 1
dim3
.
(/++) .

. , 2011 .

CUDA. GPU. CUDA C

43

GPU :
gridDim dim3,
;
blockIdx uint3,
;
blockDim dim3,
;
threadIdx uint3,
.
.

. , 2011 .

CUDA. GPU. CUDA C

44


(.. ).

.
,
x- .
idx = blockIdx.x * blockDim.x + threadIdx.x;

. , 2011 .

CUDA. GPU. CUDA C

45

CUDA API

CUDA API:
;
;
;
;
API.
cudaError_t,
cudaSuccess .
API:
(CUDA driver API): cu*;
(C runtime for CUDA): cuda*.
. , 2011 .

CUDA. GPU. CUDA C

46

:
cudaError_t cudaGetDeviceCount(int* count)
;
cudaError_t cudaGetDevice (int* dev)
;
cudaError_t cudaGetDeviceProperties (struct
cudaDeviceProp* prop, int dev) ,
.

. , 2011 .

CUDA. GPU. CUDA C

47

:
cudaError_t cudaSetDevice (int dev)
;
cudaError_t cudaChooseDevice (int* dev, const struct
cudaDeviceProp* prop) ,
.

. , 2011 .

CUDA. GPU. CUDA C

48

:
cudaError_t cudaMalloc (void** devPtr, size_t count)

;
cudaError_t cudaFree (void* devPtr)
.
:
cudaError_t cudaMemcpy (void* dst, const void* src,
size_t count, enum cudaMemcpyKind kind)

( );
cudaMemcpyAsync .
. , 2011 .

CUDA. GPU. CUDA C

49

.

.

<<< Dg, Db, Ns, S >>>
.
Dg , Dg.x
* Dg.y * Dg.z ,
.
Db
, Db.x * Db.y * Db.z .
Ns, S ,
.
. , 2011 .

CUDA. GPU. CUDA C

50


:
__global__ void kernel_func() { }

dim3 dim_grid(100, 50);


dim3 dim_block (8, 8, 8);
kernel_func<<<dim_grid, dim_block>>>( );

. , 2011 .

CUDA. GPU. CUDA C

51

void __syncthreads()
( ).

.
cudaThreadSyncronize()
( ).
.

cudaStream_t cudaEvent_t.

. , 2011 .

CUDA. GPU. CUDA C

52

CUDA Hello, World!


#include <cstdlib>
#include <iostream>
#include <cuda_runtime.h>

__global__ void hello(int * output)


{
int globalIdx = blockIdx.x * blockDim.x + threadIdx.x;
output[globalIdx] = globalIdx;
}

. , 2011 .

CUDA. GPU. CUDA C

53

CUDA Hello, World!


int main() {
int buffer_size = 4 * 512;
int * buffer = new int[buffer_size];
int * buffer_gpu;
cudaMalloc((void **) &buffer_gpu,
buffer_size * sizeof(float));
hello<<<4, 512>>>(buffer_gpu);
cudaMemcpy(buffer, buffer_gpu, buffer_size * sizeof(float),
cudaMemcpyDeviceToHost);
cudaFree(buffer_gpu); delete [] buffer;
return 0;
}
. , 2011 .

CUDA. GPU. CUDA C

54

nvcc.
Build rules Microsoft Visual Studio.
CUDA 4.0 MSVS 2005 2008.
CUDA 4.0 MSVS 2010.

. , 2011 .

CUDA. GPU. CUDA C

55

CUDA

/C++ CPU

NVCC

CPU

CUDA

CPU

CPU-GPU
. , 2011 .

CUDA. GPU. CUDA C

56

NVIDIA CUDA C Programming Guide v. 4.0:


http://developer.download.nvidia.com/compute/cuda/4_0/tool
kit/docs/CUDA_C_Programming_Guide.pdf
CUDA :
https://sites.google.com/site/cudacsmsusu/file-cabinet
.. , ..
CUDA:
https://sites.google.com/site/cudacsmsusu/file-cabinet
. , . CUDA :

(. .).

. , 2011 .

CUDA. GPU. CUDA C

57

Оценить