{"id":25946903,"url":"https://github.com/windowsnt/directmllib","last_synced_at":"2026-03-02T13:13:19.582Z","repository":{"id":278271506,"uuid":"935075550","full_name":"WindowsNT/DirectMLLib","owner":"WindowsNT","description":"A clean way to use DirectML for machine learning","archived":false,"fork":false,"pushed_at":"2025-03-03T05:12:53.000Z","size":109,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-03T05:24:57.627Z","etag":null,"topics":["cplusplus","directml","machine-learning"],"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/WindowsNT.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2025-02-18T21:34:16.000Z","updated_at":"2025-03-03T05:12:56.000Z","dependencies_parsed_at":"2025-02-18T22:42:57.996Z","dependency_job_id":null,"html_url":"https://github.com/WindowsNT/DirectMLLib","commit_stats":null,"previous_names":["windowsnt/directmllib"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindowsNT%2FDirectMLLib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindowsNT%2FDirectMLLib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindowsNT%2FDirectMLLib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindowsNT%2FDirectMLLib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WindowsNT","download_url":"https://codeload.github.com/WindowsNT/DirectMLLib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241827168,"owners_count":20026601,"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":["cplusplus","directml","machine-learning"],"created_at":"2025-03-04T10:17:21.779Z","updated_at":"2026-03-02T13:13:19.577Z","avatar_url":"https://github.com/WindowsNT.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DirectML Lib\n\nA quick way to use Direct ML for machine learning with a clean interface.\n\n# Quick Usage\n\n```\nint main()\n{\n\tCoInitializeEx(NULL, COINIT_MULTITHREADED);\n\tML ml(true);\n\tauto hr = ml.On();\n\tif (FAILED(hr))\n\t\treturn 0;\n\n\n\tMLOP op1(\u0026ml);\n\top1.\n\t\tAddInput({ DML_TENSOR_DATA_TYPE_FLOAT32, { 10,10} }).\n\t\tAddInput({ DML_TENSOR_DATA_TYPE_FLOAT32, { 10,10} }).\n\t\tAddIntermediate(dml::Sin(op1.Item(0))).\n\t\tAddIntermediate(dml::Cos(op1.Item(2))).\n\t\tAddOutput(dml::Add(op1.Item(3), op1.Item(1)));\n\tml.ops.push_back(op1.Build());\n\n\t// Initialize\n\tml.Prepare();\n\n\t// Run it 5 times\n\tfor (int y = 0; y \u003c 5; y++)\n\t{\n\t\t// Upload data\t\n\t\tstd::vector\u003cfloat\u003e data(100);\n\t\tfor (int i = 0; i \u003c 100; i++)\n\t\t\tdata[i] = (float)(i * (y + 1));\n\t\top1.Item(0).buffer-\u003eUpload(\u0026ml, data.data(), data.size() * sizeof(float));\n\t\top1.Item(1).buffer-\u003eUpload(\u0026ml, data.data(), data.size() * sizeof(float));\n\n\t\tml.Run();\n\n\t\t// Download data\n\t\tstd::vector\u003cfloat\u003e fdata(100);\n\t\tstd::vector\u003cchar\u003e cdata(400);\n\t\top1.Item(4).buffer-\u003eDownload(\u0026ml, 400, cdata);\n\t\tmemcpy(fdata.data(), cdata.data(), 400);\n\t\t}\n}\n```\n\n\nExample of executing a Linear Regression operator\n\n```\nauto LinearRegressionCPU(float* px, float* py, size_t n)\n{\n\t// Sx\n\tfloat Sx = 0, Sy = 0, Sxy = 0, Sx2 = 0;\n\tfor (size_t i = 0; i \u003c n; i++)\n\t{\n\t\tSx += px[i];\n\t\tSx2 += px[i] * px[i];\n\t\tSy += py[i];\n\t\tSxy += px[i] * py[i];\n\t}\n\tfloat B = (n * Sxy - Sx * Sy) / ((n * Sx2) - (Sx * Sx));\n\tfloat A = (Sy - (B * Sx)) / n;\n\n\tprintf(\"Linear Regression CPU:\\r\\nSx = %f\\r\\nSy = %f\\r\\nSxy = %f\\r\\nSx2 = %f\\r\\nA = %f\\r\\nB = %f\\r\\n\\r\\n\", Sx, Sy, Sxy, Sx2, A, B);\n\treturn std::tuple\u003cfloat, float\u003e(A, B);\n}\n\nvoid LinearRegressionDML(float* px, float* py, unsigned int n)\n{\n\tML ml(true);\n\tml.SetFeatureLevel(DML_FEATURE_LEVEL_6_4);\n\tauto hr = ml.On();\n\tif (FAILED(hr))\n\t\treturn;\n\n\tMLOP op1(\u0026ml);\n\t\n\t// Input X [0]\n\top1.AddInput({ DML_TENSOR_DATA_TYPE_FLOAT32, { 1,n} });\n\n\t// Input Y [1]\n\top1.AddInput({ DML_TENSOR_DATA_TYPE_FLOAT32, { 1,n} });\n\n\t// Constant n [2]\n\top1.AddIntermediate(ml.ConstantValueTensor(*op1.GetGraph().get(), (float)n, { 1,1 }));\n\n\t// Sx [3]\n\top1.AddIntermediate(dml::Slice(dml::CumulativeSummation(op1.Item(0), 1, DML_AXIS_DIRECTION_INCREASING, false), { 0, n - 1 }, { 1, 1 }, { 1, 1 }));\n\n\t// Sy [4]\n\top1.AddIntermediate(dml::Slice(dml::CumulativeSummation(op1.Item(1), 1, DML_AXIS_DIRECTION_INCREASING, false), { 0, n - 1 }, { 1, 1 }, { 1, 1 }));\n\n\t// Sxy [5]\n\top1.AddIntermediate(dml::Slice(dml::CumulativeSummation(dml::Multiply(op1.Item(0), op1.Item(1)), 1, DML_AXIS_DIRECTION_INCREASING, false), { 0, n - 1 }, { 1, 1 }, { 1, 1 }));\n\n\t// Sx2 [6]\n\top1.AddIntermediate(dml::Slice(dml::CumulativeSummation(dml::Multiply(op1.Item(0), op1.Item(0)), 1, DML_AXIS_DIRECTION_INCREASING, false), { 0, n - 1 }, { 1, 1 }, { 1, 1 }));\n\n\t// float B = (n * Sxy - Sx * Sy) / ((n * Sx2) - (Sx * Sx));\n\n\t// B [7]\n\top1.AddOutput((\n\t\tdml::Divide(\n\t\t\tdml::Subtract(\n\t\t\t\tdml::Multiply(\n\t\t\t\t\top1.Item(2),\n\t\t\t\t\top1.Item(5)\n\t\t\t\t),\n\t\t\t\tdml::Multiply(\n\t\t\t\t\top1.Item(3),\n\t\t\t\t\top1.Item(4)\n\t\t\t\t)\n\t\t\t),\n\t\t\tdml::Subtract(\n\t\t\t\tdml::Multiply(\n\t\t\t\t\top1.Item(2),\n\t\t\t\t\top1.Item(6)\n\t\t\t\t),\n\t\t\t\tdml::Multiply(\n\t\t\t\t\top1.Item(3),\n\t\t\t\t\top1.Item(3)\n\t\t\t\t)\n\t\t\t)\n\t\t)\n\t));\n\n\t// float A = (Sy - (B * Sx)) / n; [8]\n\top1.AddOutput(dml::Divide(\n\t\tdml::Subtract(\n\t\t\top1.Item(4),\n\t\t\tdml::Multiply(\n\t\t\t\top1.Item(7),\n\t\t\t\top1.Item(3)\n\t\t\t)\n\t\t),\n\t\top1.Item(2)\n\t));\n\n\n\tml.ops.push_back(op1.Build());\n\tml.Prepare();\n\n\tml.ops[0].Item(0).buffer-\u003eUpload(\u0026ml, px, n * sizeof(float));\t\n\tml.ops[0].Item(1).buffer-\u003eUpload(\u0026ml, py, n * sizeof(float));\n\t\n\tml.Run();\n\n\tstd::vector\u003cchar\u003e cdata;\n\tfloat A = 0, B = 0;\n\n\tml.ops[0].Item(7).buffer-\u003eDownload(\u0026ml, (size_t)-1, cdata);\n\tmemcpy(\u0026B, cdata.data(), 4);\n\tml.ops[0].Item(8).buffer-\u003eDownload(\u0026ml, (size_t)-1, cdata);\n\tmemcpy(\u0026A, cdata.data(), 4);\n\n\tprintf(\"Linear Regression GPU:\\r\\nA = %f\\r\\nB = %f\\r\\n\\r\\n\", A, B);\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindowsnt%2Fdirectmllib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwindowsnt%2Fdirectmllib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindowsnt%2Fdirectmllib/lists"}