Skip to content

Commit 1078a15

Browse files
hongbinghuSS-JIA
authored andcommitted
[ET-VK] Add NV cooperative matrix extension
Add NV cooperative matrix extension if available in the target platform Differential Revision: [D92570456](https://our.internmc.facebook.com/intern/diff/D92570456/) ghstack-source-id: 342450784 Pull Request resolved: pytorch#17544
1 parent 73c472e commit 1078a15

4 files changed

Lines changed: 59 additions & 0 deletions

File tree

‎backends/vulkan/runtime/vk_api/Adapter.cpp‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ VkDevice create_logical_device(
123123
defined(ETVK_INSPECT_PIPELINES)
124124
VK_KHR_PIPELINE_EXECUTABLE_PROPERTIES_EXTENSION_NAME,
125125
#endif /* VK_KHR_pipeline_executable_properties && ETVK_INSPECT_PIPELINES */
126+
#ifdef VK_KHR_cooperative_matrix
127+
VK_KHR_COOPERATIVE_MATRIX_EXTENSION_NAME,
128+
#endif /* VK_KHR_cooperative_matrix */
129+
#ifdef VK_NV_cooperative_matrix2
130+
VK_NV_COOPERATIVE_MATRIX_2_EXTENSION_NAME,
131+
#endif /* VK_NV_cooperative_matrix2 */
126132
};
127133

128134
std::vector<const char*> enabled_device_extensions;
@@ -179,6 +185,20 @@ VkDevice create_logical_device(
179185
extension_list_top = &shader_int_dot_product_features;
180186
#endif /* VK_KHR_shader_integer_dot_product */
181187

188+
#ifdef VK_KHR_cooperative_matrix
189+
VkPhysicalDeviceCooperativeMatrixFeaturesKHR cooperative_matrix_features{
190+
physical_device.cooperative_matrix_features};
191+
cooperative_matrix_features.pNext = extension_list_top;
192+
extension_list_top = &cooperative_matrix_features;
193+
#endif /* VK_KHR_cooperative_matrix */
194+
195+
#ifdef VK_NV_cooperative_matrix2
196+
VkPhysicalDeviceCooperativeMatrix2FeaturesNV cooperative_matrix2_features{
197+
physical_device.cooperative_matrix2_features};
198+
cooperative_matrix2_features.pNext = extension_list_top;
199+
extension_list_top = &cooperative_matrix2_features;
200+
#endif /* VK_NV_cooperative_matrix2 */
201+
182202
device_create_info.pNext = extension_list_top;
183203

184204
VkDevice handle = nullptr;

‎backends/vulkan/runtime/vk_api/Adapter.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,19 @@ class Adapter final {
221221
#endif /* VK_KHR_shader_integer_dot_product */
222222
}
223223

224+
inline bool supports_nv_cooperative_matrix2() {
225+
#ifdef VK_NV_cooperative_matrix2
226+
return physical_device_.cooperative_matrix2_features
227+
.cooperativeMatrixWorkgroupScope == VK_TRUE &&
228+
physical_device_.cooperative_matrix2_features
229+
.cooperativeMatrixFlexibleDimensions == VK_TRUE &&
230+
physical_device_.cooperative_matrix2_features
231+
.cooperativeMatrixTensorAddressing == VK_TRUE;
232+
#else
233+
return false;
234+
#endif /* VK_NV_cooperative_matrix2 */
235+
}
236+
224237
inline bool supports_int16_shader_types() {
225238
return physical_device_.supports_int16_shader_types;
226239
}

‎backends/vulkan/runtime/vk_api/Device.cpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ PhysicalDevice::PhysicalDevice(
5151
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_INTEGER_DOT_PRODUCT_PROPERTIES_KHR,
5252
nullptr},
5353
#endif
54+
#ifdef VK_KHR_cooperative_matrix
55+
cooperative_matrix_features{
56+
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_FEATURES_KHR},
57+
#endif /* VK_KHR_cooperative_matrix */
58+
#ifdef VK_NV_cooperative_matrix2
59+
cooperative_matrix2_features{
60+
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_2_FEATURES_NV},
61+
#endif /* VK_NV_cooperative_matrix2 */
5462
queue_families{},
5563
num_compute_queues(0),
5664
api_version_major(0),
@@ -246,6 +254,16 @@ void PhysicalDevice::query_extensions_vk_1_1() {
246254
extension_list_top = &shader_int_dot_product_features;
247255
#endif /* VK_KHR_shader_integer_dot_product */
248256

257+
#ifdef VK_KHR_cooperative_matrix
258+
cooperative_matrix_features.pNext = extension_list_top;
259+
extension_list_top = &cooperative_matrix_features;
260+
#endif /* VK_KHR_cooperative_matrix */
261+
262+
#ifdef VK_NV_cooperative_matrix2
263+
cooperative_matrix2_features.pNext = extension_list_top;
264+
extension_list_top = &cooperative_matrix2_features;
265+
#endif /* VK_NV_cooperative_matrix2 */
266+
249267
features2.pNext = extension_list_top;
250268

251269
vkGetPhysicalDeviceFeatures2(handle, &features2);

‎backends/vulkan/runtime/vk_api/Device.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ struct PhysicalDevice final {
5252
shader_int_dot_product_properties;
5353
#endif /* VK_KHR_shader_integer_dot_product */
5454

55+
#ifdef VK_KHR_cooperative_matrix
56+
VkPhysicalDeviceCooperativeMatrixFeaturesKHR cooperative_matrix_features;
57+
#endif /* VK_KHR_cooperative_matrix */
58+
59+
#ifdef VK_NV_cooperative_matrix2
60+
VkPhysicalDeviceCooperativeMatrix2FeaturesNV cooperative_matrix2_features;
61+
#endif /* VK_NV_cooperative_matrix2 */
62+
5563
// Available GPU queues
5664
std::vector<VkQueueFamilyProperties> queue_families;
5765

0 commit comments

Comments
 (0)