"WebGL 2 compute" NxN matrix multiplication C = A x B (SGEMM) v.1 naive demo.
See Tutorial:
OpenCL SGEMM tuning for Kepler. Kernel 1: Naive implementation by Cedric Nugteren.
All A, B elements are random (0 - 1). Error "er1" is calculated as
the sum of |CCPU - CGPU |/(N*N) for all matrix elements.
er2 = max(|CCPU - CGPU |).
See also Shader 1 benchmark.
#version 310 es
layout (local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
layout (std430, binding = 0) readonly buffer ssbA {
float A[];
};
layout (std430, binding = 1) readonly buffer ssbB {
float B[];
};
layout (std430, binding = 2) writeonly buffer ssbC {
float C[];
};
uniform uvec3 MNK;
void main() {
uint M = MNK.x, N = MNK.y, K = MNK.z;
// Thread identifiers
uint globalRow = gl_GlobalInvocationID.x; // Row ID of C (0..M)
uint globalCol = gl_GlobalInvocationID.y; // Col ID of C (0..N)
// Compute a single element (loop over K)
float acc = 0.0;
for (uint k=0u; k < K; k++)
acc += A[k*M + globalRow] * B[globalCol*K + k];
// Store the result
C[globalCol*M + globalRow] = acc;
}