forked from kosipov/pp_122-mko-lab2
add cuda example
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
import cupy as cp
|
||||||
|
|
||||||
|
source = r"""
|
||||||
|
extern "C" __global__
|
||||||
|
void saxpy(int n, float a, const float* x, float* y) {
|
||||||
|
int i = blockIdx.x * blockDim.x + threadIdx.x;
|
||||||
|
if (i < n) {
|
||||||
|
y[i] = a * x[i] + y[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
saxpy = cp.RawKernel(source, "saxpy")
|
||||||
|
n = x.size # x, y — массивы float32 на устройстве
|
||||||
|
threads = 256
|
||||||
|
blocks = (n + threads - 1) // threads
|
||||||
|
saxpy((blocks,), (threads,), (cp.int32(n), cp.float32(2.0), x, y))
|
||||||
Reference in New Issue
Block a user