Python bindings (#125)

Co-authored-by: Olli Saarikivi <olsaarik@microsoft.com>
Co-authored-by: Changho Hwang <changhohwang@microsoft.com>
Co-authored-by: Binyang Li <binyli@microsoft.com>
This commit is contained in:
Saeed Maleki
2023-07-19 00:35:54 -07:00
committed by GitHub
parent 2e1645782e
commit e7d5e652df
58 changed files with 785 additions and 1263 deletions

23
python/utils_py.cpp Normal file
View File

@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include <nanobind/nanobind.h>
#include <nanobind/stl/string.h>
#include <mscclpp/utils.hpp>
namespace nb = nanobind;
using namespace mscclpp;
void register_utils(nb::module_& m) {
nb::class_<Timer>(m, "Timer")
.def(nb::init<int>(), nb::arg("timeout") = -1)
.def("elapsed", &Timer::elapsed)
.def("set", &Timer::set, nb::arg("timeout"))
.def("reset", &Timer::reset)
.def("print", &Timer::print, nb::arg("name"));
nb::class_<ScopedTimer, Timer>(m, "ScopedTimer").def(nb::init<std::string>(), nb::arg("name"));
m.def("get_host_name", &getHostName, nb::arg("maxlen"), nb::arg("delim"));
}