This commit is contained in:
Daniele 2025-02-10 10:34:45 +01:00 committed by GitHub
commit 6be97996e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -37,51 +37,35 @@ void main() {
const uint gidx = gl_GlobalInvocationID.x;
const uint oh = gl_GlobalInvocationID.y;
const uint batch = gl_GlobalInvocationID.z / p.IC;
const uint ic = gl_GlobalInvocationID.z % p.IC;
const uint batch_ic = gl_GlobalInvocationID.z;
A_TYPE values[NUM_ITER];
uint offset_dst[NUM_ITER];
[[unroll]] for (uint idx = 0; idx < NUM_ITER; ++idx) {
values[idx] = A_TYPE(0);
}
const uint batch = batch_ic / p.IC;
const uint ic = batch_ic % p.IC;
const uint ksize = p.OW * ((p.KH > 1) ? p.KW : 1);
const uint src_base = ic * p.offset_delta + batch * p.batch_offset;
const uint dst_base = ((batch * p.OH + oh) * p.OW) * p.CHW + ic * p.KW * p.KH;
[[unroll]] for (uint idx = 0; idx < NUM_ITER; ++idx) {
const uint i = gidx * NUM_ITER + idx;
if (i >= p.pelements) {
continue;
}
const uint ksize = p.OW * (p.KH > 1 ? p.KW : 1);
const uint kx = i / ksize;
const uint kd = kx * ksize;
const uint ky = (i - kd) / p.OW;
const uint ky = (i % ksize) / p.OW;
const uint ix = i % p.OW;
const uint iiw = ix * p.s0 + kx * p.d0 - p.p0;
const uint iih = oh * p.s1 + ky * p.d1 - p.p1;
const int iiw = int(ix * uint(p.s0)) + int(kx * uint(p.d0)) - p.p0;
const int iih = int(oh * uint(p.s1)) + int(ky * uint(p.d1)) - p.p1;
offset_dst[idx] =
((batch * p.OH + oh) * p.OW + ix) * p.CHW +
(ic * (p.KW * p.KH) + ky * p.KW + kx);
const uint dst_offset = dst_base + ix * p.CHW + ky * p.KW + kx;
if (i >= p.pelements) {
continue;
}
const bool valid = iih >= 0 && iih < int(p.IH) && iiw >= 0 && iiw < int(p.IW);
const uint src_offset = src_base + uint(iih) * p.IW + uint(iiw);
if (iih < p.IH && iiw < p.IW) {
const uint offset_src = ic * p.offset_delta + batch * p.batch_offset;
values[idx] = data_a[offset_src + iih * p.IW + iiw];
}
}
[[unroll]] for (uint idx = 0; idx < NUM_ITER; ++idx) {
const uint i = gidx * NUM_ITER + idx;
if (i >= p.pelements) {
continue;
}
data_d[offset_dst[idx]] = D_TYPE(values[idx]);
data_d[dst_offset] = D_TYPE(valid ? data_a[src_offset] : 0.0);
}
}