𝕤𝕠𝕜𝕠𝕨𝕠𝕧𝕧𝕧 :
import pyopencl as cl
import numpy as np
# Initialize OpenCL context and command queue
ctx = cl.Context([cl.get_platforms()[0].get_devices()[0]])
q = cl.CommandQueue(ctx)
n = 10**6
# Create random float32 arrays
a = np.random.rand(n).astype(np.float32)
b = np.random.rand(n).astype(np.float32)
c = np.empty_like(a)
mf = cl.mem_flags
# Allocate GPU memory buffers
A = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=a)
B = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=b)
C = cl.Buffer(ctx, mf.WRITE_ONLY, c.nbytes)
# OpenCL kernel code
kernel_code = """
__kernel void k(__global float *a, __global float *b, __global float *c) {
int i = get_global_id(0);
for (int j = 0; j < 1000; j++) {
c[i] = sqrt(a[i] * b[i] + 0.5f);
}
}
"""
# Build kernel program
prg = cl.Program(ctx, kernel_code).build()
print("GPU load")
# Infinite stress-test loop
while True:
prg.k(q, a.shape, None, A, B, C)
#BE CAREFUL THIS MELTS CPUS!!!
2026-09-19 03:23:21