torchvulkan 0.2.1__tar.gz → 0.3.0a0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. torchvulkan-0.3.0a0/.github/scripts/fetch-moltenvk-macos.sh +23 -0
  2. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/.github/workflows/release.yaml +13 -10
  3. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/.github/workflows/test_torchvulkan.yml +6 -7
  4. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/CMakeLists.txt +24 -1
  5. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/PKG-INFO +7 -4
  6. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/README.md +2 -2
  7. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/pyproject.toml +5 -5
  8. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/scripts/build_shaders.py +2 -1
  9. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/scripts/config.py +44 -25
  10. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/scripts/pack_shaders.py +11 -7
  11. torchvulkan-0.3.0a0/scripts/splice_coop_dims.py +172 -0
  12. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/backend.cpp +18 -3
  13. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/decompositions.cpp +295 -119
  14. torchvulkan-0.3.0a0/src/api/fallback.cpp +13 -0
  15. torchvulkan-0.3.0a0/src/api/fallback.h +11 -0
  16. torchvulkan-0.3.0a0/src/api/guard.cpp +103 -0
  17. torchvulkan-0.3.0a0/src/api/hook.cpp +83 -0
  18. torchvulkan-0.3.0a0/src/api/ops/attention.cpp +762 -0
  19. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/binary.cpp +461 -76
  20. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/bitwise.cpp +19 -8
  21. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/compare.cpp +96 -18
  22. torchvulkan-0.3.0a0/src/api/ops/complex.cpp +395 -0
  23. torchvulkan-0.3.0a0/src/api/ops/conv.cpp +1321 -0
  24. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/ctc.cpp +1 -0
  25. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/distributions.cpp +9 -4
  26. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/dropout.cpp +7 -5
  27. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/fft.cpp +70 -5
  28. torchvulkan-0.3.0a0/src/api/ops/fill.cpp +134 -0
  29. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/grid_sample.cpp +17 -3
  30. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/helpers.h +253 -2
  31. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/indexing.cpp +80 -14
  32. torchvulkan-0.3.0a0/src/api/ops/internal.h +73 -0
  33. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/linalg.cpp +428 -74
  34. torchvulkan-0.3.0a0/src/api/ops/matmul.cpp +763 -0
  35. torchvulkan-0.3.0a0/src/api/ops/nested.cpp +326 -0
  36. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/nllloss.cpp +22 -4
  37. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/nn.cpp +252 -27
  38. torchvulkan-0.3.0a0/src/api/ops/norm.cpp +433 -0
  39. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/pool.cpp +54 -14
  40. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/random.cpp +25 -5
  41. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/reduce.cpp +197 -13
  42. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/sampling.cpp +26 -16
  43. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/scan.cpp +89 -12
  44. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/scatter.cpp +242 -23
  45. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/search.cpp +37 -10
  46. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/shape.cpp +36 -4
  47. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/sort.cpp +23 -3
  48. torchvulkan-0.3.0a0/src/api/ops/sparse.cpp +386 -0
  49. torchvulkan-0.3.0a0/src/api/ops/sparse_ops.cpp +831 -0
  50. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/special.cpp +7 -5
  51. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/unary.cpp +208 -62
  52. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/upsample.cpp +41 -6
  53. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/registration.cpp +1 -14
  54. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/tensor/allocation.cpp +33 -4
  55. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/tensor/cast.cpp +4 -3
  56. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/tensor/transfer.cpp +163 -9
  57. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/tensor/views.cpp +2 -2
  58. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/CMakeLists.txt +17 -3
  59. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/core/dtype.slang +26 -1
  60. torchvulkan-0.3.0a0/src/shaders/helpers/attention.slang +75 -0
  61. torchvulkan-0.3.0a0/src/shaders/helpers/conv.slang +511 -0
  62. torchvulkan-0.3.0a0/src/shaders/helpers/gemm.slang +24 -0
  63. torchvulkan-0.3.0a0/src/shaders/helpers/gemm_coop.slang +66 -0
  64. torchvulkan-0.2.1/src/shaders/ops/matmul_simd.slang → torchvulkan-0.3.0a0/src/shaders/helpers/gemm_simd.slang +12 -71
  65. {torchvulkan-0.2.1/src/shaders/ops → torchvulkan-0.3.0a0/src/shaders/helpers}/unary_ops.slang +2 -1
  66. torchvulkan-0.3.0a0/src/shaders/helpers/winograd.slang +133 -0
  67. torchvulkan-0.3.0a0/src/shaders/ops/addc.slang +69 -0
  68. torchvulkan-0.3.0a0/src/shaders/ops/attention_coop.slang +506 -0
  69. torchvulkan-0.3.0a0/src/shaders/ops/attention_simd.slang +399 -0
  70. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/binary.slang +12 -0
  71. torchvulkan-0.3.0a0/src/shaders/ops/complex_arc.slang +272 -0
  72. torchvulkan-0.3.0a0/src/shaders/ops/conv_coop.slang +311 -0
  73. torchvulkan-0.3.0a0/src/shaders/ops/conv_simd.slang +149 -0
  74. torchvulkan-0.3.0a0/src/shaders/ops/eig.slang +915 -0
  75. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/grid_sample.slang +120 -1
  76. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/householder.slang +2 -1
  77. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/jacobi.slang +64 -13
  78. torchvulkan-0.3.0a0/src/shaders/ops/ldl.slang +381 -0
  79. torchvulkan-0.3.0a0/src/shaders/ops/matmul_coop.slang +452 -0
  80. torchvulkan-0.3.0a0/src/shaders/ops/matmul_simd.slang +44 -0
  81. torchvulkan-0.3.0a0/src/shaders/ops/norm.slang +341 -0
  82. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/resample.slang +9 -0
  83. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/unary.slang +3 -1
  84. torchvulkan-0.3.0a0/src/shaders/ops/winograd_coop.slang +136 -0
  85. torchvulkan-0.3.0a0/src/shaders/ops/winograd_simd.slang +107 -0
  86. torchvulkan-0.3.0a0/src/shaders/ops/winograd_transform.slang +116 -0
  87. torchvulkan-0.3.0a0/src/vulkan/allocator.cpp +201 -0
  88. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/vulkan/allocator.h +10 -2
  89. torchvulkan-0.3.0a0/src/vulkan/autotuner.cpp +223 -0
  90. torchvulkan-0.3.0a0/src/vulkan/autotuner.h +69 -0
  91. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/vulkan/builders.h +42 -5
  92. torchvulkan-0.3.0a0/src/vulkan/cache.cpp +252 -0
  93. torchvulkan-0.3.0a0/src/vulkan/cache.h +68 -0
  94. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/vulkan/device_context.cpp +44 -2
  95. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/vulkan/device_context.h +26 -1
  96. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/vulkan/generator.cpp +31 -13
  97. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/vulkan/generator.h +13 -5
  98. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/vulkan/memory.cpp +5 -0
  99. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/vulkan/memory.h +27 -1
  100. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/vulkan/shader.cpp +163 -102
  101. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/vulkan/shader.h +32 -10
  102. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/vulkan/vulkan_context.cpp +41 -4
  103. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/vulkan/vulkan_context.h +2 -0
  104. torchvulkan-0.3.0a0/tests/run_pytorch_suites.py +649 -0
  105. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/tests/test_pytorch_ops.py +12 -7
  106. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/torchvulkan/__init__.py +93 -9
  107. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/torchvulkan/_version.py +3 -3
  108. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/tox.ini +1 -3
  109. torchvulkan-0.2.1/.github/scripts/fetch-moltenvk-macos.sh +0 -18
  110. torchvulkan-0.2.1/src/api/guard.cpp +0 -48
  111. torchvulkan-0.2.1/src/api/hook.cpp +0 -40
  112. torchvulkan-0.2.1/src/api/ops/complex.cpp +0 -75
  113. torchvulkan-0.2.1/src/api/ops/conv.cpp +0 -567
  114. torchvulkan-0.2.1/src/api/ops/fill.cpp +0 -74
  115. torchvulkan-0.2.1/src/api/ops/internal.h +0 -26
  116. torchvulkan-0.2.1/src/api/ops/matmul.cpp +0 -564
  117. torchvulkan-0.2.1/src/shaders/ops/conv.slang +0 -338
  118. torchvulkan-0.2.1/src/shaders/ops/eig.slang +0 -524
  119. torchvulkan-0.2.1/src/shaders/ops/ldl.slang +0 -254
  120. torchvulkan-0.2.1/src/shaders/ops/matmul_coop.slang +0 -530
  121. torchvulkan-0.2.1/src/vulkan/allocator.cpp +0 -111
  122. torchvulkan-0.2.1/src/vulkan/cache.cpp +0 -290
  123. torchvulkan-0.2.1/src/vulkan/cache.h +0 -74
  124. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/.github/actions/setup-toolchain/action.yml +0 -0
  125. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/.github/scripts/install-toolchain-linux.sh +0 -0
  126. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/.gitignore +0 -0
  127. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/LICENSE +0 -0
  128. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/benchmark/benchmark.py +0 -0
  129. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/examples/conv.py +0 -0
  130. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/examples/llm.py +0 -0
  131. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/examples/mlp.py +0 -0
  132. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/extern/vma/vk_mem_alloc.h +0 -0
  133. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/extern/volk/volk.c +0 -0
  134. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/extern/volk/volk.h +0 -0
  135. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/licenses/MoltenVK-LICENSE +0 -0
  136. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/media/benchmark-cuda.png +0 -0
  137. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/requirements.txt +0 -0
  138. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/api/ops/optim.cpp +0 -0
  139. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/core/cast.slang +0 -0
  140. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/core/indexing.slang +0 -0
  141. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/core/philox.slang +0 -0
  142. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/core/special_functions.slang +0 -0
  143. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/arg_reduce.slang +0 -0
  144. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/cast.slang +0 -0
  145. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/cholesky.slang +0 -0
  146. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/compare.slang +0 -0
  147. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/copy.slang +0 -0
  148. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/ctc.slang +0 -0
  149. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/distribution.slang +0 -0
  150. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/dropout.slang +0 -0
  151. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/embedding_backward.slang +0 -0
  152. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/fft.slang +0 -0
  153. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/fill.slang +0 -0
  154. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/index_gather.slang +0 -0
  155. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/integer_binary.slang +0 -0
  156. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/lu.slang +0 -0
  157. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/multinomial.slang +0 -0
  158. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/nllloss.slang +0 -0
  159. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/pool.slang +0 -0
  160. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/random.slang +0 -0
  161. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/reduce.slang +0 -0
  162. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/reduce_subgroup.slang +0 -0
  163. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/resample_u8.slang +0 -0
  164. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/scan.slang +0 -0
  165. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/scan_arg.slang +0 -0
  166. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/scatter.slang +0 -0
  167. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/searchsorted.slang +0 -0
  168. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/sort.slang +0 -0
  169. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/special.slang +0 -0
  170. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/triangular_solve.slang +0 -0
  171. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/shaders/ops/where.slang +0 -0
  172. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/vulkan/dispatch.cpp +0 -0
  173. {torchvulkan-0.2.1 → torchvulkan-0.3.0a0}/src/vulkan/dispatch.h +0 -0
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env bash
2
+ # The output path MUST match TORCHVULKAN_MOLTENVK in [tool.cibuildwheel.macos]
3
+ # environment in pyproject.toml. The dylib ships inside the macOS wheel, so the
4
+ # download is pinned by SHA-256; update the hash with the version.
5
+ set -euo pipefail
6
+
7
+ # zainsharief/MoltenVK-torchvulkan: MoltenVK + VK_KHR_cooperative_matrix (arm64).
8
+ MOLTENVK_VERSION="1.4.3-torchvulkan.1"
9
+ MOLTENVK_SHA256="1ea0c46f202f838b6f271a09776cd45613c65d28493aedcb95a3bea5dd67449b"
10
+ OUT_DIR="${MOLTENVK_OUT_DIR:-/tmp/moltenvk}"
11
+ ARCHIVE="$OUT_DIR/MoltenVK-macos-arm64.tar.gz"
12
+
13
+ mkdir -p "$OUT_DIR"
14
+ # an archive already here with the pinned hash is reused, so local reconfigures don't download again
15
+ if ! echo "${MOLTENVK_SHA256} $ARCHIVE" | shasum -a 256 -c - > /dev/null 2>&1; then
16
+ curl -sSLf -o "$ARCHIVE" \
17
+ "https://github.com/zainsharief/MoltenVK-torchvulkan/releases/download/v${MOLTENVK_VERSION}/MoltenVK-macos-arm64.tar.gz"
18
+ echo "${MOLTENVK_SHA256} $ARCHIVE" | shasum -a 256 -c -
19
+ fi
20
+ tar -xzf "$ARCHIVE" -C "$OUT_DIR"
21
+ cp "$OUT_DIR/MoltenVK/libMoltenVK.dylib" "$OUT_DIR/libMoltenVK.dylib"
22
+
23
+ test -f "$OUT_DIR/libMoltenVK.dylib"
@@ -21,7 +21,7 @@ jobs:
21
21
 
22
22
  - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
23
23
  with:
24
- python-version: "3.10"
24
+ python-version: "3.15"
25
25
 
26
26
  - name: Build sdist
27
27
  run: |
@@ -34,18 +34,20 @@ jobs:
34
34
  path: dist/*.tar.gz
35
35
 
36
36
  build_wheels:
37
- name: Wheels (${{ matrix.name }})
37
+ name: Wheels (${{ matrix.name }} / ${{ matrix.python }})
38
38
  runs-on: ${{ matrix.os }}
39
39
  strategy:
40
40
  fail-fast: false
41
41
  matrix:
42
+ os: [ubuntu-latest, macos-15, windows-latest]
43
+ python: [cp311, cp312, cp313, cp314, cp315]
42
44
  include:
43
- - name: Linux x86_64
44
- os: ubuntu-latest
45
- - name: macOS Apple Silicon
46
- os: macos-15
47
- - name: Windows x86_64
48
- os: windows-latest
45
+ - os: ubuntu-latest
46
+ name: Linux x86_64
47
+ - os: macos-15
48
+ name: macOS Apple Silicon
49
+ - os: windows-latest
50
+ name: Windows x86_64
49
51
  steps:
50
52
  - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
51
53
  with:
@@ -67,13 +69,14 @@ jobs:
67
69
  uses: ./.github/actions/setup-toolchain
68
70
 
69
71
  - name: Build wheels
70
- uses: pypa/cibuildwheel@9c00cb4f6b517705a3794b22395aedc36257242c # v3.2.1
72
+ uses: pypa/cibuildwheel@f9b966cfadf4109556cadc5bb39ddb72d0ce664e # v4.3.5
71
73
  env:
72
74
  CIBW_BUILD_VERBOSITY: "1"
75
+ CIBW_BUILD: ${{ matrix.python }}-*
73
76
 
74
77
  - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
75
78
  with:
76
- name: dist-${{ matrix.os }}
79
+ name: dist-${{ matrix.os }}-${{ matrix.python }}
77
80
  path: wheelhouse/*.whl
78
81
 
79
82
  pypi-publish:
@@ -8,7 +8,7 @@ on:
8
8
 
9
9
  jobs:
10
10
  build-and-test:
11
- name: ${{ matrix.os }} / Py${{ matrix.python-version }} / ${{ matrix.torch-factor }}
11
+ name: ${{ matrix.os }} / Py${{ matrix.python-version }}
12
12
  runs-on: ${{ matrix.os }}
13
13
  env:
14
14
  SKBUILD_CMAKE_GENERATOR: Ninja
@@ -16,8 +16,7 @@ jobs:
16
16
  fail-fast: false
17
17
  matrix:
18
18
  os: [ubuntu-latest, macos-15, windows-latest]
19
- python-version: ["3.10", "3.12", "3.14"]
20
- torch-factor: ["torch210", "torch213"]
19
+ python-version: ["3.11", "3.13", "3.15"]
21
20
 
22
21
  steps:
23
22
  - name: Checkout Code
@@ -50,7 +49,7 @@ jobs:
50
49
  DNNL_MAX_CPU_ISA: AVX2 # legacy name for the same oneDNN ISA cap (older bundled oneDNN)
51
50
  LP_NATIVE_VECTOR_WIDTH: "256" # cap lavapipe's LLVM JIT to AVX2; AVX-512 codegen faults (0xc000001d) on GHA runners
52
51
  run: |
53
- tox -e py-${{ matrix.torch-factor }}
52
+ tox -e py
54
53
 
55
54
  validation:
56
55
  name: validation layers (lavapipe, debug)
@@ -83,7 +82,7 @@ jobs:
83
82
  run: |
84
83
  python -m pip install --upgrade pip
85
84
  pip install tox
86
- tox -e py-torch213 -- -k "TestVulkanRuntime or test_correctness_add or test_correctness_mm or test_correctness_sum or test_correctness_sort or test_correctness_index or test_correctness_cumsum or test_gradients_nn_functional_linear"
85
+ tox -e py -- -k "test_correctness_add or test_correctness_mm or test_correctness_sum or test_correctness_sort or test_correctness_index or test_correctness_cumsum or test_gradients_nn_functional_linear"
87
86
 
88
87
  sanitizers:
89
88
  name: ASan + UBSan (lavapipe)
@@ -108,7 +107,7 @@ jobs:
108
107
  SKBUILD_CMAKE_ARGS: "-DCMAKE_CXX_FLAGS=-fsanitize=address,undefined -fno-omit-frame-pointer;-DCMAKE_MODULE_LINKER_FLAGS=-fsanitize=address,undefined"
109
108
  run: |
110
109
  python -m pip install --upgrade pip
111
- pip install "torch==2.13.0" pytest expecttest numpy ninja scikit-build-core setuptools_scm
110
+ pip install $(python -c 'import tomllib; print(" ".join(tomllib.load(open("pyproject.toml", "rb"))["build-system"]["requires"]))') pytest expecttest numpy ninja
112
111
  pip install . --no-build-isolation -v
113
112
 
114
113
  - name: Run tests with the sanitizer runtimes preloaded
@@ -123,7 +122,7 @@ jobs:
123
122
  run: |
124
123
  cd "$RUNNER_TEMP"
125
124
  export LD_PRELOAD="$(gcc -print-file-name=libasan.so):$(gcc -print-file-name=libubsan.so)"
126
- python -m pytest "$GITHUB_WORKSPACE/tests/test_pytorch_ops.py" -q -k "TestVulkanRuntime or test_correctness_add or test_correctness_mm or test_correctness_sort or test_correctness_index or test_correctness_sum"
125
+ python -m pytest "$GITHUB_WORKSPACE/tests/test_pytorch_ops.py" -q -k "test_correctness_add or test_correctness_mm or test_correctness_sort or test_correctness_index or test_correctness_sum"
127
126
 
128
127
  testing-success:
129
128
  name: testing success
@@ -30,8 +30,31 @@ target_compile_features(torchvulkan_lib PRIVATE cxx_std_20)
30
30
 
31
31
  install(TARGETS torchvulkan_lib DESTINATION torchvulkan)
32
32
 
33
+ file(WRITE "${TORCHVULKAN_GENERATED_DIR}/_build_info.py" "torch_version = \"${Torch_VERSION}\"\n")
34
+ install(FILES "${TORCHVULKAN_GENERATED_DIR}/_build_info.py" DESTINATION torchvulkan)
35
+
33
36
  if(APPLE)
34
- find_library(TORCHVULKAN_MOLTENVK NAMES libMoltenVK.dylib)
37
+ # a path an older configure's find_library cached is no choice; -DTORCHVULKAN_MOLTENVK=<path> still wins
38
+ get_property(TORCHVULKAN_MOLTENVK_HELP CACHE TORCHVULKAN_MOLTENVK PROPERTY HELPSTRING)
39
+ if(TORCHVULKAN_MOLTENVK_HELP STREQUAL "Path to a library.")
40
+ unset(TORCHVULKAN_MOLTENVK CACHE)
41
+ endif()
42
+
43
+ # the pinned MoltenVK release with cooperative matrices, the one CI bundles
44
+ set(TORCHVULKAN_MOLTENVK_FETCH "${CMAKE_SOURCE_DIR}/.github/scripts/fetch-moltenvk-macos.sh")
45
+ if(NOT TORCHVULKAN_MOLTENVK AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
46
+ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${TORCHVULKAN_MOLTENVK_FETCH}")
47
+ execute_process(
48
+ COMMAND ${CMAKE_COMMAND} -E env "MOLTENVK_OUT_DIR=${CMAKE_BINARY_DIR}/moltenvk" bash "${TORCHVULKAN_MOLTENVK_FETCH}"
49
+ RESULT_VARIABLE TORCHVULKAN_MOLTENVK_RESULT
50
+ )
51
+ if(NOT TORCHVULKAN_MOLTENVK_RESULT EQUAL 0)
52
+ message(FATAL_ERROR "Fetching MoltenVK failed; pass -DTORCHVULKAN_MOLTENVK=<path to libMoltenVK.dylib> to bundle another.")
53
+ endif()
54
+ set(TORCHVULKAN_MOLTENVK "${CMAKE_BINARY_DIR}/moltenvk/libMoltenVK.dylib")
55
+ else()
56
+ find_library(TORCHVULKAN_MOLTENVK NAMES libMoltenVK.dylib)
57
+ endif()
35
58
  if(TORCHVULKAN_MOLTENVK)
36
59
  get_filename_component(TORCHVULKAN_MOLTENVK_REAL "${TORCHVULKAN_MOLTENVK}" REALPATH)
37
60
  message(STATUS "Bundling MoltenVK: ${TORCHVULKAN_MOLTENVK_REAL}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: torchvulkan
3
- Version: 0.2.1
3
+ Version: 0.3.0a0
4
4
  Summary: Cross-Platform Vulkan Backend for PyTorch
5
5
  Author: Zain Sharief
6
6
  License-Expression: MIT
@@ -9,10 +9,13 @@ License-File: licenses/MoltenVK-LICENSE
9
9
  Project-URL: Homepage, https://github.com/zainsharief/torchvulkan
10
10
  Project-URL: Repository, https://github.com/zainsharief/torchvulkan
11
11
  Project-URL: Issues, https://github.com/zainsharief/torchvulkan/issues
12
- Requires-Dist: torch>=2.10.0
12
+ Requires-Python: >=3.11
13
+ Requires-Dist: torch<2.16,>=2.15.0
13
14
  Provides-Extra: test
14
15
  Requires-Dist: pytest; extra == "test"
15
16
  Requires-Dist: tox; extra == "test"
17
+ Requires-Dist: hypothesis; extra == "test"
18
+ Requires-Dist: pyyaml; extra == "test"
16
19
  Description-Content-Type: text/markdown
17
20
 
18
21
  <h1 align="center">torchvulkan</h1>
@@ -23,7 +26,7 @@ Description-Content-Type: text/markdown
23
26
  <p align="center">
24
27
  <a href="https://github.com/zainsharief/torchvulkan/actions/workflows/test_torchvulkan.yml"><img alt="CI" src="https://github.com/zainsharief/torchvulkan/actions/workflows/test_torchvulkan.yml/badge.svg"></a>
25
28
  <a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-blue.svg"></a>
26
- <img alt="Python 3.10+" src="https://img.shields.io/badge/python-3.10%2B-blue">
29
+ <img alt="Python 3.11+" src="https://img.shields.io/badge/python-3.11%2B-blue">
27
30
  <img alt="Status: experimental" src="https://img.shields.io/badge/status-experimental-orange">
28
31
  </p>
29
32
 
@@ -195,6 +198,7 @@ TORCHVULKAN_STRICT=1 python your_script.py
195
198
  | Variable | Effect |
196
199
  | --- | --- |
197
200
  | `TORCHVULKAN_STRICT=1` | Raise an error instead of falling back to the CPU. |
201
+ | `TORCHVULKAN_STRICT_ALLOCATION=1` | Raise an out-of-memory error instead of allocating past the VRAM budget. By default torchvulkan allocates anyway (with a one-time warning), and the driver may put the memory in system RAM, which is much slower. |
198
202
  | `TORCHVULKAN_SYSTEM_VULKAN=1` | macOS: use the system Vulkan loader instead of the bundled MoltenVK. |
199
203
  | `TORCHVULKAN_VALIDATION=1` | Enable the Khronos validation layer, if it's installed. `=sync` also enables synchronization validation. On macOS this needs `TORCHVULKAN_SYSTEM_VULKAN=1`. |
200
204
  | `TORCHVULKAN_PROFILE=1` | Print each compute pipeline's driver statistics (such as register use) when it's compiled, on drivers that support `VK_KHR_pipeline_executable_properties`. |
@@ -208,7 +212,6 @@ TORCHVULKAN_STRICT=1 python your_script.py
208
212
  - `float64` runs on the GPU only on devices with `shaderFloat64`; elsewhere it falls back to the CPU. Transcendental functions such as `exp`, `sin` and `tanh` are computed in `float32` precision for `float64` tensors.
209
213
  - `bfloat16` runs on the GPU only on devices with `VK_KHR_shader_bfloat16`; elsewhere it falls back to the CPU.
210
214
  - Complex tensors can live on the device and FFTs run on the GPU, but most complex arithmetic falls back to the CPU.
211
- - `torch>=2.10.0` only. The extension is compiled against 2.13.0 but has testing support for >=2.10.0.
212
215
  - APIs and coverage may change before `1.0.0`.
213
216
 
214
217
  ## How it works
@@ -6,7 +6,7 @@
6
6
  <p align="center">
7
7
  <a href="https://github.com/zainsharief/torchvulkan/actions/workflows/test_torchvulkan.yml"><img alt="CI" src="https://github.com/zainsharief/torchvulkan/actions/workflows/test_torchvulkan.yml/badge.svg"></a>
8
8
  <a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-blue.svg"></a>
9
- <img alt="Python 3.10+" src="https://img.shields.io/badge/python-3.10%2B-blue">
9
+ <img alt="Python 3.11+" src="https://img.shields.io/badge/python-3.11%2B-blue">
10
10
  <img alt="Status: experimental" src="https://img.shields.io/badge/status-experimental-orange">
11
11
  </p>
12
12
 
@@ -178,6 +178,7 @@ TORCHVULKAN_STRICT=1 python your_script.py
178
178
  | Variable | Effect |
179
179
  | --- | --- |
180
180
  | `TORCHVULKAN_STRICT=1` | Raise an error instead of falling back to the CPU. |
181
+ | `TORCHVULKAN_STRICT_ALLOCATION=1` | Raise an out-of-memory error instead of allocating past the VRAM budget. By default torchvulkan allocates anyway (with a one-time warning), and the driver may put the memory in system RAM, which is much slower. |
181
182
  | `TORCHVULKAN_SYSTEM_VULKAN=1` | macOS: use the system Vulkan loader instead of the bundled MoltenVK. |
182
183
  | `TORCHVULKAN_VALIDATION=1` | Enable the Khronos validation layer, if it's installed. `=sync` also enables synchronization validation. On macOS this needs `TORCHVULKAN_SYSTEM_VULKAN=1`. |
183
184
  | `TORCHVULKAN_PROFILE=1` | Print each compute pipeline's driver statistics (such as register use) when it's compiled, on drivers that support `VK_KHR_pipeline_executable_properties`. |
@@ -191,7 +192,6 @@ TORCHVULKAN_STRICT=1 python your_script.py
191
192
  - `float64` runs on the GPU only on devices with `shaderFloat64`; elsewhere it falls back to the CPU. Transcendental functions such as `exp`, `sin` and `tanh` are computed in `float32` precision for `float64` tensors.
192
193
  - `bfloat16` runs on the GPU only on devices with `VK_KHR_shader_bfloat16`; elsewhere it falls back to the CPU.
193
194
  - Complex tensors can live on the device and FFTs run on the GPU, but most complex arithmetic falls back to the CPU.
194
- - `torch>=2.10.0` only. The extension is compiled against 2.13.0 but has testing support for >=2.10.0.
195
195
  - APIs and coverage may change before `1.0.0`.
196
196
 
197
197
  ## How it works
@@ -1,5 +1,5 @@
1
1
  [build-system]
2
- requires = ["torch==2.13.0", "scikit-build-core", "setuptools_scm"]
2
+ requires = ["torch==2.15.0", "scikit-build-core", "setuptools_scm"]
3
3
  build-backend = "scikit_build_core.build"
4
4
 
5
5
  [project]
@@ -7,7 +7,8 @@ name = "torchvulkan"
7
7
  description = "Cross-Platform Vulkan Backend for PyTorch"
8
8
  readme = "README.md"
9
9
  dynamic = ["version"]
10
- dependencies = ["torch>=2.10.0"]
10
+ requires-python = ">=3.11"
11
+ dependencies = ["torch>=2.15.0,<2.16"]
11
12
  license = "MIT"
12
13
  license-files = ["LICENSE", "licenses/MoltenVK-LICENSE"]
13
14
  authors = [{ name = "Zain Sharief"}]
@@ -30,13 +31,12 @@ sdist.include = ["torchvulkan/_version.py"]
30
31
  write_to = "torchvulkan/_version.py"
31
32
 
32
33
  [project.optional-dependencies]
33
- test = ["pytest", "tox"]
34
+ test = ["pytest", "tox", "hypothesis", "pyyaml"]
34
35
 
35
36
  [tool.cibuildwheel]
36
- build = "cp310-* cp311-* cp312-* cp313-* cp314-*"
37
+ build = "cp311-* cp312-* cp313-* cp314-* cp315-*"
37
38
  skip = "*-musllinux_* *_i686 *-win32"
38
39
  test-command = 'python -c "import torchvulkan; print(torchvulkan.__version__)"'
39
- test-requires = "torch>=2.10.0"
40
40
 
41
41
  [tool.cibuildwheel.linux]
42
42
  manylinux-x86_64-image = "manylinux_2_34"
@@ -70,7 +70,8 @@ def main(args):
70
70
  kernel_names.append(kernel.name)
71
71
 
72
72
  for name, source, function, spec_args, aten in kernel_variants(kernel, args.src):
73
- cmake.append('torchvulkan_add_shader(' + ' '.join([name, cmake_quote(source), function] + spec_args) + ')')
73
+ coop_dims = ['COOP_DIMS', *map(str, kernel.coop_dims)] if kernel.coop_dims is not None else []
74
+ cmake.append('torchvulkan_add_shader(' + ' '.join([name, cmake_quote(source), function, *coop_dims, 'SPECIALIZE', *spec_args]) + ')')
74
75
  variants.append({'name': name, 'kernel': kernel.name, 'aten': aten})
75
76
 
76
77
  write_if_changed(args.out / 'variants.cmake', '\n'.join(cmake) + '\n')
@@ -82,7 +82,8 @@ class Entry:
82
82
  class Kernel:
83
83
  name: str
84
84
  module: str # path relative to src/shaders
85
- entries: list
85
+ entries: list
86
+ coop_dims: tuple = None # (spec constant id, placeholder) that scripts/splice_coop_dims.py swaps into CoopMat dimensions
86
87
 
87
88
 
88
89
  KERNELS = [
@@ -107,6 +108,9 @@ KERNELS = [
107
108
  Kernel('where', 'ops/where.slang', [
108
109
  Entry('where_main', DTYPES),
109
110
  ]),
111
+ Kernel('addc', 'ops/addc.slang', [
112
+ Entry('addc_main', DTYPES),
113
+ ]),
110
114
  Kernel('reduce', 'ops/reduce.slang', [
111
115
  Entry('reduce_main', DTYPES),
112
116
  ]),
@@ -122,6 +126,15 @@ KERNELS = [
122
126
  Kernel('scan_arg', 'ops/scan_arg.slang', [
123
127
  Entry('scan_arg_main', DTYPES),
124
128
  ]),
129
+ Kernel('norm', 'ops/norm.slang', [
130
+ Entry('norm_main', FLOATS),
131
+ ]),
132
+ Kernel('attention_simd', 'ops/attention_simd.slang', [
133
+ Entry('attention_simd_main', FLOATS),
134
+ ]),
135
+ Kernel('attention_simd_backward', 'ops/attention_simd.slang', [
136
+ Entry('attention_simd_backward_main', FLOATS),
137
+ ]),
125
138
  Kernel('nllloss', 'ops/nllloss.slang', [
126
139
  Entry('nllloss_main', FLOATS),
127
140
  ]),
@@ -179,36 +192,42 @@ KERNELS = [
179
192
  Kernel('eig', 'ops/eig.slang', [
180
193
  Entry('eig_main', [F64, F32]),
181
194
  ]),
195
+ Kernel('complex_arc', 'ops/complex_arc.slang', [
196
+ Entry('complex_arc_main', [F32]),
197
+ ]),
182
198
  Kernel('fft', 'ops/fft.slang', [
183
199
  Entry('fft_main', [F64, F32]),
184
200
  ]),
185
201
  Kernel('cast', 'ops/cast.slang', [
186
202
  Entry('cast_main', DTYPES, ('vec',), pairwise=True),
187
203
  ]),
188
- Kernel('matmul_simd_128', 'ops/matmul_simd.slang', [
189
- Entry('matmul_simd_main', [d for d in DTYPES if d.bytes < 8], ('vec',), constants=(128,)),
190
- ]),
191
- Kernel('matmul_simd_64', 'ops/matmul_simd.slang', [
192
- Entry('matmul_simd_main', DTYPES, ('vec',), constants=(64,)),
193
- ]),
194
- Kernel('conv_128', 'ops/conv.slang', [
195
- Entry('conv_main', [d for d in FLOATS if d.bytes < 8], ('vec',), constants=(128,)),
196
- ]),
197
- Kernel('conv_64', 'ops/conv.slang', [
198
- Entry('conv_main', FLOATS, ('vec',), constants=(64,)),
199
- ]),
200
- Kernel('matmul_coop_8', 'ops/matmul_coop.slang', [
201
- Entry('matmul_coop_main', DTYPES, ('vec',), constants=(8,)),
202
- ]),
203
- Kernel('matmul_coop_16', 'ops/matmul_coop.slang', [
204
- Entry('matmul_coop_main', DTYPES, ('vec',), constants=(16,)),
205
- ]),
206
- Kernel('matmul_coop_32', 'ops/matmul_coop.slang', [
207
- Entry('matmul_coop_main', DTYPES, ('vec',), constants=(32,)),
208
- ]),
209
- Kernel('matmul_coop_64', 'ops/matmul_coop.slang', [
210
- Entry('matmul_coop_main', DTYPES, ('vec',), constants=(64,)),
211
- ]),
204
+ Kernel('matmul_simd', 'ops/matmul_simd.slang', [
205
+ Entry('matmul_simd_main', DTYPES, ('vec',)),
206
+ ]),
207
+ Kernel('conv_simd', 'ops/conv_simd.slang', [
208
+ Entry('conv_simd_main', FLOATS, ('vec',)),
209
+ ]),
210
+ Kernel('winograd_transform', 'ops/winograd_transform.slang', [
211
+ Entry('winograd_transform_main', FLOATS),
212
+ ]),
213
+ Kernel('winograd_simd', 'ops/winograd_simd.slang', [
214
+ Entry('winograd_simd_main', FLOATS),
215
+ ]),
216
+ Kernel('matmul_coop', 'ops/matmul_coop.slang', [
217
+ Entry('matmul_coop_main', DTYPES, ('vec',)),
218
+ ], coop_dims=(18, 1009)), # BLOCK_SIZE, COOP_DIM in helpers/gemm_coop.slang
219
+ Kernel('conv_coop', 'ops/conv_coop.slang', [
220
+ Entry('conv_coop_main', FLOATS, ('vec',)),
221
+ ], coop_dims=(18, 1009)),
222
+ Kernel('attention_coop', 'ops/attention_coop.slang', [
223
+ Entry('attention_coop_main', FLOATS),
224
+ ], coop_dims=(11, 1009)), # BLOCK_SIZE, COOP_DIM in attention_coop.slang
225
+ Kernel('attention_coop_backward', 'ops/attention_coop.slang', [
226
+ Entry('attention_coop_backward_main', FLOATS),
227
+ ], coop_dims=(11, 1009)),
228
+ Kernel('winograd_coop', 'ops/winograd_coop.slang', [
229
+ Entry('winograd_coop_main', FLOATS),
230
+ ], coop_dims=(18, 1009)),
212
231
  Kernel('random', 'ops/random.slang', [
213
232
  Entry('random_main', DTYPES, ('vec',)),
214
233
  ]),
@@ -3,7 +3,7 @@ Embeds the compiled shaders in the binary: for each variant listed by
3
3
  scripts/build_shaders.py, writes its SPIR-V as a uint32_t array plus one index
4
4
  row per dtype it serves.
5
5
 
6
- Output, in the build directory, included only by src/vulkan/shader.cpp:
6
+ Output, in the build directory, included by the shader manager and the autotuner:
7
7
 
8
8
  shader_registry.h declares SHADER_BINARIES and SHADER_INDEX
9
9
  shader_registry.cpp defines them:
@@ -11,7 +11,7 @@ Output, in the build directory, included only by src/vulkan/shader.cpp:
11
11
  static const uint32_t spv_binary_f32[] = { 0x07230203, ... };
12
12
 
13
13
  const ShaderBinary SHADER_BINARIES[] = {
14
- { "binary_f32", spv_binary_f32, sizeof(spv_binary_f32) },
14
+ { "binary_f32", spv_binary_f32, sizeof(spv_binary_f32), 0x9f2c...ull },
15
15
  };
16
16
 
17
17
  const ShaderIndexEntry SHADER_INDEX[] = {
@@ -23,14 +23,15 @@ recompile tens of megabytes of SPIR-V.
23
23
  """
24
24
 
25
25
  import argparse
26
+ import hashlib
26
27
  import itertools
27
28
  import json
28
29
  import struct
29
30
  from pathlib import Path
30
31
 
31
32
 
32
- def spv_to_c_array(spv_file: Path, array_name: str) -> str:
33
- """Reads a .spv binary and formats it as a C++ uint32_t array definition."""
33
+ def spv_to_c_array(spv_file: Path, array_name: str) -> tuple[str, int]:
34
+ """Reads a .spv binary and formats it as a C++ uint32_t array definition, plus a 64-bit hash of its contents."""
34
35
  binary_data = spv_file.read_bytes()
35
36
 
36
37
  # pad to a multiple of 4 bytes
@@ -42,7 +43,8 @@ def spv_to_c_array(spv_file: Path, array_name: str) -> str:
42
43
  for i in range(0, len(words), 16):
43
44
  lines.append(','.join(f'0x{word:08x}' for word in words[i:i + 16]))
44
45
  body = ',\n'.join(lines)
45
- return f'static const uint32_t {array_name}[] = {{\n{body}\n}};\n'
46
+ digest = int.from_bytes(hashlib.blake2b(binary_data, digest_size=8).digest(), 'little')
47
+ return f'static const uint32_t {array_name}[] = {{\n{body}\n}};\n', digest
46
48
 
47
49
 
48
50
  def index_rows(variant: dict, binary: int) -> list[str]:
@@ -84,6 +86,7 @@ struct ShaderBinary {
84
86
  const char* name;
85
87
  const uint32_t* code;
86
88
  size_t size;
89
+ uint64_t hash;
87
90
  };
88
91
 
89
92
  struct ShaderIndexEntry {
@@ -111,8 +114,9 @@ def main(args):
111
114
 
112
115
  for binary, variant in enumerate(variants):
113
116
  array_name = f'spv_{variant["name"]}'
114
- arrays.append(spv_to_c_array(args.build / f'{variant["name"]}.spv', array_name))
115
- binaries.append(f' {{ "{variant["name"]}", {array_name}, sizeof({array_name}) }},')
117
+ array, digest = spv_to_c_array(args.build / f'{variant["name"]}.spv', array_name)
118
+ arrays.append(array)
119
+ binaries.append(f' {{ "{variant["name"]}", {array_name}, sizeof({array_name}), 0x{digest:016x}ull }},')
116
120
  index.extend(index_rows(variant, binary))
117
121
 
118
122
  source = [
@@ -0,0 +1,172 @@
1
+ """
2
+ Points the rows and columns of a kernel's cooperative matrices at a
3
+ specialization constant, which Slang can't emit itself: slangc requires CoopMat
4
+ dimensions to be compile-time constants, though SPIR-V allows a spec constant
5
+ there. The shader declares every CoopMat with a placeholder dimension, and this
6
+ rewrites the compiled SPIR-V, run by src/shaders/CMakeLists.txt after slangc for
7
+ the kernels scripts/config.py lists with coop_dims:
8
+
9
+ splice_coop_dims.py in.spv out.spv --spec-id 18 --placeholder 1009
10
+
11
+ Fails when the placeholder is used anywhere but a cooperative matrix type.
12
+ """
13
+
14
+ import argparse
15
+ import struct
16
+ from pathlib import Path
17
+
18
+
19
+ OP_SOURCE = 3
20
+ OP_SOURCE_EXTENSION = 4
21
+ OP_NAME = 5
22
+ OP_MEMBER_NAME = 6
23
+ OP_STRING = 7
24
+ OP_LINE = 8
25
+ OP_EXTENSION = 10
26
+ OP_EXT_INST_IMPORT = 11
27
+ OP_EXT_INST = 12
28
+ OP_MEMORY_MODEL = 14
29
+ OP_ENTRY_POINT = 15
30
+ OP_EXECUTION_MODE = 16
31
+ OP_CAPABILITY = 17
32
+ OP_TYPE_INT = 21
33
+ OP_TYPE_FLOAT = 22
34
+ OP_TYPE_VECTOR = 23
35
+ OP_TYPE_MATRIX = 24
36
+ OP_TYPE_POINTER = 32
37
+ OP_TYPE_FORWARD_POINTER = 39
38
+ OP_CONSTANT_TRUE = 41
39
+ OP_CONSTANT_FALSE = 42
40
+ OP_CONSTANT = 43
41
+ OP_SPEC_CONSTANT_TRUE = 48
42
+ OP_SPEC_CONSTANT_FALSE = 49
43
+ OP_SPEC_CONSTANT = 50
44
+ OP_SPEC_CONSTANT_OP = 52
45
+ OP_VARIABLE = 59
46
+ OP_LOAD = 61
47
+ OP_STORE = 62
48
+ OP_COPY_MEMORY = 63
49
+ OP_DECORATE = 71
50
+ OP_MEMBER_DECORATE = 72
51
+ OP_VECTOR_SHUFFLE = 79
52
+ OP_COMPOSITE_EXTRACT = 81
53
+ OP_COMPOSITE_INSERT = 82
54
+ OP_LOOP_MERGE = 246
55
+ OP_SELECTION_MERGE = 247
56
+ OP_BRANCH_CONDITIONAL = 250
57
+ OP_SWITCH = 251
58
+ OP_NO_LINE = 317
59
+ OP_TYPE_COOPERATIVE_MATRIX = 4456
60
+ OP_COOPERATIVE_MATRIX_LOAD = 4457
61
+ OP_COOPERATIVE_MATRIX_STORE = 4458
62
+ DECORATION_SPEC_ID = 1
63
+
64
+ # declarations, annotations and debug info: no operand is a use of an id
65
+ NO_ID_OPERANDS = {
66
+ OP_SOURCE, OP_SOURCE_EXTENSION, OP_NAME, OP_MEMBER_NAME, OP_STRING, OP_LINE, OP_EXTENSION, OP_EXT_INST_IMPORT,
67
+ OP_MEMORY_MODEL, OP_ENTRY_POINT, OP_EXECUTION_MODE, OP_CAPABILITY, OP_TYPE_INT, OP_TYPE_FLOAT, OP_TYPE_VECTOR,
68
+ OP_TYPE_MATRIX, OP_TYPE_POINTER, OP_TYPE_FORWARD_POINTER, OP_CONSTANT_TRUE, OP_CONSTANT_FALSE, OP_CONSTANT,
69
+ OP_SPEC_CONSTANT_TRUE, OP_SPEC_CONSTANT_FALSE, OP_SPEC_CONSTANT, OP_DECORATE, OP_MEMBER_DECORATE, OP_NO_LINE,
70
+ OP_TYPE_COOPERATIVE_MATRIX,
71
+ }
72
+
73
+ # the word offsets that are ids, for instructions that also hold literals
74
+ ID_OFFSETS = {
75
+ OP_EXT_INST: lambda count: [1, 2, 3] + list(range(5, count)),
76
+ OP_SPEC_CONSTANT_OP: lambda count: [1, 2] + list(range(4, count)),
77
+ OP_VARIABLE: lambda count: [1, 2] + list(range(4, count)),
78
+ OP_LOAD: lambda count: [1, 2, 3],
79
+ OP_STORE: lambda count: [1, 2],
80
+ OP_COPY_MEMORY: lambda count: [1, 2],
81
+ OP_VECTOR_SHUFFLE: lambda count: [1, 2, 3, 4],
82
+ OP_COMPOSITE_EXTRACT: lambda count: [1, 2, 3],
83
+ OP_COMPOSITE_INSERT: lambda count: [1, 2, 3, 4],
84
+ OP_LOOP_MERGE: lambda count: [1, 2],
85
+ OP_SELECTION_MERGE: lambda count: [1],
86
+ OP_BRANCH_CONDITIONAL: lambda count: [1, 2, 3],
87
+ OP_SWITCH: lambda count: [1, 2] + list(range(4, count, 2)),
88
+ OP_COOPERATIVE_MATRIX_LOAD: lambda count: [1, 2, 3, 4, 5],
89
+ OP_COOPERATIVE_MATRIX_STORE: lambda count: [1, 2, 3, 4],
90
+ }
91
+
92
+
93
+ def id_operands(words, start, op, count):
94
+ """The words of an instruction that use an id: every word after the opcode, unless ID_OFFSETS says otherwise."""
95
+ if op in NO_ID_OPERANDS:
96
+ return []
97
+ offsets = ID_OFFSETS.get(op, lambda count: range(1, count))(count)
98
+ return [words[start + i] for i in offsets if i < count]
99
+
100
+
101
+ def instructions(words):
102
+ """Yields (start, opcode, word count) for each instruction after the 5-word header."""
103
+ i = 5
104
+ while i < len(words):
105
+ count = words[i] >> 16
106
+ if count == 0:
107
+ raise ValueError(f'malformed SPIR-V instruction at word {i}')
108
+ yield i, words[i] & 0xFFFF, count
109
+ i += count
110
+
111
+
112
+ def splice_coop_dims(words, spec_id, placeholder, name):
113
+ """
114
+ Points the rows and columns of every CoopMat declared with `placeholder` at
115
+ the specialization constant `spec_id`, which Slang can't do itself. Fails
116
+ when the placeholder is used anywhere else.
117
+ """
118
+ words = list(words)
119
+ spec = None
120
+ placeholders = set()
121
+ for start, op, _ in instructions(words):
122
+ if op == OP_DECORATE and words[start + 2] == DECORATION_SPEC_ID and words[start + 3] == spec_id:
123
+ spec = words[start + 1]
124
+ if op == OP_CONSTANT and words[start + 3] == placeholder:
125
+ placeholders.add(words[start + 2])
126
+ if op == OP_CONSTANT and words[start + 3] not in (0, placeholder) and words[start + 3] % placeholder == 0:
127
+ raise ValueError(f'{name}: a constant of {words[start + 3]} suggests the placeholder {placeholder} was folded into arithmetic')
128
+ if spec is None:
129
+ raise ValueError(f'{name}: no specialization constant with SpecId {spec_id}')
130
+
131
+ spliced = 0
132
+ first_matrix = None
133
+ for start, op, _ in instructions(words):
134
+ if op != OP_TYPE_COOPERATIVE_MATRIX:
135
+ continue
136
+ first_matrix = start if first_matrix is None else first_matrix
137
+ for operand in (start + 4, start + 5): # rows, columns
138
+ if words[operand] in placeholders:
139
+ words[operand] = spec
140
+ spliced += 1
141
+ if spliced == 0:
142
+ raise ValueError(f'{name}: no cooperative matrix uses the placeholder dimension {placeholder}')
143
+
144
+ for start, op, count in instructions(words):
145
+ if any(word in placeholders for word in id_operands(words, start, op, count)):
146
+ raise ValueError(f'{name}: the placeholder dimension {placeholder} is used outside a cooperative matrix type (opcode {op})')
147
+
148
+ # an id must be defined before its first use
149
+ for start, op, count in instructions(words):
150
+ if op == OP_SPEC_CONSTANT and words[start + 2] == spec:
151
+ if start > first_matrix:
152
+ definition = words[start:start + count]
153
+ del words[start:start + count]
154
+ words[first_matrix:first_matrix] = definition
155
+ break
156
+ return words
157
+
158
+
159
+ def main(args):
160
+ data = args.input.read_bytes()
161
+ words = struct.unpack(f'<{len(data) // 4}I', data)
162
+ words = splice_coop_dims(words, args.spec_id, args.placeholder, args.input.name)
163
+ args.output.write_bytes(struct.pack(f'<{len(words)}I', *words))
164
+
165
+
166
+ if __name__ == '__main__':
167
+ parser = argparse.ArgumentParser(description='Splice a specialization constant into cooperative matrix dimensions.')
168
+ parser.add_argument('input', type=Path, help='SPIR-V from slangc')
169
+ parser.add_argument('output', type=Path, help='spliced SPIR-V')
170
+ parser.add_argument('--spec-id', type=int, required=True, help='SpecId of the dimension constant')
171
+ parser.add_argument('--placeholder', type=int, required=True, help='the literal dimension the shader declares')
172
+ main(parser.parse_args())