2023-06-22 10:58:07 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2023 Nomic, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software is licensed under the terms of the Software for Open Models License (SOM),
|
|
|
|
* version 1.0, as detailed in the LICENSE_SOM.txt file. A copy of this license should accompany
|
|
|
|
* this software. Except as expressly granted in the SOM license, all rights are reserved by Nomic, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#version 450
|
|
|
|
|
2023-09-21 17:00:10 +00:00
|
|
|
#include "common.comp"
|
2023-06-22 10:58:07 +00:00
|
|
|
|
2023-09-29 14:02:22 +00:00
|
|
|
#extension GL_KHR_shader_subgroup_arithmetic : require
|
|
|
|
|
|
|
|
layout(local_size_x_id = 0) in;
|
2023-06-22 10:58:07 +00:00
|
|
|
|
|
|
|
layout (binding = 0) readonly buffer tensorInA { float16_t inA[]; };
|
|
|
|
layout (binding = 1) readonly buffer tensorInB { float inB[]; };
|
|
|
|
layout (binding = 2) writeonly buffer tensorOut { float out_[]; };
|
|
|
|
|
|
|
|
layout (push_constant) uniform parameter {
|
|
|
|
uint inAOff;
|
|
|
|
uint inBOff;
|
|
|
|
uint outOff;
|
|
|
|
int ne00;
|
|
|
|
uint nb01;
|
|
|
|
uint nb02;
|
|
|
|
uint nb11;
|
|
|
|
uint nb12;
|
|
|
|
int ne0;
|
|
|
|
int ne1;
|
|
|
|
} pcs;
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
const uint r0 = gl_WorkGroupID.x;
|
|
|
|
const uint r1 = gl_WorkGroupID.y;
|
|
|
|
const uint im = gl_WorkGroupID.z;
|
|
|
|
|
|
|
|
const uint x = (r0*pcs.nb01 + im*pcs.nb02) / 2 + pcs.inAOff; // Based from inA
|
|
|
|
const uint y = (r1*pcs.nb11 + im*pcs.nb12) / 4 + pcs.inBOff; // based from inB
|
|
|
|
|
2023-09-29 14:02:22 +00:00
|
|
|
float sumf = 0.0f;
|
|
|
|
for (uint i = gl_SubgroupInvocationID.x; i < pcs.ne00; i += gl_SubgroupSize) {
|
|
|
|
sumf += float(inA[x+i]) * float(inB[y+i]);
|
2023-06-22 10:58:07 +00:00
|
|
|
}
|
|
|
|
|
2023-09-29 14:02:22 +00:00
|
|
|
const float all_sum = subgroupAdd(sumf);
|
|
|
|
if (subgroupElect()) {
|
|
|
|
out_[im*pcs.ne1*pcs.ne0 + r1*pcs.ne0 + r0 + pcs.outOff] = all_sum;
|
2023-06-22 10:58:07 +00:00
|
|
|
}
|
|
|
|
}
|