Vulkan'da VK_KHR_cooperative_matrix kullanımı

Example: VulkanExamples/p78_coopmat

VK_KHR_cooperative_matrix Vulkan’daki tensor-core şekilli op’tur: coopmat tüm bir subgroup’a dağıtılmış bir matristir — hiçbir lane ona sahip değil, coopMatLoad/coopMatStore onu scatter/gather eder ve coopMatMulAdd(A, B, C) A*B + C‘yi tek kolektif op olarak hesaplar.

example.txt
#extension GL_KHR_cooperative_matrix : require
#extension GL_KHR_memory_scope_semantics : require

coopmat<int8_t,  gl_ScopeSubgroup, 16, 16, gl_MatrixUseA> A;
coopmat<int8_t,  gl_ScopeSubgroup, 16, 16, gl_MatrixUseB> B;
coopmat<int32_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator> C;
coopMatLoad(A, a, 0, 16, gl_CooperativeMatrixLayoutRowMajor);
C = coopMatMulAdd(A, B, C);
coopMatStore(C, c, 0, 16, gl_CooperativeMatrixLayoutRowMajor);

Desteklenen şekiller bir donanım sorgusu — vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR — ve NAVI32/RADV’da tam 14 girdi var, hepsi VK_SCOPE_SUBGROUP‘ta 16×16×16, uint8/sint8/float16 girdi ve uint32/sint32/f32 accumulator’lı. Demo s8 × s8 → s32 seçer: int matematiği, yani 16×16 matmul-add CPU ile bit-bit doğrulanır, bad=0.

Pratik notlar:

  • Workgroup fiilen işbirliği yapan scope olmalı — subgroupSize ile beslenen local_size_x_id kullan (RADV wave64’te 64).
  • Layout sabiti gl_CooperativeMatrixLayoutRowMajor — gl_MatrixLayoutRowMajor değil; kısa ad mevcut değil.
  • SSBO’larda int8_t/int32_t GL_EXT_shader_8bit_storage + GL_EXT_shader_explicit_arithmetic_types_int8/int32 artı eşleşen Vulkan feature bitleri (storageBuffer8BitAccess, shaderInt8) gerektirir.
  • Lane-wise yapmakla karşılaştırınca asıl nokta: matrisin dolduruluşu gizli — hangi lane’in hangi elemanı tuttuğunu önemsemeden driver onu WMMA/dot-product donanımına map eder.

Bu serideki tüm kaynak kod CC0 1.0 Universal (CC0-1.0) altında yayınlanmıştır.


Check out similar posts by category: C++ Vulkan