warp-lang 0.10.1__py3-none-win_amd64.whl → 0.11.0__py3-none-win_amd64.whl

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.

Potentially problematic release.


This version of warp-lang might be problematic. Click here for more details.

Files changed (300) hide show
  1. warp/__init__.py +10 -4
  2. warp/__init__.pyi +1 -0
  3. warp/bin/warp-clang.dll +0 -0
  4. warp/bin/warp.dll +0 -0
  5. warp/build.py +5 -3
  6. warp/build_dll.py +29 -9
  7. warp/builtins.py +868 -507
  8. warp/codegen.py +1074 -638
  9. warp/config.py +3 -3
  10. warp/constants.py +6 -0
  11. warp/context.py +715 -222
  12. warp/fabric.py +326 -0
  13. warp/fem/__init__.py +27 -0
  14. warp/fem/cache.py +389 -0
  15. warp/fem/dirichlet.py +181 -0
  16. warp/fem/domain.py +263 -0
  17. warp/fem/field/__init__.py +101 -0
  18. warp/fem/field/field.py +149 -0
  19. warp/fem/field/nodal_field.py +299 -0
  20. warp/fem/field/restriction.py +21 -0
  21. warp/fem/field/test.py +181 -0
  22. warp/fem/field/trial.py +183 -0
  23. warp/fem/geometry/__init__.py +19 -0
  24. warp/fem/geometry/closest_point.py +70 -0
  25. warp/fem/geometry/deformed_geometry.py +271 -0
  26. warp/fem/geometry/element.py +744 -0
  27. warp/fem/geometry/geometry.py +186 -0
  28. warp/fem/geometry/grid_2d.py +373 -0
  29. warp/fem/geometry/grid_3d.py +435 -0
  30. warp/fem/geometry/hexmesh.py +953 -0
  31. warp/fem/geometry/partition.py +376 -0
  32. warp/fem/geometry/quadmesh_2d.py +532 -0
  33. warp/fem/geometry/tetmesh.py +840 -0
  34. warp/fem/geometry/trimesh_2d.py +577 -0
  35. warp/fem/integrate.py +1616 -0
  36. warp/fem/operator.py +191 -0
  37. warp/fem/polynomial.py +213 -0
  38. warp/fem/quadrature/__init__.py +2 -0
  39. warp/fem/quadrature/pic_quadrature.py +245 -0
  40. warp/fem/quadrature/quadrature.py +294 -0
  41. warp/fem/space/__init__.py +292 -0
  42. warp/fem/space/basis_space.py +489 -0
  43. warp/fem/space/collocated_function_space.py +105 -0
  44. warp/fem/space/dof_mapper.py +236 -0
  45. warp/fem/space/function_space.py +145 -0
  46. warp/fem/space/grid_2d_function_space.py +267 -0
  47. warp/fem/space/grid_3d_function_space.py +306 -0
  48. warp/fem/space/hexmesh_function_space.py +352 -0
  49. warp/fem/space/partition.py +350 -0
  50. warp/fem/space/quadmesh_2d_function_space.py +369 -0
  51. warp/fem/space/restriction.py +160 -0
  52. warp/fem/space/shape/__init__.py +15 -0
  53. warp/fem/space/shape/cube_shape_function.py +738 -0
  54. warp/fem/space/shape/shape_function.py +103 -0
  55. warp/fem/space/shape/square_shape_function.py +611 -0
  56. warp/fem/space/shape/tet_shape_function.py +567 -0
  57. warp/fem/space/shape/triangle_shape_function.py +429 -0
  58. warp/fem/space/tetmesh_function_space.py +292 -0
  59. warp/fem/space/topology.py +295 -0
  60. warp/fem/space/trimesh_2d_function_space.py +221 -0
  61. warp/fem/types.py +77 -0
  62. warp/fem/utils.py +495 -0
  63. warp/native/array.h +147 -44
  64. warp/native/builtin.h +122 -149
  65. warp/native/bvh.cpp +73 -325
  66. warp/native/bvh.cu +406 -23
  67. warp/native/bvh.h +34 -43
  68. warp/native/clang/clang.cpp +13 -8
  69. warp/native/crt.h +2 -0
  70. warp/native/cuda_crt.h +5 -0
  71. warp/native/cuda_util.cpp +15 -3
  72. warp/native/cuda_util.h +3 -1
  73. warp/native/cutlass/tools/library/scripts/conv2d_operation.py +463 -0
  74. warp/native/cutlass/tools/library/scripts/conv3d_operation.py +321 -0
  75. warp/native/cutlass/tools/library/scripts/gemm_operation.py +988 -0
  76. warp/native/cutlass/tools/library/scripts/generator.py +4625 -0
  77. warp/native/cutlass/tools/library/scripts/library.py +799 -0
  78. warp/native/cutlass/tools/library/scripts/manifest.py +402 -0
  79. warp/native/cutlass/tools/library/scripts/pycutlass/docs/source/conf.py +96 -0
  80. warp/native/cutlass/tools/library/scripts/pycutlass/profile/conv/conv2d_f16_sm80.py +106 -0
  81. warp/native/cutlass/tools/library/scripts/pycutlass/profile/gemm/gemm_f32_sm80.py +91 -0
  82. warp/native/cutlass/tools/library/scripts/pycutlass/setup.py +80 -0
  83. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/__init__.py +48 -0
  84. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/arguments.py +118 -0
  85. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/c_types.py +241 -0
  86. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/compiler.py +432 -0
  87. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/conv2d_operation.py +631 -0
  88. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/epilogue.py +1026 -0
  89. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/frontend.py +104 -0
  90. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/gemm_operation.py +1276 -0
  91. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/library.py +744 -0
  92. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/memory_manager.py +74 -0
  93. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/operation.py +110 -0
  94. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/parser.py +619 -0
  95. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/reduction_operation.py +398 -0
  96. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/tensor_ref.py +70 -0
  97. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/__init__.py +4 -0
  98. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/conv2d_testbed.py +646 -0
  99. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/gemm_grouped_testbed.py +235 -0
  100. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/gemm_testbed.py +557 -0
  101. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/profiler.py +70 -0
  102. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/type_hint.py +39 -0
  103. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/utils/__init__.py +1 -0
  104. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/utils/device.py +76 -0
  105. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/utils/reference_model.py +255 -0
  106. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/__init__.py +0 -0
  107. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_dgrad_implicit_gemm_f16nhwc_f16nhwc_f16nhwc_tensor_op_f16_sm80.py +201 -0
  108. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_dgrad_implicit_gemm_f16nhwc_f16nhwc_f32nhwc_tensor_op_f32_sm80.py +177 -0
  109. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_dgrad_implicit_gemm_f32nhwc_f32nhwc_f32nhwc_simt_f32_sm80.py +98 -0
  110. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_dgrad_implicit_gemm_tf32nhwc_tf32nhwc_f32nhwc_tensor_op_f32_sm80.py +95 -0
  111. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_few_channels_f16nhwc_f16nhwc_f16nhwc_tensor_op_f32_sm80.py +163 -0
  112. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_fixed_channels_f16nhwc_f16nhwc_f16nhwc_tensor_op_f32_sm80.py +187 -0
  113. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_implicit_gemm_f16nhwc_f16nhwc_f16nhwc_tensor_op_f16_sm80.py +309 -0
  114. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_implicit_gemm_f16nhwc_f16nhwc_f32nhwc_tensor_op_f32_sm80.py +54 -0
  115. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_implicit_gemm_f32nhwc_f32nhwc_f32nhwc_simt_f32_sm80.py +96 -0
  116. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_implicit_gemm_tf32nhwc_tf32nhwc_f32nhwc_tensor_op_f32_sm80.py +107 -0
  117. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_strided_dgrad_implicit_gemm_f16nhwc_f16nhwc_f32nhwc_tensor_op_f32_sm80.py +253 -0
  118. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_wgrad_implicit_gemm_f16nhwc_f16nhwc_f16nhwc_tensor_op_f16_sm80.py +97 -0
  119. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_wgrad_implicit_gemm_f16nhwc_f16nhwc_f32nhwc_tensor_op_f32_sm80.py +242 -0
  120. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_wgrad_implicit_gemm_f32nhwc_f32nhwc_f32nhwc_simt_f32_sm80.py +96 -0
  121. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_wgrad_implicit_gemm_tf32nhwc_tf32nhwc_f32nhwc_tensor_op_f32_sm80.py +107 -0
  122. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/run_all_tests.py +10 -0
  123. warp/native/cutlass/tools/library/scripts/pycutlass/test/frontend/test_frontend.py +146 -0
  124. warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/__init__.py +0 -0
  125. warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_bf16_sm80.py +96 -0
  126. warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_f16_sm80.py +447 -0
  127. warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_f32_sm80.py +146 -0
  128. warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_f64_sm80.py +102 -0
  129. warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_grouped_sm80.py +203 -0
  130. warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_s8_sm80.py +229 -0
  131. warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/run_all_tests.py +9 -0
  132. warp/native/cutlass/tools/library/scripts/pycutlass/test/unit/test_sm80.py +453 -0
  133. warp/native/cutlass/tools/library/scripts/rank_2k_operation.py +398 -0
  134. warp/native/cutlass/tools/library/scripts/rank_k_operation.py +387 -0
  135. warp/native/cutlass/tools/library/scripts/rt.py +796 -0
  136. warp/native/cutlass/tools/library/scripts/symm_operation.py +400 -0
  137. warp/native/cutlass/tools/library/scripts/trmm_operation.py +407 -0
  138. warp/native/cutlass_gemm.cu +5 -3
  139. warp/native/exports.h +1240 -952
  140. warp/native/fabric.h +228 -0
  141. warp/native/hashgrid.cpp +4 -4
  142. warp/native/hashgrid.h +22 -2
  143. warp/native/intersect.h +22 -7
  144. warp/native/intersect_adj.h +8 -8
  145. warp/native/intersect_tri.h +1 -1
  146. warp/native/marching.cu +157 -161
  147. warp/native/mat.h +80 -19
  148. warp/native/matnn.h +2 -2
  149. warp/native/mesh.cpp +33 -108
  150. warp/native/mesh.cu +114 -23
  151. warp/native/mesh.h +446 -46
  152. warp/native/noise.h +272 -329
  153. warp/native/quat.h +51 -8
  154. warp/native/rand.h +45 -35
  155. warp/native/range.h +6 -2
  156. warp/native/reduce.cpp +1 -1
  157. warp/native/reduce.cu +10 -12
  158. warp/native/runlength_encode.cu +6 -10
  159. warp/native/scan.cu +8 -11
  160. warp/native/sparse.cpp +4 -4
  161. warp/native/sparse.cu +164 -154
  162. warp/native/spatial.h +2 -2
  163. warp/native/temp_buffer.h +14 -30
  164. warp/native/vec.h +107 -23
  165. warp/native/volume.h +120 -0
  166. warp/native/warp.cpp +560 -30
  167. warp/native/warp.cu +431 -44
  168. warp/native/warp.h +13 -4
  169. warp/optim/__init__.py +1 -0
  170. warp/optim/linear.py +922 -0
  171. warp/optim/sgd.py +92 -0
  172. warp/render/render_opengl.py +335 -119
  173. warp/render/render_usd.py +11 -11
  174. warp/sim/__init__.py +2 -2
  175. warp/sim/articulation.py +385 -185
  176. warp/sim/collide.py +8 -0
  177. warp/sim/import_mjcf.py +297 -106
  178. warp/sim/import_urdf.py +389 -210
  179. warp/sim/import_usd.py +198 -97
  180. warp/sim/inertia.py +17 -18
  181. warp/sim/integrator_euler.py +14 -8
  182. warp/sim/integrator_xpbd.py +158 -16
  183. warp/sim/model.py +795 -291
  184. warp/sim/render.py +3 -3
  185. warp/sim/utils.py +3 -0
  186. warp/sparse.py +640 -150
  187. warp/stubs.py +606 -267
  188. warp/tape.py +61 -10
  189. warp/tests/__main__.py +3 -6
  190. warp/tests/assets/curlnoise_golden.npy +0 -0
  191. warp/tests/assets/pnoise_golden.npy +0 -0
  192. warp/tests/{test_class_kernel.py → aux_test_class_kernel.py} +9 -1
  193. warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -0
  194. warp/tests/{test_dependent.py → aux_test_dependent.py} +2 -2
  195. warp/tests/{test_reference.py → aux_test_reference.py} +1 -1
  196. warp/tests/aux_test_unresolved_func.py +14 -0
  197. warp/tests/aux_test_unresolved_symbol.py +14 -0
  198. warp/tests/disabled_kinematics.py +239 -0
  199. warp/tests/run_coverage_serial.py +31 -0
  200. warp/tests/test_adam.py +103 -106
  201. warp/tests/test_arithmetic.py +128 -74
  202. warp/tests/test_array.py +212 -97
  203. warp/tests/test_array_reduce.py +57 -23
  204. warp/tests/test_atomic.py +64 -28
  205. warp/tests/test_bool.py +99 -0
  206. warp/tests/test_builtins_resolution.py +1292 -0
  207. warp/tests/test_bvh.py +42 -18
  208. warp/tests/test_closest_point_edge_edge.py +54 -57
  209. warp/tests/test_codegen.py +208 -130
  210. warp/tests/test_compile_consts.py +28 -20
  211. warp/tests/test_conditional.py +108 -24
  212. warp/tests/test_copy.py +10 -12
  213. warp/tests/test_ctypes.py +112 -88
  214. warp/tests/test_dense.py +21 -14
  215. warp/tests/test_devices.py +98 -0
  216. warp/tests/test_dlpack.py +75 -75
  217. warp/tests/test_examples.py +277 -0
  218. warp/tests/test_fabricarray.py +955 -0
  219. warp/tests/test_fast_math.py +15 -11
  220. warp/tests/test_fem.py +1271 -0
  221. warp/tests/test_fp16.py +53 -19
  222. warp/tests/test_func.py +187 -86
  223. warp/tests/test_generics.py +194 -49
  224. warp/tests/test_grad.py +178 -109
  225. warp/tests/test_grad_customs.py +176 -0
  226. warp/tests/test_hash_grid.py +52 -37
  227. warp/tests/test_import.py +10 -23
  228. warp/tests/test_indexedarray.py +32 -31
  229. warp/tests/test_intersect.py +18 -9
  230. warp/tests/test_large.py +141 -0
  231. warp/tests/test_launch.py +14 -41
  232. warp/tests/test_lerp.py +64 -65
  233. warp/tests/test_linear_solvers.py +154 -0
  234. warp/tests/test_lvalue.py +493 -0
  235. warp/tests/test_marching_cubes.py +12 -13
  236. warp/tests/test_mat.py +517 -2898
  237. warp/tests/test_mat_lite.py +115 -0
  238. warp/tests/test_mat_scalar_ops.py +2889 -0
  239. warp/tests/test_math.py +103 -9
  240. warp/tests/test_matmul.py +305 -69
  241. warp/tests/test_matmul_lite.py +410 -0
  242. warp/tests/test_mesh.py +71 -14
  243. warp/tests/test_mesh_query_aabb.py +41 -25
  244. warp/tests/test_mesh_query_point.py +140 -22
  245. warp/tests/test_mesh_query_ray.py +39 -22
  246. warp/tests/test_mlp.py +30 -22
  247. warp/tests/test_model.py +92 -89
  248. warp/tests/test_modules_lite.py +39 -0
  249. warp/tests/test_multigpu.py +88 -114
  250. warp/tests/test_noise.py +12 -11
  251. warp/tests/test_operators.py +16 -20
  252. warp/tests/test_options.py +11 -11
  253. warp/tests/test_pinned.py +17 -18
  254. warp/tests/test_print.py +32 -11
  255. warp/tests/test_quat.py +275 -129
  256. warp/tests/test_rand.py +18 -16
  257. warp/tests/test_reload.py +38 -34
  258. warp/tests/test_rounding.py +50 -43
  259. warp/tests/test_runlength_encode.py +168 -20
  260. warp/tests/test_smoothstep.py +9 -11
  261. warp/tests/test_snippet.py +143 -0
  262. warp/tests/test_sparse.py +261 -63
  263. warp/tests/test_spatial.py +276 -243
  264. warp/tests/test_streams.py +110 -85
  265. warp/tests/test_struct.py +268 -63
  266. warp/tests/test_tape.py +39 -21
  267. warp/tests/test_torch.py +118 -89
  268. warp/tests/test_transient_module.py +12 -13
  269. warp/tests/test_types.py +614 -0
  270. warp/tests/test_utils.py +494 -0
  271. warp/tests/test_vec.py +354 -2050
  272. warp/tests/test_vec_lite.py +73 -0
  273. warp/tests/test_vec_scalar_ops.py +2099 -0
  274. warp/tests/test_volume.py +457 -293
  275. warp/tests/test_volume_write.py +124 -134
  276. warp/tests/unittest_serial.py +35 -0
  277. warp/tests/unittest_suites.py +341 -0
  278. warp/tests/unittest_utils.py +568 -0
  279. warp/tests/unused_test_misc.py +71 -0
  280. warp/tests/{test_debug.py → walkthough_debug.py} +3 -17
  281. warp/thirdparty/appdirs.py +36 -45
  282. warp/thirdparty/unittest_parallel.py +549 -0
  283. warp/torch.py +9 -6
  284. warp/types.py +1089 -366
  285. warp/utils.py +93 -387
  286. warp_lang-0.11.0.dist-info/METADATA +238 -0
  287. warp_lang-0.11.0.dist-info/RECORD +332 -0
  288. {warp_lang-0.10.1.dist-info → warp_lang-0.11.0.dist-info}/WHEEL +1 -1
  289. warp/tests/test_all.py +0 -219
  290. warp/tests/test_array_scan.py +0 -60
  291. warp/tests/test_base.py +0 -208
  292. warp/tests/test_unresolved_func.py +0 -7
  293. warp/tests/test_unresolved_symbol.py +0 -7
  294. warp_lang-0.10.1.dist-info/METADATA +0 -21
  295. warp_lang-0.10.1.dist-info/RECORD +0 -188
  296. /warp/tests/{test_compile_consts_dummy.py → aux_test_compile_consts_dummy.py} +0 -0
  297. /warp/tests/{test_reference_reference.py → aux_test_reference_reference.py} +0 -0
  298. /warp/tests/{test_square.py → aux_test_square.py} +0 -0
  299. {warp_lang-0.10.1.dist-info → warp_lang-0.11.0.dist-info}/LICENSE.md +0 -0
  300. {warp_lang-0.10.1.dist-info → warp_lang-0.11.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,988 @@
1
+ #
2
+ # \file generator.py
3
+ #
4
+ # \brief Generates the CUTLASS Library's instances
5
+ #
6
+
7
+ import enum
8
+ import os.path
9
+ import shutil
10
+ import functools
11
+ import operator
12
+ import collections
13
+
14
+ from library import *
15
+
16
+ ###################################################################################################
17
+ #
18
+ # Data structure modeling a GEMM operation
19
+ #
20
+ ###################################################################################################
21
+
22
+ #
23
+ class GemmOperation:
24
+ #
25
+ def __init__(self, gemm_kind, arch, tile_description, A, B, C, element_epilogue, \
26
+ epilogue_functor = EpilogueFunctor.LinearCombination, swizzling_functor = SwizzlingFunctor.Identity8):
27
+
28
+ self.operation_kind = OperationKind.Gemm
29
+ self.arch = arch
30
+ self.tile_description = tile_description
31
+ self.gemm_kind = gemm_kind
32
+ self.A = A
33
+ self.B = B
34
+ self.C = C
35
+ self.element_epilogue = element_epilogue
36
+ self.epilogue_functor = epilogue_functor
37
+ self.swizzling_functor = swizzling_functor
38
+
39
+ #
40
+ def is_complex(self):
41
+ complex_operators = [
42
+ MathOperation.multiply_add_complex,
43
+ MathOperation.multiply_add_complex_gaussian,
44
+ MathOperation.multiply_add_complex_fast_f32
45
+ ]
46
+ return self.tile_description.math_instruction.math_operation in complex_operators
47
+
48
+ #
49
+ def is_planar_complex(self):
50
+ return self.gemm_kind in (GemmKind.PlanarComplex, GemmKind.PlanarComplexArray)
51
+
52
+ #
53
+ def accumulator_type(self):
54
+ accum = self.tile_description.math_instruction.element_accumulator
55
+
56
+ if self.is_complex():
57
+ return get_complex_from_real(accum)
58
+
59
+ return accum
60
+
61
+ #
62
+ def short_math_name(self):
63
+ if self.tile_description.math_instruction.math_operation == MathOperation.multiply_add_complex_gaussian:
64
+ return "g%s" % ShortDataTypeNames[self.accumulator_type()]
65
+ return ShortDataTypeNames[self.accumulator_type()]
66
+
67
+
68
+ #
69
+ def core_name(self):
70
+ ''' The basic operation kind is prefixed with a letter indicating the accumulation type. '''
71
+
72
+ inst_shape = ''
73
+ inst_operation = ''
74
+ intermediate_type = ''
75
+
76
+ math_operations_map = {
77
+ MathOperation.xor_popc: 'xor',
78
+ }
79
+
80
+ if self.tile_description.math_instruction.opcode_class == OpcodeClass.TensorOp or \
81
+ self.tile_description.math_instruction.opcode_class == OpcodeClass.WmmaTensorOp:
82
+
83
+ math_op = self.tile_description.math_instruction.math_operation
84
+ math_op_string = math_operations_map[math_op] if math_op in math_operations_map.keys() else ''
85
+
86
+ inst_shape = "%d%d%d" % tuple(self.tile_description.math_instruction.instruction_shape)
87
+ inst_shape += math_op_string
88
+
89
+ if self.tile_description.math_instruction.element_a != self.A.element and \
90
+ self.tile_description.math_instruction.element_a != self.tile_description.math_instruction.element_accumulator:
91
+ intermediate_type = DataTypeNames[self.tile_description.math_instruction.element_a]
92
+
93
+ return "%s%s%s%s" % (self.short_math_name(), inst_shape, intermediate_type, GemmKindNames[self.gemm_kind])
94
+
95
+ #
96
+ def extended_name(self):
97
+ ''' Append data types if they differ from compute type. '''
98
+ if self.is_complex():
99
+ extended_name = "${core_name}"
100
+ else:
101
+ if self.C.element != self.tile_description.math_instruction.element_accumulator and \
102
+ self.A.element != self.tile_description.math_instruction.element_accumulator:
103
+ extended_name = "${element_c}_${core_name}_${element_a}"
104
+ elif self.C.element == self.tile_description.math_instruction.element_accumulator and \
105
+ self.A.element != self.tile_description.math_instruction.element_accumulator:
106
+ extended_name = "${core_name}_${element_a}"
107
+ else:
108
+ extended_name = "${core_name}"
109
+
110
+ extended_name = SubstituteTemplate(extended_name, {
111
+ 'element_a': DataTypeNames[self.A.element],
112
+ 'element_c': DataTypeNames[self.C.element],
113
+ 'core_name': self.core_name()
114
+ })
115
+
116
+ return extended_name
117
+
118
+ #
119
+ def layout_name(self):
120
+ if self.is_complex() or self.is_planar_complex():
121
+ return "%s%s" % (
122
+ ShortComplexLayoutNames[(self.A.layout, self.A.complex_transform)],
123
+ ShortComplexLayoutNames[(self.B.layout, self.B.complex_transform)]
124
+ )
125
+ return "%s%s" % (ShortLayoutTypeNames[self.A.layout], ShortLayoutTypeNames[self.B.layout])
126
+
127
+ #
128
+ def procedural_name(self):
129
+ ''' The full procedural name indicates architecture, extended name, tile size, and layout. '''
130
+ threadblock = self.tile_description.procedural_name()
131
+
132
+ opcode_class_name = OpcodeClassNames[self.tile_description.math_instruction.opcode_class]
133
+
134
+ alignment = max([self.A.alignment, self.B.alignment, self.C.alignment])
135
+
136
+ return SubstituteTemplate(
137
+ "cutlass_${opcode_class}_${extended_name}_${threadblock}_${layout}_align${alignment}",
138
+ {
139
+ 'opcode_class': opcode_class_name,
140
+ 'extended_name': self.extended_name(),
141
+ 'threadblock': threadblock,
142
+ 'layout': self.layout_name(),
143
+ 'alignment': "%d" % self.A.alignment,
144
+ }
145
+ )
146
+
147
+ #
148
+ def configuration_name(self):
149
+ ''' The full procedural name indicates architecture, extended name, tile size, and layout. '''
150
+ return self.procedural_name()
151
+
152
+
153
+ ###################################################################################################
154
+ #
155
+ # Data structure modeling a grouped GEMM operation
156
+ #
157
+ ###################################################################################################
158
+
159
+ #
160
+ class GroupedGemmOperation(GemmOperation):
161
+ #
162
+ def __init__(self, gemm_kind, arch, tile_description, A, B, C, element_epilogue, \
163
+ epilogue_functor = EpilogueFunctor.LinearCombination, swizzling_functor = SwizzlingFunctor.Identity8, \
164
+ scheduler_mode = GroupScheduleMode.Device):
165
+ super().__init__(gemm_kind, arch, tile_description, A, B, C, element_epilogue, \
166
+ epilogue_functor, swizzling_functor)
167
+
168
+ self.scheduler_mode = scheduler_mode
169
+
170
+ #
171
+ def procedural_name(self):
172
+ ''' The full procedural name indicates architecture, extended name, tile size, and layout. '''
173
+ base = super().procedural_name()
174
+ return SubstituteTemplate(
175
+ base + "_schedule${schedule}",
176
+ {
177
+ 'schedule': ShortGroupScheduleModeNames[self.scheduler_mode]
178
+ })
179
+
180
+
181
+ ###################################################################################################
182
+ #
183
+ # Emits single instances of a CUTLASS device-wide operator
184
+ #
185
+ ###################################################################################################
186
+
187
+ #
188
+ class EmitGemmInstance:
189
+ ''' Responsible for emitting a CUTLASS template definition'''
190
+
191
+ def __init__(self, operation_suffix = ''):
192
+ self.operation_suffix = operation_suffix
193
+ self.includes = []
194
+ self.gemm_template = """
195
+ // Gemm operator ${operation_name}
196
+ using Operation_${operation_name} = cutlass::gemm::device::Gemm<
197
+ ${element_a}, ${layout_a},
198
+ ${element_b}, ${layout_b},
199
+ ${element_c}, ${layout_c},
200
+ ${element_accumulator},
201
+ ${opcode_class},
202
+ ${arch},
203
+ cutlass::gemm::GemmShape<${threadblock_shape_m}, ${threadblock_shape_n}, ${threadblock_shape_k}>,
204
+ cutlass::gemm::GemmShape<${warp_shape_m}, ${warp_shape_n}, ${warp_shape_k}>,
205
+ cutlass::gemm::GemmShape<${instruction_shape_m}, ${instruction_shape_n}, ${instruction_shape_k}>,
206
+ ${epilogue_functor}<
207
+ ${element_c},
208
+ ${epilogue_vector_length},
209
+ ${element_accumulator},
210
+ ${element_epilogue}
211
+ >,
212
+ ${swizzling_functor},
213
+ ${stages},
214
+ ${align_a},
215
+ ${align_b},
216
+ false,
217
+ ${math_operation}
218
+ ${residual}
219
+ >;
220
+ """
221
+ self.gemm_complex_template = """
222
+ // Gemm operator ${operation_name}
223
+ using Operation_${operation_name} = cutlass::gemm::device::GemmComplex<
224
+ ${element_a}, ${layout_a},
225
+ ${element_b}, ${layout_b},
226
+ ${element_c}, ${layout_c},
227
+ ${element_accumulator},
228
+ ${opcode_class},
229
+ ${arch},
230
+ cutlass::gemm::GemmShape<${threadblock_shape_m}, ${threadblock_shape_n}, ${threadblock_shape_k}>,
231
+ cutlass::gemm::GemmShape<${warp_shape_m}, ${warp_shape_n}, ${warp_shape_k}>,
232
+ cutlass::gemm::GemmShape<${instruction_shape_m}, ${instruction_shape_n}, ${instruction_shape_k}>,
233
+ ${epilogue_functor}<
234
+ ${element_c},
235
+ ${epilogue_vector_length},
236
+ ${element_accumulator},
237
+ ${element_epilogue}
238
+ >,
239
+ ${swizzling_functor},
240
+ ${stages},
241
+ ${transform_a},
242
+ ${transform_b},
243
+ ${math_operation}
244
+ ${residual}
245
+ >;
246
+ """
247
+
248
+ #
249
+ def instance_template(self):
250
+ return """
251
+ ${compile_guard_start}
252
+ manifest.append(new ${gemm_kind}<Operation_${operation_name}>("${operation_name}"));
253
+ ${compile_guard_end}
254
+ """
255
+
256
+ #
257
+ def emit(self, operation):
258
+
259
+ warp_shape = [operation.tile_description.threadblock_shape[idx] // operation.tile_description.warp_count[idx] for idx in range(3)]
260
+
261
+ epilogue_vector_length = int(min(operation.C.alignment * DataTypeSize[operation.C.element], 128) / DataTypeSize[operation.C.element])
262
+
263
+ residual = ''
264
+
265
+ values = {
266
+ 'operation_name': operation.procedural_name(),
267
+ 'element_a': DataTypeTag[operation.A.element],
268
+ 'layout_a': LayoutTag[operation.A.layout],
269
+ 'element_b': DataTypeTag[operation.B.element],
270
+ 'layout_b': LayoutTag[operation.B.layout],
271
+ 'element_c': DataTypeTag[operation.C.element],
272
+ 'layout_c': LayoutTag[operation.C.layout],
273
+ 'element_accumulator': DataTypeTag[operation.accumulator_type()],
274
+ 'opcode_class': OpcodeClassTag[operation.tile_description.math_instruction.opcode_class],
275
+ 'arch': "cutlass::arch::Sm%d" % operation.arch,
276
+ 'threadblock_shape_m': str(operation.tile_description.threadblock_shape[0]),
277
+ 'threadblock_shape_n': str(operation.tile_description.threadblock_shape[1]),
278
+ 'threadblock_shape_k': str(operation.tile_description.threadblock_shape[2]),
279
+ 'warp_shape_m': str(warp_shape[0]),
280
+ 'warp_shape_n': str(warp_shape[1]),
281
+ 'warp_shape_k': str(warp_shape[2]),
282
+ 'instruction_shape_m': str(operation.tile_description.math_instruction.instruction_shape[0]),
283
+ 'instruction_shape_n': str(operation.tile_description.math_instruction.instruction_shape[1]),
284
+ 'instruction_shape_k': str(operation.tile_description.math_instruction.instruction_shape[2]),
285
+ 'epilogue_vector_length': str(epilogue_vector_length),
286
+ 'element_epilogue': str(DataTypeTag[operation.element_epilogue]),
287
+ 'epilogue_functor': EpilogueFunctorTag[operation.epilogue_functor],
288
+ 'swizzling_functor': SwizzlingFunctorTag[operation.swizzling_functor],
289
+ 'stages': str(operation.tile_description.stages),
290
+ 'align_a': str(operation.A.alignment),
291
+ 'align_b': str(operation.B.alignment),
292
+ 'transform_a': ComplexTransformTag[operation.A.complex_transform],
293
+ 'transform_b': ComplexTransformTag[operation.B.complex_transform],
294
+ 'math_operation': MathOperationTag[operation.tile_description.math_instruction.math_operation],
295
+ 'residual': residual
296
+ }
297
+
298
+ template = self.gemm_complex_template if operation.is_complex() else self.gemm_template
299
+
300
+ return SubstituteTemplate(template, values)
301
+
302
+ ###################################################################################################
303
+
304
+ class EmitSparseGemmInstance:
305
+ ''' Responsible for emitting a CUTLASS template definition'''
306
+
307
+ def __init__(self, operation_suffix = ''):
308
+ self.operation_suffix = operation_suffix
309
+ self.includes = []
310
+ self.gemm_template = """
311
+ // Gemm operator ${operation_name}
312
+ using Operation_${operation_name} = cutlass::gemm::device::SparseGemm<
313
+ ${element_a}, ${layout_a},
314
+ ${element_b}, ${layout_b},
315
+ ${element_c}, ${layout_c},
316
+ ${element_accumulator},
317
+ ${opcode_class},
318
+ ${arch},
319
+ cutlass::gemm::GemmShape<${threadblock_shape_m}, ${threadblock_shape_n}, ${threadblock_shape_k}>,
320
+ cutlass::gemm::GemmShape<${warp_shape_m}, ${warp_shape_n}, ${warp_shape_k}>,
321
+ cutlass::gemm::GemmShape<${instruction_shape_m}, ${instruction_shape_n}, ${instruction_shape_k}>,
322
+ ${epilogue_functor}<
323
+ ${element_c},
324
+ ${epilogue_vector_length},
325
+ ${element_accumulator},
326
+ ${element_epilogue}
327
+ >,
328
+ ${swizzling_functor},
329
+ ${stages},
330
+ ${align_a},
331
+ ${align_b},
332
+ false,
333
+ ${math_operation}
334
+ ${residual}
335
+ >;
336
+ """
337
+
338
+ #
339
+ def instance_template(self):
340
+ return """
341
+ ${compile_guard_start}
342
+ manifest.append(new ${gemm_kind}<Operation_${operation_name}>("${operation_name}"));
343
+ ${compile_guard_end}
344
+ """
345
+
346
+ #
347
+ def emit(self, operation):
348
+
349
+ warp_shape = [operation.tile_description.threadblock_shape[idx] // operation.tile_description.warp_count[idx] for idx in range(3)]
350
+
351
+ epilogue_vector_length = int(min(operation.C.alignment * DataTypeSize[operation.C.element], 128) / DataTypeSize[operation.C.element])
352
+
353
+ residual = ''
354
+
355
+ values = {
356
+ 'operation_name': operation.procedural_name(),
357
+ 'element_a': DataTypeTag[operation.A.element],
358
+ 'layout_a': LayoutTag[operation.A.layout],
359
+ 'element_b': DataTypeTag[operation.B.element],
360
+ 'layout_b': LayoutTag[operation.B.layout],
361
+ 'element_c': DataTypeTag[operation.C.element],
362
+ 'layout_c': LayoutTag[operation.C.layout],
363
+ 'element_accumulator': DataTypeTag[operation.accumulator_type()],
364
+ 'opcode_class': OpcodeClassTag[operation.tile_description.math_instruction.opcode_class],
365
+ 'arch': "cutlass::arch::Sm%d" % operation.arch,
366
+ 'threadblock_shape_m': str(operation.tile_description.threadblock_shape[0]),
367
+ 'threadblock_shape_n': str(operation.tile_description.threadblock_shape[1]),
368
+ 'threadblock_shape_k': str(operation.tile_description.threadblock_shape[2]),
369
+ 'warp_shape_m': str(warp_shape[0]),
370
+ 'warp_shape_n': str(warp_shape[1]),
371
+ 'warp_shape_k': str(warp_shape[2]),
372
+ 'instruction_shape_m': str(operation.tile_description.math_instruction.instruction_shape[0]),
373
+ 'instruction_shape_n': str(operation.tile_description.math_instruction.instruction_shape[1]),
374
+ 'instruction_shape_k': str(operation.tile_description.math_instruction.instruction_shape[2]),
375
+ 'epilogue_vector_length': str(epilogue_vector_length),
376
+ 'element_epilogue': str(DataTypeTag[operation.element_epilogue]),
377
+ 'epilogue_functor': EpilogueFunctorTag[operation.epilogue_functor],
378
+ 'swizzling_functor': SwizzlingFunctorTag[operation.swizzling_functor],
379
+ 'stages': str(operation.tile_description.stages),
380
+ 'align_a': str(operation.A.alignment),
381
+ 'align_b': str(operation.B.alignment),
382
+ 'transform_a': ComplexTransformTag[operation.A.complex_transform],
383
+ 'transform_b': ComplexTransformTag[operation.B.complex_transform],
384
+ 'math_operation': MathOperationTag[operation.tile_description.math_instruction.math_operation],
385
+ 'residual': residual
386
+ }
387
+
388
+ template = self.gemm_template
389
+
390
+ return SubstituteTemplate(template, values)
391
+
392
+ ###################################################################################################
393
+
394
+
395
+ #
396
+ class EmitGemmUniversalInstance:
397
+ ''' Responsible for emitting a CUTLASS template definition'''
398
+
399
+ def __init__(self, operation_suffix = ''):
400
+ self.operation_suffix = operation_suffix
401
+ self.includes = [
402
+ "cutlass/cutlass.h",
403
+ "cutlass/numeric_types.h",
404
+ "cutlass/arch/arch.h",
405
+ "cutlass/arch/mma.h",
406
+ "cutlass/layout/matrix.h",
407
+ "cutlass/gemm/device/gemm.h",
408
+ "cutlass/gemm/device/gemm_universal_adapter.h",
409
+ "cutlass/gemm/kernel/default_gemm_universal.h",
410
+ ]
411
+ self.builtin_epilogue_functor_template = """
412
+ ${epilogue_functor}<
413
+ ${element_c},
414
+ ${epilogue_vector_length},
415
+ ${element_accumulator},
416
+ ${element_epilogue}
417
+ >
418
+ """
419
+ self.gemm_template = """
420
+ // Gemm operator ${operation_name}
421
+ using ${operation_name}_base =
422
+ typename cutlass::gemm::kernel::DefaultGemmUniversal<
423
+ ${element_b}, ${layout_b}, ${transform_b}, ${align_b}, // transposed B operand
424
+ ${element_a}, ${layout_a}, ${transform_a}, ${align_a}, // transposed A operand
425
+ ${element_c}, ${layout_c},
426
+ ${element_accumulator},
427
+ ${opcode_class},
428
+ ${arch},
429
+ cutlass::gemm::GemmShape<${threadblock_shape_m}, ${threadblock_shape_n}, ${threadblock_shape_k}>,
430
+ cutlass::gemm::GemmShape<${warp_shape_m}, ${warp_shape_n}, ${warp_shape_k}>,
431
+ cutlass::gemm::GemmShape<${instruction_shape_m}, ${instruction_shape_n}, ${instruction_shape_k}>,
432
+ ${epilogue_functor},
433
+ ${swizzling_functor},
434
+ ${stages},
435
+ ${math_operation}
436
+ >::GemmKernel;
437
+
438
+ // Define named type
439
+ struct ${operation_name}${operation_suffix} :
440
+ public ${operation_name}_base { };
441
+ """
442
+ self.gemm_template_interleaved = """
443
+ // Gemm operator ${operation_name}
444
+ using ${operation_name}_base =
445
+ typename cutlass::gemm::kernel::DefaultGemmUniversal<
446
+ ${element_a}, ${layout_a}, ${transform_a}, ${align_a},
447
+ ${element_b}, ${layout_b}, ${transform_b}, ${align_b},
448
+ ${element_c}, ${layout_c},
449
+ ${element_accumulator},
450
+ ${opcode_class},
451
+ ${arch},
452
+ cutlass::gemm::GemmShape<${threadblock_shape_m}, ${threadblock_shape_n}, ${threadblock_shape_k}>,
453
+ cutlass::gemm::GemmShape<${warp_shape_m}, ${warp_shape_n}, ${warp_shape_k}>,
454
+ cutlass::gemm::GemmShape<${instruction_shape_m}, ${instruction_shape_n}, ${instruction_shape_k}>,
455
+ ${epilogue_functor},
456
+ ${swizzling_functor},
457
+ ${stages},
458
+ ${math_operation}
459
+ >::GemmKernel;
460
+
461
+ // Define named type
462
+ struct ${operation_name}${operation_suffix} :
463
+ public ${operation_name}_base { };
464
+ """
465
+
466
+ #
467
+ def instance_template(self):
468
+ return """
469
+ ${compile_guard_start}
470
+ manifest.append(new ${gemm_kind}<
471
+ cutlass::gemm::device::GemmUniversalAdapter<${operation_name}>
472
+ >("${operation_name}"));
473
+ ${compile_guard_end}
474
+ """
475
+
476
+ #
477
+ def emit(self, operation):
478
+
479
+ threadblock_shape = operation.tile_description.threadblock_shape
480
+ warp_count = operation.tile_description.warp_count
481
+
482
+ warp_shape = [threadblock_shape[idx] // warp_count[idx] for idx in range(3)]
483
+
484
+ transpose_layouts = {
485
+ LayoutType.ColumnMajor: LayoutType.RowMajor,
486
+ LayoutType.RowMajor: LayoutType.ColumnMajor
487
+ }
488
+
489
+ if operation.A.layout in transpose_layouts.keys() and \
490
+ operation.B.layout in transpose_layouts.keys() and \
491
+ operation.C.layout in transpose_layouts.keys():
492
+
493
+ instance_layout_A = transpose_layouts[operation.A.layout]
494
+ instance_layout_B = transpose_layouts[operation.B.layout]
495
+ instance_layout_C = transpose_layouts[operation.C.layout]
496
+
497
+ gemm_template = self.gemm_template
498
+ else:
499
+ instance_layout_A, instance_layout_B, instance_layout_C = \
500
+ (operation.A.layout, operation.B.layout, operation.C.layout)
501
+
502
+ gemm_template = self.gemm_template_interleaved
503
+ #
504
+
505
+ # Support built-in epilogue functors or user-defined functions
506
+ if isinstance(operation.epilogue_functor, enum.Enum):
507
+
508
+ epilogue_vector_length = \
509
+ min(operation.C.alignment * DataTypeSize[operation.C.element], 128) // DataTypeSize[operation.C.element]
510
+
511
+ values = {
512
+ 'epilogue_vector_length': str(epilogue_vector_length),
513
+ 'element_epilogue': str(DataTypeTag[operation.element_epilogue]),
514
+ 'epilogue_functor': EpilogueFunctorTag[operation.epilogue_functor],
515
+ }
516
+ epilogue_functor = SubstituteTemplate(self.builtin_epilogue_functor_template, values)
517
+ else:
518
+ epilogue_functor = self.epilogue_functor.emit_declaration()
519
+ #
520
+
521
+ values = {
522
+ 'operation_name': operation.procedural_name(),
523
+ 'operation_suffix': self.operation_suffix,
524
+ 'element_a': DataTypeTag[operation.A.element],
525
+ 'layout_a': LayoutTag[instance_layout_A],
526
+ 'element_b': DataTypeTag[operation.B.element],
527
+ 'layout_b': LayoutTag[instance_layout_B],
528
+ 'element_c': DataTypeTag[operation.C.element],
529
+ 'layout_c': LayoutTag[instance_layout_C],
530
+ 'element_accumulator': DataTypeTag[operation.accumulator_type()],
531
+ 'opcode_class': OpcodeClassTag[operation.tile_description.math_instruction.opcode_class],
532
+ 'arch': "cutlass::arch::Sm%d" % operation.arch,
533
+ 'threadblock_shape_m': str(operation.tile_description.threadblock_shape[0]),
534
+ 'threadblock_shape_n': str(operation.tile_description.threadblock_shape[1]),
535
+ 'threadblock_shape_k': str(operation.tile_description.threadblock_shape[2]),
536
+ 'warp_shape_m': str(warp_shape[0]),
537
+ 'warp_shape_n': str(warp_shape[1]),
538
+ 'warp_shape_k': str(warp_shape[2]),
539
+ 'instruction_shape_m': str(operation.tile_description.math_instruction.instruction_shape[0]),
540
+ 'instruction_shape_n': str(operation.tile_description.math_instruction.instruction_shape[1]),
541
+ 'instruction_shape_k': str(operation.tile_description.math_instruction.instruction_shape[2]),
542
+ 'epilogue_functor': epilogue_functor,
543
+ 'swizzling_functor': SwizzlingFunctorTag[operation.swizzling_functor],
544
+ 'stages': str(operation.tile_description.stages),
545
+ 'align_a': str(operation.A.alignment),
546
+ 'align_b': str(operation.B.alignment),
547
+ 'transform_a': ComplexTransformTag[operation.A.complex_transform],
548
+ 'transform_b': ComplexTransformTag[operation.B.complex_transform],
549
+ 'math_operation': MathOperationTag[operation.tile_description.math_instruction.math_operation]
550
+ }
551
+
552
+ return SubstituteTemplate(gemm_template, values)
553
+
554
+ ###################################################################################################
555
+
556
+ #
557
+ class EmitGemmPlanarComplexInstance:
558
+ ''' Responsible for emitting a CUTLASS template definition'''
559
+
560
+ def __init__(self, operation_suffix = ''):
561
+ self.operation_suffix = operation_suffix
562
+ self.includes = []
563
+ self.template = """
564
+ // Gemm operator ${operation_name}
565
+ using Operation_${operation_name} = typename cutlass::gemm::kernel::DefaultGemmPlanarComplexUniversal<
566
+ ${element_a}, ${layout_a}, ${transform_a}, ${alignment_a},
567
+ ${element_b}, ${layout_b}, ${transform_b}, ${alignment_b},
568
+ ${element_c}, cutlass::layout::RowMajor,
569
+ ${element_accumulator},
570
+ ${opcode_class},
571
+ ${arch},
572
+ cutlass::gemm::GemmShape<${threadblock_shape_m}, ${threadblock_shape_n}, ${threadblock_shape_k}>,
573
+ cutlass::gemm::GemmShape<${warp_shape_m}, ${warp_shape_n}, ${warp_shape_k}>,
574
+ cutlass::gemm::GemmShape<${instruction_shape_m}, ${instruction_shape_n}, ${instruction_shape_k}>,
575
+ cutlass::epilogue::thread::LinearCombinationPlanarComplex<
576
+ ${element_c},
577
+ ${alignment_c},
578
+ ${element_accumulator},
579
+ ${element_epilogue}
580
+ >,
581
+ cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
582
+ ${stages},
583
+ ${math_operator}
584
+ >::GemmKernel;
585
+
586
+ struct ${operation_name} :
587
+ public Operation_${operation_name} { };
588
+ """
589
+
590
+ #
591
+ def instance_template(self):
592
+ return """
593
+ ${compile_guard_start}
594
+ manifest.append(new ${gemm_kind}<
595
+ cutlass::gemm::device::GemmUniversalAdapter<${operation_name}>
596
+ >("${operation_name}"));
597
+ ${compile_guard_end}
598
+ """
599
+
600
+ #
601
+ def emit(self, operation):
602
+
603
+ warp_shape = [operation.tile_description.threadblock_shape[idx] // operation.tile_description.warp_count[idx] for idx in range(3)]
604
+
605
+ # exchange and transpose A and B types, layouts, and complex transforms since the C layout is row-major
606
+ transposed_layout_A = TransposedLayout[operation.A.layout]
607
+ transposed_layout_B = TransposedLayout[operation.B.layout]
608
+
609
+ values = {
610
+ 'operation_name': operation.procedural_name(),
611
+ 'element_a': DataTypeTag[operation.B.element],
612
+ 'layout_a': LayoutTag[transposed_layout_B],
613
+ 'transform_a': ComplexTransformTag[operation.B.complex_transform],
614
+ 'alignment_a': str(operation.B.alignment),
615
+ 'element_b': DataTypeTag[operation.A.element],
616
+ 'layout_b': LayoutTag[transposed_layout_A],
617
+ 'transform_b': ComplexTransformTag[operation.A.complex_transform],
618
+ 'alignment_b': str(operation.A.alignment),
619
+ 'element_c': DataTypeTag[operation.C.element],
620
+ 'layout_c': LayoutTag[operation.C.layout],
621
+ 'element_accumulator': DataTypeTag[operation.tile_description.math_instruction.element_accumulator],
622
+ 'opcode_class': OpcodeClassTag[operation.tile_description.math_instruction.opcode_class],
623
+ 'arch': "cutlass::arch::Sm%d" % operation.arch,
624
+ 'threadblock_shape_m': str(operation.tile_description.threadblock_shape[0]),
625
+ 'threadblock_shape_n': str(operation.tile_description.threadblock_shape[1]),
626
+ 'threadblock_shape_k': str(operation.tile_description.threadblock_shape[2]),
627
+ 'warp_shape_m': str(warp_shape[0]),
628
+ 'warp_shape_n': str(warp_shape[1]),
629
+ 'warp_shape_k': str(warp_shape[2]),
630
+ 'instruction_shape_m': str(operation.tile_description.math_instruction.instruction_shape[0]),
631
+ 'instruction_shape_n': str(operation.tile_description.math_instruction.instruction_shape[1]),
632
+ 'instruction_shape_k': str(operation.tile_description.math_instruction.instruction_shape[2]),
633
+ 'alignment_c': str(operation.C.alignment),
634
+ 'element_epilogue': str(DataTypeTag[operation.element_epilogue]),
635
+ 'stages': str(operation.tile_description.stages),
636
+ 'math_operator': 'cutlass::arch::OpMultiplyAdd'
637
+ }
638
+
639
+ return SubstituteTemplate(self.template, values)
640
+
641
+ ###################################################################################################
642
+
643
+ #
644
+ class EmitGemmPlanarComplexArrayInstance:
645
+ ''' Responsible for emitting a CUTLASS template definition'''
646
+
647
+ def __init__(self, operation_suffix = ''):
648
+ self.operation_suffix = operation_suffix
649
+ self.includes = []
650
+ self.template = """
651
+ // Gemm operator ${operation_name}
652
+ using Operation_${operation_name} = typename cutlass::gemm::kernel::DefaultGemmPlanarComplexUniversal<
653
+ ${element_a}, ${layout_a}, ${transform_a}, ${alignment_a},
654
+ ${element_b}, ${layout_b}, ${transform_b}, ${alignment_b},
655
+ ${element_c}, cutlass::layout::RowMajor,
656
+ ${element_accumulator},
657
+ ${opcode_class},
658
+ ${arch},
659
+ cutlass::gemm::GemmShape<${threadblock_shape_m}, ${threadblock_shape_n}, ${threadblock_shape_k}>,
660
+ cutlass::gemm::GemmShape<${warp_shape_m}, ${warp_shape_n}, ${warp_shape_k}>,
661
+ cutlass::gemm::GemmShape<${instruction_shape_m}, ${instruction_shape_n}, ${instruction_shape_k}>,
662
+ cutlass::epilogue::thread::LinearCombinationPlanarComplex<
663
+ ${element_c},
664
+ ${alignment_c},
665
+ ${element_accumulator},
666
+ ${element_epilogue}
667
+ >,
668
+ cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
669
+ ${stages},
670
+ ${math_operator}
671
+ >::GemmArrayKernel;
672
+
673
+ struct ${operation_name} : public Operation_${operation_name} { };
674
+ """
675
+
676
+ #
677
+ def instance_template(self):
678
+ return """
679
+ ${compile_guard_start}
680
+ manifest.append(new ${gemm_kind}<
681
+ cutlass::gemm::device::GemmUniversalAdapter<${operation_name}>
682
+ >("${operation_name}"));
683
+ ${compile_guard_end}
684
+ """
685
+
686
+ #
687
+ def emit(self, operation):
688
+
689
+ warp_shape = [operation.tile_description.threadblock_shape[idx] // operation.tile_description.warp_count[idx] for idx in range(3)]
690
+
691
+ # exchange and transpose A and B types, layouts, and complex transforms since the C layout is row-major
692
+ transposed_layout_A = TransposedLayout[operation.A.layout]
693
+ transposed_layout_B = TransposedLayout[operation.B.layout]
694
+
695
+ values = {
696
+ 'operation_name': operation.procedural_name(),
697
+ 'element_a': DataTypeTag[operation.B.element],
698
+ 'layout_a': LayoutTag[transposed_layout_B],
699
+ 'transform_a': ComplexTransformTag[operation.B.complex_transform],
700
+ 'alignment_a': str(operation.B.alignment),
701
+ 'element_b': DataTypeTag[operation.A.element],
702
+ 'layout_b': LayoutTag[transposed_layout_A],
703
+ 'transform_b': ComplexTransformTag[operation.A.complex_transform],
704
+ 'alignment_b': str(operation.A.alignment),
705
+ 'element_c': DataTypeTag[operation.C.element],
706
+ 'layout_c': LayoutTag[operation.C.layout],
707
+ 'element_accumulator': DataTypeTag[operation.tile_description.math_instruction.element_accumulator],
708
+ 'opcode_class': OpcodeClassTag[operation.tile_description.math_instruction.opcode_class],
709
+ 'arch': "cutlass::arch::Sm%d" % operation.arch,
710
+ 'threadblock_shape_m': str(operation.tile_description.threadblock_shape[0]),
711
+ 'threadblock_shape_n': str(operation.tile_description.threadblock_shape[1]),
712
+ 'threadblock_shape_k': str(operation.tile_description.threadblock_shape[2]),
713
+ 'warp_shape_m': str(warp_shape[0]),
714
+ 'warp_shape_n': str(warp_shape[1]),
715
+ 'warp_shape_k': str(warp_shape[2]),
716
+ 'instruction_shape_m': str(operation.tile_description.math_instruction.instruction_shape[0]),
717
+ 'instruction_shape_n': str(operation.tile_description.math_instruction.instruction_shape[1]),
718
+ 'instruction_shape_k': str(operation.tile_description.math_instruction.instruction_shape[2]),
719
+ 'alignment_c': str(operation.C.alignment),
720
+ 'element_epilogue': str(DataTypeTag[operation.element_epilogue]),
721
+ 'stages': str(operation.tile_description.stages),
722
+ 'math_operator': 'cutlass::arch::OpMultiplyAdd'
723
+ }
724
+
725
+ return SubstituteTemplate(self.template, values)
726
+
727
+ ###################################################################################################
728
+
729
+ #
730
+ class EmitGemmGroupedInstance:
731
+ ''' Responsible for emitting a CUTLASS template definition'''
732
+
733
+ def __init__(self, operation_suffix = ''):
734
+ self.operation_suffix = operation_suffix
735
+ self.includes = [
736
+ "cutlass/cutlass.h",
737
+ "cutlass/numeric_types.h",
738
+ "cutlass/arch/arch.h",
739
+ "cutlass/arch/mma.h",
740
+ "cutlass/layout/matrix.h",
741
+ "cutlass/gemm/device/gemm.h",
742
+ "cutlass/gemm/kernel/gemm_grouped.h",
743
+ "cutlass/gemm/kernel/default_gemm_grouped.h",
744
+ "cutlass/gemm/device/gemm_grouped.h"
745
+ ]
746
+ self.builtin_epilogue_functor_template = """
747
+ ${epilogue_functor}<
748
+ ${element_c},
749
+ ${epilogue_vector_length},
750
+ ${element_accumulator},
751
+ ${element_epilogue}
752
+ >
753
+ """
754
+ self.gemm_template = """
755
+ // Gemm operator ${operation_name}
756
+ using ${operation_name}_base =
757
+ typename cutlass::gemm::kernel::DefaultGemmGrouped<
758
+ ${element_a}, ${layout_a}, ${transform_a}, ${align_a},
759
+ ${element_b}, ${layout_b}, ${transform_b}, ${align_b},
760
+ ${element_c}, ${layout_c},
761
+ ${element_accumulator},
762
+ ${opcode_class},
763
+ ${arch},
764
+ cutlass::gemm::GemmShape<${threadblock_shape_m}, ${threadblock_shape_n}, ${threadblock_shape_k}>,
765
+ cutlass::gemm::GemmShape<${warp_shape_m}, ${warp_shape_n}, ${warp_shape_k}>,
766
+ cutlass::gemm::GemmShape<${instruction_shape_m}, ${instruction_shape_n}, ${instruction_shape_k}>,
767
+ ${epilogue_functor},
768
+ ${swizzling_functor},
769
+ ${stages},
770
+ ${scheduler_mode},
771
+ ${math_operation}
772
+ >::GemmKernel;
773
+
774
+ // Define named type
775
+ struct ${operation_name}${operation_suffix} :
776
+ public ${operation_name}_base { };
777
+ """
778
+
779
+ #
780
+ def instance_template(self):
781
+ return """
782
+ ${compile_guard_start}
783
+ manifest.append(new ${gemm_kind}<
784
+ cutlass::gemm::device::GemmGrouped<${operation_name}>
785
+ >("${operation_name}"));
786
+ ${compile_guard_end}
787
+ """
788
+
789
+ #
790
+ def emit(self, operation):
791
+
792
+ threadblock_shape = operation.tile_description.threadblock_shape
793
+ warp_count = operation.tile_description.warp_count
794
+
795
+ warp_shape = [threadblock_shape[idx] // warp_count[idx] for idx in range(3)]
796
+
797
+ transpose_layouts = {
798
+ LayoutType.ColumnMajor: LayoutType.RowMajor,
799
+ LayoutType.RowMajor: LayoutType.ColumnMajor
800
+ }
801
+
802
+ instance_layout_A, instance_layout_B, instance_layout_C = \
803
+ (operation.A.layout, operation.B.layout, operation.C.layout)
804
+ #
805
+
806
+ # Support built-in epilogue functors or user-defined functions
807
+ if isinstance(operation.epilogue_functor, enum.Enum):
808
+
809
+ epilogue_vector_length = \
810
+ min(operation.C.alignment * DataTypeSize[operation.C.element], 128) // DataTypeSize[operation.C.element]
811
+
812
+ values = {
813
+ 'epilogue_vector_length': str(epilogue_vector_length),
814
+ 'element_epilogue': str(DataTypeTag[operation.element_epilogue]),
815
+ 'epilogue_functor': EpilogueFunctorTag[operation.epilogue_functor],
816
+ }
817
+ epilogue_functor = SubstituteTemplate(self.builtin_epilogue_functor_template, values)
818
+ else:
819
+ epilogue_functor = self.epilogue_functor.emit_declaration()
820
+ #
821
+
822
+ values = {
823
+ 'operation_name': operation.procedural_name(),
824
+ 'operation_suffix': self.operation_suffix,
825
+ 'element_a': DataTypeTag[operation.A.element],
826
+ 'layout_a': LayoutTag[instance_layout_A],
827
+ 'element_b': DataTypeTag[operation.B.element],
828
+ 'layout_b': LayoutTag[instance_layout_B],
829
+ 'element_c': DataTypeTag[operation.C.element],
830
+ 'layout_c': LayoutTag[instance_layout_C],
831
+ 'element_accumulator': DataTypeTag[operation.accumulator_type()],
832
+ 'opcode_class': OpcodeClassTag[operation.tile_description.math_instruction.opcode_class],
833
+ 'arch': "cutlass::arch::Sm%d" % operation.arch,
834
+ 'threadblock_shape_m': str(operation.tile_description.threadblock_shape[0]),
835
+ 'threadblock_shape_n': str(operation.tile_description.threadblock_shape[1]),
836
+ 'threadblock_shape_k': str(operation.tile_description.threadblock_shape[2]),
837
+ 'warp_shape_m': str(warp_shape[0]),
838
+ 'warp_shape_n': str(warp_shape[1]),
839
+ 'warp_shape_k': str(warp_shape[2]),
840
+ 'instruction_shape_m': str(operation.tile_description.math_instruction.instruction_shape[0]),
841
+ 'instruction_shape_n': str(operation.tile_description.math_instruction.instruction_shape[1]),
842
+ 'instruction_shape_k': str(operation.tile_description.math_instruction.instruction_shape[2]),
843
+ 'epilogue_functor': epilogue_functor,
844
+ 'swizzling_functor': SwizzlingFunctorTag[operation.swizzling_functor],
845
+ 'stages': str(operation.tile_description.stages),
846
+ 'align_a': str(operation.A.alignment),
847
+ 'align_b': str(operation.B.alignment),
848
+ 'transform_a': ComplexTransformTag[operation.A.complex_transform],
849
+ 'transform_b': ComplexTransformTag[operation.B.complex_transform],
850
+ 'scheduler_mode': GroupScheduleModeTag[operation.scheduler_mode],
851
+ 'math_operation': MathOperationTag[operation.tile_description.math_instruction.math_operation]
852
+ }
853
+
854
+ return SubstituteTemplate(self.gemm_template, values)
855
+
856
+ ###################################################################################################
857
+ #
858
+ # Emitters functions for all targets
859
+ #
860
+ ###################################################################################################
861
+
862
+ class EmitGemmConfigurationLibrary:
863
+ def __init__(self, operation_path, configuration_name):
864
+ self.configuration_name = configuration_name
865
+ self.configuration_path = os.path.join(operation_path, "%s.cu" % configuration_name).replace('\\', '/')
866
+
867
+ self.instance_emitter = {
868
+ GemmKind.Gemm: EmitGemmInstance,
869
+ GemmKind.Sparse: EmitSparseGemmInstance,
870
+ GemmKind.Universal: EmitGemmUniversalInstance,
871
+ GemmKind.PlanarComplex: EmitGemmPlanarComplexInstance,
872
+ GemmKind.PlanarComplexArray: EmitGemmPlanarComplexArrayInstance,
873
+ GemmKind.Grouped: EmitGemmGroupedInstance
874
+ }
875
+
876
+ self.gemm_kind_wrappers = {
877
+ GemmKind.Gemm: 'GemmOperation',
878
+ GemmKind.Sparse: 'GemmSparseOperation',
879
+ GemmKind.Universal: 'GemmUniversalOperation',
880
+ GemmKind.PlanarComplex: 'GemmPlanarComplexOperation',
881
+ GemmKind.PlanarComplexArray: 'GemmPlanarComplexArrayOperation',
882
+ GemmKind.Grouped: 'GemmGroupedOperation'
883
+ }
884
+
885
+ self.wmma_guard_start = "#if defined(CUTLASS_ARCH_WMMA_SM${sm_number}_ENABLED)"
886
+
887
+ self.separator = """
888
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
889
+
890
+ """
891
+
892
+ self.header_template = """
893
+ /*
894
+ Generated by gemm_operation.py - Do not edit.
895
+ */
896
+ """
897
+
898
+ self.initialize_function_template = """
899
+
900
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
901
+
902
+ namespace cutlass {
903
+ namespace library {
904
+
905
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
906
+
907
+ void initialize_${configuration_name}(Manifest &manifest) {
908
+
909
+ """
910
+ self.epilogue_template = """
911
+
912
+ }
913
+
914
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
915
+
916
+ } // namespace library
917
+ } // namespace cutlass
918
+
919
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
920
+
921
+ """
922
+
923
+ def __enter__(self):
924
+ self.configuration_file = open(self.configuration_path, "w")
925
+ self.configuration_file.write(self.header_template)
926
+ self.configuration_file.write(self.separator)
927
+
928
+ self.includes = collections.OrderedDict([
929
+ ("cutlass/cutlass.h", None),
930
+ ("cutlass/library/library.h", None),
931
+ ("cutlass/library/manifest.h", None),
932
+ ("library_internal.h", None),
933
+ ("gemm_operation.h", None),
934
+ ("cutlass/arch/wmma.h", None),
935
+ ])
936
+ self.instance_definitions = []
937
+ self.instance_wrappers = []
938
+
939
+ self.operations = []
940
+ return self
941
+
942
+ def emit(self, operation):
943
+ emitter = self.instance_emitter[operation.gemm_kind]()
944
+
945
+ for incl in emitter.includes:
946
+ self.includes[incl] = None
947
+
948
+ self.operations.append(operation)
949
+
950
+ self.instance_definitions.append(emitter.emit(operation))
951
+
952
+ self.instance_wrappers.append(SubstituteTemplate(emitter.instance_template(), {
953
+ 'configuration_name': self.configuration_name,
954
+ 'operation_name': operation.procedural_name(),
955
+ 'gemm_kind': self.gemm_kind_wrappers[operation.gemm_kind],
956
+ 'compile_guard_start': SubstituteTemplate(self.wmma_guard_start, {'sm_number': str(operation.arch)}) \
957
+ if operation.tile_description.math_instruction.opcode_class == OpcodeClass.WmmaTensorOp else "",
958
+ 'compile_guard_end': "#endif" \
959
+ if operation.tile_description.math_instruction.opcode_class == OpcodeClass.WmmaTensorOp else ""
960
+ }))
961
+
962
+ def __exit__(self, exception_type, exception_value, traceback):
963
+
964
+ # Write includes
965
+ for incl, _ in self.includes.items():
966
+ include_statement = "#include \"%s\"\n" % incl
967
+ self.configuration_file.write(include_statement)
968
+
969
+ self.configuration_file.write(self.separator)
970
+
971
+ # Write instance definitions in top-level namespace
972
+ for instance_definition in self.instance_definitions:
973
+ self.configuration_file.write(instance_definition)
974
+
975
+ # Add wrapper objects within initialize() function
976
+ self.configuration_file.write(SubstituteTemplate(self.initialize_function_template, {
977
+ 'configuration_name': self.configuration_name
978
+ }))
979
+
980
+ for instance_wrapper in self.instance_wrappers:
981
+ self.configuration_file.write(instance_wrapper)
982
+
983
+ self.configuration_file.write(self.epilogue_template)
984
+ self.configuration_file.close()
985
+
986
+ ###################################################################################################
987
+ ###################################################################################################
988
+