Skip to content

Commit

Permalink
pyxrt updates for windows (Xilinx#7582)
Browse files Browse the repository at this point in the history
* pyxrt updates

* cmake updates

* added pyd target property

* pybind CMakeLists cleanup

* Signoff commit

Signed-off-by: sarunask <[email protected]>

* DCO Remediation Commit for sarunask <[email protected]>

I, sarunask <[email protected]>, hereby add my Signed-off-by to this commit: a32f9f0
I, sarunask <[email protected]>, hereby add my Signed-off-by to this commit: f5eb54d
I, sarunask <[email protected]>, hereby add my Signed-off-by to this commit: 9333985

Signed-off-by: sarunask <[email protected]>

* DCO Remediation Commit for skalade <[email protected]>

I, skalade <[email protected]>, hereby add my Signed-off-by to this commit: 528fd83

Signed-off-by: skalade <[email protected]>

* DCO Remediation Commit for sarunask <[email protected]>

I, sarunask <[email protected]>, hereby add my Signed-off-by to this commit: 289d1d8

Signed-off-by: sarunask <[email protected]>

* DCO Remediation Commit for skalade <[email protected]>

I, skalade <[email protected]>, hereby add my Signed-off-by to this commit: 528fd83

Signed-off-by: skalade <[email protected]>

* removed XRT_BO_* enums, we use pyxrt.bo.flags.*
removed commented out code
add_subdirectory -> xrt_add_subdirectory

Signed-off-by: sarunask <[email protected]>

* revert linux cmake changes, keep localized to windows

Signed-off-by: sarunask <[email protected]>

* linux pybind11==2.6.0

Signed-off-by: sarunask <[email protected]>

* DCO Remediation Commit for sarunask <[email protected]>

I, sarunask <[email protected]>, hereby add my Signed-off-by to this commit: a835180

Signed-off-by: sarunask <[email protected]>

* DCO Remediation Commit for skalade <[email protected]>

I, skalade <[email protected]>, hereby add my Signed-off-by to this commit: 528fd83

Signed-off-by: skalade <[email protected]>

* use python executable to get windows-friendly package path

Signed-off-by: skalade <[email protected]>

* add more debug messaging

Signed-off-by: skalade <[email protected]>

---------

Signed-off-by: sarunask <[email protected]>
Signed-off-by: skalade <[email protected]>
  • Loading branch information
skalade authored Jun 13, 2023
1 parent 5fb2900 commit 531dc42
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 43 deletions.
3 changes: 3 additions & 0 deletions src/CMake/nativeWin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ add_subdirectory(runtime_src)

# --- Find Package Support ---
include (CMake/findpackage.cmake)

# --- Python bindings ---
xrt_add_subdirectory(python)
49 changes: 49 additions & 0 deletions src/python/pybind11/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Copyright (C) 2020-2021 Xilinx, Inc. All rights reserved.
#

if( NOT WIN32)

# find_package(PythonLibs is depracted as of cmake 3.12.
if (CMAKE_VERSION VERSION_LESS "3.12")
find_package(PythonLibs 3.4.0 REQUIRED)
Expand Down Expand Up @@ -47,3 +49,50 @@ if (pybind11_FOUND)
else(pybind11_FOUND)
message(WARNING "-- pybind11 or python3 libs not found, pybind11 support disabled")
endif(pybind11_FOUND)

else()
# = WINDOWS ===================================================================

find_package(Python3 COMPONENTS Development Interpreter)
if (Python3_FOUND)
message("-- Python libs version: ${Python3_VERSION}")
message("-- PYTHON_INCLUDE_PATH ${Python3_INCLUDE_DIRS}")
set(PYTHONLIBS_VERSION_MAJOR ${Python3_VERSION_MAJOR})
set(PYTHONLIBS_VERSION_MINOR ${Python3_VERSION_MINOR})
endif(Python3_FOUND)

set(HAS_PYTHON ${Python3_FOUND})

if (HAS_PYTHON)
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import os, pathlib, pybind11; print(pathlib.Path(os.path.dirname(pybind11.__file__)).as_posix())"
RESULT_VARIABLE pybind_found
OUTPUT_VARIABLE PKGDIR
ERROR_VARIABLE pybind_error
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(pybind_found EQUAL 0)
message("-- pybind11 location: ${PKGDIR}")
find_package(pybind11 2.10.4 REQUIRED PATHS "${PKGDIR}")
else()
message(WARNING "-- Failed to import pybind11. Error: ${pybind_error}")
endif()

endif(HAS_PYTHON)

if (pybind11_FOUND)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
pybind11_add_module(pyxrt src/pyxrt.cpp)
target_link_libraries(pyxrt PRIVATE xrt_coreutil uuid)
set_target_properties(pyxrt PROPERTIES SUFFIX ".pyd")

install(TARGETS pyxrt
EXPORT xrt-targets
LIBRARY DESTINATION ${XRT_INSTALL_PYTHON_DIR} ${XRT_NAMELINK_SKIP}
)

else(pybind11_FOUND)
message(WARNING "-- pybind11 or python3 libs not found, pybind11 support disabled")
endif(pybind11_FOUND)

endif()
69 changes: 26 additions & 43 deletions src/python/pybind11/src/pyxrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* [email protected]
*/


// XRT includes
#include "xrt/xrt_device.h"
#include "xrt/xrt_kernel.h"
Expand Down Expand Up @@ -79,7 +78,8 @@ PYBIND11_MODULE(pyxrt, m) {
.value("host", xrt::info::device::host)
.value("dynamic_regions", xrt::info::device::dynamic_regions)
.value("vmr", xrt::info::device::vmr);
/*

/*
*
* XRT:: UUID (needed since UUID classes passed outside of objects)
*
Expand All @@ -88,6 +88,16 @@ PYBIND11_MODULE(pyxrt, m) {
.def(py::init<char *>())
.def("to_string", &xrt::uuid::to_string, "Convert XRT UUID object to string");

/*
* xrt::hw_context
*/

py::class_<xrt::hw_context>(m, "hw_context", "A hardware context associates an xclbin with hardware resources.")
.def(py::init<>())
.def(py::init([](const xrt::device& d, const xrt::uuid& u) {
return new xrt::hw_context(d, u);
}));

/*
*
* xrt::device
Expand All @@ -105,6 +115,9 @@ PYBIND11_MODULE(pyxrt, m) {
.def("load_xclbin", [](xrt::device& d, const xrt::xclbin& xclbin) {
return d.load_xclbin(xclbin);
}, "Load the xclbin to the device")
.def("register_xclbin", [](xrt::device& d, const xrt::xclbin& xclbin) {
return d.register_xclbin(xclbin);
}, "Register an xclbin with the device")
.def("get_xclbin_uuid", &xrt::device::get_xclbin_uuid, "Return the UUID object representing the xclbin loaded on the device")
.def("get_info", [] (xrt::device& d, xrt::info::device key) {
/* Convert the value to string since we can have only one return type for get_info() */
Expand Down Expand Up @@ -188,14 +201,17 @@ PYBIND11_MODULE(pyxrt, m) {
xrt::kernel::cu_access_mode m) {
return new xrt::kernel(d, u, n, m);
}))
.def(py::init([](const xrt::device& d, const xrt::uuid& u, const std::string& n) {
return new xrt::kernel(d, u, n);
.def(py::init([](const xrt::device& d, const xrt::uuid& u, const std::string& n) {
return new xrt::kernel(d, u, n);
}))
.def(py::init([](const xrt::hw_context& ctx, const std::string& n) {
return new xrt::kernel(ctx, n);
}))
.def("__call__", [](xrt::kernel& k, py::args args) -> xrt::run {
int i = 0;
xrt::run r(k);

for (const auto& item : args) {
for (auto item : args) {
try {
r.set_arg(i, item.cast<xrt::bo>());
}
Expand Down Expand Up @@ -246,6 +262,9 @@ PYBIND11_MODULE(pyxrt, m) {
.def("sync", ([](xrt::bo &b, xclBOSyncDirection dir, size_t size, size_t offset) {
b.sync(dir, size, offset);
}), "Synchronize (DMA or cache flush/invalidation) the buffer in the requested direction")
.def("sync", ([](xrt::bo& b, xclBOSyncDirection dir) {
b.sync(dir);
}), "Sync entire buffer content in specified direction.")
.def("map", ([](xrt::bo &b) {
return py::memoryview::from_memory(b.map(), b.size());
}), "Create a byte accessible memory view of the buffer object")
Expand Down Expand Up @@ -292,46 +311,10 @@ PYBIND11_MODULE(pyxrt, m) {
.def(py::init([](const axlf* top) {
return new xrt::xclbin(top);
}))
.def("get_ips", ([](xrt::xclbin& xbin) {
xbin.get_ips();
}))
.def("get_ips", ([](xrt::xclbin& xbin, const std::string& nm) {
xbin.get_ips(nm);
}))
.def("get_kernels", &xrt::xclbin::get_kernels, "Get list of kernels from xclbin")
.def("get_xsa_name", &xrt::xclbin::get_xsa_name, "Get Xilinx Support Archive (XSA) name of xclbin")
.def("get_uuid", &xrt::xclbin::get_uuid, "Get the uuid of the xclbin")
.def("get_mems", &xrt::xclbin::get_mems, "Get list of memory objects");


#if !defined(__x86_64__)
py::enum_<xrt::graph::access_mode>(m, "xrt_graph_access_mode")
.value("exclusive", xrt::graph::access_mode::exclusive)
.value("primary", xrt::graph::access_mode::primary)
.value("shared", xrt::graph::access_mode::shared);

.def("get_mems", &xrt::xclbin::get_mems, "Get list of memory objects")
.def("get_axlf", &xrt::xclbin::get_axlf, "Get the axlf data of the xclbin");

/*
*
* xrt::graph
*
*/
py::class_<xrt::graph>(m, "graph")
.def(py::init([] (const xrt::device& device, const xrt::uuid& xclbin_id, const std::string& name,
xrt::graph::access_mode am = xrt::graph::access_mode::primary) {
return new xrt::graph(device, xclbin_id, name, am);
}))
.def("reset", &xrt::graph::reset)
.def("get_timestamp", &xrt::graph::get_timestamp)
.def("run", &xrt::graph::run)
.def("wait", ([](xrt::graph &g, uint64_t cycles) {
g.wait(cycles);
}))
.def("wait", ([](xrt::graph &g, std::chrono::milliseconds timeout_ms) {
g.wait(timeout_ms);
}))
.def("suspend", &xrt::graph::suspend)
.def("resume", &xrt::graph::resume)
.def("end", &xrt::graph::end);
#endif
}

0 comments on commit 531dc42

Please sign in to comment.