torchvulkan 0.2.2__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 (170) hide show
  1. torchvulkan-0.3.0a0/.github/scripts/fetch-moltenvk-macos.sh +23 -0
  2. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/CMakeLists.txt +21 -1
  3. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/PKG-INFO +3 -1
  4. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/pyproject.toml +1 -1
  5. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/scripts/build_shaders.py +2 -1
  6. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/scripts/config.py +44 -25
  7. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/scripts/pack_shaders.py +11 -7
  8. torchvulkan-0.3.0a0/scripts/splice_coop_dims.py +172 -0
  9. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/backend.cpp +17 -2
  10. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/decompositions.cpp +289 -118
  11. torchvulkan-0.3.0a0/src/api/guard.cpp +103 -0
  12. torchvulkan-0.3.0a0/src/api/hook.cpp +83 -0
  13. torchvulkan-0.3.0a0/src/api/ops/attention.cpp +762 -0
  14. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/binary.cpp +458 -74
  15. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/bitwise.cpp +17 -7
  16. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/compare.cpp +95 -18
  17. torchvulkan-0.3.0a0/src/api/ops/complex.cpp +395 -0
  18. torchvulkan-0.3.0a0/src/api/ops/conv.cpp +1321 -0
  19. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/ctc.cpp +1 -0
  20. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/distributions.cpp +9 -4
  21. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/dropout.cpp +7 -5
  22. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/fft.cpp +70 -5
  23. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/fill.cpp +60 -1
  24. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/grid_sample.cpp +16 -1
  25. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/helpers.h +253 -2
  26. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/indexing.cpp +75 -10
  27. torchvulkan-0.3.0a0/src/api/ops/internal.h +73 -0
  28. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/linalg.cpp +425 -65
  29. torchvulkan-0.3.0a0/src/api/ops/matmul.cpp +763 -0
  30. torchvulkan-0.3.0a0/src/api/ops/nested.cpp +326 -0
  31. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/nllloss.cpp +19 -2
  32. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/nn.cpp +252 -27
  33. torchvulkan-0.3.0a0/src/api/ops/norm.cpp +433 -0
  34. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/pool.cpp +54 -14
  35. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/random.cpp +25 -5
  36. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/reduce.cpp +194 -12
  37. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/sampling.cpp +26 -16
  38. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/scan.cpp +87 -13
  39. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/scatter.cpp +240 -22
  40. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/search.cpp +35 -9
  41. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/shape.cpp +36 -4
  42. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/sort.cpp +21 -2
  43. torchvulkan-0.3.0a0/src/api/ops/sparse.cpp +386 -0
  44. torchvulkan-0.3.0a0/src/api/ops/sparse_ops.cpp +831 -0
  45. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/special.cpp +5 -4
  46. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/unary.cpp +206 -61
  47. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/upsample.cpp +41 -6
  48. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/registration.cpp +1 -0
  49. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/tensor/allocation.cpp +33 -4
  50. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/tensor/cast.cpp +4 -3
  51. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/tensor/transfer.cpp +162 -9
  52. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/tensor/views.cpp +2 -2
  53. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/CMakeLists.txt +17 -3
  54. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/core/dtype.slang +23 -0
  55. torchvulkan-0.3.0a0/src/shaders/helpers/attention.slang +75 -0
  56. torchvulkan-0.3.0a0/src/shaders/helpers/conv.slang +511 -0
  57. torchvulkan-0.3.0a0/src/shaders/helpers/gemm.slang +24 -0
  58. torchvulkan-0.3.0a0/src/shaders/helpers/gemm_coop.slang +66 -0
  59. torchvulkan-0.2.2/src/shaders/ops/matmul_simd.slang → torchvulkan-0.3.0a0/src/shaders/helpers/gemm_simd.slang +12 -71
  60. {torchvulkan-0.2.2/src/shaders/ops → torchvulkan-0.3.0a0/src/shaders/helpers}/unary_ops.slang +2 -1
  61. torchvulkan-0.3.0a0/src/shaders/helpers/winograd.slang +133 -0
  62. torchvulkan-0.3.0a0/src/shaders/ops/addc.slang +69 -0
  63. torchvulkan-0.3.0a0/src/shaders/ops/attention_coop.slang +506 -0
  64. torchvulkan-0.3.0a0/src/shaders/ops/attention_simd.slang +399 -0
  65. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/binary.slang +12 -0
  66. torchvulkan-0.3.0a0/src/shaders/ops/complex_arc.slang +272 -0
  67. torchvulkan-0.3.0a0/src/shaders/ops/conv_coop.slang +311 -0
  68. torchvulkan-0.3.0a0/src/shaders/ops/conv_simd.slang +149 -0
  69. torchvulkan-0.3.0a0/src/shaders/ops/eig.slang +915 -0
  70. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/jacobi.slang +64 -13
  71. torchvulkan-0.3.0a0/src/shaders/ops/ldl.slang +381 -0
  72. torchvulkan-0.3.0a0/src/shaders/ops/matmul_coop.slang +452 -0
  73. torchvulkan-0.3.0a0/src/shaders/ops/matmul_simd.slang +44 -0
  74. torchvulkan-0.3.0a0/src/shaders/ops/norm.slang +341 -0
  75. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/resample.slang +9 -0
  76. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/unary.slang +3 -1
  77. torchvulkan-0.3.0a0/src/shaders/ops/winograd_coop.slang +136 -0
  78. torchvulkan-0.3.0a0/src/shaders/ops/winograd_simd.slang +107 -0
  79. torchvulkan-0.3.0a0/src/shaders/ops/winograd_transform.slang +116 -0
  80. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/vulkan/allocator.cpp +59 -2
  81. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/vulkan/allocator.h +10 -1
  82. torchvulkan-0.3.0a0/src/vulkan/autotuner.cpp +223 -0
  83. torchvulkan-0.3.0a0/src/vulkan/autotuner.h +69 -0
  84. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/vulkan/builders.h +42 -5
  85. torchvulkan-0.3.0a0/src/vulkan/cache.cpp +252 -0
  86. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/vulkan/cache.h +15 -27
  87. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/vulkan/device_context.cpp +8 -0
  88. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/vulkan/device_context.h +21 -1
  89. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/vulkan/generator.cpp +31 -13
  90. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/vulkan/generator.h +13 -5
  91. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/vulkan/memory.cpp +5 -0
  92. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/vulkan/memory.h +27 -1
  93. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/vulkan/shader.cpp +167 -99
  94. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/vulkan/shader.h +32 -9
  95. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/vulkan/vulkan_context.cpp +40 -4
  96. torchvulkan-0.3.0a0/tests/run_pytorch_suites.py +649 -0
  97. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/torchvulkan/__init__.py +78 -4
  98. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/torchvulkan/_version.py +3 -3
  99. torchvulkan-0.2.2/.github/scripts/fetch-moltenvk-macos.sh +0 -18
  100. torchvulkan-0.2.2/src/api/guard.cpp +0 -48
  101. torchvulkan-0.2.2/src/api/hook.cpp +0 -40
  102. torchvulkan-0.2.2/src/api/ops/complex.cpp +0 -75
  103. torchvulkan-0.2.2/src/api/ops/conv.cpp +0 -567
  104. torchvulkan-0.2.2/src/api/ops/internal.h +0 -26
  105. torchvulkan-0.2.2/src/api/ops/matmul.cpp +0 -565
  106. torchvulkan-0.2.2/src/shaders/ops/conv.slang +0 -338
  107. torchvulkan-0.2.2/src/shaders/ops/eig.slang +0 -524
  108. torchvulkan-0.2.2/src/shaders/ops/ldl.slang +0 -254
  109. torchvulkan-0.2.2/src/shaders/ops/matmul_coop.slang +0 -530
  110. torchvulkan-0.2.2/src/vulkan/cache.cpp +0 -313
  111. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/.github/actions/setup-toolchain/action.yml +0 -0
  112. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/.github/scripts/install-toolchain-linux.sh +0 -0
  113. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/.github/workflows/release.yaml +0 -0
  114. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/.github/workflows/test_torchvulkan.yml +0 -0
  115. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/.gitignore +0 -0
  116. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/LICENSE +0 -0
  117. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/README.md +0 -0
  118. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/benchmark/benchmark.py +0 -0
  119. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/examples/conv.py +0 -0
  120. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/examples/llm.py +0 -0
  121. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/examples/mlp.py +0 -0
  122. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/extern/vma/vk_mem_alloc.h +0 -0
  123. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/extern/volk/volk.c +0 -0
  124. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/extern/volk/volk.h +0 -0
  125. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/licenses/MoltenVK-LICENSE +0 -0
  126. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/media/benchmark-cuda.png +0 -0
  127. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/requirements.txt +0 -0
  128. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/fallback.cpp +0 -0
  129. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/fallback.h +0 -0
  130. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/api/ops/optim.cpp +0 -0
  131. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/core/cast.slang +0 -0
  132. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/core/indexing.slang +0 -0
  133. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/core/philox.slang +0 -0
  134. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/core/special_functions.slang +0 -0
  135. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/arg_reduce.slang +0 -0
  136. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/cast.slang +0 -0
  137. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/cholesky.slang +0 -0
  138. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/compare.slang +0 -0
  139. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/copy.slang +0 -0
  140. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/ctc.slang +0 -0
  141. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/distribution.slang +0 -0
  142. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/dropout.slang +0 -0
  143. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/embedding_backward.slang +0 -0
  144. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/fft.slang +0 -0
  145. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/fill.slang +0 -0
  146. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/grid_sample.slang +0 -0
  147. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/householder.slang +0 -0
  148. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/index_gather.slang +0 -0
  149. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/integer_binary.slang +0 -0
  150. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/lu.slang +0 -0
  151. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/multinomial.slang +0 -0
  152. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/nllloss.slang +0 -0
  153. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/pool.slang +0 -0
  154. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/random.slang +0 -0
  155. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/reduce.slang +0 -0
  156. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/reduce_subgroup.slang +0 -0
  157. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/resample_u8.slang +0 -0
  158. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/scan.slang +0 -0
  159. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/scan_arg.slang +0 -0
  160. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/scatter.slang +0 -0
  161. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/searchsorted.slang +0 -0
  162. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/sort.slang +0 -0
  163. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/special.slang +0 -0
  164. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/triangular_solve.slang +0 -0
  165. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/shaders/ops/where.slang +0 -0
  166. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/vulkan/dispatch.cpp +0 -0
  167. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/vulkan/dispatch.h +0 -0
  168. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/src/vulkan/vulkan_context.h +0 -0
  169. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/tests/test_pytorch_ops.py +0 -0
  170. {torchvulkan-0.2.2 → torchvulkan-0.3.0a0}/tox.ini +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"
@@ -34,7 +34,27 @@ file(WRITE "${TORCHVULKAN_GENERATED_DIR}/_build_info.py" "torch_version = \"${To
34
34
  install(FILES "${TORCHVULKAN_GENERATED_DIR}/_build_info.py" DESTINATION torchvulkan)
35
35
 
36
36
  if(APPLE)
37
- 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()
38
58
  if(TORCHVULKAN_MOLTENVK)
39
59
  get_filename_component(TORCHVULKAN_MOLTENVK_REAL "${TORCHVULKAN_MOLTENVK}" REALPATH)
40
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.2
3
+ Version: 0.3.0a0
4
4
  Summary: Cross-Platform Vulkan Backend for PyTorch
5
5
  Author: Zain Sharief
6
6
  License-Expression: MIT
@@ -14,6 +14,8 @@ Requires-Dist: torch<2.16,>=2.15.0
14
14
  Provides-Extra: test
15
15
  Requires-Dist: pytest; extra == "test"
16
16
  Requires-Dist: tox; extra == "test"
17
+ Requires-Dist: hypothesis; extra == "test"
18
+ Requires-Dist: pyyaml; extra == "test"
17
19
  Description-Content-Type: text/markdown
18
20
 
19
21
  <h1 align="center">torchvulkan</h1>
@@ -31,7 +31,7 @@ sdist.include = ["torchvulkan/_version.py"]
31
31
  write_to = "torchvulkan/_version.py"
32
32
 
33
33
  [project.optional-dependencies]
34
- test = ["pytest", "tox"]
34
+ test = ["pytest", "tox", "hypothesis", "pyyaml"]
35
35
 
36
36
  [tool.cibuildwheel]
37
37
  build = "cp311-* cp312-* cp313-* cp314-* cp315-*"
@@ -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())
@@ -1,6 +1,7 @@
1
1
  #include <torch/extension.h>
2
2
  #include <torch/csrc/Generator.h>
3
3
  #include "vulkan/vulkan_context.h"
4
+ #include "vulkan/memory.h"
4
5
  #include "vulkan/allocator.h"
5
6
  #include "vulkan/generator.h"
6
7
  #include "vulkan/shader.h"
@@ -54,7 +55,7 @@ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
54
55
 
55
56
  m.def("_save_pipeline_caches", []() {
56
57
  if (!VulkanContext::IsInitialized() || VulkanContext::IsInBadFork()) return;
57
- for (DeviceContext* device : VulkanContext::Instance().devices) device->shader_manager->savePipelineCache();
58
+ for (DeviceContext* device : VulkanContext::Instance().devices) device->cache.savePipelineCache();
58
59
  });
59
60
 
60
61
  m.def("_amp_supported_dtypes", [](int64_t device_index) {
@@ -69,6 +70,10 @@ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
69
70
  return VulkanContext::Instance().GetDeviceContext(static_cast<c10::DeviceIndex>(device_index))->memoryUsage();
70
71
  });
71
72
 
73
+ m.def("_memory_reserved", [](int64_t device_index) -> uint64_t {
74
+ return VulkanContext::Instance().GetDeviceContext(static_cast<c10::DeviceIndex>(device_index))->reservedBytes();
75
+ });
76
+
72
77
  m.def("_mem_get_info", [](int64_t device_index) -> std::pair<uint64_t, uint64_t> {
73
78
  DeviceContext* device = VulkanContext::Instance().GetDeviceContext(static_cast<c10::DeviceIndex>(device_index));
74
79
  return {device->memoryFree(), device->memoryTotal()};
@@ -87,6 +92,10 @@ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
87
92
  device->peak_allocated_bytes.store(device->allocated_bytes.load());
88
93
  });
89
94
 
95
+ m.def("_record_storage_slice_deleter", [](const at::Tensor& slice) {
96
+ storage_slice_deleter() = slice.storage().data_ptr().get_deleter();
97
+ });
98
+
90
99
  m.def("_is_initialized", []() -> bool {
91
100
  return VulkanContext::IsInitialized();
92
101
  });
@@ -105,7 +114,13 @@ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
105
114
  info["device_id"] = props.deviceID;
106
115
  info["api_version"] = std::to_string(VK_API_VERSION_MAJOR(props.apiVersion)) + "." + std::to_string(VK_API_VERSION_MINOR(props.apiVersion)) + "." + std::to_string(VK_API_VERSION_PATCH(props.apiVersion));
107
116
  info["driver_version"] = props.driverVersion;
108
- info["subgroup_size"] = device->subgroup_size;
117
+ info["subgroup_size"] = device->default_subgroup_size;
118
+ info["has_fp64"] = device->support_float64;
119
+ info["has_int64"] = device->support_int64;
120
+ info["has_fp16"] = device->support_float16;
121
+ info["has_bf16"] = device->support_bfloat16;
122
+ info["has_int16"] = device->support_int16;
123
+ info["has_int8"] = device->support_int8;
109
124
  return info;
110
125
  });
111
126