This commit is contained in:
2026-11-28 10:19:11 +03:00
parent ebddaff938
commit 40f9183193
+17
View File
@@ -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))