| @@ -331,8 +331,6 @@ void main() | |||
| { | |||
| if (elempack == 1) | |||
| { | |||
| const uint cstepd4 = psc(cstep) / 4; | |||
| const uint Md4_K_USGM_USGK = Md4 * K * UNROLL_SG_M * UNROLL_SG_K; | |||
| const uint Md4_K_USGM_USGK_d_subgroupsize = (Md4_K_USGM_USGK + (ncnn_subgroupSize * UNROLL_WG_N - 1)) / (ncnn_subgroupSize * UNROLL_WG_N); | |||
| [[unroll]] for (uint q = 0; q < Md4_K_USGM_USGK_d_subgroupsize; q++) | |||
| @@ -347,8 +345,6 @@ void main() | |||
| } | |||
| else // if (elempack == 4) | |||
| { | |||
| const uint inchd4 = inch / 4; | |||
| const uint Kd4_M_USGM_USGK = Kd4 * M * UNROLL_SG_M * UNROLL_SG_K; | |||
| const uint Kd4_M_USGM_USGK_d_subgroupsize = (Kd4_M_USGM_USGK + (ncnn_subgroupSize * UNROLL_WG_N - 1)) / (ncnn_subgroupSize * UNROLL_WG_N); | |||
| [[unroll]] for (uint q = 0; q < Kd4_M_USGM_USGK_d_subgroupsize; q++) | |||
| @@ -365,11 +361,7 @@ void main() | |||
| // load weight | |||
| { | |||
| const uint Nd4_K_USGN = Nd4 * K * UNROLL_SG_N; | |||
| const uint Nd4_K_USGN_USGK = Nd4 * K * UNROLL_SG_N * UNROLL_SG_K; | |||
| const uint w_offset = ((wgni * kk) * UNROLL_WG_N) * Nd4_K_USGN + ((k / UNROLL_SG_K) * UNROLL_WG_N + sgni) * Nd4_K_USGN_USGK; | |||
| const uint Nd4_K_USGN_USGK_d_subgroupsize = (Nd4_K_USGN_USGK + (ncnn_subgroupSize * UNROLL_WG_M - 1)) / (ncnn_subgroupSize * UNROLL_WG_M); | |||
| [[unroll]] for (uint q = 0; q < Nd4_K_USGN_USGK_d_subgroupsize; q++) | |||
| { | |||
| @@ -537,29 +529,29 @@ void main() | |||
| { | |||
| if (elempack == 1) | |||
| { | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| coopMatLoad(A[zm], tmp_v[sgmi], (zk * UNROLL_SG_M + zm) * (Md4 * K), Md4, gl_CooperativeMatrixLayoutColumnMajor); | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| coopMatLoadNV(A[zm], tmp_v[sgmi], (zk * UNROLL_SG_M + zm) * (Md4 * K), Md4, true); | |||
| #endif | |||
| #endif | |||
| } | |||
| else // if (elempack == 4) | |||
| { | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| coopMatLoad(A[zm], tmp_v[sgmi], (zk * UNROLL_SG_M + zm) * (Kd4 * M), Kd4, gl_CooperativeMatrixLayoutRowMajor); | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| coopMatLoadNV(A[zm], tmp_v[sgmi], (zk * UNROLL_SG_M + zm) * (Kd4 * M), Kd4, false); | |||
| #endif | |||
| #endif | |||
| } | |||
| } | |||
| [[unroll]] for (uint zn = 0; zn < UNROLL_SG_N; zn++) | |||
| { | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| coopMatLoad(B[zn], tmp_k[sgni], (zk * UNROLL_SG_N + zn) * (Nd4 * K), Nd4, gl_CooperativeMatrixLayoutRowMajor); | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| coopMatLoadNV(B[zn], tmp_k[sgni], (zk * UNROLL_SG_N + zn) * (Nd4 * K), Nd4, false); | |||
| #endif | |||
| #endif | |||
| } | |||
| // sum += k * v | |||
| @@ -567,11 +559,11 @@ void main() | |||
| { | |||
| [[unroll]] for (uint zm = 0; zm < UNROLL_SG_M; zm++) | |||
| { | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| sum[zn][zm] = coopMatMulAdd(A[zm], B[zn], sum[zn][zm]); | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| sum[zn][zm] = coopMatMulAddNV(A[zm], B[zn], sum[zn][zm]); | |||
| #endif | |||
| #endif | |||
| } | |||
| } | |||
| } | |||
| @@ -585,8 +577,6 @@ void main() | |||
| { | |||
| if (elempack == 1) | |||
| { | |||
| const uint cstepd4 = psc(cstep) / 4; | |||
| const uint Md4_K_USGM_USGK = Md4 * K * UNROLL_SG_M * UNROLL_SG_K; | |||
| const uint Md4_K_USGM_USGK_d_subgroupsize = (Md4_K_USGM_USGK + (ncnn_subgroupSize * UNROLL_WG_N - 1)) / (ncnn_subgroupSize * UNROLL_WG_N); | |||
| [[unroll]] for (uint q = 0; q < Md4_K_USGM_USGK_d_subgroupsize; q++) | |||
| @@ -601,8 +591,6 @@ void main() | |||
| } | |||
| else // if (elempack == 4) | |||
| { | |||
| const uint inchd4 = inch / 4; | |||
| const uint Kd4_M_USGM_USGK = Kd4 * M * UNROLL_SG_M * UNROLL_SG_K; | |||
| const uint Kd4_M_USGM_USGK_d_subgroupsize = (Kd4_M_USGM_USGK + (ncnn_subgroupSize * UNROLL_WG_N - 1)) / (ncnn_subgroupSize * UNROLL_WG_N); | |||
| [[unroll]] for (uint q = 0; q < Kd4_M_USGM_USGK_d_subgroupsize; q++) | |||
| @@ -619,11 +607,7 @@ void main() | |||
| // load weight | |||
| { | |||
| const uint Nd4_K_USGN = Nd4 * K * UNROLL_SG_N; | |||
| const uint Nd4_K_USGN_USGK = Nd4 * K * UNROLL_SG_N * UNROLL_SG_K; | |||
| const uint w_offset = ((wgni * kk) * UNROLL_WG_N) * Nd4_K_USGN + ((k / UNROLL_SG_K) * UNROLL_WG_N + sgni) * Nd4_K_USGN_USGK; | |||
| const uint Nd4_K_USGN_USGK_d_subgroupsize = (Nd4_K_USGN_USGK + (ncnn_subgroupSize * UNROLL_WG_M - 1)) / (ncnn_subgroupSize * UNROLL_WG_M); | |||
| [[unroll]] for (uint q = 0; q < Nd4_K_USGN_USGK_d_subgroupsize; q++) | |||
| { | |||
| @@ -3,16 +3,17 @@ | |||
| #version 450 | |||
| #define shape_constant_id_offset 0 | |||
| layout (constant_id = 0) const int c = 0; | |||
| #define shape_constant_id_offset 1 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int w = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int h = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outcstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outcstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 6) const int block_y = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int block_y = 0; | |||
| layout (binding = 0) readonly buffer bottom_blob { sfp bottom_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer bottom_tm_blob { sfp bottom_tm_blob_data[]; }; | |||
| @@ -21,7 +22,6 @@ layout (push_constant) uniform parameter | |||
| { | |||
| int w; | |||
| int h; | |||
| int c; | |||
| int cstep; | |||
| int outcstep; | |||
| @@ -36,7 +36,7 @@ void main() | |||
| int gy = int(gl_GlobalInvocationID.y); | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= psc(c)) | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= c) | |||
| return; | |||
| // load 4x4 | |||
| @@ -115,22 +115,22 @@ void main() | |||
| v33 = m33 - m31; | |||
| // store 16 | |||
| int v_tm_offset = gz * psc(block_x) * psc(block_y) + gy * psc(block_x) + gx; | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 0 * psc(outcstep), v00); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 1 * psc(outcstep), v01); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 2 * psc(outcstep), v02); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 3 * psc(outcstep), v03); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 4 * psc(outcstep), v10); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 5 * psc(outcstep), v11); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 6 * psc(outcstep), v12); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 7 * psc(outcstep), v13); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 8 * psc(outcstep), v20); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 9 * psc(outcstep), v21); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 10 * psc(outcstep), v22); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 11 * psc(outcstep), v23); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 12 * psc(outcstep), v30); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 13 * psc(outcstep), v31); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 14 * psc(outcstep), v32); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 15 * psc(outcstep), v33); | |||
| int v_tm_offset = gz * psc(outcstep) + gy * psc(block_x) + gx; | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 0 * psc(outcstep) * c, v00); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 1 * psc(outcstep) * c, v01); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 2 * psc(outcstep) * c, v02); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 3 * psc(outcstep) * c, v03); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 4 * psc(outcstep) * c, v10); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 5 * psc(outcstep) * c, v11); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 6 * psc(outcstep) * c, v12); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 7 * psc(outcstep) * c, v13); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 8 * psc(outcstep) * c, v20); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 9 * psc(outcstep) * c, v21); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 10 * psc(outcstep) * c, v22); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 11 * psc(outcstep) * c, v23); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 12 * psc(outcstep) * c, v30); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 13 * psc(outcstep) * c, v31); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 14 * psc(outcstep) * c, v32); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 15 * psc(outcstep) * c, v33); | |||
| } | |||
| @@ -10,17 +10,17 @@ layout (constant_id = 0) const int bias_term = 0; | |||
| layout (constant_id = 1) const int activation_type = 0; | |||
| layout (constant_id = 2) const float activation_param_0 = 0; | |||
| layout (constant_id = 3) const float activation_param_1 = 0; | |||
| layout (constant_id = 4) const int c = 0; | |||
| #define shape_constant_id_offset 4 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int cstep = 0; | |||
| #define shape_constant_id_offset 5 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int block_y = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int block_y = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int outh = 0; | |||
| layout (constant_id = shape_constant_id_offset + 6) const int outcstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outh = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int outcstep = 0; | |||
| layout (binding = 0) readonly buffer top_tm_blob { sfp top_tm_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer top_blob { sfp top_blob_data[]; }; | |||
| @@ -28,7 +28,6 @@ layout (binding = 2) readonly buffer bias_blob { sfp bias_data[]; }; | |||
| layout (push_constant) uniform parameter | |||
| { | |||
| int c; | |||
| int cstep; | |||
| int block_x; | |||
| @@ -45,28 +44,28 @@ void main() | |||
| int gy = int(gl_GlobalInvocationID.y); | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= psc(c)) | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= c) | |||
| return; | |||
| // load 16 | |||
| int v_tm_offset = gz * psc(block_x) * psc(block_y) + gy * psc(block_x) + gx; | |||
| afp v00 = buffer_ld1(top_tm_blob_data, v_tm_offset + 0 * psc(cstep)); | |||
| afp v01 = buffer_ld1(top_tm_blob_data, v_tm_offset + 1 * psc(cstep)); | |||
| afp v02 = buffer_ld1(top_tm_blob_data, v_tm_offset + 2 * psc(cstep)); | |||
| afp v03 = buffer_ld1(top_tm_blob_data, v_tm_offset + 3 * psc(cstep)); | |||
| afp v10 = buffer_ld1(top_tm_blob_data, v_tm_offset + 4 * psc(cstep)); | |||
| afp v11 = buffer_ld1(top_tm_blob_data, v_tm_offset + 5 * psc(cstep)); | |||
| afp v12 = buffer_ld1(top_tm_blob_data, v_tm_offset + 6 * psc(cstep)); | |||
| afp v13 = buffer_ld1(top_tm_blob_data, v_tm_offset + 7 * psc(cstep)); | |||
| afp v20 = buffer_ld1(top_tm_blob_data, v_tm_offset + 8 * psc(cstep)); | |||
| afp v21 = buffer_ld1(top_tm_blob_data, v_tm_offset + 9 * psc(cstep)); | |||
| afp v22 = buffer_ld1(top_tm_blob_data, v_tm_offset + 10 * psc(cstep)); | |||
| afp v23 = buffer_ld1(top_tm_blob_data, v_tm_offset + 11 * psc(cstep)); | |||
| afp v30 = buffer_ld1(top_tm_blob_data, v_tm_offset + 12 * psc(cstep)); | |||
| afp v31 = buffer_ld1(top_tm_blob_data, v_tm_offset + 13 * psc(cstep)); | |||
| afp v32 = buffer_ld1(top_tm_blob_data, v_tm_offset + 14 * psc(cstep)); | |||
| afp v33 = buffer_ld1(top_tm_blob_data, v_tm_offset + 15 * psc(cstep)); | |||
| int v_tm_offset = gz * psc(cstep) + gy * psc(block_x) + gx; | |||
| afp v00 = buffer_ld1(top_tm_blob_data, v_tm_offset + 0 * psc(cstep) * c); | |||
| afp v01 = buffer_ld1(top_tm_blob_data, v_tm_offset + 1 * psc(cstep) * c); | |||
| afp v02 = buffer_ld1(top_tm_blob_data, v_tm_offset + 2 * psc(cstep) * c); | |||
| afp v03 = buffer_ld1(top_tm_blob_data, v_tm_offset + 3 * psc(cstep) * c); | |||
| afp v10 = buffer_ld1(top_tm_blob_data, v_tm_offset + 4 * psc(cstep) * c); | |||
| afp v11 = buffer_ld1(top_tm_blob_data, v_tm_offset + 5 * psc(cstep) * c); | |||
| afp v12 = buffer_ld1(top_tm_blob_data, v_tm_offset + 6 * psc(cstep) * c); | |||
| afp v13 = buffer_ld1(top_tm_blob_data, v_tm_offset + 7 * psc(cstep) * c); | |||
| afp v20 = buffer_ld1(top_tm_blob_data, v_tm_offset + 8 * psc(cstep) * c); | |||
| afp v21 = buffer_ld1(top_tm_blob_data, v_tm_offset + 9 * psc(cstep) * c); | |||
| afp v22 = buffer_ld1(top_tm_blob_data, v_tm_offset + 10 * psc(cstep) * c); | |||
| afp v23 = buffer_ld1(top_tm_blob_data, v_tm_offset + 11 * psc(cstep) * c); | |||
| afp v30 = buffer_ld1(top_tm_blob_data, v_tm_offset + 12 * psc(cstep) * c); | |||
| afp v31 = buffer_ld1(top_tm_blob_data, v_tm_offset + 13 * psc(cstep) * c); | |||
| afp v32 = buffer_ld1(top_tm_blob_data, v_tm_offset + 14 * psc(cstep) * c); | |||
| afp v33 = buffer_ld1(top_tm_blob_data, v_tm_offset + 15 * psc(cstep) * c); | |||
| // const float itm[2][4] = { | |||
| // {1.0f, 1.0f, 1.0f, 0.0f}, | |||
| @@ -3,16 +3,17 @@ | |||
| #version 450 | |||
| #define shape_constant_id_offset 0 | |||
| layout (constant_id = 0) const int c = 0; | |||
| #define shape_constant_id_offset 1 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int w = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int h = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outcstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outcstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 6) const int block_y = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int block_y = 0; | |||
| layout (binding = 0) readonly buffer bottom_blob { sfp bottom_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer bottom_tm_blob { sfp bottom_tm_blob_data[]; }; | |||
| @@ -21,7 +22,6 @@ layout (push_constant) uniform parameter | |||
| { | |||
| int w; | |||
| int h; | |||
| int c; | |||
| int cstep; | |||
| int outcstep; | |||
| @@ -36,7 +36,7 @@ void main() | |||
| int gy = int(gl_GlobalInvocationID.y); | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= psc(c)) | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= c) | |||
| return; | |||
| // load 6x6 | |||
| @@ -187,42 +187,42 @@ void main() | |||
| v55 = m51 - m53 * afp(2.5) + m55; | |||
| // store 36 | |||
| int v_tm_offset = gz * psc(block_x) * psc(block_y) + gy * psc(block_x) + gx; | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 0 * psc(outcstep), v00); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 1 * psc(outcstep), v01); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 2 * psc(outcstep), v02); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 3 * psc(outcstep), v03); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 4 * psc(outcstep), v04); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 5 * psc(outcstep), v05); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 6 * psc(outcstep), v10); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 7 * psc(outcstep), v11); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 8 * psc(outcstep), v12); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 9 * psc(outcstep), v13); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 10 * psc(outcstep), v14); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 11 * psc(outcstep), v15); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 12 * psc(outcstep), v20); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 13 * psc(outcstep), v21); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 14 * psc(outcstep), v22); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 15 * psc(outcstep), v23); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 16 * psc(outcstep), v24); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 17 * psc(outcstep), v25); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 18 * psc(outcstep), v30); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 19 * psc(outcstep), v31); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 20 * psc(outcstep), v32); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 21 * psc(outcstep), v33); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 22 * psc(outcstep), v34); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 23 * psc(outcstep), v35); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 24 * psc(outcstep), v40); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 25 * psc(outcstep), v41); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 26 * psc(outcstep), v42); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 27 * psc(outcstep), v43); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 28 * psc(outcstep), v44); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 29 * psc(outcstep), v45); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 30 * psc(outcstep), v50); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 31 * psc(outcstep), v51); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 32 * psc(outcstep), v52); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 33 * psc(outcstep), v53); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 34 * psc(outcstep), v54); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 35 * psc(outcstep), v55); | |||
| int v_tm_offset = gz * psc(outcstep) + gy * psc(block_x) + gx; | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 0 * psc(outcstep) * c, v00); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 1 * psc(outcstep) * c, v01); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 2 * psc(outcstep) * c, v02); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 3 * psc(outcstep) * c, v03); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 4 * psc(outcstep) * c, v04); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 5 * psc(outcstep) * c, v05); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 6 * psc(outcstep) * c, v10); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 7 * psc(outcstep) * c, v11); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 8 * psc(outcstep) * c, v12); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 9 * psc(outcstep) * c, v13); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 10 * psc(outcstep) * c, v14); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 11 * psc(outcstep) * c, v15); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 12 * psc(outcstep) * c, v20); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 13 * psc(outcstep) * c, v21); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 14 * psc(outcstep) * c, v22); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 15 * psc(outcstep) * c, v23); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 16 * psc(outcstep) * c, v24); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 17 * psc(outcstep) * c, v25); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 18 * psc(outcstep) * c, v30); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 19 * psc(outcstep) * c, v31); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 20 * psc(outcstep) * c, v32); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 21 * psc(outcstep) * c, v33); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 22 * psc(outcstep) * c, v34); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 23 * psc(outcstep) * c, v35); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 24 * psc(outcstep) * c, v40); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 25 * psc(outcstep) * c, v41); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 26 * psc(outcstep) * c, v42); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 27 * psc(outcstep) * c, v43); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 28 * psc(outcstep) * c, v44); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 29 * psc(outcstep) * c, v45); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 30 * psc(outcstep) * c, v50); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 31 * psc(outcstep) * c, v51); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 32 * psc(outcstep) * c, v52); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 33 * psc(outcstep) * c, v53); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 34 * psc(outcstep) * c, v54); | |||
| buffer_st1(bottom_tm_blob_data, v_tm_offset + 35 * psc(outcstep) * c, v55); | |||
| } | |||
| @@ -10,17 +10,17 @@ layout (constant_id = 0) const int bias_term = 0; | |||
| layout (constant_id = 1) const int activation_type = 0; | |||
| layout (constant_id = 2) const float activation_param_0 = 0; | |||
| layout (constant_id = 3) const float activation_param_1 = 0; | |||
| layout (constant_id = 4) const int c = 0; | |||
| #define shape_constant_id_offset 4 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int cstep = 0; | |||
| #define shape_constant_id_offset 5 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int block_y = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int block_y = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int outh = 0; | |||
| layout (constant_id = shape_constant_id_offset + 6) const int outcstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outh = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int outcstep = 0; | |||
| layout (binding = 0) readonly buffer top_tm_blob { sfp top_tm_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer top_blob { sfp top_blob_data[]; }; | |||
| @@ -28,7 +28,6 @@ layout (binding = 2) readonly buffer bias_blob { sfp bias_data[]; }; | |||
| layout (push_constant) uniform parameter | |||
| { | |||
| int c; | |||
| int cstep; | |||
| int block_x; | |||
| @@ -45,48 +44,48 @@ void main() | |||
| int gy = int(gl_GlobalInvocationID.y); | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= psc(c)) | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= c) | |||
| return; | |||
| // load 36 | |||
| int v_tm_offset = gz * psc(block_x) * psc(block_y) + gy * psc(block_x) + gx; | |||
| afp v00 = buffer_ld1(top_tm_blob_data, v_tm_offset + 0 * psc(cstep)); | |||
| afp v01 = buffer_ld1(top_tm_blob_data, v_tm_offset + 1 * psc(cstep)); | |||
| afp v02 = buffer_ld1(top_tm_blob_data, v_tm_offset + 2 * psc(cstep)); | |||
| afp v03 = buffer_ld1(top_tm_blob_data, v_tm_offset + 3 * psc(cstep)); | |||
| afp v04 = buffer_ld1(top_tm_blob_data, v_tm_offset + 4 * psc(cstep)); | |||
| afp v05 = buffer_ld1(top_tm_blob_data, v_tm_offset + 5 * psc(cstep)); | |||
| afp v10 = buffer_ld1(top_tm_blob_data, v_tm_offset + 6 * psc(cstep)); | |||
| afp v11 = buffer_ld1(top_tm_blob_data, v_tm_offset + 7 * psc(cstep)); | |||
| afp v12 = buffer_ld1(top_tm_blob_data, v_tm_offset + 8 * psc(cstep)); | |||
| afp v13 = buffer_ld1(top_tm_blob_data, v_tm_offset + 9 * psc(cstep)); | |||
| afp v14 = buffer_ld1(top_tm_blob_data, v_tm_offset + 10 * psc(cstep)); | |||
| afp v15 = buffer_ld1(top_tm_blob_data, v_tm_offset + 11 * psc(cstep)); | |||
| afp v20 = buffer_ld1(top_tm_blob_data, v_tm_offset + 12 * psc(cstep)); | |||
| afp v21 = buffer_ld1(top_tm_blob_data, v_tm_offset + 13 * psc(cstep)); | |||
| afp v22 = buffer_ld1(top_tm_blob_data, v_tm_offset + 14 * psc(cstep)); | |||
| afp v23 = buffer_ld1(top_tm_blob_data, v_tm_offset + 15 * psc(cstep)); | |||
| afp v24 = buffer_ld1(top_tm_blob_data, v_tm_offset + 16 * psc(cstep)); | |||
| afp v25 = buffer_ld1(top_tm_blob_data, v_tm_offset + 17 * psc(cstep)); | |||
| afp v30 = buffer_ld1(top_tm_blob_data, v_tm_offset + 18 * psc(cstep)); | |||
| afp v31 = buffer_ld1(top_tm_blob_data, v_tm_offset + 19 * psc(cstep)); | |||
| afp v32 = buffer_ld1(top_tm_blob_data, v_tm_offset + 20 * psc(cstep)); | |||
| afp v33 = buffer_ld1(top_tm_blob_data, v_tm_offset + 21 * psc(cstep)); | |||
| afp v34 = buffer_ld1(top_tm_blob_data, v_tm_offset + 22 * psc(cstep)); | |||
| afp v35 = buffer_ld1(top_tm_blob_data, v_tm_offset + 23 * psc(cstep)); | |||
| afp v40 = buffer_ld1(top_tm_blob_data, v_tm_offset + 24 * psc(cstep)); | |||
| afp v41 = buffer_ld1(top_tm_blob_data, v_tm_offset + 25 * psc(cstep)); | |||
| afp v42 = buffer_ld1(top_tm_blob_data, v_tm_offset + 26 * psc(cstep)); | |||
| afp v43 = buffer_ld1(top_tm_blob_data, v_tm_offset + 27 * psc(cstep)); | |||
| afp v44 = buffer_ld1(top_tm_blob_data, v_tm_offset + 28 * psc(cstep)); | |||
| afp v45 = buffer_ld1(top_tm_blob_data, v_tm_offset + 29 * psc(cstep)); | |||
| afp v50 = buffer_ld1(top_tm_blob_data, v_tm_offset + 30 * psc(cstep)); | |||
| afp v51 = buffer_ld1(top_tm_blob_data, v_tm_offset + 31 * psc(cstep)); | |||
| afp v52 = buffer_ld1(top_tm_blob_data, v_tm_offset + 32 * psc(cstep)); | |||
| afp v53 = buffer_ld1(top_tm_blob_data, v_tm_offset + 33 * psc(cstep)); | |||
| afp v54 = buffer_ld1(top_tm_blob_data, v_tm_offset + 34 * psc(cstep)); | |||
| afp v55 = buffer_ld1(top_tm_blob_data, v_tm_offset + 35 * psc(cstep)); | |||
| int v_tm_offset = gz * psc(cstep) + gy * psc(block_x) + gx; | |||
| afp v00 = buffer_ld1(top_tm_blob_data, v_tm_offset + 0 * psc(cstep) * c); | |||
| afp v01 = buffer_ld1(top_tm_blob_data, v_tm_offset + 1 * psc(cstep) * c); | |||
| afp v02 = buffer_ld1(top_tm_blob_data, v_tm_offset + 2 * psc(cstep) * c); | |||
| afp v03 = buffer_ld1(top_tm_blob_data, v_tm_offset + 3 * psc(cstep) * c); | |||
| afp v04 = buffer_ld1(top_tm_blob_data, v_tm_offset + 4 * psc(cstep) * c); | |||
| afp v05 = buffer_ld1(top_tm_blob_data, v_tm_offset + 5 * psc(cstep) * c); | |||
| afp v10 = buffer_ld1(top_tm_blob_data, v_tm_offset + 6 * psc(cstep) * c); | |||
| afp v11 = buffer_ld1(top_tm_blob_data, v_tm_offset + 7 * psc(cstep) * c); | |||
| afp v12 = buffer_ld1(top_tm_blob_data, v_tm_offset + 8 * psc(cstep) * c); | |||
| afp v13 = buffer_ld1(top_tm_blob_data, v_tm_offset + 9 * psc(cstep) * c); | |||
| afp v14 = buffer_ld1(top_tm_blob_data, v_tm_offset + 10 * psc(cstep) * c); | |||
| afp v15 = buffer_ld1(top_tm_blob_data, v_tm_offset + 11 * psc(cstep) * c); | |||
| afp v20 = buffer_ld1(top_tm_blob_data, v_tm_offset + 12 * psc(cstep) * c); | |||
| afp v21 = buffer_ld1(top_tm_blob_data, v_tm_offset + 13 * psc(cstep) * c); | |||
| afp v22 = buffer_ld1(top_tm_blob_data, v_tm_offset + 14 * psc(cstep) * c); | |||
| afp v23 = buffer_ld1(top_tm_blob_data, v_tm_offset + 15 * psc(cstep) * c); | |||
| afp v24 = buffer_ld1(top_tm_blob_data, v_tm_offset + 16 * psc(cstep) * c); | |||
| afp v25 = buffer_ld1(top_tm_blob_data, v_tm_offset + 17 * psc(cstep) * c); | |||
| afp v30 = buffer_ld1(top_tm_blob_data, v_tm_offset + 18 * psc(cstep) * c); | |||
| afp v31 = buffer_ld1(top_tm_blob_data, v_tm_offset + 19 * psc(cstep) * c); | |||
| afp v32 = buffer_ld1(top_tm_blob_data, v_tm_offset + 20 * psc(cstep) * c); | |||
| afp v33 = buffer_ld1(top_tm_blob_data, v_tm_offset + 21 * psc(cstep) * c); | |||
| afp v34 = buffer_ld1(top_tm_blob_data, v_tm_offset + 22 * psc(cstep) * c); | |||
| afp v35 = buffer_ld1(top_tm_blob_data, v_tm_offset + 23 * psc(cstep) * c); | |||
| afp v40 = buffer_ld1(top_tm_blob_data, v_tm_offset + 24 * psc(cstep) * c); | |||
| afp v41 = buffer_ld1(top_tm_blob_data, v_tm_offset + 25 * psc(cstep) * c); | |||
| afp v42 = buffer_ld1(top_tm_blob_data, v_tm_offset + 26 * psc(cstep) * c); | |||
| afp v43 = buffer_ld1(top_tm_blob_data, v_tm_offset + 27 * psc(cstep) * c); | |||
| afp v44 = buffer_ld1(top_tm_blob_data, v_tm_offset + 28 * psc(cstep) * c); | |||
| afp v45 = buffer_ld1(top_tm_blob_data, v_tm_offset + 29 * psc(cstep) * c); | |||
| afp v50 = buffer_ld1(top_tm_blob_data, v_tm_offset + 30 * psc(cstep) * c); | |||
| afp v51 = buffer_ld1(top_tm_blob_data, v_tm_offset + 31 * psc(cstep) * c); | |||
| afp v52 = buffer_ld1(top_tm_blob_data, v_tm_offset + 32 * psc(cstep) * c); | |||
| afp v53 = buffer_ld1(top_tm_blob_data, v_tm_offset + 33 * psc(cstep) * c); | |||
| afp v54 = buffer_ld1(top_tm_blob_data, v_tm_offset + 34 * psc(cstep) * c); | |||
| afp v55 = buffer_ld1(top_tm_blob_data, v_tm_offset + 35 * psc(cstep) * c); | |||
| #define sq2 1.41421356237 | |||
| #define sq2_m2 1.41421356237*2 | |||
| @@ -6,14 +6,13 @@ | |||
| #define LOCAL_MEMORY_UNROLL_INCH 8 | |||
| layout (constant_id = 0) const int batch = 1; | |||
| layout (constant_id = 1) const int c = 0; | |||
| layout (constant_id = 2) const int outc = 0; | |||
| #define shape_constant_id_offset 1 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outc = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outcstep = 0; | |||
| #define shape_constant_id_offset 3 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outcstep = 0; | |||
| layout (binding = 0) readonly buffer bottom_tm_blob { sfp bottom_tm_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer top_tm_blob { sfp top_tm_blob_data[]; }; | |||
| @@ -21,11 +20,8 @@ layout (binding = 2) readonly buffer weight_tm_blob { sfp weight_tm_data[]; }; | |||
| layout (push_constant) uniform parameter | |||
| { | |||
| int c; | |||
| int cstep; | |||
| int outw; | |||
| int outc; | |||
| int outcstep; | |||
| } p; | |||
| @@ -41,7 +37,7 @@ void main() | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| #if !NCNN_shader_local_memory | |||
| if (gx >= psc(outw) || gy >= psc(outc) || gz >= batch) | |||
| if (gx >= psc(outw) || gy >= outc || gz >= batch) | |||
| return; | |||
| #endif | |||
| @@ -50,21 +46,21 @@ void main() | |||
| afp sum2 = afp(0.f); | |||
| afp sum3 = afp(0.f); | |||
| int v_offset = gz * psc(cstep) + gx; | |||
| int w_offset = gz * psc(c) * psc(outc) + gy * psc(c); | |||
| int v_offset = gz * c * psc(cstep) + gx; | |||
| int w_offset = gz * c * outc + gy * c; | |||
| #if NCNN_shader_local_memory | |||
| const int lx = int(gl_LocalInvocationID.x); | |||
| const int ly = int(gl_LocalInvocationID.y); | |||
| int z = 0; | |||
| for (; z + (LOCAL_MEMORY_UNROLL_INCH - 1) < psc(c); z += LOCAL_MEMORY_UNROLL_INCH) | |||
| for (; z + (LOCAL_MEMORY_UNROLL_INCH - 1) < c; z += LOCAL_MEMORY_UNROLL_INCH) | |||
| { | |||
| if (ly < 4) | |||
| { | |||
| for (int z4 = 0; z4 < LOCAL_MEMORY_UNROLL_INCH; z4++) | |||
| { | |||
| tmp_v[lx][z4][ly] = sfp2lfp(buffer_ld1(bottom_tm_blob_data, v_offset + z4 * psc(outw) + ly)); | |||
| tmp_v[lx][z4][ly] = sfp2lfp(buffer_ld1(bottom_tm_blob_data, v_offset + z4 * psc(cstep) + ly)); | |||
| } | |||
| } | |||
| @@ -93,21 +89,21 @@ void main() | |||
| sum3 += v3 * k; | |||
| } | |||
| v_offset += LOCAL_MEMORY_UNROLL_INCH * psc(outw); | |||
| v_offset += LOCAL_MEMORY_UNROLL_INCH * psc(cstep); | |||
| w_offset += LOCAL_MEMORY_UNROLL_INCH; | |||
| barrier(); | |||
| } | |||
| if (z < psc(c)) | |||
| if (z < c) | |||
| { | |||
| const int remain = psc(c) - z; | |||
| const int remain = c - z; | |||
| if (ly < 4) | |||
| { | |||
| for (int z4 = 0; z4 < remain; z4++) | |||
| { | |||
| tmp_v[lx][z4][ly] = sfp2lfp(buffer_ld1(bottom_tm_blob_data, v_offset + z4 * psc(outw) + ly)); | |||
| tmp_v[lx][z4][ly] = sfp2lfp(buffer_ld1(bottom_tm_blob_data, v_offset + z4 * psc(cstep) + ly)); | |||
| } | |||
| } | |||
| @@ -137,7 +133,7 @@ void main() | |||
| } | |||
| } | |||
| #else | |||
| for (int z = 0; z < psc(c); z++) | |||
| for (int z = 0; z < c; z++) | |||
| { | |||
| afp v0 = buffer_ld1(bottom_tm_blob_data, v_offset + 0); | |||
| afp v1 = buffer_ld1(bottom_tm_blob_data, v_offset + 1); | |||
| @@ -151,17 +147,17 @@ void main() | |||
| sum2 += v2 * k; | |||
| sum3 += v3 * k; | |||
| v_offset += psc(outw); | |||
| v_offset += psc(cstep); | |||
| w_offset += 1; | |||
| } | |||
| #endif | |||
| #if NCNN_shader_local_memory | |||
| if (gx >= psc(outw) || gy >= psc(outc) || gz >= batch) | |||
| if (gx >= psc(outw) || gy >= outc || gz >= batch) | |||
| return; | |||
| #endif | |||
| int gi = gz * psc(outcstep) + gy * psc(outw) + gx; | |||
| int gi = gz * outc * psc(outcstep) + gy * psc(outcstep) + gx; | |||
| buffer_st1(top_tm_blob_data, gi + 0, sum0); | |||
| if (gx + 1 < psc(outw)) buffer_st1(top_tm_blob_data, gi + 1, sum1); | |||
| @@ -385,8 +385,6 @@ void main() | |||
| { | |||
| if (elempack == 1) | |||
| { | |||
| const uint cstepd4 = psc(cstep) / 4; | |||
| const uint Md4_K_USGM_USGK = Md4 * K * UNROLL_SG_M * UNROLL_SG_K; | |||
| const uint Md4_K_USGM_USGK_d_subgroupsize = (Md4_K_USGM_USGK + (ncnn_subgroupSize * UNROLL_WG_N - 1)) / (ncnn_subgroupSize * UNROLL_WG_N); | |||
| [[unroll]] for (uint q = 0; q < Md4_K_USGM_USGK_d_subgroupsize; q++) | |||
| @@ -401,8 +399,6 @@ void main() | |||
| } | |||
| else // if (elempack == 4) | |||
| { | |||
| const uint inchd4 = inch / 4; | |||
| const uint Kd4_M_USGM_USGK = Kd4 * M * UNROLL_SG_M * UNROLL_SG_K; | |||
| const uint Kd4_M_USGM_USGK_d_subgroupsize = (Kd4_M_USGM_USGK + (ncnn_subgroupSize * UNROLL_WG_N - 1)) / (ncnn_subgroupSize * UNROLL_WG_N); | |||
| [[unroll]] for (uint q = 0; q < Kd4_M_USGM_USGK_d_subgroupsize; q++) | |||
| @@ -419,11 +415,7 @@ void main() | |||
| // load weight | |||
| { | |||
| const uint Nd4_K_USGN = Nd4 * K * UNROLL_SG_N; | |||
| const uint Nd4_K_USGN_USGK = Nd4 * K * UNROLL_SG_N * UNROLL_SG_K; | |||
| const uint w_offset = ((wgni * kk) * UNROLL_WG_N) * Nd4_K_USGN + ((k / UNROLL_SG_K) * UNROLL_WG_N + sgni) * Nd4_K_USGN_USGK; | |||
| const uint Nd4_K_USGN_USGK_d_subgroupsize = (Nd4_K_USGN_USGK + (ncnn_subgroupSize * UNROLL_WG_M - 1)) / (ncnn_subgroupSize * UNROLL_WG_M); | |||
| [[unroll]] for (uint q = 0; q < Nd4_K_USGN_USGK_d_subgroupsize; q++) | |||
| { | |||
| @@ -629,29 +621,29 @@ void main() | |||
| { | |||
| if (elempack == 1) | |||
| { | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| coopMatLoad(A[zm], tmp_v[sgmi], (zk * UNROLL_SG_M + zm) * (Md4 * K), Md4, gl_CooperativeMatrixLayoutColumnMajor); | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| coopMatLoadNV(A[zm], tmp_v[sgmi], (zk * UNROLL_SG_M + zm) * (Md4 * K), Md4, true); | |||
| #endif | |||
| #endif | |||
| } | |||
| else // if (elempack == 4) | |||
| { | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| coopMatLoad(A[zm], tmp_v[sgmi], (zk * UNROLL_SG_M + zm) * (Kd4 * M), Kd4, gl_CooperativeMatrixLayoutRowMajor); | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| coopMatLoadNV(A[zm], tmp_v[sgmi], (zk * UNROLL_SG_M + zm) * (Kd4 * M), Kd4, false); | |||
| #endif | |||
| #endif | |||
| } | |||
| } | |||
| [[unroll]] for (uint zn = 0; zn < UNROLL_SG_N; zn++) | |||
| { | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| coopMatLoad(B[zn], tmp_k[sgni], (zk * UNROLL_SG_N + zn) * (Nd4 * K), Nd4, gl_CooperativeMatrixLayoutRowMajor); | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| coopMatLoadNV(B[zn], tmp_k[sgni], (zk * UNROLL_SG_N + zn) * (Nd4 * K), Nd4, false); | |||
| #endif | |||
| #endif | |||
| } | |||
| // sum += k * v | |||
| @@ -659,11 +651,11 @@ void main() | |||
| { | |||
| [[unroll]] for (uint zm = 0; zm < UNROLL_SG_M; zm++) | |||
| { | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| sum[zn][zm] = coopMatMulAdd(A[zm], B[zn], sum[zn][zm]); | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| sum[zn][zm] = coopMatMulAddNV(A[zm], B[zn], sum[zn][zm]); | |||
| #endif | |||
| #endif | |||
| } | |||
| } | |||
| } | |||
| @@ -691,8 +683,6 @@ void main() | |||
| } | |||
| else // if (elempack == 4) | |||
| { | |||
| const uint inchd4 = inch / 4; | |||
| const uint Kd4_M_USGM_USGK = Kd4 * M * UNROLL_SG_M * UNROLL_SG_K; | |||
| const uint Kd4_M_USGM_USGK_d_subgroupsize = (Kd4_M_USGM_USGK + (ncnn_subgroupSize * UNROLL_WG_N - 1)) / (ncnn_subgroupSize * UNROLL_WG_N); | |||
| [[unroll]] for (uint q = 0; q < Kd4_M_USGM_USGK_d_subgroupsize; q++) | |||
| @@ -709,11 +699,7 @@ void main() | |||
| // load weight | |||
| { | |||
| const uint Nd4_K_USGN = Nd4 * K * UNROLL_SG_N; | |||
| const uint Nd4_K_USGN_USGK = Nd4 * K * UNROLL_SG_N * UNROLL_SG_K; | |||
| const uint w_offset = ((wgni * kk) * UNROLL_WG_N) * Nd4_K_USGN + ((k / UNROLL_SG_K) * UNROLL_WG_N + sgni) * Nd4_K_USGN_USGK; | |||
| const uint Nd4_K_USGN_USGK_d_subgroupsize = (Nd4_K_USGN_USGK + (ncnn_subgroupSize * UNROLL_WG_M - 1)) / (ncnn_subgroupSize * UNROLL_WG_M); | |||
| [[unroll]] for (uint q = 0; q < Nd4_K_USGN_USGK_d_subgroupsize; q++) | |||
| { | |||
| @@ -6,14 +6,13 @@ | |||
| #define LOCAL_MEMORY_UNROLL_INCH 8 | |||
| layout (constant_id = 0) const int batch = 1; | |||
| layout (constant_id = 1) const int c = 0; | |||
| layout (constant_id = 2) const int outc = 0; | |||
| #define shape_constant_id_offset 1 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outc = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outcstep = 0; | |||
| #define shape_constant_id_offset 3 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outcstep = 0; | |||
| layout (binding = 0) readonly buffer bottom_tm_blob { sfp bottom_tm_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer top_tm_blob { sfpvec4 top_tm_blob_data[]; }; | |||
| @@ -21,11 +20,8 @@ layout (binding = 2) readonly buffer weight_tm_blob { sfpvec4 weight_tm_data[]; | |||
| layout (push_constant) uniform parameter | |||
| { | |||
| int c; | |||
| int cstep; | |||
| int outw; | |||
| int outc; | |||
| int outcstep; | |||
| } p; | |||
| @@ -41,7 +37,7 @@ void main() | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| #if !NCNN_shader_local_memory | |||
| if (gx >= psc(outw) || gy >= psc(outc) || gz >= batch) | |||
| if (gx >= psc(outw) || gy >= outc || gz >= batch) | |||
| return; | |||
| #endif | |||
| @@ -50,21 +46,21 @@ void main() | |||
| afpvec4 sum2 = afpvec4(0.f); | |||
| afpvec4 sum3 = afpvec4(0.f); | |||
| int v_offset = gz * psc(cstep) + gx; | |||
| int w_offset = gz * psc(c) * psc(outc) + gy * psc(c); | |||
| int v_offset = gz * c * psc(cstep) + gx; | |||
| int w_offset = gz * c * outc + gy * c; | |||
| #if NCNN_shader_local_memory | |||
| const int lx = int(gl_LocalInvocationID.x); | |||
| const int ly = int(gl_LocalInvocationID.y); | |||
| int z = 0; | |||
| for (; z + (LOCAL_MEMORY_UNROLL_INCH - 1) < psc(c); z += LOCAL_MEMORY_UNROLL_INCH) | |||
| for (; z + (LOCAL_MEMORY_UNROLL_INCH - 1) < c; z += LOCAL_MEMORY_UNROLL_INCH) | |||
| { | |||
| if (ly < 4) | |||
| { | |||
| for (int z4 = 0; z4 < LOCAL_MEMORY_UNROLL_INCH; z4++) | |||
| { | |||
| tmp_v[lx][z4][ly] = sfp2lfp(buffer_ld1(bottom_tm_blob_data, v_offset + z4 * psc(outw) + ly)); | |||
| tmp_v[lx][z4][ly] = sfp2lfp(buffer_ld1(bottom_tm_blob_data, v_offset + z4 * psc(cstep) + ly)); | |||
| } | |||
| } | |||
| @@ -93,21 +89,21 @@ void main() | |||
| sum3 += v3 * k; | |||
| } | |||
| v_offset += LOCAL_MEMORY_UNROLL_INCH * psc(outw); | |||
| v_offset += LOCAL_MEMORY_UNROLL_INCH * psc(cstep); | |||
| w_offset += LOCAL_MEMORY_UNROLL_INCH; | |||
| barrier(); | |||
| } | |||
| if (z < psc(c)) | |||
| if (z < c) | |||
| { | |||
| const int remain = psc(c) - z; | |||
| const int remain = c - z; | |||
| if (ly < 4) | |||
| { | |||
| for (int z4 = 0; z4 < remain; z4++) | |||
| { | |||
| tmp_v[lx][z4][ly] = sfp2lfp(buffer_ld1(bottom_tm_blob_data, v_offset + z4 * psc(outw) + ly)); | |||
| tmp_v[lx][z4][ly] = sfp2lfp(buffer_ld1(bottom_tm_blob_data, v_offset + z4 * psc(cstep) + ly)); | |||
| } | |||
| } | |||
| @@ -137,7 +133,7 @@ void main() | |||
| } | |||
| } | |||
| #else | |||
| for (int z = 0; z < psc(c); z++) | |||
| for (int z = 0; z < c; z++) | |||
| { | |||
| afp v0 = buffer_ld1(bottom_tm_blob_data, v_offset + 0); | |||
| afp v1 = buffer_ld1(bottom_tm_blob_data, v_offset + 1); | |||
| @@ -151,17 +147,17 @@ void main() | |||
| sum2 += v2 * k; | |||
| sum3 += v3 * k; | |||
| v_offset += psc(outw); | |||
| v_offset += psc(cstep); | |||
| w_offset += 1; | |||
| } | |||
| #endif | |||
| #if NCNN_shader_local_memory | |||
| if (gx >= psc(outw) || gy >= psc(outc) || gz >= batch) | |||
| if (gx >= psc(outw) || gy >= outc || gz >= batch) | |||
| return; | |||
| #endif | |||
| int gi = gz * psc(outcstep) + gy * psc(outw) + gx; | |||
| int gi = gz * outc * psc(outcstep) + gy * psc(outcstep) + gx; | |||
| buffer_st4(top_tm_blob_data, gi + 0, sum0); | |||
| if (gx + 1 < psc(outw)) buffer_st4(top_tm_blob_data, gi + 1, sum1); | |||
| @@ -4,14 +4,13 @@ | |||
| #version 450 | |||
| layout (constant_id = 0) const int batch = 1; | |||
| layout (constant_id = 1) const int c = 0; | |||
| layout (constant_id = 2) const int outc = 0; | |||
| #define shape_constant_id_offset 1 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outc = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outcstep = 0; | |||
| #define shape_constant_id_offset 3 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outcstep = 0; | |||
| layout (binding = 0) readonly buffer bottom_tm_blob { sfp bottom_tm_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer top_tm_blob { sfpvec8 top_tm_blob_data[]; }; | |||
| @@ -19,11 +18,8 @@ layout (binding = 2) readonly buffer weight_tm_blob { sfpvec8 weight_tm_data[]; | |||
| layout (push_constant) uniform parameter | |||
| { | |||
| int c; | |||
| int cstep; | |||
| int outw; | |||
| int outc; | |||
| int outcstep; | |||
| } p; | |||
| @@ -33,7 +29,7 @@ void main() | |||
| int gy = int(gl_GlobalInvocationID.y); | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| if (gx >= psc(outw) || gy >= psc(outc) || gz >= batch) | |||
| if (gx >= psc(outw) || gy >= outc || gz >= batch) | |||
| return; | |||
| afpvec8 sum0 = afpvec8(afpvec4(0.f), afpvec4(0.f)); | |||
| @@ -41,10 +37,10 @@ void main() | |||
| afpvec8 sum2 = afpvec8(afpvec4(0.f), afpvec4(0.f)); | |||
| afpvec8 sum3 = afpvec8(afpvec4(0.f), afpvec4(0.f)); | |||
| int v_offset = gz * psc(cstep) + gx; | |||
| int w_offset = gz * psc(c) * psc(outc) + gy * psc(c); | |||
| int v_offset = gz * c * psc(cstep) + gx; | |||
| int w_offset = gz * c * outc + gy * c; | |||
| for (int z = 0; z < psc(c); z++) | |||
| for (int z = 0; z < c; z++) | |||
| { | |||
| afp v0 = buffer_ld1(bottom_tm_blob_data, v_offset + 0); | |||
| afp v1 = buffer_ld1(bottom_tm_blob_data, v_offset + 1); | |||
| @@ -66,11 +62,11 @@ void main() | |||
| sum3[0] += v3 * k[0]; | |||
| sum3[1] += v3 * k[1]; | |||
| v_offset += psc(outw); | |||
| v_offset += psc(cstep); | |||
| w_offset += 1; | |||
| } | |||
| int gi = gz * psc(outcstep) + gy * psc(outw) + gx; | |||
| int gi = gz * outc * psc(outcstep) + gy * psc(outcstep) + gx; | |||
| buffer_st8(top_tm_blob_data, gi + 0, sum0); | |||
| if (gx + 1 < psc(outw)) buffer_st8(top_tm_blob_data, gi + 1, sum1); | |||
| @@ -3,16 +3,17 @@ | |||
| #version 450 | |||
| #define shape_constant_id_offset 0 | |||
| layout (constant_id = 0) const int c = 0; | |||
| #define shape_constant_id_offset 1 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int w = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int h = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outcstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outcstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 6) const int block_y = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int block_y = 0; | |||
| layout (binding = 0) readonly buffer bottom_blob { sfpvec4 bottom_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer bottom_tm_blob { sfpvec4 bottom_tm_blob_data[]; }; | |||
| @@ -21,7 +22,6 @@ layout (push_constant) uniform parameter | |||
| { | |||
| int w; | |||
| int h; | |||
| int c; | |||
| int cstep; | |||
| int outcstep; | |||
| @@ -36,7 +36,7 @@ void main() | |||
| int gy = int(gl_GlobalInvocationID.y); | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= psc(c)) | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= c) | |||
| return; | |||
| // load 4x4 | |||
| @@ -115,22 +115,22 @@ void main() | |||
| v33 = m33 - m31; | |||
| // store 16 | |||
| int v_tm_offset = gz * psc(block_x) * psc(block_y) + gy * psc(block_x) + gx; | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 0 * psc(outcstep), v00); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 1 * psc(outcstep), v01); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 2 * psc(outcstep), v02); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 3 * psc(outcstep), v03); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 4 * psc(outcstep), v10); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 5 * psc(outcstep), v11); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 6 * psc(outcstep), v12); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 7 * psc(outcstep), v13); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 8 * psc(outcstep), v20); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 9 * psc(outcstep), v21); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 10 * psc(outcstep), v22); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 11 * psc(outcstep), v23); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 12 * psc(outcstep), v30); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 13 * psc(outcstep), v31); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 14 * psc(outcstep), v32); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 15 * psc(outcstep), v33); | |||
| int v_tm_offset = gz * psc(outcstep) + gy * psc(block_x) + gx; | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 0 * psc(outcstep) * c, v00); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 1 * psc(outcstep) * c, v01); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 2 * psc(outcstep) * c, v02); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 3 * psc(outcstep) * c, v03); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 4 * psc(outcstep) * c, v10); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 5 * psc(outcstep) * c, v11); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 6 * psc(outcstep) * c, v12); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 7 * psc(outcstep) * c, v13); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 8 * psc(outcstep) * c, v20); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 9 * psc(outcstep) * c, v21); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 10 * psc(outcstep) * c, v22); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 11 * psc(outcstep) * c, v23); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 12 * psc(outcstep) * c, v30); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 13 * psc(outcstep) * c, v31); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 14 * psc(outcstep) * c, v32); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 15 * psc(outcstep) * c, v33); | |||
| } | |||
| @@ -10,17 +10,17 @@ layout (constant_id = 0) const int bias_term = 0; | |||
| layout (constant_id = 1) const int activation_type = 0; | |||
| layout (constant_id = 2) const float activation_param_0 = 0; | |||
| layout (constant_id = 3) const float activation_param_1 = 0; | |||
| layout (constant_id = 4) const int c = 0; | |||
| #define shape_constant_id_offset 4 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int cstep = 0; | |||
| #define shape_constant_id_offset 5 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int block_y = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int block_y = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int outh = 0; | |||
| layout (constant_id = shape_constant_id_offset + 6) const int outcstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outh = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int outcstep = 0; | |||
| layout (binding = 0) readonly buffer top_tm_blob { sfpvec4 top_tm_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer top_blob { sfpvec4 top_blob_data[]; }; | |||
| @@ -28,7 +28,6 @@ layout (binding = 2) readonly buffer bias_blob { sfpvec4 bias_data[]; }; | |||
| layout (push_constant) uniform parameter | |||
| { | |||
| int c; | |||
| int cstep; | |||
| int block_x; | |||
| @@ -45,28 +44,28 @@ void main() | |||
| int gy = int(gl_GlobalInvocationID.y); | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= psc(c)) | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= c) | |||
| return; | |||
| // load 16 | |||
| int v_tm_offset = gz * psc(block_x) * psc(block_y) + gy * psc(block_x) + gx; | |||
| afpvec4 v00 = buffer_ld4(top_tm_blob_data, v_tm_offset + 0 * psc(cstep)); | |||
| afpvec4 v01 = buffer_ld4(top_tm_blob_data, v_tm_offset + 1 * psc(cstep)); | |||
| afpvec4 v02 = buffer_ld4(top_tm_blob_data, v_tm_offset + 2 * psc(cstep)); | |||
| afpvec4 v03 = buffer_ld4(top_tm_blob_data, v_tm_offset + 3 * psc(cstep)); | |||
| afpvec4 v10 = buffer_ld4(top_tm_blob_data, v_tm_offset + 4 * psc(cstep)); | |||
| afpvec4 v11 = buffer_ld4(top_tm_blob_data, v_tm_offset + 5 * psc(cstep)); | |||
| afpvec4 v12 = buffer_ld4(top_tm_blob_data, v_tm_offset + 6 * psc(cstep)); | |||
| afpvec4 v13 = buffer_ld4(top_tm_blob_data, v_tm_offset + 7 * psc(cstep)); | |||
| afpvec4 v20 = buffer_ld4(top_tm_blob_data, v_tm_offset + 8 * psc(cstep)); | |||
| afpvec4 v21 = buffer_ld4(top_tm_blob_data, v_tm_offset + 9 * psc(cstep)); | |||
| afpvec4 v22 = buffer_ld4(top_tm_blob_data, v_tm_offset + 10 * psc(cstep)); | |||
| afpvec4 v23 = buffer_ld4(top_tm_blob_data, v_tm_offset + 11 * psc(cstep)); | |||
| afpvec4 v30 = buffer_ld4(top_tm_blob_data, v_tm_offset + 12 * psc(cstep)); | |||
| afpvec4 v31 = buffer_ld4(top_tm_blob_data, v_tm_offset + 13 * psc(cstep)); | |||
| afpvec4 v32 = buffer_ld4(top_tm_blob_data, v_tm_offset + 14 * psc(cstep)); | |||
| afpvec4 v33 = buffer_ld4(top_tm_blob_data, v_tm_offset + 15 * psc(cstep)); | |||
| int v_tm_offset = gz * psc(cstep) + gy * psc(block_x) + gx; | |||
| afpvec4 v00 = buffer_ld4(top_tm_blob_data, v_tm_offset + 0 * psc(cstep) * c); | |||
| afpvec4 v01 = buffer_ld4(top_tm_blob_data, v_tm_offset + 1 * psc(cstep) * c); | |||
| afpvec4 v02 = buffer_ld4(top_tm_blob_data, v_tm_offset + 2 * psc(cstep) * c); | |||
| afpvec4 v03 = buffer_ld4(top_tm_blob_data, v_tm_offset + 3 * psc(cstep) * c); | |||
| afpvec4 v10 = buffer_ld4(top_tm_blob_data, v_tm_offset + 4 * psc(cstep) * c); | |||
| afpvec4 v11 = buffer_ld4(top_tm_blob_data, v_tm_offset + 5 * psc(cstep) * c); | |||
| afpvec4 v12 = buffer_ld4(top_tm_blob_data, v_tm_offset + 6 * psc(cstep) * c); | |||
| afpvec4 v13 = buffer_ld4(top_tm_blob_data, v_tm_offset + 7 * psc(cstep) * c); | |||
| afpvec4 v20 = buffer_ld4(top_tm_blob_data, v_tm_offset + 8 * psc(cstep) * c); | |||
| afpvec4 v21 = buffer_ld4(top_tm_blob_data, v_tm_offset + 9 * psc(cstep) * c); | |||
| afpvec4 v22 = buffer_ld4(top_tm_blob_data, v_tm_offset + 10 * psc(cstep) * c); | |||
| afpvec4 v23 = buffer_ld4(top_tm_blob_data, v_tm_offset + 11 * psc(cstep) * c); | |||
| afpvec4 v30 = buffer_ld4(top_tm_blob_data, v_tm_offset + 12 * psc(cstep) * c); | |||
| afpvec4 v31 = buffer_ld4(top_tm_blob_data, v_tm_offset + 13 * psc(cstep) * c); | |||
| afpvec4 v32 = buffer_ld4(top_tm_blob_data, v_tm_offset + 14 * psc(cstep) * c); | |||
| afpvec4 v33 = buffer_ld4(top_tm_blob_data, v_tm_offset + 15 * psc(cstep) * c); | |||
| // const float itm[2][4] = { | |||
| // {1.0f, 1.0f, 1.0f, 0.0f}, | |||
| @@ -3,16 +3,17 @@ | |||
| #version 450 | |||
| #define shape_constant_id_offset 0 | |||
| layout (constant_id = 0) const int c = 0; | |||
| #define shape_constant_id_offset 1 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int w = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int h = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outcstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outcstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 6) const int block_y = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int block_y = 0; | |||
| layout (binding = 0) readonly buffer bottom_blob { sfpvec4 bottom_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer bottom_tm_blob { sfpvec4 bottom_tm_blob_data[]; }; | |||
| @@ -21,7 +22,6 @@ layout (push_constant) uniform parameter | |||
| { | |||
| int w; | |||
| int h; | |||
| int c; | |||
| int cstep; | |||
| int outcstep; | |||
| @@ -36,7 +36,7 @@ void main() | |||
| int gy = int(gl_GlobalInvocationID.y); | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= psc(c)) | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= c) | |||
| return; | |||
| // load 6x6 | |||
| @@ -187,42 +187,42 @@ void main() | |||
| v55 = m51 - m53 * afp(2.5) + m55; | |||
| // store 36 | |||
| int v_tm_offset = gz * psc(block_x) * psc(block_y) + gy * psc(block_x) + gx; | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 0 * psc(outcstep), v00); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 1 * psc(outcstep), v01); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 2 * psc(outcstep), v02); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 3 * psc(outcstep), v03); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 4 * psc(outcstep), v04); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 5 * psc(outcstep), v05); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 6 * psc(outcstep), v10); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 7 * psc(outcstep), v11); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 8 * psc(outcstep), v12); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 9 * psc(outcstep), v13); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 10 * psc(outcstep), v14); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 11 * psc(outcstep), v15); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 12 * psc(outcstep), v20); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 13 * psc(outcstep), v21); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 14 * psc(outcstep), v22); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 15 * psc(outcstep), v23); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 16 * psc(outcstep), v24); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 17 * psc(outcstep), v25); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 18 * psc(outcstep), v30); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 19 * psc(outcstep), v31); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 20 * psc(outcstep), v32); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 21 * psc(outcstep), v33); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 22 * psc(outcstep), v34); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 23 * psc(outcstep), v35); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 24 * psc(outcstep), v40); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 25 * psc(outcstep), v41); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 26 * psc(outcstep), v42); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 27 * psc(outcstep), v43); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 28 * psc(outcstep), v44); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 29 * psc(outcstep), v45); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 30 * psc(outcstep), v50); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 31 * psc(outcstep), v51); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 32 * psc(outcstep), v52); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 33 * psc(outcstep), v53); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 34 * psc(outcstep), v54); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 35 * psc(outcstep), v55); | |||
| int v_tm_offset = gz * psc(outcstep) + gy * psc(block_x) + gx; | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 0 * psc(outcstep) * c, v00); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 1 * psc(outcstep) * c, v01); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 2 * psc(outcstep) * c, v02); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 3 * psc(outcstep) * c, v03); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 4 * psc(outcstep) * c, v04); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 5 * psc(outcstep) * c, v05); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 6 * psc(outcstep) * c, v10); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 7 * psc(outcstep) * c, v11); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 8 * psc(outcstep) * c, v12); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 9 * psc(outcstep) * c, v13); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 10 * psc(outcstep) * c, v14); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 11 * psc(outcstep) * c, v15); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 12 * psc(outcstep) * c, v20); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 13 * psc(outcstep) * c, v21); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 14 * psc(outcstep) * c, v22); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 15 * psc(outcstep) * c, v23); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 16 * psc(outcstep) * c, v24); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 17 * psc(outcstep) * c, v25); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 18 * psc(outcstep) * c, v30); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 19 * psc(outcstep) * c, v31); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 20 * psc(outcstep) * c, v32); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 21 * psc(outcstep) * c, v33); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 22 * psc(outcstep) * c, v34); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 23 * psc(outcstep) * c, v35); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 24 * psc(outcstep) * c, v40); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 25 * psc(outcstep) * c, v41); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 26 * psc(outcstep) * c, v42); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 27 * psc(outcstep) * c, v43); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 28 * psc(outcstep) * c, v44); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 29 * psc(outcstep) * c, v45); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 30 * psc(outcstep) * c, v50); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 31 * psc(outcstep) * c, v51); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 32 * psc(outcstep) * c, v52); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 33 * psc(outcstep) * c, v53); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 34 * psc(outcstep) * c, v54); | |||
| buffer_st4(bottom_tm_blob_data, v_tm_offset + 35 * psc(outcstep) * c, v55); | |||
| } | |||
| @@ -10,17 +10,17 @@ layout (constant_id = 0) const int bias_term = 0; | |||
| layout (constant_id = 1) const int activation_type = 0; | |||
| layout (constant_id = 2) const float activation_param_0 = 0; | |||
| layout (constant_id = 3) const float activation_param_1 = 0; | |||
| layout (constant_id = 4) const int c = 0; | |||
| #define shape_constant_id_offset 4 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int cstep = 0; | |||
| #define shape_constant_id_offset 5 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int block_y = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int block_y = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int outh = 0; | |||
| layout (constant_id = shape_constant_id_offset + 6) const int outcstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outh = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int outcstep = 0; | |||
| layout (binding = 0) readonly buffer top_tm_blob { sfpvec4 top_tm_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer top_blob { sfpvec4 top_blob_data[]; }; | |||
| @@ -28,7 +28,6 @@ layout (binding = 2) readonly buffer bias_blob { sfpvec4 bias_data[]; }; | |||
| layout (push_constant) uniform parameter | |||
| { | |||
| int c; | |||
| int cstep; | |||
| int block_x; | |||
| @@ -45,48 +44,48 @@ void main() | |||
| int gy = int(gl_GlobalInvocationID.y); | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= psc(c)) | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= c) | |||
| return; | |||
| // load 36 | |||
| int v_tm_offset = gz * psc(block_x) * psc(block_y) + gy * psc(block_x) + gx; | |||
| afpvec4 v00 = buffer_ld4(top_tm_blob_data, v_tm_offset + 0 * psc(cstep)); | |||
| afpvec4 v01 = buffer_ld4(top_tm_blob_data, v_tm_offset + 1 * psc(cstep)); | |||
| afpvec4 v02 = buffer_ld4(top_tm_blob_data, v_tm_offset + 2 * psc(cstep)); | |||
| afpvec4 v03 = buffer_ld4(top_tm_blob_data, v_tm_offset + 3 * psc(cstep)); | |||
| afpvec4 v04 = buffer_ld4(top_tm_blob_data, v_tm_offset + 4 * psc(cstep)); | |||
| afpvec4 v05 = buffer_ld4(top_tm_blob_data, v_tm_offset + 5 * psc(cstep)); | |||
| afpvec4 v10 = buffer_ld4(top_tm_blob_data, v_tm_offset + 6 * psc(cstep)); | |||
| afpvec4 v11 = buffer_ld4(top_tm_blob_data, v_tm_offset + 7 * psc(cstep)); | |||
| afpvec4 v12 = buffer_ld4(top_tm_blob_data, v_tm_offset + 8 * psc(cstep)); | |||
| afpvec4 v13 = buffer_ld4(top_tm_blob_data, v_tm_offset + 9 * psc(cstep)); | |||
| afpvec4 v14 = buffer_ld4(top_tm_blob_data, v_tm_offset + 10 * psc(cstep)); | |||
| afpvec4 v15 = buffer_ld4(top_tm_blob_data, v_tm_offset + 11 * psc(cstep)); | |||
| afpvec4 v20 = buffer_ld4(top_tm_blob_data, v_tm_offset + 12 * psc(cstep)); | |||
| afpvec4 v21 = buffer_ld4(top_tm_blob_data, v_tm_offset + 13 * psc(cstep)); | |||
| afpvec4 v22 = buffer_ld4(top_tm_blob_data, v_tm_offset + 14 * psc(cstep)); | |||
| afpvec4 v23 = buffer_ld4(top_tm_blob_data, v_tm_offset + 15 * psc(cstep)); | |||
| afpvec4 v24 = buffer_ld4(top_tm_blob_data, v_tm_offset + 16 * psc(cstep)); | |||
| afpvec4 v25 = buffer_ld4(top_tm_blob_data, v_tm_offset + 17 * psc(cstep)); | |||
| afpvec4 v30 = buffer_ld4(top_tm_blob_data, v_tm_offset + 18 * psc(cstep)); | |||
| afpvec4 v31 = buffer_ld4(top_tm_blob_data, v_tm_offset + 19 * psc(cstep)); | |||
| afpvec4 v32 = buffer_ld4(top_tm_blob_data, v_tm_offset + 20 * psc(cstep)); | |||
| afpvec4 v33 = buffer_ld4(top_tm_blob_data, v_tm_offset + 21 * psc(cstep)); | |||
| afpvec4 v34 = buffer_ld4(top_tm_blob_data, v_tm_offset + 22 * psc(cstep)); | |||
| afpvec4 v35 = buffer_ld4(top_tm_blob_data, v_tm_offset + 23 * psc(cstep)); | |||
| afpvec4 v40 = buffer_ld4(top_tm_blob_data, v_tm_offset + 24 * psc(cstep)); | |||
| afpvec4 v41 = buffer_ld4(top_tm_blob_data, v_tm_offset + 25 * psc(cstep)); | |||
| afpvec4 v42 = buffer_ld4(top_tm_blob_data, v_tm_offset + 26 * psc(cstep)); | |||
| afpvec4 v43 = buffer_ld4(top_tm_blob_data, v_tm_offset + 27 * psc(cstep)); | |||
| afpvec4 v44 = buffer_ld4(top_tm_blob_data, v_tm_offset + 28 * psc(cstep)); | |||
| afpvec4 v45 = buffer_ld4(top_tm_blob_data, v_tm_offset + 29 * psc(cstep)); | |||
| afpvec4 v50 = buffer_ld4(top_tm_blob_data, v_tm_offset + 30 * psc(cstep)); | |||
| afpvec4 v51 = buffer_ld4(top_tm_blob_data, v_tm_offset + 31 * psc(cstep)); | |||
| afpvec4 v52 = buffer_ld4(top_tm_blob_data, v_tm_offset + 32 * psc(cstep)); | |||
| afpvec4 v53 = buffer_ld4(top_tm_blob_data, v_tm_offset + 33 * psc(cstep)); | |||
| afpvec4 v54 = buffer_ld4(top_tm_blob_data, v_tm_offset + 34 * psc(cstep)); | |||
| afpvec4 v55 = buffer_ld4(top_tm_blob_data, v_tm_offset + 35 * psc(cstep)); | |||
| int v_tm_offset = gz * psc(cstep) + gy * psc(block_x) + gx; | |||
| afpvec4 v00 = buffer_ld4(top_tm_blob_data, v_tm_offset + 0 * psc(cstep) * c); | |||
| afpvec4 v01 = buffer_ld4(top_tm_blob_data, v_tm_offset + 1 * psc(cstep) * c); | |||
| afpvec4 v02 = buffer_ld4(top_tm_blob_data, v_tm_offset + 2 * psc(cstep) * c); | |||
| afpvec4 v03 = buffer_ld4(top_tm_blob_data, v_tm_offset + 3 * psc(cstep) * c); | |||
| afpvec4 v04 = buffer_ld4(top_tm_blob_data, v_tm_offset + 4 * psc(cstep) * c); | |||
| afpvec4 v05 = buffer_ld4(top_tm_blob_data, v_tm_offset + 5 * psc(cstep) * c); | |||
| afpvec4 v10 = buffer_ld4(top_tm_blob_data, v_tm_offset + 6 * psc(cstep) * c); | |||
| afpvec4 v11 = buffer_ld4(top_tm_blob_data, v_tm_offset + 7 * psc(cstep) * c); | |||
| afpvec4 v12 = buffer_ld4(top_tm_blob_data, v_tm_offset + 8 * psc(cstep) * c); | |||
| afpvec4 v13 = buffer_ld4(top_tm_blob_data, v_tm_offset + 9 * psc(cstep) * c); | |||
| afpvec4 v14 = buffer_ld4(top_tm_blob_data, v_tm_offset + 10 * psc(cstep) * c); | |||
| afpvec4 v15 = buffer_ld4(top_tm_blob_data, v_tm_offset + 11 * psc(cstep) * c); | |||
| afpvec4 v20 = buffer_ld4(top_tm_blob_data, v_tm_offset + 12 * psc(cstep) * c); | |||
| afpvec4 v21 = buffer_ld4(top_tm_blob_data, v_tm_offset + 13 * psc(cstep) * c); | |||
| afpvec4 v22 = buffer_ld4(top_tm_blob_data, v_tm_offset + 14 * psc(cstep) * c); | |||
| afpvec4 v23 = buffer_ld4(top_tm_blob_data, v_tm_offset + 15 * psc(cstep) * c); | |||
| afpvec4 v24 = buffer_ld4(top_tm_blob_data, v_tm_offset + 16 * psc(cstep) * c); | |||
| afpvec4 v25 = buffer_ld4(top_tm_blob_data, v_tm_offset + 17 * psc(cstep) * c); | |||
| afpvec4 v30 = buffer_ld4(top_tm_blob_data, v_tm_offset + 18 * psc(cstep) * c); | |||
| afpvec4 v31 = buffer_ld4(top_tm_blob_data, v_tm_offset + 19 * psc(cstep) * c); | |||
| afpvec4 v32 = buffer_ld4(top_tm_blob_data, v_tm_offset + 20 * psc(cstep) * c); | |||
| afpvec4 v33 = buffer_ld4(top_tm_blob_data, v_tm_offset + 21 * psc(cstep) * c); | |||
| afpvec4 v34 = buffer_ld4(top_tm_blob_data, v_tm_offset + 22 * psc(cstep) * c); | |||
| afpvec4 v35 = buffer_ld4(top_tm_blob_data, v_tm_offset + 23 * psc(cstep) * c); | |||
| afpvec4 v40 = buffer_ld4(top_tm_blob_data, v_tm_offset + 24 * psc(cstep) * c); | |||
| afpvec4 v41 = buffer_ld4(top_tm_blob_data, v_tm_offset + 25 * psc(cstep) * c); | |||
| afpvec4 v42 = buffer_ld4(top_tm_blob_data, v_tm_offset + 26 * psc(cstep) * c); | |||
| afpvec4 v43 = buffer_ld4(top_tm_blob_data, v_tm_offset + 27 * psc(cstep) * c); | |||
| afpvec4 v44 = buffer_ld4(top_tm_blob_data, v_tm_offset + 28 * psc(cstep) * c); | |||
| afpvec4 v45 = buffer_ld4(top_tm_blob_data, v_tm_offset + 29 * psc(cstep) * c); | |||
| afpvec4 v50 = buffer_ld4(top_tm_blob_data, v_tm_offset + 30 * psc(cstep) * c); | |||
| afpvec4 v51 = buffer_ld4(top_tm_blob_data, v_tm_offset + 31 * psc(cstep) * c); | |||
| afpvec4 v52 = buffer_ld4(top_tm_blob_data, v_tm_offset + 32 * psc(cstep) * c); | |||
| afpvec4 v53 = buffer_ld4(top_tm_blob_data, v_tm_offset + 33 * psc(cstep) * c); | |||
| afpvec4 v54 = buffer_ld4(top_tm_blob_data, v_tm_offset + 34 * psc(cstep) * c); | |||
| afpvec4 v55 = buffer_ld4(top_tm_blob_data, v_tm_offset + 35 * psc(cstep) * c); | |||
| #define sq2 1.41421356237 | |||
| #define sq2_m2 1.41421356237*2 | |||
| @@ -6,14 +6,13 @@ | |||
| #define LOCAL_MEMORY_UNROLL_INCH 8 | |||
| layout (constant_id = 0) const int batch = 1; | |||
| layout (constant_id = 1) const int c = 0; | |||
| layout (constant_id = 2) const int outc = 0; | |||
| #define shape_constant_id_offset 1 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outc = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outcstep = 0; | |||
| #define shape_constant_id_offset 3 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outcstep = 0; | |||
| layout (binding = 0) readonly buffer bottom_tm_blob { sfpvec4 bottom_tm_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer top_tm_blob { sfpvec4 top_tm_blob_data[]; }; | |||
| @@ -21,11 +20,8 @@ layout (binding = 2) readonly buffer weight_tm_blob { sfpvec4 weight_tm_data[]; | |||
| layout (push_constant) uniform parameter | |||
| { | |||
| int c; | |||
| int cstep; | |||
| int outw; | |||
| int outc; | |||
| int outcstep; | |||
| } p; | |||
| @@ -41,7 +37,7 @@ void main() | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| #if !NCNN_shader_local_memory | |||
| if (gx >= psc(outw) || gy >= psc(outc) || gz >= batch) | |||
| if (gx >= psc(outw) || gy >= outc || gz >= batch) | |||
| return; | |||
| #endif | |||
| @@ -50,21 +46,21 @@ void main() | |||
| afpvec4 sum2 = afpvec4(0.f); | |||
| afpvec4 sum3 = afpvec4(0.f); | |||
| int v_offset = gz * psc(cstep) + gx; | |||
| int w_offset = (gz * psc(c) * psc(outc) + gy * psc(c)) * 4; | |||
| int v_offset = gz * c * psc(cstep) + gx; | |||
| int w_offset = (gz * c * outc + gy * c) * 4; | |||
| #if NCNN_shader_local_memory | |||
| const int lx = int(gl_LocalInvocationID.x); | |||
| const int ly = int(gl_LocalInvocationID.y); | |||
| int z = 0; | |||
| for (; z + (LOCAL_MEMORY_UNROLL_INCH - 1) < psc(c); z += LOCAL_MEMORY_UNROLL_INCH) | |||
| for (; z + (LOCAL_MEMORY_UNROLL_INCH - 1) < c; z += LOCAL_MEMORY_UNROLL_INCH) | |||
| { | |||
| if (ly < 4) | |||
| { | |||
| for (int z4 = 0; z4 < LOCAL_MEMORY_UNROLL_INCH; z4++) | |||
| { | |||
| tmp_v[lx][z4][ly] = sfp2lfpvec4(bottom_tm_blob_data[v_offset + z4 * psc(outw) + ly]); | |||
| tmp_v[lx][z4][ly] = sfp2lfpvec4(bottom_tm_blob_data[v_offset + z4 * psc(cstep) + ly]); | |||
| } | |||
| } | |||
| @@ -98,21 +94,21 @@ void main() | |||
| sum3 += v3 * k; | |||
| } | |||
| v_offset += LOCAL_MEMORY_UNROLL_INCH * psc(outw); | |||
| v_offset += LOCAL_MEMORY_UNROLL_INCH * psc(cstep); | |||
| w_offset += LOCAL_MEMORY_UNROLL_INCH * 4; | |||
| barrier(); | |||
| } | |||
| if (z < psc(c)) | |||
| if (z < c) | |||
| { | |||
| const int remain = psc(c) - z; | |||
| const int remain = c - z; | |||
| if (ly < 4) | |||
| { | |||
| for (int z4 = 0; z4 < remain; z4++) | |||
| { | |||
| tmp_v[lx][z4][ly] = sfp2lfpvec4(bottom_tm_blob_data[v_offset + z4 * psc(outw) + ly]); | |||
| tmp_v[lx][z4][ly] = sfp2lfpvec4(bottom_tm_blob_data[v_offset + z4 * psc(cstep) + ly]); | |||
| } | |||
| } | |||
| @@ -147,7 +143,7 @@ void main() | |||
| } | |||
| } | |||
| #else | |||
| for (int z = 0; z < psc(c); z++) | |||
| for (int z = 0; z < c; z++) | |||
| { | |||
| afpvec4 v0 = buffer_ld4(bottom_tm_blob_data, v_offset + 0); | |||
| afpvec4 v1 = buffer_ld4(bottom_tm_blob_data, v_offset + 1); | |||
| @@ -166,17 +162,17 @@ void main() | |||
| sum2 += v2 * k; | |||
| sum3 += v3 * k; | |||
| v_offset += psc(outw); | |||
| v_offset += psc(cstep); | |||
| w_offset += 4; | |||
| } | |||
| #endif | |||
| #if NCNN_shader_local_memory | |||
| if (gx >= psc(outw) || gy >= psc(outc) || gz >= batch) | |||
| if (gx >= psc(outw) || gy >= outc || gz >= batch) | |||
| return; | |||
| #endif | |||
| int gi = gz * psc(outcstep) + gy * psc(outw) + gx; | |||
| int gi = gz * outc * psc(outcstep) + gy * psc(outcstep) + gx; | |||
| buffer_st4(top_tm_blob_data, gi + 0, sum0); | |||
| if (gx + 1 < psc(outw)) buffer_st4(top_tm_blob_data, gi + 1, sum1); | |||
| @@ -1,258 +0,0 @@ | |||
| // Copyright 2023 Tencent | |||
| // SPDX-License-Identifier: BSD-3-Clause | |||
| #version 450 | |||
| #extension GL_KHR_memory_scope_semantics: require | |||
| #extension GL_EXT_shader_explicit_arithmetic_types: require | |||
| #extension GL_EXT_shader_explicit_arithmetic_types_float16: require | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| #extension GL_KHR_cooperative_matrix: require | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| #extension GL_NV_cooperative_matrix: require | |||
| #endif | |||
| layout (constant_id = 0) const int batch = 1; | |||
| #define shape_constant_id_offset 1 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outc = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outcstep = 0; | |||
| layout (binding = 0) readonly buffer bottom_tm_blob { uvec2 bottom_tm_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer top_tm_blob { uvec2 top_tm_blob_data[]; }; | |||
| layout (binding = 2) readonly buffer weight_tm_blob { uvec2 weight_tm_data[]; }; | |||
| layout (push_constant) uniform parameter | |||
| { | |||
| int c; | |||
| int cstep; | |||
| int outw; | |||
| int outc; | |||
| int outcstep; | |||
| } p; | |||
| #define UNROLL_INCH 2 | |||
| shared uvec2 tmp_v0[UNROLL_INCH * 16*4]; | |||
| shared uvec2 tmp_v1[UNROLL_INCH * 16*4]; | |||
| shared uvec2 tmp_k0[UNROLL_INCH * 16*4]; | |||
| shared uvec2 tmp_k1[UNROLL_INCH * 16*4]; | |||
| void main() | |||
| { | |||
| int gx = int(gl_GlobalInvocationID.x) / 32 * 2 * 16; | |||
| int gy = int(gl_GlobalInvocationID.y) * 2 * 4; | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| const int lx = int(gl_LocalInvocationID.x); | |||
| const int lxd16 = lx / 16; // 0 1 | |||
| const int lxm16 = lx % 16; // 0 1 2 3 .... 15 | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| coopmat<afp, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator> sum0 = coopmat<afp, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator>(0.f); | |||
| coopmat<afp, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator> sum1 = coopmat<afp, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator>(0.f); | |||
| coopmat<afp, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator> sum2 = coopmat<afp, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator>(0.f); | |||
| coopmat<afp, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator> sum3 = coopmat<afp, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator>(0.f); | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| #if NCNN_fp16_arithmetic | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 16> sum0 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 16>(0.f); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 16> sum1 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 16>(0.f); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 16> sum2 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 16>(0.f); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 16> sum3 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 16>(0.f); | |||
| #else | |||
| fcoopmatNV<32, gl_ScopeSubgroup, 16, 16> sum0 = fcoopmatNV<32, gl_ScopeSubgroup, 16, 16>(0.f); | |||
| fcoopmatNV<32, gl_ScopeSubgroup, 16, 16> sum1 = fcoopmatNV<32, gl_ScopeSubgroup, 16, 16>(0.f); | |||
| fcoopmatNV<32, gl_ScopeSubgroup, 16, 16> sum2 = fcoopmatNV<32, gl_ScopeSubgroup, 16, 16>(0.f); | |||
| fcoopmatNV<32, gl_ScopeSubgroup, 16, 16> sum3 = fcoopmatNV<32, gl_ScopeSubgroup, 16, 16>(0.f); | |||
| #endif | |||
| #endif | |||
| const int N = psc(c) / 4; | |||
| int z = 0; | |||
| for (; z + (UNROLL_INCH - 1) < N; z += UNROLL_INCH) | |||
| { | |||
| { | |||
| for (int j = 0; j < 4; j++) | |||
| { | |||
| const int tmp_i = lxd16*16*4 + lxm16 * 4 + j; | |||
| const int v_offset = gz * psc(cstep) + ((z + lxd16) * 4 + j) * psc(outw) + (gx + lxm16); | |||
| tmp_v0[tmp_i] = (gx + lxm16) < psc(outw) ? bottom_tm_blob_data[v_offset] : uvec2(0); | |||
| tmp_v1[tmp_i] = (gx + lxm16 + 16) < psc(outw) ? bottom_tm_blob_data[v_offset + 16] : uvec2(0); | |||
| const int w_offset = gz * psc(outc) * psc(c) * 4 + gy * psc(c) * 4 + (z + lxd16) * 4 * 16 + (lxm16 * 4 + j); | |||
| tmp_k0[tmp_i] = weight_tm_data[w_offset]; | |||
| tmp_k1[tmp_i] = weight_tm_data[w_offset + psc(c) * 16]; | |||
| } | |||
| } | |||
| barrier(); | |||
| for (int z4 = 0; z4 < UNROLL_INCH; z4++) | |||
| { | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseA> A0; | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseA> A1; | |||
| coopMatLoad(A0, tmp_v0, z4*16*4, 4, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatLoad(A1, tmp_v1, z4*16*4, 4, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseB> B0; | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseB> B1; | |||
| coopMatLoad(B0, tmp_k0, z4*16*4, 4, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatLoad(B1, tmp_k1, z4*16*4, 4, gl_CooperativeMatrixLayoutRowMajor); | |||
| // sum += v * k | |||
| sum0 = coopMatMulAdd(A0, B0, sum0); | |||
| sum1 = coopMatMulAdd(A1, B0, sum1); | |||
| sum2 = coopMatMulAdd(A0, B1, sum2); | |||
| sum3 = coopMatMulAdd(A1, B1, sum3); | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 16> A0; | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 16> A1; | |||
| coopMatLoadNV(A0, tmp_v0, z4*16*4, 4, false); | |||
| coopMatLoadNV(A1, tmp_v1, z4*16*4, 4, false); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 16> B0; | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 16> B1; | |||
| coopMatLoadNV(B0, tmp_k0, z4*16*4, 4, false); | |||
| coopMatLoadNV(B1, tmp_k1, z4*16*4, 4, false); | |||
| // sum += v * k | |||
| sum0 = coopMatMulAddNV(A0, B0, sum0); | |||
| sum1 = coopMatMulAddNV(A1, B0, sum1); | |||
| sum2 = coopMatMulAddNV(A0, B1, sum2); | |||
| sum3 = coopMatMulAddNV(A1, B1, sum3); | |||
| #endif | |||
| } | |||
| barrier(); | |||
| } | |||
| if (z < N) | |||
| { | |||
| const int remain = N - z; | |||
| if (lxd16 == 0) | |||
| { | |||
| for (int j = 0; j < 4; j++) | |||
| { | |||
| const int tmp_i = lxd16*16*4 + lxm16 * 4 + j; | |||
| const int v_offset = gz * psc(cstep) + ((z + lxd16) * 4 + j) * psc(outw) + (gx + lxm16); | |||
| tmp_v0[tmp_i] = (gx + lxm16) < psc(outw) ? bottom_tm_blob_data[v_offset] : uvec2(0); | |||
| tmp_v1[tmp_i] = (gx + lxm16 + 16) < psc(outw) ? bottom_tm_blob_data[v_offset + 16] : uvec2(0); | |||
| const int w_offset = gz * psc(outc) * psc(c) * 4 + gy * psc(c) * 4 + (z + lxd16) * 4 * 16 + (lxm16 * 4 + j); | |||
| tmp_k0[tmp_i] = weight_tm_data[w_offset]; | |||
| tmp_k1[tmp_i] = weight_tm_data[w_offset + psc(c) * 16]; | |||
| } | |||
| } | |||
| barrier(); | |||
| for (int z4 = 0; z4 < remain; z4++) | |||
| { | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseA> A0; | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseA> A1; | |||
| coopMatLoad(A0, tmp_v0, z4*16*4, 4, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatLoad(A1, tmp_v1, z4*16*4, 4, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseB> B0; | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseB> B1; | |||
| coopMatLoad(B0, tmp_k0, z4*16*4, 4, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatLoad(B1, tmp_k1, z4*16*4, 4, gl_CooperativeMatrixLayoutRowMajor); | |||
| // sum += v * k | |||
| sum0 = coopMatMulAdd(A0, B0, sum0); | |||
| sum1 = coopMatMulAdd(A1, B0, sum1); | |||
| sum2 = coopMatMulAdd(A0, B1, sum2); | |||
| sum3 = coopMatMulAdd(A1, B1, sum3); | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 16> A0; | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 16> A1; | |||
| coopMatLoadNV(A0, tmp_v0, z4*16*4, 4, false); | |||
| coopMatLoadNV(A1, tmp_v1, z4*16*4, 4, false); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 16> B0; | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 16> B1; | |||
| coopMatLoadNV(B0, tmp_k0, z4*16*4, 4, false); | |||
| coopMatLoadNV(B1, tmp_k1, z4*16*4, 4, false); | |||
| // sum += v * k | |||
| sum0 = coopMatMulAddNV(A0, B0, sum0); | |||
| sum1 = coopMatMulAddNV(A1, B0, sum1); | |||
| sum2 = coopMatMulAddNV(A0, B1, sum2); | |||
| sum3 = coopMatMulAddNV(A1, B1, sum3); | |||
| #endif | |||
| } | |||
| barrier(); | |||
| } | |||
| if (gx >= psc(outw) || gy >= psc(outc) || gz >= batch) | |||
| return; | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| #if NCNN_fp16_arithmetic | |||
| coopMatStore(sum0, tmp_v0, 0, 4, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum1, tmp_v1, 0, 4, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum2, tmp_v0, 16*4, 4, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum3, tmp_v1, 16*4, 4, gl_CooperativeMatrixLayoutRowMajor); | |||
| #else | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator> sum0_fp16 = coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator>(sum0); | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator> sum1_fp16 = coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator>(sum1); | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator> sum2_fp16 = coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator>(sum2); | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator> sum3_fp16 = coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator>(sum3); | |||
| coopMatStore(sum0_fp16, tmp_v0, 0, 4, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum1_fp16, tmp_v1, 0, 4, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum2_fp16, tmp_v0, 16*4, 4, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum3_fp16, tmp_v1, 16*4, 4, gl_CooperativeMatrixLayoutRowMajor); | |||
| #endif | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| #if NCNN_fp16_arithmetic | |||
| coopMatStoreNV(sum0, tmp_v0, 0, 4, false); | |||
| coopMatStoreNV(sum1, tmp_v1, 0, 4, false); | |||
| coopMatStoreNV(sum2, tmp_v0, 16*4, 4, false); | |||
| coopMatStoreNV(sum3, tmp_v1, 16*4, 4, false); | |||
| #else | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 16> sum0_fp16 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 16>(sum0); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 16> sum1_fp16 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 16>(sum1); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 16> sum2_fp16 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 16>(sum2); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 16> sum3_fp16 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 16>(sum3); | |||
| coopMatStoreNV(sum0_fp16, tmp_v0, 0, 4, false); | |||
| coopMatStoreNV(sum1_fp16, tmp_v1, 0, 4, false); | |||
| coopMatStoreNV(sum2_fp16, tmp_v0, 16*4, 4, false); | |||
| coopMatStoreNV(sum3_fp16, tmp_v1, 16*4, 4, false); | |||
| #endif | |||
| #endif | |||
| barrier(); | |||
| { | |||
| for (int j = 0; j < 4; j++) | |||
| { | |||
| const int tmp_vi = lxm16 * 4 + j + lxd16*16*4; | |||
| const int gi = gz * psc(outcstep) + (gy + lxd16 * 4 + j) * psc(outw) + (gx + lxm16); | |||
| if (gy + lxd16 * 4 + j < psc(outc)) | |||
| { | |||
| if (gx + lxm16 < psc(outw)) top_tm_blob_data[gi] = tmp_v0[tmp_vi]; | |||
| if (gx + lxm16 + 16 < psc(outw)) top_tm_blob_data[gi + 16] = tmp_v1[tmp_vi]; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1,343 +0,0 @@ | |||
| // Copyright 2023 Tencent | |||
| // SPDX-License-Identifier: BSD-3-Clause | |||
| #version 450 | |||
| #extension GL_KHR_memory_scope_semantics: require | |||
| #extension GL_EXT_shader_explicit_arithmetic_types: require | |||
| #extension GL_EXT_shader_explicit_arithmetic_types_float16: require | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| #extension GL_KHR_cooperative_matrix: require | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| #extension GL_NV_cooperative_matrix: require | |||
| #endif | |||
| layout (constant_id = 0) const int batch = 1; | |||
| #define shape_constant_id_offset 1 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outc = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outcstep = 0; | |||
| layout (binding = 0) readonly buffer bottom_tm_blob { uvec2 bottom_tm_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer top_tm_blob { uvec2 top_tm_blob_data[]; }; | |||
| layout (binding = 2) readonly buffer weight_tm_blob { uvec2 weight_tm_data[]; }; | |||
| layout (push_constant) uniform parameter | |||
| { | |||
| int c; | |||
| int cstep; | |||
| int outw; | |||
| int outc; | |||
| int outcstep; | |||
| } p; | |||
| #define UNROLL_INCH 4 | |||
| shared uvec2 tmp_v0[UNROLL_INCH * 16*2]; | |||
| shared uvec2 tmp_v1[UNROLL_INCH * 16*2]; | |||
| shared uvec2 tmp_k0[UNROLL_INCH * 8*2]; | |||
| shared uvec2 tmp_k1[UNROLL_INCH * 8*2]; | |||
| shared uvec2 tmp_k2[UNROLL_INCH * 8*2]; | |||
| shared uvec2 tmp_k3[UNROLL_INCH * 8*2]; | |||
| void main() | |||
| { | |||
| int gx = int(gl_GlobalInvocationID.x) / 32 * 2 * 16; | |||
| int gy = int(gl_GlobalInvocationID.y) * 2 * 4; | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| const int lx = int(gl_LocalInvocationID.x); | |||
| const int lxd8 = lx / 8; // 0 1 2 3 | |||
| const int lxm8 = lx % 8; // 0 1 2 3 .... 7 | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| coopmat<afp, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> sum0 = coopmat<afp, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator>(0.f); | |||
| coopmat<afp, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> sum1 = coopmat<afp, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator>(0.f); | |||
| coopmat<afp, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> sum2 = coopmat<afp, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator>(0.f); | |||
| coopmat<afp, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> sum3 = coopmat<afp, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator>(0.f); | |||
| coopmat<afp, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> sum4 = coopmat<afp, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator>(0.f); | |||
| coopmat<afp, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> sum5 = coopmat<afp, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator>(0.f); | |||
| coopmat<afp, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> sum6 = coopmat<afp, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator>(0.f); | |||
| coopmat<afp, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> sum7 = coopmat<afp, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator>(0.f); | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| #if NCNN_fp16_arithmetic | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> sum0 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 8>(0.f); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> sum1 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 8>(0.f); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> sum2 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 8>(0.f); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> sum3 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 8>(0.f); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> sum4 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 8>(0.f); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> sum5 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 8>(0.f); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> sum6 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 8>(0.f); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> sum7 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 8>(0.f); | |||
| #else | |||
| fcoopmatNV<32, gl_ScopeSubgroup, 16, 8> sum0 = fcoopmatNV<32, gl_ScopeSubgroup, 16, 8>(0.f); | |||
| fcoopmatNV<32, gl_ScopeSubgroup, 16, 8> sum1 = fcoopmatNV<32, gl_ScopeSubgroup, 16, 8>(0.f); | |||
| fcoopmatNV<32, gl_ScopeSubgroup, 16, 8> sum2 = fcoopmatNV<32, gl_ScopeSubgroup, 16, 8>(0.f); | |||
| fcoopmatNV<32, gl_ScopeSubgroup, 16, 8> sum3 = fcoopmatNV<32, gl_ScopeSubgroup, 16, 8>(0.f); | |||
| fcoopmatNV<32, gl_ScopeSubgroup, 16, 8> sum4 = fcoopmatNV<32, gl_ScopeSubgroup, 16, 8>(0.f); | |||
| fcoopmatNV<32, gl_ScopeSubgroup, 16, 8> sum5 = fcoopmatNV<32, gl_ScopeSubgroup, 16, 8>(0.f); | |||
| fcoopmatNV<32, gl_ScopeSubgroup, 16, 8> sum6 = fcoopmatNV<32, gl_ScopeSubgroup, 16, 8>(0.f); | |||
| fcoopmatNV<32, gl_ScopeSubgroup, 16, 8> sum7 = fcoopmatNV<32, gl_ScopeSubgroup, 16, 8>(0.f); | |||
| #endif | |||
| #endif | |||
| const int N = psc(c) / 2; | |||
| int z = 0; | |||
| for (; z + (UNROLL_INCH - 1) < N; z += UNROLL_INCH) | |||
| { | |||
| { | |||
| for (int j = 0; j < 2; j++) | |||
| { | |||
| const int tmp_vi = lxd8*16*2 + lxm8 * 2 + j; | |||
| int v_offset = gz * psc(cstep) + ((z + lxd8) * 2 + j) * psc(outw) + (gx + lxm8); | |||
| tmp_v0[tmp_vi] = (gx + lxm8) < psc(outw) ? bottom_tm_blob_data[v_offset] : uvec2(0); | |||
| tmp_v0[tmp_vi + 16] = (gx + lxm8 + 8) < psc(outw) ? bottom_tm_blob_data[v_offset + 8] : uvec2(0); | |||
| tmp_v1[tmp_vi] = (gx + lxm8 + 16) < psc(outw) ? bottom_tm_blob_data[v_offset + 16] : uvec2(0); | |||
| tmp_v1[tmp_vi + 16] = (gx + lxm8 + 24) < psc(outw) ? bottom_tm_blob_data[v_offset + 24] : uvec2(0); | |||
| const int tmp_ki = lxd8*8*2 + lxm8 * 2 + j; | |||
| int w_offset = gz * psc(outc) * psc(c) * 4 + gy * psc(c) * 4 + (z + lxd8) * 2 * 8 + (lxm8 * 2 + j); | |||
| tmp_k0[tmp_ki] = weight_tm_data[w_offset]; | |||
| tmp_k1[tmp_ki] = weight_tm_data[w_offset + psc(c) * 8]; | |||
| tmp_k2[tmp_ki] = weight_tm_data[w_offset + psc(c) * 16]; | |||
| tmp_k3[tmp_ki] = weight_tm_data[w_offset + psc(c) * 24]; | |||
| } | |||
| } | |||
| barrier(); | |||
| for (int z4 = 0; z4 < UNROLL_INCH; z4++) | |||
| { | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseA> A0; | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseA> A1; | |||
| coopMatLoad(A0, tmp_v0, z4*16*2, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatLoad(A1, tmp_v1, z4*16*2, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopmat<float16_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseB> B0; | |||
| coopmat<float16_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseB> B1; | |||
| coopmat<float16_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseB> B2; | |||
| coopmat<float16_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseB> B3; | |||
| coopMatLoad(B0, tmp_k0, z4*8*2, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatLoad(B1, tmp_k1, z4*8*2, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatLoad(B2, tmp_k2, z4*8*2, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatLoad(B3, tmp_k3, z4*8*2, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| // sum += v * k | |||
| sum0 = coopMatMulAdd(A0, B0, sum0); | |||
| sum1 = coopMatMulAdd(A1, B0, sum1); | |||
| sum2 = coopMatMulAdd(A0, B1, sum2); | |||
| sum3 = coopMatMulAdd(A1, B1, sum3); | |||
| sum4 = coopMatMulAdd(A0, B2, sum4); | |||
| sum5 = coopMatMulAdd(A1, B2, sum5); | |||
| sum6 = coopMatMulAdd(A0, B3, sum6); | |||
| sum7 = coopMatMulAdd(A1, B3, sum7); | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> A0; | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> A1; | |||
| coopMatLoadNV(A0, tmp_v0, z4*16*2, 2, false); | |||
| coopMatLoadNV(A1, tmp_v1, z4*16*2, 2, false); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 8, 8> B0; | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 8, 8> B1; | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 8, 8> B2; | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 8, 8> B3; | |||
| coopMatLoadNV(B0, tmp_k0, z4*8*2, 2, false); | |||
| coopMatLoadNV(B1, tmp_k1, z4*8*2, 2, false); | |||
| coopMatLoadNV(B2, tmp_k2, z4*8*2, 2, false); | |||
| coopMatLoadNV(B3, tmp_k3, z4*8*2, 2, false); | |||
| // sum += v * k | |||
| sum0 = coopMatMulAddNV(A0, B0, sum0); | |||
| sum1 = coopMatMulAddNV(A1, B0, sum1); | |||
| sum2 = coopMatMulAddNV(A0, B1, sum2); | |||
| sum3 = coopMatMulAddNV(A1, B1, sum3); | |||
| sum4 = coopMatMulAddNV(A0, B2, sum4); | |||
| sum5 = coopMatMulAddNV(A1, B2, sum5); | |||
| sum6 = coopMatMulAddNV(A0, B3, sum6); | |||
| sum7 = coopMatMulAddNV(A1, B3, sum7); | |||
| #endif | |||
| } | |||
| barrier(); | |||
| } | |||
| if (z < N) | |||
| { | |||
| const int remain = N - z; | |||
| if (lxd8 < remain) | |||
| { | |||
| for (int j = 0; j < 2; j++) | |||
| { | |||
| const int tmp_vi = lxd8*16*2 + lxm8 * 2 + j; | |||
| int v_offset = gz * psc(cstep) + ((z + lxd8) * 2 + j) * psc(outw) + (gx + lxm8); | |||
| tmp_v0[tmp_vi] = (gx + lxm8) < psc(outw) ? bottom_tm_blob_data[v_offset] : uvec2(0); | |||
| tmp_v0[tmp_vi + 16] = (gx + lxm8 + 8) < psc(outw) ? bottom_tm_blob_data[v_offset + 8] : uvec2(0); | |||
| tmp_v1[tmp_vi] = (gx + lxm8 + 16) < psc(outw) ? bottom_tm_blob_data[v_offset + 16] : uvec2(0); | |||
| tmp_v1[tmp_vi + 16] = (gx + lxm8 + 24) < psc(outw) ? bottom_tm_blob_data[v_offset + 24] : uvec2(0); | |||
| const int tmp_ki = lxd8*8*2 + lxm8 * 2 + j; | |||
| int w_offset = gz * psc(outc) * psc(c) * 4 + gy * psc(c) * 4 + (z + lxd8) * 2 * 8 + (lxm8 * 2 + j); | |||
| tmp_k0[tmp_ki] = weight_tm_data[w_offset]; | |||
| tmp_k1[tmp_ki] = weight_tm_data[w_offset + psc(c) * 8]; | |||
| tmp_k2[tmp_ki] = weight_tm_data[w_offset + psc(c) * 16]; | |||
| tmp_k3[tmp_ki] = weight_tm_data[w_offset + psc(c) * 24]; | |||
| } | |||
| } | |||
| barrier(); | |||
| for (int z4 = 0; z4 < remain; z4++) | |||
| { | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseA> A0; | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseA> A1; | |||
| coopMatLoad(A0, tmp_v0, z4*16*2, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatLoad(A1, tmp_v1, z4*16*2, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopmat<float16_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseB> B0; | |||
| coopmat<float16_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseB> B1; | |||
| coopmat<float16_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseB> B2; | |||
| coopmat<float16_t, gl_ScopeSubgroup, 8, 8, gl_MatrixUseB> B3; | |||
| coopMatLoad(B0, tmp_k0, z4*8*2, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatLoad(B1, tmp_k1, z4*8*2, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatLoad(B2, tmp_k2, z4*8*2, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatLoad(B3, tmp_k3, z4*8*2, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| // sum += v * k | |||
| sum0 = coopMatMulAdd(A0, B0, sum0); | |||
| sum1 = coopMatMulAdd(A1, B0, sum1); | |||
| sum2 = coopMatMulAdd(A0, B1, sum2); | |||
| sum3 = coopMatMulAdd(A1, B1, sum3); | |||
| sum4 = coopMatMulAdd(A0, B2, sum4); | |||
| sum5 = coopMatMulAdd(A1, B2, sum5); | |||
| sum6 = coopMatMulAdd(A0, B3, sum6); | |||
| sum7 = coopMatMulAdd(A1, B3, sum7); | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> A0; | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> A1; | |||
| coopMatLoadNV(A0, tmp_v0, z4*16*2, 2, false); | |||
| coopMatLoadNV(A1, tmp_v1, z4*16*2, 2, false); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 8, 8> B0; | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 8, 8> B1; | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 8, 8> B2; | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 8, 8> B3; | |||
| coopMatLoadNV(B0, tmp_k0, z4*8*2, 2, false); | |||
| coopMatLoadNV(B1, tmp_k1, z4*8*2, 2, false); | |||
| coopMatLoadNV(B2, tmp_k2, z4*8*2, 2, false); | |||
| coopMatLoadNV(B3, tmp_k3, z4*8*2, 2, false); | |||
| // sum += v * k | |||
| sum0 = coopMatMulAddNV(A0, B0, sum0); | |||
| sum1 = coopMatMulAddNV(A1, B0, sum1); | |||
| sum2 = coopMatMulAddNV(A0, B1, sum2); | |||
| sum3 = coopMatMulAddNV(A1, B1, sum3); | |||
| sum4 = coopMatMulAddNV(A0, B2, sum4); | |||
| sum5 = coopMatMulAddNV(A1, B2, sum5); | |||
| sum6 = coopMatMulAddNV(A0, B3, sum6); | |||
| sum7 = coopMatMulAddNV(A1, B3, sum7); | |||
| #endif | |||
| } | |||
| barrier(); | |||
| } | |||
| if (gx >= psc(outw) || gy >= psc(outc) || gz >= batch) | |||
| return; | |||
| #if ncnn_VK_KHR_cooperative_matrix | |||
| #if NCNN_fp16_arithmetic | |||
| coopMatStore(sum0, tmp_v0, 0, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum1, tmp_v1, 0, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum2, tmp_v0, 16*2, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum3, tmp_v1, 16*2, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum4, tmp_v0, 16*4, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum5, tmp_v1, 16*4, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum6, tmp_v0, 16*6, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum7, tmp_v1, 16*6, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| #else | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> sum0_fp16 = coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator>(sum0); | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> sum1_fp16 = coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator>(sum1); | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> sum2_fp16 = coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator>(sum2); | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> sum3_fp16 = coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator>(sum3); | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> sum4_fp16 = coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator>(sum4); | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> sum5_fp16 = coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator>(sum5); | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> sum6_fp16 = coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator>(sum6); | |||
| coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator> sum7_fp16 = coopmat<float16_t, gl_ScopeSubgroup, 16, 8, gl_MatrixUseAccumulator>(sum7); | |||
| coopMatStore(sum0_fp16, tmp_v0, 0, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum1_fp16, tmp_v1, 0, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum2_fp16, tmp_v0, 16*2, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum3_fp16, tmp_v1, 16*2, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum4_fp16, tmp_v0, 16*4, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum5_fp16, tmp_v1, 16*4, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum6_fp16, tmp_v0, 16*6, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| coopMatStore(sum7_fp16, tmp_v1, 16*6, 2, gl_CooperativeMatrixLayoutRowMajor); | |||
| #endif | |||
| #elif ncnn_VK_NV_cooperative_matrix | |||
| #if NCNN_fp16_arithmetic | |||
| coopMatStoreNV(sum0, tmp_v0, 0, 2, false); | |||
| coopMatStoreNV(sum1, tmp_v1, 0, 2, false); | |||
| coopMatStoreNV(sum2, tmp_v0, 16*2, 2, false); | |||
| coopMatStoreNV(sum3, tmp_v1, 16*2, 2, false); | |||
| coopMatStoreNV(sum4, tmp_v0, 16*4, 2, false); | |||
| coopMatStoreNV(sum5, tmp_v1, 16*4, 2, false); | |||
| coopMatStoreNV(sum6, tmp_v0, 16*6, 2, false); | |||
| coopMatStoreNV(sum7, tmp_v1, 16*6, 2, false); | |||
| #else | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> sum0_fp16 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 8>(sum0); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> sum1_fp16 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 8>(sum1); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> sum2_fp16 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 8>(sum2); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> sum3_fp16 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 8>(sum3); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> sum4_fp16 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 8>(sum4); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> sum5_fp16 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 8>(sum5); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> sum6_fp16 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 8>(sum6); | |||
| fcoopmatNV<16, gl_ScopeSubgroup, 16, 8> sum7_fp16 = fcoopmatNV<16, gl_ScopeSubgroup, 16, 8>(sum7); | |||
| coopMatStoreNV(sum0_fp16, tmp_v0, 0, 2, false); | |||
| coopMatStoreNV(sum1_fp16, tmp_v1, 0, 2, false); | |||
| coopMatStoreNV(sum2_fp16, tmp_v0, 16*2, 2, false); | |||
| coopMatStoreNV(sum3_fp16, tmp_v1, 16*2, 2, false); | |||
| coopMatStoreNV(sum4_fp16, tmp_v0, 16*4, 2, false); | |||
| coopMatStoreNV(sum5_fp16, tmp_v1, 16*4, 2, false); | |||
| coopMatStoreNV(sum6_fp16, tmp_v0, 16*6, 2, false); | |||
| coopMatStoreNV(sum7_fp16, tmp_v1, 16*6, 2, false); | |||
| #endif | |||
| #endif | |||
| barrier(); | |||
| const int lxd16 = lx / 16; // 0 1 | |||
| const int lxm16 = lx % 16; // 0 1 2 3 .... 15 | |||
| { | |||
| for (int j = 0; j < 4; j++) | |||
| { | |||
| const int tmp_vi = lxm16 * 2 + lxd16 + j*16*2; | |||
| const int gi = gz * psc(outcstep) + (gy + lxd16 + j*2) * psc(outw) + (gx + lxm16); | |||
| if (gy + j * 2 + lxd16 < psc(outc)) | |||
| { | |||
| if (gx + lxm16 < psc(outw)) top_tm_blob_data[gi] = tmp_v0[tmp_vi]; | |||
| if (gx + lxm16 + 16 < psc(outw)) top_tm_blob_data[gi + 16] = tmp_v1[tmp_vi]; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -6,14 +6,13 @@ | |||
| #define LOCAL_MEMORY_UNROLL_INCH 8 | |||
| layout (constant_id = 0) const int batch = 1; | |||
| layout (constant_id = 1) const int c = 0; | |||
| layout (constant_id = 2) const int outc = 0; | |||
| #define shape_constant_id_offset 1 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outc = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outcstep = 0; | |||
| #define shape_constant_id_offset 3 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outcstep = 0; | |||
| layout (binding = 0) readonly buffer bottom_tm_blob { sfpvec4 bottom_tm_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer top_tm_blob { sfp top_tm_blob_data[]; }; | |||
| @@ -21,11 +20,8 @@ layout (binding = 2) readonly buffer weight_tm_blob { sfpvec4 weight_tm_data[]; | |||
| layout (push_constant) uniform parameter | |||
| { | |||
| int c; | |||
| int cstep; | |||
| int outw; | |||
| int outc; | |||
| int outcstep; | |||
| } p; | |||
| @@ -41,7 +37,7 @@ void main() | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| #if !NCNN_shader_local_memory | |||
| if (gx >= psc(outw) || gy >= psc(outc) || gz >= batch) | |||
| if (gx >= psc(outw) || gy >= outc || gz >= batch) | |||
| return; | |||
| #endif | |||
| @@ -50,21 +46,21 @@ void main() | |||
| afp sum2 = afp(0.f); | |||
| afp sum3 = afp(0.f); | |||
| int v_offset = gz * psc(cstep) + gx; | |||
| int w_offset = gz * psc(c) * psc(outc) + gy * psc(c); | |||
| int v_offset = gz * c * psc(cstep) + gx; | |||
| int w_offset = gz * c * outc + gy * c; | |||
| #if NCNN_shader_local_memory | |||
| const int lx = int(gl_LocalInvocationID.x); | |||
| const int ly = int(gl_LocalInvocationID.y); | |||
| int z = 0; | |||
| for (; z + (LOCAL_MEMORY_UNROLL_INCH - 1) < psc(c); z += LOCAL_MEMORY_UNROLL_INCH) | |||
| for (; z + (LOCAL_MEMORY_UNROLL_INCH - 1) < c; z += LOCAL_MEMORY_UNROLL_INCH) | |||
| { | |||
| if (ly < 4) | |||
| { | |||
| for (int z4 = 0; z4 < LOCAL_MEMORY_UNROLL_INCH; z4++) | |||
| { | |||
| tmp_v[lx][z4][ly] = sfp2lfpvec4(bottom_tm_blob_data[v_offset + z4 * psc(outw) + ly]); | |||
| tmp_v[lx][z4][ly] = sfp2lfpvec4(bottom_tm_blob_data[v_offset + z4 * psc(cstep) + ly]); | |||
| } | |||
| } | |||
| @@ -93,21 +89,21 @@ void main() | |||
| sum3 += dot(v3, k); | |||
| } | |||
| v_offset += LOCAL_MEMORY_UNROLL_INCH * psc(outw); | |||
| v_offset += LOCAL_MEMORY_UNROLL_INCH * psc(cstep); | |||
| w_offset += LOCAL_MEMORY_UNROLL_INCH; | |||
| barrier(); | |||
| } | |||
| if (z < psc(c)) | |||
| if (z < c) | |||
| { | |||
| const int remain = psc(c) - z; | |||
| const int remain = c - z; | |||
| if (ly < 4) | |||
| { | |||
| for (int z4 = 0; z4 < remain; z4++) | |||
| { | |||
| tmp_v[lx][z4][ly] = sfp2lfpvec4(bottom_tm_blob_data[v_offset + z4 * psc(outw) + ly]); | |||
| tmp_v[lx][z4][ly] = sfp2lfpvec4(bottom_tm_blob_data[v_offset + z4 * psc(cstep) + ly]); | |||
| } | |||
| } | |||
| @@ -137,7 +133,7 @@ void main() | |||
| } | |||
| } | |||
| #else | |||
| for (int z = 0; z < psc(c); z++) | |||
| for (int z = 0; z < c; z++) | |||
| { | |||
| afpvec4 v0 = buffer_ld4(bottom_tm_blob_data, v_offset + 0); | |||
| afpvec4 v1 = buffer_ld4(bottom_tm_blob_data, v_offset + 1); | |||
| @@ -151,17 +147,17 @@ void main() | |||
| sum2 += dot(v2, k); | |||
| sum3 += dot(v3, k); | |||
| v_offset += psc(outw); | |||
| v_offset += psc(cstep); | |||
| w_offset += 1; | |||
| } | |||
| #endif | |||
| #if NCNN_shader_local_memory | |||
| if (gx >= psc(outw) || gy >= psc(outc) || gz >= batch) | |||
| if (gx >= psc(outw) || gy >= outc || gz >= batch) | |||
| return; | |||
| #endif | |||
| int gi = gz * psc(outcstep) + gy * psc(outw) + gx; | |||
| int gi = gz * outc * psc(outcstep) + gy * psc(outcstep) + gx; | |||
| buffer_st1(top_tm_blob_data, gi + 0, sum0); | |||
| if (gx + 1 < psc(outw)) buffer_st1(top_tm_blob_data, gi + 1, sum1); | |||
| @@ -4,14 +4,13 @@ | |||
| #version 450 | |||
| layout (constant_id = 0) const int batch = 1; | |||
| layout (constant_id = 1) const int c = 0; | |||
| layout (constant_id = 2) const int outc = 0; | |||
| #define shape_constant_id_offset 1 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outc = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outcstep = 0; | |||
| #define shape_constant_id_offset 3 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outcstep = 0; | |||
| layout (binding = 0) readonly buffer bottom_tm_blob { sfpvec4 bottom_tm_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer top_tm_blob { sfpvec8 top_tm_blob_data[]; }; | |||
| @@ -19,11 +18,8 @@ layout (binding = 2) readonly buffer weight_tm_blob { sfpvec4 weight_tm_data[]; | |||
| layout (push_constant) uniform parameter | |||
| { | |||
| int c; | |||
| int cstep; | |||
| int outw; | |||
| int outc; | |||
| int outcstep; | |||
| } p; | |||
| @@ -33,7 +29,7 @@ void main() | |||
| int gy = int(gl_GlobalInvocationID.y); | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| if (gx >= psc(outw) || gy >= psc(outc) || gz >= batch) | |||
| if (gx >= psc(outw) || gy >= outc || gz >= batch) | |||
| return; | |||
| afpvec8 sum0 = afpvec8(afpvec4(0.f), afpvec4(0.f)); | |||
| @@ -41,10 +37,10 @@ void main() | |||
| afpvec8 sum2 = afpvec8(afpvec4(0.f), afpvec4(0.f)); | |||
| afpvec8 sum3 = afpvec8(afpvec4(0.f), afpvec4(0.f)); | |||
| int v_offset = gz * psc(cstep) + gx; | |||
| int w_offset = (gz * psc(c) * psc(outc) + gy * psc(c)) * 8; | |||
| int v_offset = gz * c * psc(cstep) + gx; | |||
| int w_offset = (gz * c * outc + gy * c) * 8; | |||
| for (int z = 0; z < psc(c); z++) | |||
| for (int z = 0; z < c; z++) | |||
| { | |||
| afpvec4 v0 = buffer_ld4(bottom_tm_blob_data, v_offset + 0); | |||
| afpvec4 v1 = buffer_ld4(bottom_tm_blob_data, v_offset + 1); | |||
| @@ -97,11 +93,11 @@ void main() | |||
| sum3[1].b += dot(v3, k6); | |||
| sum3[1].a += dot(v3, k7); | |||
| v_offset += psc(outw); | |||
| v_offset += psc(cstep); | |||
| w_offset += 8; | |||
| } | |||
| int gi = gz * psc(outcstep) + gy * psc(outw) + gx; | |||
| int gi = gz * outc * psc(outcstep) + gy * psc(outcstep) + gx; | |||
| buffer_st8(top_tm_blob_data, gi + 0, sum0); | |||
| if (gx + 1 < psc(outw)) buffer_st8(top_tm_blob_data, gi + 1, sum1); | |||
| @@ -3,16 +3,17 @@ | |||
| #version 450 | |||
| #define shape_constant_id_offset 0 | |||
| layout (constant_id = 0) const int c = 0; | |||
| #define shape_constant_id_offset 1 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int w = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int h = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outcstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outcstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 6) const int block_y = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int block_y = 0; | |||
| layout (binding = 0) readonly buffer bottom_blob { sfpvec8 bottom_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer bottom_tm_blob { sfpvec8 bottom_tm_blob_data[]; }; | |||
| @@ -21,7 +22,6 @@ layout (push_constant) uniform parameter | |||
| { | |||
| int w; | |||
| int h; | |||
| int c; | |||
| int cstep; | |||
| int outcstep; | |||
| @@ -36,7 +36,7 @@ void main() | |||
| int gy = int(gl_GlobalInvocationID.y); | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= psc(c)) | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= c) | |||
| return; | |||
| // load 4x4 | |||
| @@ -115,22 +115,22 @@ void main() | |||
| v33 = m33 - m31; | |||
| // store 16 | |||
| int v_tm_offset = gz * psc(block_x) * psc(block_y) + gy * psc(block_x) + gx; | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 0 * psc(outcstep), v00); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 1 * psc(outcstep), v01); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 2 * psc(outcstep), v02); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 3 * psc(outcstep), v03); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 4 * psc(outcstep), v10); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 5 * psc(outcstep), v11); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 6 * psc(outcstep), v12); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 7 * psc(outcstep), v13); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 8 * psc(outcstep), v20); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 9 * psc(outcstep), v21); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 10 * psc(outcstep), v22); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 11 * psc(outcstep), v23); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 12 * psc(outcstep), v30); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 13 * psc(outcstep), v31); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 14 * psc(outcstep), v32); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 15 * psc(outcstep), v33); | |||
| int v_tm_offset = gz * psc(outcstep) + gy * psc(block_x) + gx; | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 0 * psc(outcstep) * c, v00); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 1 * psc(outcstep) * c, v01); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 2 * psc(outcstep) * c, v02); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 3 * psc(outcstep) * c, v03); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 4 * psc(outcstep) * c, v10); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 5 * psc(outcstep) * c, v11); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 6 * psc(outcstep) * c, v12); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 7 * psc(outcstep) * c, v13); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 8 * psc(outcstep) * c, v20); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 9 * psc(outcstep) * c, v21); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 10 * psc(outcstep) * c, v22); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 11 * psc(outcstep) * c, v23); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 12 * psc(outcstep) * c, v30); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 13 * psc(outcstep) * c, v31); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 14 * psc(outcstep) * c, v32); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 15 * psc(outcstep) * c, v33); | |||
| } | |||
| @@ -10,17 +10,17 @@ layout (constant_id = 0) const int bias_term = 0; | |||
| layout (constant_id = 1) const int activation_type = 0; | |||
| layout (constant_id = 2) const float activation_param_0 = 0; | |||
| layout (constant_id = 3) const float activation_param_1 = 0; | |||
| layout (constant_id = 4) const int c = 0; | |||
| #define shape_constant_id_offset 4 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int cstep = 0; | |||
| #define shape_constant_id_offset 5 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int block_y = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int block_y = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int outh = 0; | |||
| layout (constant_id = shape_constant_id_offset + 6) const int outcstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outh = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int outcstep = 0; | |||
| layout (binding = 0) readonly buffer top_tm_blob { sfpvec8 top_tm_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer top_blob { sfpvec8 top_blob_data[]; }; | |||
| @@ -28,7 +28,6 @@ layout (binding = 2) readonly buffer bias_blob { sfpvec8 bias_data[]; }; | |||
| layout (push_constant) uniform parameter | |||
| { | |||
| int c; | |||
| int cstep; | |||
| int block_x; | |||
| @@ -45,28 +44,28 @@ void main() | |||
| int gy = int(gl_GlobalInvocationID.y); | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= psc(c)) | |||
| if (gx >= psc(block_x) || gy >= psc(block_y) || gz >= c) | |||
| return; | |||
| // load 16 | |||
| int v_tm_offset = gz * psc(block_x) * psc(block_y) + gy * psc(block_x) + gx; | |||
| afpvec8 v00 = buffer_ld8(top_tm_blob_data, v_tm_offset + 0 * psc(cstep)); | |||
| afpvec8 v01 = buffer_ld8(top_tm_blob_data, v_tm_offset + 1 * psc(cstep)); | |||
| afpvec8 v02 = buffer_ld8(top_tm_blob_data, v_tm_offset + 2 * psc(cstep)); | |||
| afpvec8 v03 = buffer_ld8(top_tm_blob_data, v_tm_offset + 3 * psc(cstep)); | |||
| afpvec8 v10 = buffer_ld8(top_tm_blob_data, v_tm_offset + 4 * psc(cstep)); | |||
| afpvec8 v11 = buffer_ld8(top_tm_blob_data, v_tm_offset + 5 * psc(cstep)); | |||
| afpvec8 v12 = buffer_ld8(top_tm_blob_data, v_tm_offset + 6 * psc(cstep)); | |||
| afpvec8 v13 = buffer_ld8(top_tm_blob_data, v_tm_offset + 7 * psc(cstep)); | |||
| afpvec8 v20 = buffer_ld8(top_tm_blob_data, v_tm_offset + 8 * psc(cstep)); | |||
| afpvec8 v21 = buffer_ld8(top_tm_blob_data, v_tm_offset + 9 * psc(cstep)); | |||
| afpvec8 v22 = buffer_ld8(top_tm_blob_data, v_tm_offset + 10 * psc(cstep)); | |||
| afpvec8 v23 = buffer_ld8(top_tm_blob_data, v_tm_offset + 11 * psc(cstep)); | |||
| afpvec8 v30 = buffer_ld8(top_tm_blob_data, v_tm_offset + 12 * psc(cstep)); | |||
| afpvec8 v31 = buffer_ld8(top_tm_blob_data, v_tm_offset + 13 * psc(cstep)); | |||
| afpvec8 v32 = buffer_ld8(top_tm_blob_data, v_tm_offset + 14 * psc(cstep)); | |||
| afpvec8 v33 = buffer_ld8(top_tm_blob_data, v_tm_offset + 15 * psc(cstep)); | |||
| int v_tm_offset = gz * psc(cstep) + gy * psc(block_x) + gx; | |||
| afpvec8 v00 = buffer_ld8(top_tm_blob_data, v_tm_offset + 0 * psc(cstep) * c); | |||
| afpvec8 v01 = buffer_ld8(top_tm_blob_data, v_tm_offset + 1 * psc(cstep) * c); | |||
| afpvec8 v02 = buffer_ld8(top_tm_blob_data, v_tm_offset + 2 * psc(cstep) * c); | |||
| afpvec8 v03 = buffer_ld8(top_tm_blob_data, v_tm_offset + 3 * psc(cstep) * c); | |||
| afpvec8 v10 = buffer_ld8(top_tm_blob_data, v_tm_offset + 4 * psc(cstep) * c); | |||
| afpvec8 v11 = buffer_ld8(top_tm_blob_data, v_tm_offset + 5 * psc(cstep) * c); | |||
| afpvec8 v12 = buffer_ld8(top_tm_blob_data, v_tm_offset + 6 * psc(cstep) * c); | |||
| afpvec8 v13 = buffer_ld8(top_tm_blob_data, v_tm_offset + 7 * psc(cstep) * c); | |||
| afpvec8 v20 = buffer_ld8(top_tm_blob_data, v_tm_offset + 8 * psc(cstep) * c); | |||
| afpvec8 v21 = buffer_ld8(top_tm_blob_data, v_tm_offset + 9 * psc(cstep) * c); | |||
| afpvec8 v22 = buffer_ld8(top_tm_blob_data, v_tm_offset + 10 * psc(cstep) * c); | |||
| afpvec8 v23 = buffer_ld8(top_tm_blob_data, v_tm_offset + 11 * psc(cstep) * c); | |||
| afpvec8 v30 = buffer_ld8(top_tm_blob_data, v_tm_offset + 12 * psc(cstep) * c); | |||
| afpvec8 v31 = buffer_ld8(top_tm_blob_data, v_tm_offset + 13 * psc(cstep) * c); | |||
| afpvec8 v32 = buffer_ld8(top_tm_blob_data, v_tm_offset + 14 * psc(cstep) * c); | |||
| afpvec8 v33 = buffer_ld8(top_tm_blob_data, v_tm_offset + 15 * psc(cstep) * c); | |||
| // const float itm[2][4] = { | |||
| // {1.0f, 1.0f, 1.0f, 0.0f}, | |||
| @@ -3,16 +3,17 @@ | |||
| #version 450 | |||
| #define shape_constant_id_offset 0 | |||
| layout (constant_id = 0) const int c = 0; | |||
| #define shape_constant_id_offset 1 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int w = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int h = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outcstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outcstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 6) const int block_y = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int block_y = 0; | |||
| layout (binding = 0) readonly buffer bottom_blob { sfpvec8 bottom_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer bottom_tm_blob { sfpvec8 bottom_tm_blob_data[]; }; | |||
| @@ -21,7 +22,6 @@ layout (push_constant) uniform parameter | |||
| { | |||
| int w; | |||
| int h; | |||
| int c; | |||
| int cstep; | |||
| int outcstep; | |||
| @@ -36,7 +36,7 @@ void main() | |||
| int gy = int(gl_GlobalInvocationID.y); | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| if (gx >= p.block_x || gy >= p.block_y || gz >= psc(c)) | |||
| if (gx >= p.block_x || gy >= p.block_y || gz >= c) | |||
| return; | |||
| // load 6x6 | |||
| @@ -187,42 +187,42 @@ void main() | |||
| v55 = m51 - m53 * afp(2.5) + m55; | |||
| // store 36 | |||
| int v_tm_offset = gz * psc(block_x) * psc(block_y) + gy * psc(block_x) + gx; | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 0 * psc(outcstep), v00); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 1 * psc(outcstep), v01); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 2 * psc(outcstep), v02); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 3 * psc(outcstep), v03); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 4 * psc(outcstep), v04); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 5 * psc(outcstep), v05); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 6 * psc(outcstep), v10); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 7 * psc(outcstep), v11); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 8 * psc(outcstep), v12); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 9 * psc(outcstep), v13); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 10 * psc(outcstep), v14); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 11 * psc(outcstep), v15); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 12 * psc(outcstep), v20); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 13 * psc(outcstep), v21); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 14 * psc(outcstep), v22); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 15 * psc(outcstep), v23); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 16 * psc(outcstep), v24); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 17 * psc(outcstep), v25); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 18 * psc(outcstep), v30); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 19 * psc(outcstep), v31); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 20 * psc(outcstep), v32); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 21 * psc(outcstep), v33); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 22 * psc(outcstep), v34); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 23 * psc(outcstep), v35); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 24 * psc(outcstep), v40); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 25 * psc(outcstep), v41); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 26 * psc(outcstep), v42); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 27 * psc(outcstep), v43); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 28 * psc(outcstep), v44); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 29 * psc(outcstep), v45); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 30 * psc(outcstep), v50); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 31 * psc(outcstep), v51); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 32 * psc(outcstep), v52); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 33 * psc(outcstep), v53); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 34 * psc(outcstep), v54); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 35 * psc(outcstep), v55); | |||
| int v_tm_offset = gz * psc(outcstep) + gy * psc(block_x) + gx; | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 0 * psc(outcstep) * c, v00); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 1 * psc(outcstep) * c, v01); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 2 * psc(outcstep) * c, v02); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 3 * psc(outcstep) * c, v03); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 4 * psc(outcstep) * c, v04); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 5 * psc(outcstep) * c, v05); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 6 * psc(outcstep) * c, v10); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 7 * psc(outcstep) * c, v11); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 8 * psc(outcstep) * c, v12); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 9 * psc(outcstep) * c, v13); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 10 * psc(outcstep) * c, v14); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 11 * psc(outcstep) * c, v15); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 12 * psc(outcstep) * c, v20); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 13 * psc(outcstep) * c, v21); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 14 * psc(outcstep) * c, v22); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 15 * psc(outcstep) * c, v23); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 16 * psc(outcstep) * c, v24); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 17 * psc(outcstep) * c, v25); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 18 * psc(outcstep) * c, v30); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 19 * psc(outcstep) * c, v31); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 20 * psc(outcstep) * c, v32); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 21 * psc(outcstep) * c, v33); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 22 * psc(outcstep) * c, v34); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 23 * psc(outcstep) * c, v35); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 24 * psc(outcstep) * c, v40); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 25 * psc(outcstep) * c, v41); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 26 * psc(outcstep) * c, v42); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 27 * psc(outcstep) * c, v43); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 28 * psc(outcstep) * c, v44); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 29 * psc(outcstep) * c, v45); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 30 * psc(outcstep) * c, v50); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 31 * psc(outcstep) * c, v51); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 32 * psc(outcstep) * c, v52); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 33 * psc(outcstep) * c, v53); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 34 * psc(outcstep) * c, v54); | |||
| buffer_st8(bottom_tm_blob_data, v_tm_offset + 35 * psc(outcstep) * c, v55); | |||
| } | |||
| @@ -10,17 +10,17 @@ layout (constant_id = 0) const int bias_term = 0; | |||
| layout (constant_id = 1) const int activation_type = 0; | |||
| layout (constant_id = 2) const float activation_param_0 = 0; | |||
| layout (constant_id = 3) const float activation_param_1 = 0; | |||
| layout (constant_id = 4) const int c = 0; | |||
| #define shape_constant_id_offset 4 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int cstep = 0; | |||
| #define shape_constant_id_offset 5 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int block_y = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int block_x = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int block_y = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int outh = 0; | |||
| layout (constant_id = shape_constant_id_offset + 6) const int outcstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outh = 0; | |||
| layout (constant_id = shape_constant_id_offset + 5) const int outcstep = 0; | |||
| layout (binding = 0) readonly buffer top_tm_blob { sfpvec8 top_tm_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer top_blob { sfpvec8 top_blob_data[]; }; | |||
| @@ -28,7 +28,6 @@ layout (binding = 2) readonly buffer bias_blob { sfpvec8 bias_data[]; }; | |||
| layout (push_constant) uniform parameter | |||
| { | |||
| int c; | |||
| int cstep; | |||
| int block_x; | |||
| @@ -45,48 +44,48 @@ void main() | |||
| int gy = int(gl_GlobalInvocationID.y); | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| if (gx >= p.block_x || gy >= p.block_y || gz >= psc(c)) | |||
| if (gx >= p.block_x || gy >= p.block_y || gz >= c) | |||
| return; | |||
| // load 36 | |||
| int v_tm_offset = gz * psc(block_x) * psc(block_y) + gy * psc(block_x) + gx; | |||
| afpvec8 v00 = buffer_ld8(top_tm_blob_data, v_tm_offset + 0 * psc(cstep)); | |||
| afpvec8 v01 = buffer_ld8(top_tm_blob_data, v_tm_offset + 1 * psc(cstep)); | |||
| afpvec8 v02 = buffer_ld8(top_tm_blob_data, v_tm_offset + 2 * psc(cstep)); | |||
| afpvec8 v03 = buffer_ld8(top_tm_blob_data, v_tm_offset + 3 * psc(cstep)); | |||
| afpvec8 v04 = buffer_ld8(top_tm_blob_data, v_tm_offset + 4 * psc(cstep)); | |||
| afpvec8 v05 = buffer_ld8(top_tm_blob_data, v_tm_offset + 5 * psc(cstep)); | |||
| afpvec8 v10 = buffer_ld8(top_tm_blob_data, v_tm_offset + 6 * psc(cstep)); | |||
| afpvec8 v11 = buffer_ld8(top_tm_blob_data, v_tm_offset + 7 * psc(cstep)); | |||
| afpvec8 v12 = buffer_ld8(top_tm_blob_data, v_tm_offset + 8 * psc(cstep)); | |||
| afpvec8 v13 = buffer_ld8(top_tm_blob_data, v_tm_offset + 9 * psc(cstep)); | |||
| afpvec8 v14 = buffer_ld8(top_tm_blob_data, v_tm_offset + 10 * psc(cstep)); | |||
| afpvec8 v15 = buffer_ld8(top_tm_blob_data, v_tm_offset + 11 * psc(cstep)); | |||
| afpvec8 v20 = buffer_ld8(top_tm_blob_data, v_tm_offset + 12 * psc(cstep)); | |||
| afpvec8 v21 = buffer_ld8(top_tm_blob_data, v_tm_offset + 13 * psc(cstep)); | |||
| afpvec8 v22 = buffer_ld8(top_tm_blob_data, v_tm_offset + 14 * psc(cstep)); | |||
| afpvec8 v23 = buffer_ld8(top_tm_blob_data, v_tm_offset + 15 * psc(cstep)); | |||
| afpvec8 v24 = buffer_ld8(top_tm_blob_data, v_tm_offset + 16 * psc(cstep)); | |||
| afpvec8 v25 = buffer_ld8(top_tm_blob_data, v_tm_offset + 17 * psc(cstep)); | |||
| afpvec8 v30 = buffer_ld8(top_tm_blob_data, v_tm_offset + 18 * psc(cstep)); | |||
| afpvec8 v31 = buffer_ld8(top_tm_blob_data, v_tm_offset + 19 * psc(cstep)); | |||
| afpvec8 v32 = buffer_ld8(top_tm_blob_data, v_tm_offset + 20 * psc(cstep)); | |||
| afpvec8 v33 = buffer_ld8(top_tm_blob_data, v_tm_offset + 21 * psc(cstep)); | |||
| afpvec8 v34 = buffer_ld8(top_tm_blob_data, v_tm_offset + 22 * psc(cstep)); | |||
| afpvec8 v35 = buffer_ld8(top_tm_blob_data, v_tm_offset + 23 * psc(cstep)); | |||
| afpvec8 v40 = buffer_ld8(top_tm_blob_data, v_tm_offset + 24 * psc(cstep)); | |||
| afpvec8 v41 = buffer_ld8(top_tm_blob_data, v_tm_offset + 25 * psc(cstep)); | |||
| afpvec8 v42 = buffer_ld8(top_tm_blob_data, v_tm_offset + 26 * psc(cstep)); | |||
| afpvec8 v43 = buffer_ld8(top_tm_blob_data, v_tm_offset + 27 * psc(cstep)); | |||
| afpvec8 v44 = buffer_ld8(top_tm_blob_data, v_tm_offset + 28 * psc(cstep)); | |||
| afpvec8 v45 = buffer_ld8(top_tm_blob_data, v_tm_offset + 29 * psc(cstep)); | |||
| afpvec8 v50 = buffer_ld8(top_tm_blob_data, v_tm_offset + 30 * psc(cstep)); | |||
| afpvec8 v51 = buffer_ld8(top_tm_blob_data, v_tm_offset + 31 * psc(cstep)); | |||
| afpvec8 v52 = buffer_ld8(top_tm_blob_data, v_tm_offset + 32 * psc(cstep)); | |||
| afpvec8 v53 = buffer_ld8(top_tm_blob_data, v_tm_offset + 33 * psc(cstep)); | |||
| afpvec8 v54 = buffer_ld8(top_tm_blob_data, v_tm_offset + 34 * psc(cstep)); | |||
| afpvec8 v55 = buffer_ld8(top_tm_blob_data, v_tm_offset + 35 * psc(cstep)); | |||
| int v_tm_offset = gz * psc(cstep) + gy * psc(block_x) + gx; | |||
| afpvec8 v00 = buffer_ld8(top_tm_blob_data, v_tm_offset + 0 * psc(cstep) * c); | |||
| afpvec8 v01 = buffer_ld8(top_tm_blob_data, v_tm_offset + 1 * psc(cstep) * c); | |||
| afpvec8 v02 = buffer_ld8(top_tm_blob_data, v_tm_offset + 2 * psc(cstep) * c); | |||
| afpvec8 v03 = buffer_ld8(top_tm_blob_data, v_tm_offset + 3 * psc(cstep) * c); | |||
| afpvec8 v04 = buffer_ld8(top_tm_blob_data, v_tm_offset + 4 * psc(cstep) * c); | |||
| afpvec8 v05 = buffer_ld8(top_tm_blob_data, v_tm_offset + 5 * psc(cstep) * c); | |||
| afpvec8 v10 = buffer_ld8(top_tm_blob_data, v_tm_offset + 6 * psc(cstep) * c); | |||
| afpvec8 v11 = buffer_ld8(top_tm_blob_data, v_tm_offset + 7 * psc(cstep) * c); | |||
| afpvec8 v12 = buffer_ld8(top_tm_blob_data, v_tm_offset + 8 * psc(cstep) * c); | |||
| afpvec8 v13 = buffer_ld8(top_tm_blob_data, v_tm_offset + 9 * psc(cstep) * c); | |||
| afpvec8 v14 = buffer_ld8(top_tm_blob_data, v_tm_offset + 10 * psc(cstep) * c); | |||
| afpvec8 v15 = buffer_ld8(top_tm_blob_data, v_tm_offset + 11 * psc(cstep) * c); | |||
| afpvec8 v20 = buffer_ld8(top_tm_blob_data, v_tm_offset + 12 * psc(cstep) * c); | |||
| afpvec8 v21 = buffer_ld8(top_tm_blob_data, v_tm_offset + 13 * psc(cstep) * c); | |||
| afpvec8 v22 = buffer_ld8(top_tm_blob_data, v_tm_offset + 14 * psc(cstep) * c); | |||
| afpvec8 v23 = buffer_ld8(top_tm_blob_data, v_tm_offset + 15 * psc(cstep) * c); | |||
| afpvec8 v24 = buffer_ld8(top_tm_blob_data, v_tm_offset + 16 * psc(cstep) * c); | |||
| afpvec8 v25 = buffer_ld8(top_tm_blob_data, v_tm_offset + 17 * psc(cstep) * c); | |||
| afpvec8 v30 = buffer_ld8(top_tm_blob_data, v_tm_offset + 18 * psc(cstep) * c); | |||
| afpvec8 v31 = buffer_ld8(top_tm_blob_data, v_tm_offset + 19 * psc(cstep) * c); | |||
| afpvec8 v32 = buffer_ld8(top_tm_blob_data, v_tm_offset + 20 * psc(cstep) * c); | |||
| afpvec8 v33 = buffer_ld8(top_tm_blob_data, v_tm_offset + 21 * psc(cstep) * c); | |||
| afpvec8 v34 = buffer_ld8(top_tm_blob_data, v_tm_offset + 22 * psc(cstep) * c); | |||
| afpvec8 v35 = buffer_ld8(top_tm_blob_data, v_tm_offset + 23 * psc(cstep) * c); | |||
| afpvec8 v40 = buffer_ld8(top_tm_blob_data, v_tm_offset + 24 * psc(cstep) * c); | |||
| afpvec8 v41 = buffer_ld8(top_tm_blob_data, v_tm_offset + 25 * psc(cstep) * c); | |||
| afpvec8 v42 = buffer_ld8(top_tm_blob_data, v_tm_offset + 26 * psc(cstep) * c); | |||
| afpvec8 v43 = buffer_ld8(top_tm_blob_data, v_tm_offset + 27 * psc(cstep) * c); | |||
| afpvec8 v44 = buffer_ld8(top_tm_blob_data, v_tm_offset + 28 * psc(cstep) * c); | |||
| afpvec8 v45 = buffer_ld8(top_tm_blob_data, v_tm_offset + 29 * psc(cstep) * c); | |||
| afpvec8 v50 = buffer_ld8(top_tm_blob_data, v_tm_offset + 30 * psc(cstep) * c); | |||
| afpvec8 v51 = buffer_ld8(top_tm_blob_data, v_tm_offset + 31 * psc(cstep) * c); | |||
| afpvec8 v52 = buffer_ld8(top_tm_blob_data, v_tm_offset + 32 * psc(cstep) * c); | |||
| afpvec8 v53 = buffer_ld8(top_tm_blob_data, v_tm_offset + 33 * psc(cstep) * c); | |||
| afpvec8 v54 = buffer_ld8(top_tm_blob_data, v_tm_offset + 34 * psc(cstep) * c); | |||
| afpvec8 v55 = buffer_ld8(top_tm_blob_data, v_tm_offset + 35 * psc(cstep) * c); | |||
| #define sq2 1.41421356237 | |||
| #define sq2_m2 1.41421356237*2 | |||
| @@ -4,14 +4,13 @@ | |||
| #version 450 | |||
| layout (constant_id = 0) const int batch = 1; | |||
| layout (constant_id = 1) const int c = 0; | |||
| layout (constant_id = 2) const int outc = 0; | |||
| #define shape_constant_id_offset 1 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outc = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outcstep = 0; | |||
| #define shape_constant_id_offset 3 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outcstep = 0; | |||
| layout (binding = 0) readonly buffer bottom_tm_blob { sfpvec8 bottom_tm_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer top_tm_blob { sfpvec8 top_tm_blob_data[]; }; | |||
| @@ -19,11 +18,8 @@ layout (binding = 2) readonly buffer weight_tm_blob { sfpvec8 weight_tm_data[]; | |||
| layout (push_constant) uniform parameter | |||
| { | |||
| int c; | |||
| int cstep; | |||
| int outw; | |||
| int outc; | |||
| int outcstep; | |||
| } p; | |||
| @@ -33,7 +29,7 @@ void main() | |||
| int gy = int(gl_GlobalInvocationID.y); | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| if (gx >= psc(outw) || gy >= psc(outc) || gz >= batch) | |||
| if (gx >= psc(outw) || gy >= outc || gz >= batch) | |||
| return; | |||
| afpvec8 sum0 = afpvec8(afpvec4(0.f), afpvec4(0.f)); | |||
| @@ -41,10 +37,10 @@ void main() | |||
| afpvec8 sum2 = afpvec8(afpvec4(0.f), afpvec4(0.f)); | |||
| afpvec8 sum3 = afpvec8(afpvec4(0.f), afpvec4(0.f)); | |||
| int v_offset = gz * psc(cstep) + gx; | |||
| int w_offset = (gz * psc(c) * psc(outc) + gy * psc(c)) * 8; | |||
| int v_offset = gz * c * psc(cstep) + gx; | |||
| int w_offset = (gz * c * outc + gy * c) * 8; | |||
| for (int z = 0; z < psc(c); z++) | |||
| for (int z = 0; z < c; z++) | |||
| { | |||
| afpvec8 v0 = buffer_ld8(bottom_tm_blob_data, v_offset + 0); | |||
| afpvec8 v1 = buffer_ld8(bottom_tm_blob_data, v_offset + 1); | |||
| @@ -97,11 +93,11 @@ void main() | |||
| sum3[1].b += dot(v3[0], k6[0]) + dot(v3[1], k6[1]); | |||
| sum3[1].a += dot(v3[0], k7[0]) + dot(v3[1], k7[1]); | |||
| v_offset += psc(outw); | |||
| v_offset += psc(cstep); | |||
| w_offset += 8; | |||
| } | |||
| int gi = gz * psc(outcstep) + gy * psc(outw) + gx; | |||
| int gi = gz * outc * psc(outcstep) + gy * psc(outcstep) + gx; | |||
| buffer_st8(top_tm_blob_data, gi + 0, sum0); | |||
| if (gx + 1 < psc(outw)) buffer_st8(top_tm_blob_data, gi + 1, sum1); | |||
| @@ -4,14 +4,13 @@ | |||
| #version 450 | |||
| layout (constant_id = 0) const int batch = 1; | |||
| layout (constant_id = 1) const int c = 0; | |||
| layout (constant_id = 2) const int outc = 0; | |||
| #define shape_constant_id_offset 1 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outc = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outcstep = 0; | |||
| #define shape_constant_id_offset 3 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outcstep = 0; | |||
| layout (binding = 0) readonly buffer bottom_tm_blob { sfpvec8 bottom_tm_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer top_tm_blob { sfp top_tm_blob_data[]; }; | |||
| @@ -19,11 +18,8 @@ layout (binding = 2) readonly buffer weight_tm_blob { sfpvec8 weight_tm_data[]; | |||
| layout (push_constant) uniform parameter | |||
| { | |||
| int c; | |||
| int cstep; | |||
| int outw; | |||
| int outc; | |||
| int outcstep; | |||
| } p; | |||
| @@ -33,7 +29,7 @@ void main() | |||
| int gy = int(gl_GlobalInvocationID.y); | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| if (gx >= psc(outw) || gy >= psc(outc) || gz >= batch) | |||
| if (gx >= psc(outw) || gy >= outc || gz >= batch) | |||
| return; | |||
| afp sum0 = afp(0.f); | |||
| @@ -41,10 +37,10 @@ void main() | |||
| afp sum2 = afp(0.f); | |||
| afp sum3 = afp(0.f); | |||
| int v_offset = gz * psc(cstep) + gx; | |||
| int w_offset = gz * psc(c) * psc(outc) + gy * psc(c); | |||
| int v_offset = gz * c * psc(cstep) + gx; | |||
| int w_offset = gz * c * outc + gy * c; | |||
| for (int z = 0; z < psc(c); z++) | |||
| for (int z = 0; z < c; z++) | |||
| { | |||
| afpvec8 v0 = buffer_ld8(bottom_tm_blob_data, v_offset + 0); | |||
| afpvec8 v1 = buffer_ld8(bottom_tm_blob_data, v_offset + 1); | |||
| @@ -59,11 +55,11 @@ void main() | |||
| sum2 += dot(v2[0], k[0]) + dot(v2[1], k[1]); | |||
| sum3 += dot(v3[0], k[0]) + dot(v3[1], k[1]); | |||
| v_offset += psc(outw); | |||
| v_offset += psc(cstep); | |||
| w_offset += 1; | |||
| } | |||
| int gi = gz * psc(outcstep) + gy * psc(outw) + gx; | |||
| int gi = gz * outc * psc(outcstep) + gy * psc(outcstep) + gx; | |||
| buffer_st1(top_tm_blob_data, gi + 0, sum0); | |||
| if (gx + 1 < psc(outw)) buffer_st1(top_tm_blob_data, gi + 1, sum1); | |||
| @@ -4,14 +4,13 @@ | |||
| #version 450 | |||
| layout (constant_id = 0) const int batch = 1; | |||
| layout (constant_id = 1) const int c = 0; | |||
| layout (constant_id = 2) const int outc = 0; | |||
| #define shape_constant_id_offset 1 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int c = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 3) const int outc = 0; | |||
| layout (constant_id = shape_constant_id_offset + 4) const int outcstep = 0; | |||
| #define shape_constant_id_offset 3 | |||
| layout (constant_id = shape_constant_id_offset + 0) const int cstep = 0; | |||
| layout (constant_id = shape_constant_id_offset + 1) const int outw = 0; | |||
| layout (constant_id = shape_constant_id_offset + 2) const int outcstep = 0; | |||
| layout (binding = 0) readonly buffer bottom_tm_blob { sfpvec8 bottom_tm_blob_data[]; }; | |||
| layout (binding = 1) writeonly buffer top_tm_blob { sfpvec4 top_tm_blob_data[]; }; | |||
| @@ -19,11 +18,8 @@ layout (binding = 2) readonly buffer weight_tm_blob { sfpvec8 weight_tm_data[]; | |||
| layout (push_constant) uniform parameter | |||
| { | |||
| int c; | |||
| int cstep; | |||
| int outw; | |||
| int outc; | |||
| int outcstep; | |||
| } p; | |||
| @@ -33,7 +29,7 @@ void main() | |||
| int gy = int(gl_GlobalInvocationID.y); | |||
| int gz = int(gl_GlobalInvocationID.z); | |||
| if (gx >= psc(outw) || gy >= psc(outc) || gz >= batch) | |||
| if (gx >= psc(outw) || gy >= outc || gz >= batch) | |||
| return; | |||
| afpvec4 sum0 = afpvec4(0.f); | |||
| @@ -41,10 +37,10 @@ void main() | |||
| afpvec4 sum2 = afpvec4(0.f); | |||
| afpvec4 sum3 = afpvec4(0.f); | |||
| int v_offset = gz * psc(cstep) + gx; | |||
| int w_offset = (gz * psc(c) * psc(outc) + gy * psc(c)) * 4; | |||
| int v_offset = gz * c * psc(cstep) + gx; | |||
| int w_offset = (gz * c * outc + gy * c) * 4; | |||
| for (int z = 0; z < psc(c); z++) | |||
| for (int z = 0; z < c; z++) | |||
| { | |||
| afpvec8 v0 = buffer_ld8(bottom_tm_blob_data, v_offset + 0); | |||
| afpvec8 v1 = buffer_ld8(bottom_tm_blob_data, v_offset + 1); | |||
| @@ -77,11 +73,11 @@ void main() | |||
| sum3.b += dot(v3[0], k2[0]) + dot(v3[1], k2[1]); | |||
| sum3.a += dot(v3[0], k3[0]) + dot(v3[1], k3[1]); | |||
| v_offset += psc(outw); | |||
| v_offset += psc(cstep); | |||
| w_offset += 4; | |||
| } | |||
| int gi = gz * psc(outcstep) + gy * psc(outw) + gx; | |||
| int gi = gz * outc * psc(outcstep) + gy * psc(outcstep) + gx; | |||
| buffer_st4(top_tm_blob_data, gi + 0, sum0); | |||
| if (gx + 1 < psc(outw)) buffer_st4(top_tm_blob_data, gi + 1, sum1); | |||