Készítette: Závodszky Gábor / @Zega21
Hidrodinamikai Rendszerek Tanszék
Alapvető linux felhasználói ismeretek:
(A kurzus folyamán elsajátítható)
Alapvető C/C++ programozási ismeretek:
(A kurzus folyamán NEM elsajátítható (bár gyakorolható). A következő órára ezekre az ismeretekre mindenkinek szüksége lesz! TUTORIAL a honlapon!)
![]() |
![]() |
![]() |
|
![]() |
![]() |
|
|
![]() |
\[ S(N) = \alpha + (1 - \alpha)N \]
Suppose a car is traveling between two cities 60 miles apart, and has already spent one hour traveling half the distance at 30 mph. No matter how fast you drive the last half, it is impossible to achieve 90 mph average before reaching the second city. Since it has already taken you 1 hour and you only have a distance of 60 miles total; going infinitely fast you would only achieve 60 mph.
\[ S(N) = \frac{N}{1 + (N-1)\alpha } \]
Suppose a car has already been traveling for some time at less than 90mph. Given enough time and distance to travel, the car's average speed can always eventually reach 90mph, no matter how long or how slowly it has already traveled. For example, if the car spent one hour at 30 mph, it could achieve this by driving at 120 mph for two additional hours, or at 150 mph for an hour, and so on.
#include <stdio.h>
#include <cuda.h>
__global__ void square_array(float *a, int N)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx<N) a[idx] = a[idx] * a[idx];
}
int main(void)
{
float *a_h, *a_d;
const int N = 10;
size_t size = N * sizeof(float);
a_h = (float *)malloc(size);
cudaMalloc((void **) &a_d, size);
for (int i=0; i<N; i++) a_h[i] = (float)i;
cudaMemcpy(a_d, a_h, size, cudaMemcpyHostToDevice);
int block_size = 4;
int n_blocks = N/block_size + (N%block_size == 0 ? 0:1);
square_array <<<a n_blocks, block_size >>> (a_d, N);
cudaMemcpy(a_h, a_d, sizeof(float)*N, cudaMemcpyDeviceToHost);
for (int i=0; i<N; i++) printf("%d %f\n", i, a_h[i]);
free(a_h); cudaFree(a_d);
}
Sávszélesség (GB/s) | A PCIe-hez képest | |
PCIe x16 2.0 | 8 | 1 |
GPU globális memória | 200 | 25 |