{"id":17549178,"url":"https://github.com/yhirose/mtlcpp","last_synced_at":"2025-04-24T02:12:06.356Z","repository":{"id":198750090,"uuid":"700053038","full_name":"yhirose/mtlcpp","owner":"yhirose","description":"Utilities for Metal-cpp","archived":false,"fork":false,"pushed_at":"2024-06-15T20:01:13.000Z","size":2073,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-18T10:22:51.053Z","etag":null,"topics":["apple-silicon","cpp","cpp20","header-only","m1-mac","metal","metal-cpp"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yhirose.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-03T21:11:29.000Z","updated_at":"2025-04-16T20:54:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"2fee0d83-1a17-4082-89c8-3f9d27073159","html_url":"https://github.com/yhirose/mtlcpp","commit_stats":null,"previous_names":["yhirose/mtlcpp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yhirose%2Fmtlcpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yhirose%2Fmtlcpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yhirose%2Fmtlcpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yhirose%2Fmtlcpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yhirose","download_url":"https://codeload.github.com/yhirose/mtlcpp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250546086,"owners_count":21448260,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apple-silicon","cpp","cpp20","header-only","m1-mac","metal","metal-cpp"],"created_at":"2024-10-21T02:50:03.890Z","updated_at":"2025-04-24T02:12:06.334Z","avatar_url":"https://github.com/yhirose.png","language":"C++","readme":"mtlcpp\n======\n\nA header-only C++20 linear algebra library for Metal on MacOS\n\n * This project is still in development and is far from reaching the first alpha version :)\n * Data types supported in this library are `int` and `float` only, since Metal doesn't support `double`\n * This library uses GPU cores in Apple M1 chip with [Metal-cpp](https://developer.apple.com/metal/cpp/)\n\nBuild and run unit tests and benchmark\n--------------------------------------\n\n * Install Xcode Command Line Tools\n * Run the following commands in Terminal\n\n```bash\ncd test\nmake\n```\n\nBenchmark as of 3/2/2024 on M1 MacBook Pro 14\n---------------------------------------------\n\n|               ns/op |                op/s | benchmark\n|--------------------:|--------------------:|:----------\n|      150,856,709.00 |                6.63 | CPU: `a + b`\n|        2,262,442.07 |              442.00 | GPU: `a + b`\n|        1,351,401.59 |              739.97 | Eigen: `a + b`\n|      964,220,500.00 |                1.04 | CPU: `a.dot(b)`\n|        1,094,602.35 |              913.57 | GPU: `a.dot(b)`\n|        3,002,299.36 |              333.08 | Eigen: `a * b`\n\n```cpp\n// test/bench.cpp\n\n// `add` benchmark\nconst size_t n = 10'000'000;\n\nauto a = mtl::ones\u003cfloat\u003e({n});\nauto b = mtl::ones\u003cfloat\u003e({n});\nauto c = mtl::array\u003cfloat\u003e();\n\nmtl::use_cpu();\nBench().run(\"CPU: a + b\", [\u0026] {\n  c = a + b;\n});\n\nmtl::use_gpu();\nBench().run(\"GPU: a + b\", [\u0026] {\n  c = a + b;\n});\n\nauto aa = Eigen::Vector\u003cfloat, Eigen::Dynamic\u003e::Ones(n);\nauto bb = Eigen::Vector\u003cfloat, Eigen::Dynamic\u003e::Ones(n);\nauto cc = Eigen::Vector\u003cfloat, Eigen::Dynamic\u003e(n);\n\nBench().run(\"Eigen: a + b\", [\u0026] {\n  cc = aa + bb;\n});\n\n// `dot` benchmark\nauto a = mtl::ones\u003cfloat\u003e({1000, 1000});\nauto b = mtl::ones\u003cfloat\u003e({1000, 100});\nauto c = mtl::array\u003cfloat\u003e();\n\nmtl::use_cpu();\nBench().run(\"CPU: a.dot(b)\", [\u0026] {\n  c = a.dot(b);\n});\n\nmtl::use_gpu();\nBench().run(\"GPU: a.dot(b)\", [\u0026] {\n  c = a.dot(b);\n});\n\nauto aa = Eigen::Matrix\u003cfloat, Eigen::Dynamic, Eigen::Dynamic\u003e::Ones(1000, 1000);\nauto bb = Eigen::Matrix\u003cfloat, Eigen::Dynamic, Eigen::Dynamic\u003e::Ones(1000, 100);\nauto cc = Eigen::Matrix\u003cfloat, Eigen::Dynamic, Eigen::Dynamic\u003e();\n\nBench().run(\"Eigen: a * b\", [\u0026] {\n  cc = aa * bb;\n});\n```\n\nOperations\n----------\n\n### GPU and CPU\n\n * `+` (add)\n * `-` (sub)\n * `*` (mul)\n * `/` (div)\n * `dot` (dot product)\n\n### CPU only\n\n * `==`\n * `clone`\n * `constants`\n * `empty`\n * `zeros`\n * `ones`\n * `random`\n * `transpose`\n * `sigmoid`\n * `sum`\n * `mean`\n * `min`\n * `max`\n * `count`\n * `all`\n * `softmax`\n * `argmax`\n * `array_equal`\n * `allclose`\n\nLicense\n-------\n\nMIT license (© 2024 Yuji Hirose)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyhirose%2Fmtlcpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyhirose%2Fmtlcpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyhirose%2Fmtlcpp/lists"}