diff --git a/crate-tmp/.gitignore b/crate-tmp/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/crate-tmp/.gitignore @@ -0,0 +1 @@ +/target diff --git a/crate-tmp/Cargo.lock b/crate-tmp/Cargo.lock new file mode 100644 index 0000000..a4103d2 --- /dev/null +++ b/crate-tmp/Cargo.lock @@ -0,0 +1,373 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "bindgen" +version = "0.69.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "itertools", + "lazy_static", + "lazycell", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", + "which", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "cc" +version = "1.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "either" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[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.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" +dependencies = [ + "cfg-if", + "windows-targets", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "nvtxw" +version = "0.0.0" +dependencies = [ + "bindgen", + "cc", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "prettyplease" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" +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 = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + +[[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.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +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.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/crate-tmp/Cargo.toml b/crate-tmp/Cargo.toml new file mode 100644 index 0000000..c9a4f19 --- /dev/null +++ b/crate-tmp/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "nvtxw" +version = "0.0.0" +edition = "2021" +license = "Apache-2.0 WITH LLVM-exception" +description = "Rust bindings for the NVIDIA® Tools Extension SDK Writer API (NVTXW)" +include = ["src/*", "build.rs"] + +[dependencies] + +[build-dependencies] +bindgen = ">=0" +cc = ">=1" diff --git a/crate-tmp/LICENSE.txt b/crate-tmp/LICENSE.txt new file mode 100644 index 0000000..537293d --- /dev/null +++ b/crate-tmp/LICENSE.txt @@ -0,0 +1,218 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +---- LLVM Exceptions to the Apache 2.0 License ---- + +As an exception, if, as a result of your compiling your source code, portions +of this Software are embedded into an Object form of such source code, you +may redistribute such embedded portions in such Object form without complying +with the conditions of Sections 4(a), 4(b) and 4(d) of the License. + +In addition, if you combine or link compiled forms of this Software with +software that is licensed under the GPLv2 ("Combined Software") and if a +court of competent jurisdiction determines that the patent provision (Section +3), the indemnity provision (Section 9) or other Section of the License +conflicts with the conditions of the GPLv2, you may retroactively and +prospectively choose to deem waived or otherwise exclude such Section(s) of +the License, but only in their entirety and only with respect to the Combined +Software. diff --git a/crate-tmp/build.rs b/crate-tmp/build.rs new file mode 100644 index 0000000..0a8e38e --- /dev/null +++ b/crate-tmp/build.rs @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023-2024, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions. + * See LICENSE.txt for license information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +fn main() { + extern crate bindgen; + + use std::env; + use std::path::PathBuf; + + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + + let bindings = bindgen::Builder::default() + .header("src/nvtxw-sys/tools/nvtxw/c/nvtxw3.h") + .clang_arg("-Isrc/nvtxw-sys/tools/nvtxw/c") + .clang_arg("-Isrc/nvtxw-sys") + .clang_arg("-Isrc/nvtxw-sys/nvtxext") + .allowlist_item("nvtx.*") + .allowlist_item("NVTX.*") + .default_macro_constant_type(bindgen::MacroTypeVariation::Signed) + .derive_default(true) + .generate() + .expect("Unable to generate bindings"); + + bindings + .write_to_file(out_path.join("nvtxw_bindings.rs")) + .expect("Unable to write bindings"); + + cc::Build::new() + .include("src/nvtxw-sys") + .include("src/nvtxw-sys/nvtxext") + .include("src/nvtxw-sys/tools/nvtxw/c") + .file("src/nvtxw-sys/tools/nvtxw/c/nvtxw3.c") + .compile("nvtxw-sys"); +} diff --git a/crate-tmp/src/lib.rs b/crate-tmp/src/lib.rs new file mode 100644 index 0000000..e85ced0 --- /dev/null +++ b/crate-tmp/src/lib.rs @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023-2024, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions. + * See LICENSE.txt for license information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +pub mod nvtxw; +mod nvtxw_bindings; diff --git a/crate-tmp/src/nvtxw.rs b/crate-tmp/src/nvtxw.rs new file mode 100644 index 0000000..46eb35e --- /dev/null +++ b/crate-tmp/src/nvtxw.rs @@ -0,0 +1,248 @@ +/* + * Copyright (c) 2023-2024, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions. + * See LICENSE.txt for license information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +use std::ffi::c_void; +use std::ffi::CString; +use std::mem::size_of; +use std::path::PathBuf; +use std::ptr::{null, null_mut}; + +use crate::nvtxw_bindings; + +pub use crate::nvtxw_bindings::nvtxPayloadData_t as PayloadData; +pub use crate::nvtxw_bindings::nvtxPayloadSchemaAttr_t as PayloadSchemaAttr; +pub use crate::nvtxw_bindings::nvtxPayloadSchemaEntry_t as PayloadSchemaEntry; +pub use crate::nvtxw_bindings::nvtxwInterfaceCore_t as InterfaceHandle; +pub use crate::nvtxw_bindings::nvtxwResultCode_t as ResultCode; +use crate::nvtxw_bindings::nvtxwSessionAttributes_t as SessionAttributes; +pub use crate::nvtxw_bindings::nvtxwSessionHandle_t as SessionHandle; +use crate::nvtxw_bindings::nvtxwStreamAttributes_t as StreamAttributes; +pub use crate::nvtxw_bindings::nvtxwStreamHandle_t as StreamHandle; + +use crate::nvtxw_bindings::NVTXW3_INIT_MODE_LIBRARY_FILENAME; +use crate::nvtxw_bindings::NVTXW3_INTERFACE_ID_CORE_V1; +use crate::nvtxw_bindings::NVTXW3_RESULT_FAILED; +use crate::nvtxw_bindings::NVTXW3_RESULT_INVALID_ARGUMENT; +use crate::nvtxw_bindings::NVTXW3_RESULT_SUCCESS; +use crate::nvtxw_bindings::NVTXW3_STREAM_ORDERING_SKID_NONE; + +pub const NVTX_PAYLOAD_ENTRY_FLAG_POINTER: u64 = + nvtxw_bindings::NVTX_PAYLOAD_ENTRY_FLAG_POINTER as u64; +pub const NVTX_PAYLOAD_ENTRY_FLAG_EVENT_MESSAGE: u64 = + nvtxw_bindings::NVTX_PAYLOAD_ENTRY_FLAG_EVENT_MESSAGE as u64; +pub const NVTX_PAYLOAD_ENTRY_FLAG_ARRAY_ZERO_TERMINATED: u64 = + nvtxw_bindings::NVTX_PAYLOAD_ENTRY_FLAG_ARRAY_ZERO_TERMINATED as u64; +pub const NVTX_PAYLOAD_ENTRY_FLAG_EVENT_TIMESTAMP: u64 = + nvtxw_bindings::NVTX_PAYLOAD_ENTRY_FLAG_EVENT_TIMESTAMP as u64; +pub const NVTX_PAYLOAD_ENTRY_FLAG_RANGE_BEGIN: u64 = + nvtxw_bindings::NVTX_PAYLOAD_ENTRY_FLAG_RANGE_BEGIN as u64; +pub const NVTX_PAYLOAD_ENTRY_FLAG_RANGE_END: u64 = + nvtxw_bindings::NVTX_PAYLOAD_ENTRY_FLAG_RANGE_END as u64; +pub const NVTX_PAYLOAD_ENTRY_TYPE_UINT64: u64 = + nvtxw_bindings::NVTX_PAYLOAD_ENTRY_TYPE_UINT64 as u64; +pub const NVTX_PAYLOAD_ENTRY_TYPE_NVTX_COLOR: u64 = + nvtxw_bindings::NVTX_PAYLOAD_ENTRY_TYPE_NVTX_COLOR as u64; +pub const NVTX_PAYLOAD_ENTRY_TYPE_CSTRING: u64 = + nvtxw_bindings::NVTX_PAYLOAD_ENTRY_TYPE_CSTRING as u64; +pub const NVTX_PAYLOAD_SCHEMA_TYPE_STATIC: u64 = + nvtxw_bindings::NVTX_PAYLOAD_SCHEMA_TYPE_STATIC as u64; +pub const NVTX_PAYLOAD_SCHEMA_TYPE_DYNAMIC: u64 = + nvtxw_bindings::NVTX_PAYLOAD_SCHEMA_TYPE_DYNAMIC as u64; +pub const NVTX_PAYLOAD_SCHEMA_FLAG_NONE: u64 = nvtxw_bindings::NVTX_PAYLOAD_SCHEMA_FLAG_NONE as u64; +pub const NVTX_PAYLOAD_SCHEMA_FLAG_REFERENCED: u64 = + nvtxw_bindings::NVTX_PAYLOAD_SCHEMA_FLAG_REFERENCED as u64; +pub const NVTX_PAYLOAD_SCHEMA_ATTR_NAME: u64 = nvtxw_bindings::NVTX_PAYLOAD_SCHEMA_ATTR_NAME as u64; +pub const NVTX_PAYLOAD_SCHEMA_ATTR_TYPE: u64 = nvtxw_bindings::NVTX_PAYLOAD_SCHEMA_ATTR_TYPE as u64; +pub const NVTX_PAYLOAD_SCHEMA_ATTR_FLAGS: u64 = + nvtxw_bindings::NVTX_PAYLOAD_SCHEMA_ATTR_FLAGS as u64; +pub const NVTX_PAYLOAD_SCHEMA_ATTR_ENTRIES: u64 = + nvtxw_bindings::NVTX_PAYLOAD_SCHEMA_ATTR_ENTRIES as u64; +pub const NVTX_PAYLOAD_SCHEMA_ATTR_NUM_ENTRIES: u64 = + nvtxw_bindings::NVTX_PAYLOAD_SCHEMA_ATTR_NUM_ENTRIES as u64; +pub const NVTX_PAYLOAD_SCHEMA_ATTR_STATIC_SIZE: u64 = + nvtxw_bindings::NVTX_PAYLOAD_SCHEMA_ATTR_STATIC_SIZE as u64; +pub const NVTX_PAYLOAD_SCHEMA_ATTR_SCHEMA_ID: u64 = + nvtxw_bindings::NVTX_PAYLOAD_SCHEMA_ATTR_SCHEMA_ID as u64; + +pub const NVTXW3_STREAM_ORDER_INTERLEAVING_NONE: i16 = 0; +pub const NVTXW3_STREAM_ORDERING_TYPE_UNKNOWN: i16 = 0; + +fn check(result: ResultCode) -> Result<(), ResultCode> { + if result != NVTXW3_RESULT_SUCCESS { + return Err(result); + } + Ok(()) +} + +pub fn initialize_simple() -> Result { + let so_name = "libNvtxwBackend.so"; + let c_mode_string = CString::new(so_name).expect("modeString CString::new failed"); + let cptr_mode_string = c_mode_string.as_ptr(); + + let mut get_interface_func: nvtxw_bindings::nvtxwGetInterface_t = Default::default(); + check(unsafe { + nvtxw_bindings::nvtxwInitialize( + NVTXW3_INIT_MODE_LIBRARY_FILENAME, + cptr_mode_string, + &mut get_interface_func, + null_mut(), + ) + })?; + + let get_interface = get_interface_func.ok_or(NVTXW3_RESULT_FAILED)?; + + let mut interface_void: *const c_void = null(); + check(unsafe { get_interface(NVTXW3_INTERFACE_ID_CORE_V1, &mut interface_void) })?; + + if interface_void.is_null() { + return Err(NVTXW3_RESULT_FAILED); + } + + let ptr_interface = interface_void as *const nvtxw_bindings::nvtxwInterfaceCore_t; + let interface; + unsafe { + interface = *ptr_interface; + } + + Ok(interface) +} + +pub fn session_begin_simple( + interface: InterfaceHandle, + o_output: Option, + o_merge: Option, +) -> Result { + let func = interface + .SessionBegin + .ok_or(NVTXW3_RESULT_INVALID_ARGUMENT)?; + + let mut c_output: CString = CString::new("").expect("CString::new failed"); + if let Some(os_output) = o_output { + let s_output = os_output.to_string_lossy(); + let session_name = match s_output.strip_suffix(".nsys-rep") { + Some(s) => s, + None => &s_output, + }; + c_output = CString::new(session_name).expect("CString::new failed"); + } + + let mut c_config: CString = CString::new("").expect("CString::new failed"); + if let Some(os_merge) = o_merge { + let s_merge = os_merge.to_string_lossy(); + let s_config = format!("ReportMerge={}", s_merge); + + c_config = CString::new(s_config).expect("CString::new failed"); + } + + let session_attr = SessionAttributes { + struct_size: size_of::(), + name: if c_output.is_empty() { + null_mut() + } else { + c_output.as_ptr() + }, + configString: if c_config.is_empty() { + null_mut() + } else { + c_config.as_ptr() + }, + }; + + let mut session: SessionHandle = Default::default(); + check(unsafe { func(&mut session, &session_attr) })?; + + if session.opaque.is_null() { + return Err(NVTXW3_RESULT_FAILED); + } + + Ok(session) +} + +pub fn stream_open_simple( + interface: InterfaceHandle, + session: SessionHandle, + stream_name: String, + domain_name: String, +) -> Result { + let func = interface.StreamOpen.ok_or(NVTXW3_RESULT_INVALID_ARGUMENT)?; + + let c_stream_name = CString::new(stream_name).expect("CString::new failed"); + let c_domain_name = CString::new(domain_name).expect("CString::new failed"); + + let stream_attr = StreamAttributes { + struct_size: size_of::(), + name: c_stream_name.as_ptr(), + nvtxDomainName: c_domain_name.as_ptr(), + eventScopePath: null(), + orderInterleaving: NVTXW3_STREAM_ORDER_INTERLEAVING_NONE, + orderingType: NVTXW3_STREAM_ORDERING_TYPE_UNKNOWN, + orderingSkid: NVTXW3_STREAM_ORDERING_SKID_NONE, + orderingSkidAmount: 0, + }; + + let mut stream: StreamHandle = Default::default(); + check(unsafe { func(&mut stream, session, &stream_attr) })?; + + if stream.opaque.is_null() { + return Err(NVTXW3_RESULT_FAILED); + } + + Ok(stream) +} + +pub fn schema_register( + interface: InterfaceHandle, + stream: StreamHandle, + schema_attr: &PayloadSchemaAttr, +) -> Result<(), ResultCode> { + let func = interface + .SchemaRegister + .ok_or(NVTXW3_RESULT_INVALID_ARGUMENT)?; + + check(unsafe { func(stream, schema_attr) }) +} + +pub fn event_write( + interface: InterfaceHandle, + stream: StreamHandle, + events: &[PayloadData], +) -> Result<(), ResultCode> { + let func = interface.EventWrite.ok_or(NVTXW3_RESULT_INVALID_ARGUMENT)?; + + let count = events.len(); + let ptr = events.as_ptr(); + + check(unsafe { func(stream, ptr, count) }) +} + +pub fn stream_end(interface: InterfaceHandle, stream: StreamHandle) -> Result<(), ResultCode> { + let func = interface + .StreamClose + .ok_or(NVTXW3_RESULT_INVALID_ARGUMENT)?; + + check(unsafe { func(stream) }) +} + +pub fn session_end(interface: InterfaceHandle, session: SessionHandle) -> Result<(), ResultCode> { + let func = interface.SessionEnd.ok_or(NVTXW3_RESULT_INVALID_ARGUMENT)?; + + check(unsafe { func(session) }) +} diff --git a/crate-tmp/src/nvtxw_bindings.rs b/crate-tmp/src/nvtxw_bindings.rs new file mode 100644 index 0000000..7e506e3 --- /dev/null +++ b/crate-tmp/src/nvtxw_bindings.rs @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023-2024, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions. + * See LICENSE.txt for license information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#![allow(dead_code)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] + +include!(concat!(env!("OUT_DIR"), "/nvtxw_bindings.rs"));