Title: Low GEMM Performance on Hopper GPU with Small M Shapes · Issue #21 · NVIDIA/nvmath-python · GitHub
Open Graph Title: Low GEMM Performance on Hopper GPU with Small M Shapes · Issue #21 · NVIDIA/nvmath-python
X Title: Low GEMM Performance on Hopper GPU with Small M Shapes · Issue #21 · NVIDIA/nvmath-python
Description: Hi, Thank you for the great library! I’m observing some unexpected performance with GEMM on Hopper GPUs when using small M dimensions. I followed the example in example14_autotune.py. Compared to the PyTorch implementation, the performan...
Open Graph Description: Hi, Thank you for the great library! I’m observing some unexpected performance with GEMM on Hopper GPUs when using small M dimensions. I followed the example in example14_autotune.py. Compared to t...
X Description: Hi, Thank you for the great library! I’m observing some unexpected performance with GEMM on Hopper GPUs when using small M dimensions. I followed the example in example14_autotune.py. Compared to t...
Opengraph URL: https://github.com/NVIDIA/nvmath-python/issues/21
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Low GEMM Performance on Hopper GPU with Small M Shapes","articleBody":"Hi,\n\nThank you for the great library! I’m observing some unexpected performance with GEMM on Hopper GPUs when using small M dimensions. I followed the example in [example14_autotune.py](https://github.com/NVIDIA/nvmath-python/blob/main/examples/linalg/advanced/matmul/example14_autotune.py).\n\nCompared to the PyTorch implementation, the performance is significantly lower — around 30% of the expected TFLOPS and memory bandwidth utilization.\n\n\u003cimg width=\"565\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/d5a87505-8f0b-4426-a522-a2dac97c9b96\" /\u003e\n\nNot sure I am correctly using the API — I would greatly appreciate any suggestions.\n\nEnvironment:\n\t•\tGPU: H200\n\t•\tCUDA: 12.8\n\t•\tPyTorch: 2.6.0\n\t•\tnvmath-python: 0.3.0\n\nBenchmark code:\n\n```python\nimport argparse\n\nimport torch\nimport nvmath\nfrom triton.testing import do_bench\n\n\ndef profile(m, n, k, dtype):\n device = torch.device(\"cuda\")\n assert isinstance(device, torch.device)\n\n X = torch.randn(m, k, device=device, dtype=dtype)\n Y = torch.randn(n, k, device=device, dtype=dtype)\n \n _torch_gemm = lambda: torch.matmul(X, Y)\n \n mm = nvmath.linalg.advanced.Matmul(X, Y)\n \n mm.plan(preferences={\"limit\":1000})\n mm.autotune(iterations=1000)\n \n # print(mm.algorithms[0].capabilities)\n _nvmath_gemm = lambda: mm.execute()\n \n t_torch = do_bench(_torch_gemm)\n t_nvmath = do_bench(_nvmath_gemm)\n \n return t_torch, t_nvmath\n\n\nif __name__ == \"__main__\":\n parser = argparse.ArgumentParser(description=\"GEMM profile\")\n parser.add_argument(\"--m\", type=int, default=4096)\n parser.add_argument(\"--n\", type=int, default=4096)\n parser.add_argument(\"--k\", type=int, default=4096)\n args = parser.parse_args()\n\n print(\"Provider,Operation,dtype,m,n,k,Runtime,GB/s,GFLOPs\")\n \n for dtype in [torch.float16, torch.bfloat16]:\n t_torch, t_nvmath = profile(args.m, args.n, args.k, dtype)\n\n m = args.m\n n = args.n\n k = args.k\n\n torch_mem_bd = 2 * (m * n + n * k + m * k) * 1e3 / t_torch / 1e9\n torch_gflops = 2 * m * n * k * 1e3 / t_torch / 1e9\n nv_mem_bd = 2 * (m * n + n * k + m * k) * 1e3 / t_nvmath / 1e9\n nv_gflops = 2 * m * n * k * 1e3 / t_nvmath / 1e9\n \n print(f\"TORCH,0,{dtype},{args.m},{args.n},{args.k},{t_torch},{torch_mem_bd},{torch_gflops}\")\n print(f\"NVMATH,0,{dtype},{args.m},{args.n},{args.k},{t_nvmath},{nv_mem_bd},{nv_gflops}\")\n```\n","author":{"url":"https://github.com/happierpig","@type":"Person","name":"happierpig"},"datePublished":"2025-03-28T00:22:34.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/21/nvmath-python/issues/21"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ff5693f9-b21e-307d-3a5e-afdb1e7eee54 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C2F6:3E8D3B:210B4F4:2FE68EA:6A60AEC9 |
| html-safe-nonce | 18eff4f771c7308c9870084bdc23bf767da09f8345823e77a7af52735f1e5716 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMkY2OjNFOEQzQjoyMTBCNEY0OjJGRTY4RUE6NkE2MEFFQzkiLCJ2aXNpdG9yX2lkIjoiNDc2NTI2MjQ0NTcxNTQzNTIwOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 24712d5aeeec8d97a2c8aa237d451254da01f54b80eba9194eb15064483e57ed |
| hovercard-subject-tag | issue:2954716062 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/NVIDIA/nvmath-python/21/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5e592047a5a7b903fa25c286a09a049018598e1033d6d9b2fddcbd126fb9caa8/NVIDIA/nvmath-python/issues/21 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5e592047a5a7b903fa25c286a09a049018598e1033d6d9b2fddcbd126fb9caa8/NVIDIA/nvmath-python/issues/21 |
| og:image:alt | Hi, Thank you for the great library! I’m observing some unexpected performance with GEMM on Hopper GPUs when using small M dimensions. I followed the example in example14_autotune.py. Compared to t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | happierpig |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66af895cfa11168648b21cb54f2bdc3b0587503cc95c3040344b93f2cd4f9e08 |
| turbo-cache-control | no-preview |
| go-import | github.com/NVIDIA/nvmath-python git https://github.com/NVIDIA/nvmath-python.git |
| octolytics-dimension-user_id | 1728152 |
| octolytics-dimension-user_login | NVIDIA |
| octolytics-dimension-repository_id | 788208729 |
| octolytics-dimension-repository_nwo | NVIDIA/nvmath-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 788208729 |
| octolytics-dimension-repository_network_root_nwo | NVIDIA/nvmath-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b2efb079bef4751afb19e51eb8a7bfb7a46dd1a0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width