From 071b1da19c34959d006283548bd840ff2d41b49d Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Sun, 15 Sep 2024 12:11:50 -0400 Subject: [PATCH 1/4] chore: remove rust --- .gitignore | 3 +- Cargo.lock | 991 -------------------------------------------------- Cargo.toml | 25 -- src/api.rs | 25 -- src/client.rs | 188 ---------- src/lib.rs | 5 - src/main.rs | 34 -- src/server.rs | 142 -------- 8 files changed, 1 insertion(+), 1412 deletions(-) delete mode 100644 Cargo.lock delete mode 100644 Cargo.toml delete mode 100644 src/api.rs delete mode 100644 src/client.rs delete mode 100644 src/lib.rs delete mode 100644 src/main.rs delete mode 100644 src/server.rs diff --git a/.gitignore b/.gitignore index 24685f3..e5a0d89 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -/target libscuda.so -server \ No newline at end of file +a.out \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index 54998dc..0000000 --- a/Cargo.lock +++ /dev/null @@ -1,991 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "anyhow" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" - -[[package]] -name = "async-trait" -version = "0.1.81" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.74", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - -[[package]] -name = "bumpalo" -version = "3.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "bytes" -version = "1.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" - -[[package]] -name = "cc" -version = "1.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9e8aabfac534be767c909e0690571677d49f41bd8465ae876fe043d52ba5292" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "crossbeam-channel" -version = "0.5.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" - -[[package]] -name = "educe" -version = "0.4.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f0042ff8246a363dbe77d2ceedb073339e85a804b9a47636c6e016a9a32c05f" -dependencies = [ - "enum-ordinalize", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "enum-ordinalize" -version = "3.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf1fa3f06bbff1ea5b1a9c7b14aa992a39657db60a2759457328d7e058f49ee" -dependencies = [ - "num-bigint", - "num-traits", - "proc-macro2", - "quote", - "syn 2.0.74", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.74", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "getrandom" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "gimli" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown", -] - -[[package]] -name = "itoa" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" - -[[package]] -name = "js-sys" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - -[[package]] -name = "libc" -version = "0.2.155" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" - -[[package]] -name = "libloading" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" -dependencies = [ - "cfg-if", - "windows-targets", -] - -[[package]] -name = "log" -version = "0.4.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" - -[[package]] -name = "memchr" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - -[[package]] -name = "miniz_oxide" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4569e456d394deccd22ce1c1913e6ea0e54519f577285001215d33557431afe4" -dependencies = [ - "hermit-abi", - "libc", - "wasi", - "windows-sys", -] - -[[package]] -name = "num-bigint" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" -dependencies = [ - "num-integer", - "num-traits", -] - -[[package]] -name = "num-integer" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -dependencies = [ - "autocfg", -] - -[[package]] -name = "nvml-wrapper-sys" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "698d45156f28781a4e79652b6ebe2eaa0589057d588d3aec1333f6466f13fcb5" -dependencies = [ - "libloading", -] - -[[package]] -name = "object" -version = "0.36.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9" -dependencies = [ - "memchr", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "opentelemetry" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69d6c3d7288a106c0a363e4b0e8d308058d56902adefb16f4936f417ffef086e" -dependencies = [ - "opentelemetry_api", - "opentelemetry_sdk", -] - -[[package]] -name = "opentelemetry_api" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c24f96e21e7acc813c7a8394ee94978929db2bcc46cf6b5014fc612bf7760c22" -dependencies = [ - "futures-channel", - "futures-util", - "indexmap", - "js-sys", - "once_cell", - "pin-project-lite", - "thiserror", -] - -[[package]] -name = "opentelemetry_sdk" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ca41c4933371b61c2a2f214bf16931499af4ec90543604ec828f7a625c09113" -dependencies = [ - "async-trait", - "crossbeam-channel", - "futures-channel", - "futures-executor", - "futures-util", - "once_cell", - "opentelemetry_api", - "percent-encoding", - "rand", - "thiserror", -] - -[[package]] -name = "percent-encoding" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" - -[[package]] -name = "pin-project" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.74", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "ppv-lite86" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" -dependencies = [ - "zerocopy", -] - -[[package]] -name = "proc-macro2" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "ryu" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" - -[[package]] -name = "scuda" -version = "0.1.0" -dependencies = [ - "anyhow", - "futures", - "libc", - "nvml-wrapper-sys", - "tarpc", - "tokio", -] - -[[package]] -name = "serde" -version = "1.0.204" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.204" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.74", -] - -[[package]] -name = "serde_json" -version = "1.0.121" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ab380d7d9f22ef3f21ad3e6c1ebe8e4fc7a2000ccba2e4d71fc96f15b2cb609" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", -] - -[[package]] -name = "sharded-slab" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tarpc" -version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93a1870169fb9490fb3b37df7f50782986475c33cb90955f9f9b9ae659124200" -dependencies = [ - "anyhow", - "fnv", - "futures", - "humantime", - "opentelemetry", - "pin-project", - "rand", - "serde", - "static_assertions", - "tarpc-plugins", - "thiserror", - "tokio", - "tokio-serde", - "tokio-util", - "tracing", - "tracing-opentelemetry", -] - -[[package]] -name = "tarpc-plugins" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad8302bea2fb8a2b01b025d23414b0b4ed32a783b95e5d818c3320a8bc4baada" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "thiserror" -version = "1.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.74", -] - -[[package]] -name = "thread_local" -version = "1.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" -dependencies = [ - "cfg-if", - "once_cell", -] - -[[package]] -name = "tokio" -version = "1.39.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daa4fb1bc778bd6f04cbfc4bb2d06a7396a8f299dc33ea1900cedaa316f467b1" -dependencies = [ - "backtrace", - "libc", - "mio", - "pin-project-lite", - "socket2", - "tokio-macros", - "windows-sys", -] - -[[package]] -name = "tokio-macros" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.74", -] - -[[package]] -name = "tokio-serde" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "911a61637386b789af998ee23f50aa30d5fd7edcec8d6d3dedae5e5815205466" -dependencies = [ - "bincode", - "bytes", - "educe", - "futures-core", - "futures-sink", - "pin-project", - "serde", - "serde_json", -] - -[[package]] -name = "tokio-util" -version = "0.7.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "slab", - "tokio", -] - -[[package]] -name = "tracing" -version = "0.1.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" -dependencies = [ - "log", - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.74", -] - -[[package]] -name = "tracing-core" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" -dependencies = [ - "once_cell", - "valuable", -] - -[[package]] -name = "tracing-opentelemetry" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21ebb87a95ea13271332df069020513ab70bdb5637ca42d6e492dc3bbbad48de" -dependencies = [ - "once_cell", - "opentelemetry", - "tracing", - "tracing-core", - "tracing-subscriber", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" -dependencies = [ - "sharded-slab", - "thread_local", - "tracing-core", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wasm-bindgen" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn 2.0.74", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.74", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - -[[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "byteorder", - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.74", -] diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index ed415f2..0000000 --- a/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "scuda" -version = "0.1.0" -edition = "2021" - -[lib] -name = "scuda" -crate-type = ["rlib", "cdylib"] -path = "src/lib.rs" - -[[bin]] -name = "scuda-server" -path = "src/main.rs" -required-features = ["disable-preload"] - -[features] -disable-preload = [] - -[dependencies] -libc = "0.2.155" -nvml-wrapper-sys = "0.8.0" -anyhow = "1.0.86" -futures = "0.3.30" -tarpc = { version = "0.34.0", features = ["full"] } -tokio = { version = "1.39.2", features = ["macros", "rt", "rt-multi-thread"] } \ No newline at end of file diff --git a/src/api.rs b/src/api.rs deleted file mode 100644 index ae64f5e..0000000 --- a/src/api.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![allow(non_snake_case)] // easier to match the C API. - -use nvml_wrapper_sys::bindings::nvmlReturn_t; - -#[tarpc::service] -pub trait Scuda { - // 4.11 Initialization and Cleanup - async fn nvmlInitWithFlags(flags: u32) -> nvmlReturn_t; - async fn nvmlInit_v2() -> nvmlReturn_t; - async fn nvmlShutdown() -> nvmlReturn_t; - - // 4.12 Error reporting - async fn nvmlErrorString(result: nvmlReturn_t) -> String; - - // 4.14 System Queries - async fn nvmlSystemGetCudaDriverVersion() -> (nvmlReturn_t, i32); - async fn nvmlSystemGetCudaDriverVersion_v2() -> (nvmlReturn_t, i32); - async fn nvmlSystemGetDriverVersion(length: u32) -> (nvmlReturn_t, String); - async fn nvmlSystemGetNVMLVersion(length: u32) -> (nvmlReturn_t, String); - async fn nvmlSystemGetProcessName(pid: u32, length: u32) -> (nvmlReturn_t, String); - - async fn nvml_device_get_name(device: u64, length: u32) -> String; - - async fn nvml_system_get_cuda_driver_version_v2() -> i32; -} diff --git a/src/client.rs b/src/client.rs deleted file mode 100644 index 1bba91c..0000000 --- a/src/client.rs +++ /dev/null @@ -1,188 +0,0 @@ -use libc::RTLD_NEXT; -use libc::{c_char, c_int, c_uint, c_void}; -use nvml_wrapper_sys::bindings::{ - nvmlReturn_enum_NVML_ERROR_GPU_IS_LOST, nvmlReturn_enum_NVML_ERROR_INSUFFICIENT_SIZE, - nvmlReturn_enum_NVML_SUCCESS, nvmlReturn_t, -}; -use std::ffi::{CStr, CString}; -use std::net::{IpAddr, Ipv6Addr}; -use std::sync::LazyLock; -use tarpc::client::{NewClient, RpcError}; -use tarpc::tokio_serde::formats::Json; -use tarpc::{client, context}; -use tokio::runtime::{self, Runtime}; - -use crate::api; - -static RUNTIME: LazyLock = LazyLock::new(|| { - runtime::Builder::new_multi_thread() - .enable_io() - .enable_time() - .build() - .unwrap() -}); - -static CLIENT: LazyLock = LazyLock::new(|| { - let server_addr = (IpAddr::V6(Ipv6Addr::LOCALHOST), 31337); - let mut transport = tarpc::serde_transport::tcp::connect(server_addr, Json::default); - transport.config_mut().max_frame_length(usize::MAX); - let tx = RUNTIME.block_on(transport).unwrap(); - let NewClient { client, dispatch } = api::ScudaClient::new(client::Config::default(), tx); - RUNTIME.spawn(dispatch); - - client -}); - -fn handle_response(response: Result) -> nvmlReturn_t { - match response { - Ok(response) => response, - Err(e) => { - eprintln!("Error: {:?}", e); - nvmlReturn_enum_NVML_ERROR_GPU_IS_LOST - } - } -} - -// 4.11 Initialization and Cleanup -#[no_mangle] -pub extern "C" fn nvmlInitWithFlags(flags: u32) -> nvmlReturn_t { - handle_response(RUNTIME.block_on(CLIENT.nvmlInitWithFlags(context::current(), flags))) -} - -#[no_mangle] -pub extern "C" fn nvmlInit_v2() -> nvmlReturn_t { - handle_response(RUNTIME.block_on(CLIENT.nvmlInit_v2(context::current()))) -} - -#[no_mangle] -pub extern "C" fn nvmlShutdown() -> nvmlReturn_t { - handle_response(RUNTIME.block_on(CLIENT.nvmlShutdown(context::current()))) -} - -// 4.12 Error reporting -#[no_mangle] -pub extern "C" fn nvmlErrorString(result: nvmlReturn_t) -> *const c_char { - match RUNTIME.block_on(CLIENT.nvmlErrorString(context::current(), result)) { - Ok(response) => CString::new(response).unwrap().into_raw(), - Err(_) => CString::new("Unknown error").unwrap().into_raw(), - } -} - -// 4.14 System Queries -#[no_mangle] -pub extern "C" fn nvmlSystemGetCudaDriverVersion(cuda_driver_version: *mut c_int) -> nvmlReturn_t { - match RUNTIME.block_on(CLIENT.nvmlSystemGetCudaDriverVersion(context::current())) { - Ok((result, version)) => { - unsafe { - *cuda_driver_version = version; - } - result - } - Err(_) => nvmlReturn_enum_NVML_ERROR_GPU_IS_LOST, - } -} - -#[no_mangle] -pub extern "C" fn nvmlSystemGetCudaDriverVersion_v2( - cuda_driver_version: *mut c_int, -) -> nvmlReturn_t { - match RUNTIME.block_on(CLIENT.nvmlSystemGetCudaDriverVersion_v2(context::current())) { - Ok((result, version)) => { - unsafe { - *cuda_driver_version = version; - } - result - } - Err(_) => nvmlReturn_enum_NVML_ERROR_GPU_IS_LOST, - } -} - -#[no_mangle] -pub extern "C" fn nvmlSystemGetDriverVersion( - driver_version: *mut c_char, - length: c_uint, -) -> nvmlReturn_t { - match RUNTIME.block_on(CLIENT.nvmlSystemGetDriverVersion(context::current(), length)) { - Ok((result, version)) => { - let version = CString::new(version).unwrap(); - unsafe { - std::ptr::copy_nonoverlapping(version.as_ptr(), driver_version, length as usize); - } - result - } - Err(_) => nvmlReturn_enum_NVML_ERROR_INSUFFICIENT_SIZE, - } -} - -#[no_mangle] -pub extern "C" fn nvmlSystemGetNVMLVersion( - nvml_version: *mut c_char, - length: c_uint, -) -> nvmlReturn_t { - match RUNTIME.block_on(CLIENT.nvmlSystemGetNVMLVersion(context::current(), length)) { - Ok((result, version)) => { - let version = CString::new(version).unwrap(); - unsafe { - std::ptr::copy_nonoverlapping(version.as_ptr(), nvml_version, length as usize); - } - result - } - Err(_) => nvmlReturn_enum_NVML_ERROR_INSUFFICIENT_SIZE, - } -} - -#[no_mangle] -pub extern "C" fn nvmlSystemGetProcessName( - pid: c_uint, - process_name: *mut c_char, - length: c_uint, -) -> nvmlReturn_t { - let length = length as u32; - let (result, name) = RUNTIME - .block_on(CLIENT.nvmlSystemGetProcessName(context::current(), pid, length)) - .unwrap(); - if result == nvmlReturn_enum_NVML_SUCCESS { - let name = CString::new(name).unwrap(); - unsafe { - std::ptr::copy_nonoverlapping(name.as_ptr(), process_name, length as usize); - } - } - result -} - -#[no_mangle] -pub extern "C" fn nvmlDeviceGetCount_v2(device_count: *mut c_uint) -> nvmlReturn_t { - unsafe { - *device_count = 1; - } - nvmlReturn_enum_NVML_SUCCESS -} - -extern "C" { - pub fn dlvsym( - handle: *mut c_void, - symbol: *const c_char, - version: *const c_char, - ) -> *mut c_void; -} - -#[no_mangle] -pub extern "C" fn dlsym(handle: *mut c_void, name: *const c_char) -> *mut c_void { - unsafe { - let symbol_name = CStr::from_ptr(name).to_str().unwrap(); - - match symbol_name { - "nvmlInitWithFlags" => nvmlInitWithFlags as *mut c_void, - "nvmlSystemGetCudaDriverVersion_v2" => nvmlSystemGetCudaDriverVersion_v2 as *mut c_void, - "nvmlDeviceGetCount_v2" => nvmlDeviceGetCount_v2 as *mut c_void, - "dlsym" => dlvsym as *mut c_void, - _ => { - let dlsym = CString::new("dlsym").unwrap(); - let glibc = CString::new("GLIBC_2.2.5").unwrap(); - let real_dlsym: unsafe extern "C" fn(*mut c_void, *const c_char) -> *mut c_void = - std::mem::transmute(dlvsym(RTLD_NEXT, dlsym.as_ptr(), glibc.as_ptr())); - real_dlsym(handle, name) - } - } - } -} diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index 978a937..0000000 --- a/src/lib.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub mod api; -pub mod server; - -#[cfg(not(feature = "disable-preload"))] -pub mod client; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index 1b61a52..0000000 --- a/src/main.rs +++ /dev/null @@ -1,34 +0,0 @@ -use futures::StreamExt; -use scuda::{ - api::Scuda, - server::{spawn, ScudaServer}, -}; -use std::{ - future::{self}, - net::{IpAddr, Ipv6Addr}, -}; - -use tarpc::{ - server::{self, incoming::Incoming, Channel}, - tokio_serde::formats::Json, -}; - -#[tokio::main] -async fn main() -> anyhow::Result<()> { - let server_addr = (IpAddr::V6(Ipv6Addr::LOCALHOST), 31337); - let mut listener = tarpc::serde_transport::tcp::listen(&server_addr, Json::default).await?; - listener.config_mut().max_frame_length(usize::MAX); - listener - .filter_map(|r| future::ready(r.ok())) - .map(server::BaseChannel::with_defaults) - .max_channels_per_key(1, |t| t.transport().peer_addr().unwrap().ip()) - .map(|channel| { - let server = ScudaServer(channel.transport().peer_addr().unwrap()); - channel.execute(server.serve()).for_each(spawn) - }) - .buffer_unordered(10) - .for_each(|_| async {}) - .await; - - Ok(()) -} diff --git a/src/server.rs b/src/server.rs deleted file mode 100644 index 0f8e6f4..0000000 --- a/src/server.rs +++ /dev/null @@ -1,142 +0,0 @@ -use std::{ - ffi::{CStr, CString}, - future::Future, - net::SocketAddr, - sync::LazyLock, -}; - -use crate::api::Scuda; -use libc::c_char; -use nvml_wrapper_sys::bindings::{ - nvmlDevice_t, nvmlReturn_enum_NVML_SUCCESS, nvmlReturn_t, NvmlLib, -}; -use tarpc::context; - -#[derive(Clone)] -pub struct ScudaServer(pub SocketAddr); - -static NVML_LIB: LazyLock = - LazyLock::new(|| unsafe { NvmlLib::new("libnvidia-ml.so").unwrap() }); - -impl Scuda for ScudaServer { - // 4.11 Initialization and Cleanup - async fn nvmlInitWithFlags(self, _: context::Context, flags: u32) -> nvmlReturn_t { - unsafe { NVML_LIB.nvmlInitWithFlags(flags) } - } - - async fn nvmlInit_v2(self, _: ::tarpc::context::Context) -> nvmlReturn_t { - unsafe { NVML_LIB.nvmlInit_v2() } - } - - async fn nvmlShutdown(self, _: context::Context) -> nvmlReturn_t { - unsafe { NVML_LIB.nvmlShutdown() } - } - - // 4.12 Error reporting - async fn nvmlErrorString(self, _: context::Context, result: nvmlReturn_t) -> String { - let error_string = unsafe { CStr::from_ptr(NVML_LIB.nvmlErrorString(result)) }; - error_string.to_string_lossy().into_owned() - } - - // 4.14 System Queries - async fn nvmlSystemGetCudaDriverVersion(self, _: context::Context) -> (nvmlReturn_t, i32) { - let mut cuda_driver_version = 0; - let result = unsafe { NVML_LIB.nvmlSystemGetCudaDriverVersion(&mut cuda_driver_version) }; - (result, cuda_driver_version) - } - - async fn nvmlSystemGetCudaDriverVersion_v2(self, _: context::Context) -> (nvmlReturn_t, i32) { - let mut cuda_driver_version = 0; - let result = - unsafe { NVML_LIB.nvmlSystemGetCudaDriverVersion_v2(&mut cuda_driver_version) }; - (result, cuda_driver_version) - } - - async fn nvmlSystemGetDriverVersion( - self, - _: context::Context, - length: u32, - ) -> (nvmlReturn_t, String) { - let mut driver_version = vec![0u8; length as usize]; - let driver_version_ptr = driver_version.as_mut_ptr() as *mut c_char; - let result = unsafe { NVML_LIB.nvmlSystemGetDriverVersion(driver_version_ptr, length) }; - if result != nvmlReturn_enum_NVML_SUCCESS { - return (result, String::new()); - } - let driver_version = unsafe { CStr::from_ptr(driver_version_ptr) }; - (result, driver_version.to_string_lossy().into_owned()) - } - - async fn nvmlSystemGetNVMLVersion( - self, - _: context::Context, - length: u32, - ) -> (nvmlReturn_t, String) { - let mut nvml_version = vec![0u8; length as usize]; - let nvml_version_ptr = nvml_version.as_mut_ptr() as *mut c_char; - let result = unsafe { NVML_LIB.nvmlSystemGetNVMLVersion(nvml_version_ptr, length) }; - if result != nvmlReturn_enum_NVML_SUCCESS { - return (result, String::new()); - } - let nvml_version = unsafe { CStr::from_ptr(nvml_version_ptr) }; - (result, nvml_version.to_string_lossy().into_owned()) - } - - async fn nvmlSystemGetProcessName( - self, - _: context::Context, - pid: u32, - length: u32, - ) -> (nvmlReturn_t, String) { - let mut process_name = vec![0u8; length as usize]; - let process_name_ptr = process_name.as_mut_ptr() as *mut c_char; - let result = unsafe { NVML_LIB.nvmlSystemGetProcessName(pid, process_name_ptr, length) }; - if result != nvmlReturn_enum_NVML_SUCCESS { - return (result, String::new()); - } - let process_name = unsafe { CStr::from_ptr(process_name_ptr) }; - (result, process_name.to_string_lossy().into_owned()) - } - - async fn nvml_device_get_name(self, _: context::Context, device: u64, length: u32) -> String { - let mut name = vec![0u8; length as usize]; - let name_ptr = name.as_mut_ptr() as *mut c_char; - let lib = unsafe { NvmlLib::new("libnvidia-ml.so").unwrap() }; - let result = unsafe { lib.nvmlDeviceGetName(device as nvmlDevice_t, name_ptr, length) }; - // set the first five bytes to MUGIT - name[0] = 77; - name[1] = 85; - name[2] = 71; - name[3] = 73; - name[4] = 84; - if result != nvmlReturn_enum_NVML_SUCCESS { - return String::new(); - } - String::from_utf8(name).unwrap() - } - - async fn nvml_system_get_cuda_driver_version_v2(self, _: context::Context) -> i32 { - let mut cuda_driver_version = 0; - let lib = unsafe { NvmlLib::new("libnvidia-ml.so").unwrap() }; - unsafe { - let r = lib.nvmlInit_v2(); - if r != nvmlReturn_enum_NVML_SUCCESS { - println!("Failed to initialize NVML: {}", r); - return 543534; - } - } - let result = unsafe { lib.nvmlSystemGetCudaDriverVersion_v2(&mut cuda_driver_version) }; - println!( - "CUDA Driver Version: {} result: {}", - cuda_driver_version, result - ); - if result != nvmlReturn_enum_NVML_SUCCESS { - return 123; - } - cuda_driver_version - } -} - -pub async fn spawn(fut: impl Future + Send + 'static) { - tokio::spawn(fut); -} From 57965266eeea6b48741c85d21e30f08c656d879f Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Sun, 15 Sep 2024 22:38:46 +0000 Subject: [PATCH 2/4] fix: functioning end to end --- api.h | 2 + client.cu | 79 +++++++++++++++++++++---------------- server.cu | 101 ++++++++++++++++++++++++++---------------------- test.Dockerfile | 9 +++++ 4 files changed, 112 insertions(+), 79 deletions(-) create mode 100644 test.Dockerfile diff --git a/api.h b/api.h index b9e2e60..08a19e6 100644 --- a/api.h +++ b/api.h @@ -5,6 +5,8 @@ #define RPC_nvmlInit_v2 1 #define RPC_nvmlShutdown 2 +#define RPC_nvmlDeviceGetCount_v2 4 #define RPC_nvmlDeviceGetName 3 +#define RPC_nvmlDeviceGetHandleByIndex_v2 5 #endif \ No newline at end of file diff --git a/client.cu b/client.cu index 669985d..ce32a78 100644 --- a/client.cu +++ b/client.cu @@ -6,6 +6,9 @@ #include #include #include +#include +#include +#include #include "api.h" @@ -16,22 +19,33 @@ int open_rpc_client() struct sockaddr_in servaddr; if (sockfd != 0) - { return sockfd; + + char* server_ip = getenv("SCUDA_SERVER"); + if (server_ip == NULL) + { + printf("SCUDA_SERVER environment variable not set\n"); + exit(0); + } + + addrinfo hints, *res; + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + if (getaddrinfo(server_ip, "14833", &hints, &res) != 0) + { + printf("getaddrinfo failed\n"); + exit(0); } - sockfd = socket(AF_INET, SOCK_STREAM, 0); + sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (sockfd == -1) { printf("socket creation failed...\n"); exit(0); } - bzero(&servaddr, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); - servaddr.sin_port = htons(14833); - if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) != 0) + if (connect(sockfd, res->ai_addr, res->ai_addrlen) != 0) { printf("connection with the server failed...\n"); exit(0); @@ -54,7 +68,6 @@ nvmlReturn_t send_rpc_message( int request_id = next_request_id++; - printf("Sending request %d\n", request_id); if (write(sockfd, &request_id, sizeof(int)) < 0 || write(sockfd, &op, sizeof(unsigned int)) < 0) { @@ -62,8 +75,6 @@ nvmlReturn_t send_rpc_message( return NVML_ERROR_GPU_IS_LOST; } - printf("Sending %lu requests\n", requests.size()); - for (auto r : requests) if (write(sockfd, r.first, r.second) < 0) { @@ -74,12 +85,9 @@ nvmlReturn_t send_rpc_message( // wait for the response while (true) { - printf("Waiting for response %d\n", request_id); while (active_response_id != request_id && active_response_id != -1) pthread_cond_wait(&cond, &mutex); - printf("Got response active %d\n", active_response_id); - // we currently own mutex. if active response id is -1, read the response id if (active_response_id == -1) { @@ -89,8 +97,6 @@ nvmlReturn_t send_rpc_message( return NVML_ERROR_GPU_IS_LOST; } - printf("Got response id %d\n", active_response_id); - if (active_response_id != request_id) { pthread_cond_broadcast(&cond); @@ -100,18 +106,7 @@ nvmlReturn_t send_rpc_message( active_response_id = -1; - printf("Reading response %d\n", request_id); - // it's our turn to read the response. - nvmlReturn_t ret; - if (read(sockfd, &ret, sizeof(nvmlReturn_t)) < 0 || ret != NVML_SUCCESS) - { - pthread_mutex_unlock(&mutex); - return NVML_ERROR_GPU_IS_LOST; - } - - printf("Reading %lu responses\n", responses.size()); - for (auto r : responses) if (read(sockfd, r.first, r.second) < 0) { @@ -119,7 +114,9 @@ nvmlReturn_t send_rpc_message( return NVML_ERROR_GPU_IS_LOST; } - printf("done!\n"); + nvmlReturn_t ret; + if (read(sockfd, &ret, sizeof(nvmlReturn_t)) < 0) + ret = NVML_ERROR_GPU_IS_LOST; // we are done, unlock and return. pthread_mutex_unlock(&mutex); @@ -151,24 +148,40 @@ nvmlReturn_t nvmlShutdown() return send_rpc_message(RPC_nvmlShutdown); } +nvmlReturn_t nvmlDeviceGetCount_v2(unsigned int* deviceCount) +{ + open_rpc_client(); + return send_rpc_message(RPC_nvmlDeviceGetCount_v2, {}, {{deviceCount, sizeof(unsigned int)}}); +} + nvmlReturn_t nvmlDeviceGetName(nvmlDevice_t device, char *name, unsigned int length) { open_rpc_client(); return send_rpc_message(RPC_nvmlDeviceGetName, {{&device, sizeof(nvmlDevice_t)}, {&length, sizeof(int)}}, {{name, length}}); } +nvmlReturn_t nvmlDeviceGetHandleByIndex_v2(unsigned int index, nvmlDevice_t *device) +{ + open_rpc_client(); + return send_rpc_message(RPC_nvmlDeviceGetHandleByIndex_v2, {{&index, sizeof(unsigned int)}}, {{device, sizeof(nvmlDevice_t)}}); +} + void *dlsym(void *handle, const char *name) __THROW { printf("Resolving symbol: %s\n", name); if (!strcmp(name, "nvmlInitWithFlags")) return (void *)nvmlInitWithFlags; - // if (!strcmp(name, "nvmlInit_v2")) - // return (void *)nvmlInit_v2; - // if (!strcmp(name, "nvmlShutdown")) - // return (void *)nvmlShutdown; - // if (!strcmp(name, "nvmlDeviceGetName")) - // return (void *)nvmlDeviceGetName; + if (!strcmp(name, "nvmlInit_v2")) + return (void *)nvmlInit_v2; + if (!strcmp(name, "nvmlShutdown")) + return (void *)nvmlShutdown; + if (!strcmp(name, "nvmlDeviceGetCount_v2")) + return (void *)nvmlDeviceGetCount_v2; + if (!strcmp(name, "nvmlDeviceGetName")) + return (void *)nvmlDeviceGetName; + if (!strcmp(name, "nvmlDeviceGetHandleByIndex_v2")) + return (void *)nvmlDeviceGetHandleByIndex_v2; static void *(*real_dlsym)(void *, const char *) = NULL; if (real_dlsym == NULL) diff --git a/server.cu b/server.cu index 4829071..f4ed305 100644 --- a/server.cu +++ b/server.cu @@ -12,31 +12,60 @@ #define PORT 14833 #define MAX_CLIENTS 10 -int sockfd; - -void nvmlInitWithFlagsHandler(int connfd, unsigned int flags) -{ - nvmlReturn_t result = nvmlInitWithFlags(flags); - write(connfd, &result, sizeof(result)); -} - -void nvmlShutdownHandler(int connfd) -{ - nvmlReturn_t result = nvmlShutdown(); - write(connfd, &result, sizeof(result)); -} +int request_handler(int connfd) { + unsigned int op; + if (read(connfd, &op, sizeof(unsigned int)) < 0) + return -1; -void nvmlDeviceGetNameHandler(int connfd, nvmlDevice_t device) -{ - char name[NVML_DEVICE_NAME_BUFFER_SIZE]; - nvmlReturn_t result = nvmlDeviceGetName(device, name, NVML_DEVICE_NAME_BUFFER_SIZE); - write(connfd, &result, sizeof(result)); - if (result == NVML_SUCCESS) + switch (op) + { + case RPC_nvmlInitWithFlags: + { + unsigned int flags; + if (read(connfd, &flags, sizeof(unsigned int)) < 0) + return -1; + return nvmlInitWithFlags(flags); + } + case RPC_nvmlShutdown: + return nvmlShutdown(); + case RPC_nvmlDeviceGetName: + { + nvmlDevice_t device; + char name[NVML_DEVICE_NAME_BUFFER_SIZE]; + unsigned int length; + if (read(connfd, &device, sizeof(nvmlDevice_t)) < 0) + return -1; + if (read(connfd, &length, sizeof(unsigned int)) < 0) + return -1; + nvmlReturn_t result = nvmlDeviceGetName(device, name, length); + if (write(connfd, name, length) < 0) + return -1; + return result; + } + case RPC_nvmlDeviceGetCount_v2: + { + unsigned int deviceCount = 0; + nvmlReturn_t result = nvmlDeviceGetCount_v2(&deviceCount); + if (write(connfd, &deviceCount, sizeof(unsigned int)) < 0) + return -1; + return result; + } + case RPC_nvmlDeviceGetHandleByIndex_v2: { - int len = strlen(name) + 1; // including null terminator - write(connfd, &len, sizeof(len)); - write(connfd, name, len); + unsigned int index; + nvmlDevice_t device; + if (read(connfd, &index, sizeof(unsigned int)) < 0) + return -1; + nvmlReturn_t result = nvmlDeviceGetHandleByIndex_v2(index, &device); + if (write(connfd, &device, sizeof(nvmlDevice_t)) < 0) + return -1; + return result; } + default: + printf("Unknown operation %d\n", op); + break; + } + return -1; } void *client_handler(void *arg) @@ -44,37 +73,17 @@ void *client_handler(void *arg) int connfd = *(int *)arg; free(arg); - unsigned int op; int request_id; - int argslen; while (read(connfd, &request_id, sizeof(int)) >= 0) { - if (read(connfd, &op, sizeof(unsigned int)) < 0) - goto exit; - if (write(connfd, &request_id, sizeof(int)) < 0) - goto exit; - - // Handle different NVML operations - switch (op) - { - case RPC_nvmlInitWithFlags: - { - unsigned int flags; - if (read(connfd, &flags, sizeof(unsigned int)) < 0) - goto exit; - printf("Received nvmlInitWithFlags request %d %d\n", request_id, flags); - nvmlReturn_t result = nvmlInitWithFlags(flags); - printf("Sending nvmlInitWithFlags response %d %d\n", request_id, result); - if (write(connfd, &result, sizeof(nvmlReturn_t)) < 0) - goto exit; break; - } - } + int result = request_handler(connfd); + if (write(connfd, &result, sizeof(int)) < 0) + break; } -exit: close(connfd); pthread_exit(NULL); } @@ -82,7 +91,7 @@ exit: int main() { struct sockaddr_in servaddr, cli; - sockfd = socket(AF_INET, SOCK_STREAM, 0); + int sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd == -1) { printf("Socket creation failed.\n"); diff --git a/test.Dockerfile b/test.Dockerfile new file mode 100644 index 0000000..41f1c34 --- /dev/null +++ b/test.Dockerfile @@ -0,0 +1,9 @@ +# Convenience file to emulate a server with no GPU. + +# sudo docker build -f test.Dockerfile -t test . +# sudo docker run -v $(pwd):/workspace -e SCUDA_SERVER=172.17.0.1 -e LD_PRELOAD=/workspace/libscuda.so test nvidia-smi --query-gpu=name --format=csv +FROM ubuntu:24.04 + +RUN apt-get update && apt-get install -y nvidia-utils-550 + +CMD ["nvidia-smi"] \ No newline at end of file From f05e7396669f7d9cfc9e1dd85754002729557f0c Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Sun, 15 Sep 2024 22:45:50 +0000 Subject: [PATCH 3/4] chore: add todo list --- TODO.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 TODO.md diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..1eda21d --- /dev/null +++ b/TODO.md @@ -0,0 +1,6 @@ +Features: +- Multithread the server + +Bugs: +- Server exits when the client disconnects +- Client dlsym resolution needs to switch to a hashmap or trie-based lookup table instead of linear strcmp \ No newline at end of file From 782fc4524d107c85d97d0f87b5ea6757366026af Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Sun, 15 Sep 2024 22:50:49 +0000 Subject: [PATCH 4/4] chore: better error handling --- TODO.md | 2 ++ client.cu | 25 +++++++++++-------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/TODO.md b/TODO.md index 1eda21d..740e358 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,7 @@ Features: +- Add moar APIs - Multithread the server +- Make port configurable Bugs: - Server exits when the client disconnects diff --git a/client.cu b/client.cu index ce32a78..b5d9bd8 100644 --- a/client.cu +++ b/client.cu @@ -18,14 +18,11 @@ int open_rpc_client() { struct sockaddr_in servaddr; - if (sockfd != 0) - return sockfd; - char* server_ip = getenv("SCUDA_SERVER"); if (server_ip == NULL) { printf("SCUDA_SERVER environment variable not set\n"); - exit(0); + return -1; } addrinfo hints, *res; @@ -35,20 +32,20 @@ int open_rpc_client() if (getaddrinfo(server_ip, "14833", &hints, &res) != 0) { printf("getaddrinfo failed\n"); - exit(0); + return -1; } sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (sockfd == -1) { printf("socket creation failed...\n"); - exit(0); + return -1; } if (connect(sockfd, res->ai_addr, res->ai_addrlen) != 0) { printf("connection with the server failed...\n"); - exit(0); + return -1; } return sockfd; } @@ -132,37 +129,37 @@ void close_rpc_client() nvmlReturn_t nvmlInitWithFlags(unsigned int flags) { - open_rpc_client(); + if (open_rpc_client() < 0) + return NVML_ERROR_GPU_IS_LOST; return send_rpc_message(RPC_nvmlInitWithFlags, {{&flags, sizeof(unsigned int)}}); } nvmlReturn_t nvmlInit_v2() { - open_rpc_client(); + if (open_rpc_client() < 0) + return NVML_ERROR_GPU_IS_LOST; return send_rpc_message(RPC_nvmlInit_v2); } nvmlReturn_t nvmlShutdown() { - open_rpc_client(); - return send_rpc_message(RPC_nvmlShutdown); + nvmlReturn_t result = send_rpc_message(RPC_nvmlShutdown); + close_rpc_client(); + return result; } nvmlReturn_t nvmlDeviceGetCount_v2(unsigned int* deviceCount) { - open_rpc_client(); return send_rpc_message(RPC_nvmlDeviceGetCount_v2, {}, {{deviceCount, sizeof(unsigned int)}}); } nvmlReturn_t nvmlDeviceGetName(nvmlDevice_t device, char *name, unsigned int length) { - open_rpc_client(); return send_rpc_message(RPC_nvmlDeviceGetName, {{&device, sizeof(nvmlDevice_t)}, {&length, sizeof(int)}}, {{name, length}}); } nvmlReturn_t nvmlDeviceGetHandleByIndex_v2(unsigned int index, nvmlDevice_t *device) { - open_rpc_client(); return send_rpc_message(RPC_nvmlDeviceGetHandleByIndex_v2, {{&index, sizeof(unsigned int)}}, {{device, sizeof(nvmlDevice_t)}}); }