Example: VulkanExamples/p78_coopmat
VK_KHR_cooperative_matrix هو العملية المشكّلة كنواة موتر في Vulkan:
coopmat هي مصفوفة موزعة عبر مجموعة فرعية كاملة — لا
lane يملكها، coopMatLoad/coopMatStore تبعثرها/تجمعها، و
coopMatMulAdd(A, B, C) يحسب A*B + C كعملية جماعية واحدة.
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);الأشكال المدعومة استعلام عتادي —
vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR — وعلى
NAVI32/RADV هناك بالضبط 14 إدخالًا، كلها 16×16×16 عند
VK_SCOPE_SUBGROUP، بمداخل uint8/sint8/float16 و
مراكمات uint32/sint32/f32. يختار العرض s8 × s8 → s32: حساب
صحيح، لذا 16×16 ضرب-جمع مصفوفات يتحقق بالبت تمامًا مقابل
الـ CPU، bad=0.
ملاحظات عملية:
- يجب أن تكون الـ workgroup فعليًا هي النطاق المتعاون — استخدم
local_size_x_idمغذّى بـsubgroupSize(64 على RADV wave64). - ثابت التخطيط هو
gl_CooperativeMatrixLayoutRowMajor— لاgl_MatrixLayoutRowMajor؛ الاسم الأقصر غير موجود. int8_t/int32_tفي SSBOs يحتاجانGL_EXT_shader_8bit_storage+GL_EXT_shader_explicit_arithmetic_types_int8/int32زائد بتّات ميزات Vulkan المطابقة (storageBuffer8BitAccess،shaderInt8).- الفكرة كاملة مقابل عملها lane-بـlane: ملء المصفوفة مخفي — التعريف يعينها على عتاد WMMA/جداء-نقطي دون أن تهتم أي lane يحمل أي عنصر.
كل الشفرة المصدرية في هذه السلسلة منشورة تحت CC0 1.0 Universal (CC0-1.0).
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow