Commit 0feb4f13 authored by Artur Wojcik's avatar Artur Wojcik
Browse files

Python bindings - default ON on Linux, UNAVAILABLE on Windows

parent 75af6e31
...@@ -268,6 +268,9 @@ target_link_libraries(migraphx INTERFACE $<BUILD_INTERFACE:msgpackc-cxx>) ...@@ -268,6 +268,9 @@ target_link_libraries(migraphx INTERFACE $<BUILD_INTERFACE:msgpackc-cxx>)
add_library(migraphx_all_targets INTERFACE) add_library(migraphx_all_targets INTERFACE)
include(CMakeDependentOption)
cmake_dependent_option(MIGRAPHX_ENABLE_PYTHON "Enable python bindings" ON "WIN32" OFF)
set(PACKAGE_DEPENDS) set(PACKAGE_DEPENDS)
add_subdirectory(api) add_subdirectory(api)
......
...@@ -46,7 +46,11 @@ endif() ...@@ -46,7 +46,11 @@ endif()
target_compile_options(driver PRIVATE -Wno-ignored-attributes -Wno-unused-parameter) target_compile_options(driver PRIVATE -Wno-ignored-attributes -Wno-unused-parameter)
rocm_clang_tidy_check(driver) rocm_clang_tidy_check(driver)
target_link_libraries(driver migraphx_all_targets migraphx_onnx migraphx_tf migraphx_py) target_link_libraries(driver migraphx_all_targets migraphx_onnx migraphx_tf)
if(MIGRAPHX_ENABLE_PYTHON)
target_link_libraries(driver migraphx_py)
endif()
rocm_install_targets( rocm_install_targets(
TARGETS driver TARGETS driver
......
...@@ -32,7 +32,9 @@ ...@@ -32,7 +32,9 @@
#include <migraphx/tf.hpp> #include <migraphx/tf.hpp>
#include <migraphx/onnx.hpp> #include <migraphx/onnx.hpp>
#ifdef MIGRAPHX_ENABLE_PYTHON
#include <migraphx/py.hpp> #include <migraphx/py.hpp>
#endif
#include <migraphx/stringutils.hpp> #include <migraphx/stringutils.hpp>
#include <migraphx/convert_to_json.hpp> #include <migraphx/convert_to_json.hpp>
#include <migraphx/load_save.hpp> #include <migraphx/load_save.hpp>
...@@ -281,10 +283,12 @@ struct loader ...@@ -281,10 +283,12 @@ struct loader
options.format = "json"; options.format = "json";
p = migraphx::load(file, options); p = migraphx::load(file, options);
} }
#ifdef MIGRAPHX_ENABLE_PYTHON
else if(file_type == "py") else if(file_type == "py")
{ {
p = migraphx::load_py(file); p = migraphx::load_py(file);
} }
#endif
else if(file_type == "migraphx") else if(file_type == "migraphx")
{ {
p = migraphx::load(file); p = migraphx::load(file);
......
...@@ -47,7 +47,9 @@ struct MIGRAPHX_EXPORT dynamic_loader ...@@ -47,7 +47,9 @@ struct MIGRAPHX_EXPORT dynamic_loader
static fs::path path(void* address); static fs::path path(void* address);
#endif #endif
#ifdef MIGRAPHX_ENABLE_PYTHON
static optional<dynamic_loader> try_load(const fs::path& p); static optional<dynamic_loader> try_load(const fs::path& p);
#endif
dynamic_loader() = default; dynamic_loader() = default;
......
...@@ -68,7 +68,14 @@ struct convert : unary<convert> ...@@ -68,7 +68,14 @@ struct convert : unary<convert>
auto y = x; auto y = x;
shape::visit(type, [&](auto as) { shape::visit(type, [&](auto as) {
// clamping value between target_type's max and min doesn't work for NaNs, // clamping value between target_type's max and min doesn't work for NaNs,
if(std::isnan(x))
// WIN32: The standard library from MSVC does implement std::isfinite()
// (used by std::isnan() internally) for floating-point types only
// - there are no additional overloads for integer types, which should be
// treated as doubles according to the C++ specification.
// Reference: https://en.cppreference.com/w/cpp/numeric/math/isfinite
if(std::isnan(static_cast<double>(x)))
{ {
y = as.nan(); y = as.nan();
} }
......
...@@ -22,21 +22,21 @@ ...@@ -22,21 +22,21 @@
# THE SOFTWARE. # THE SOFTWARE.
##################################################################################### #####################################################################################
option(MIGRAPHX_ENABLE_PYTHON "Enable python bindings" ON)
add_library(migraphx_py py_loader.cpp)
target_include_directories(migraphx_py PRIVATE include)
target_link_libraries(migraphx_py PUBLIC migraphx)
rocm_install_targets(TARGETS migraphx_py INCLUDE include)
if(MIGRAPHX_ENABLE_PYTHON) if(MIGRAPHX_ENABLE_PYTHON)
include(PythonModules) add_compile_definitions($<$<COMPILE_LANGUAGE:CXX,C>:MIGRAPHX_ENABLE_PYTHON>)
add_library(migraphx_py py_loader.cpp)
target_include_directories(migraphx_py PRIVATE include)
target_link_libraries(migraphx_py PUBLIC migraphx)
rocm_install_targets(TARGETS migraphx_py INCLUDE include)
include(PythonModules)
foreach(PYTHON_VERSION ${PYTHON_VERSIONS}) foreach(PYTHON_VERSION ${PYTHON_VERSIONS})
py_add_module(migraphx_pybind_${PYTHON_VERSION} migraphx_py.cpp PYTHON_VERSION ${PYTHON_VERSION} PYTHON_MODULE migraphx) py_add_module(migraphx_pybind_${PYTHON_VERSION} migraphx_py.cpp PYTHON_VERSION ${PYTHON_VERSION} PYTHON_MODULE migraphx)
target_link_libraries(migraphx_pybind_${PYTHON_VERSION} PRIVATE migraphx migraphx_tf migraphx_onnx migraphx_all_targets) target_link_libraries(migraphx_pybind_${PYTHON_VERSION} PRIVATE migraphx migraphx_tf migraphx_onnx migraphx_all_targets)
rocm_install_targets(TARGETS migraphx_pybind_${PYTHON_VERSION}) rocm_install_targets(TARGETS migraphx_pybind_${PYTHON_VERSION})
add_dependencies(migraphx_py migraphx_pybind_${PYTHON_VERSION}) add_dependencies(migraphx_py migraphx_pybind_${PYTHON_VERSION})
add_library(migraphx_py_${PYTHON_VERSION} py.cpp) add_library(migraphx_py_${PYTHON_VERSION} py.cpp)
target_include_directories(migraphx_py_${PYTHON_VERSION} PRIVATE include) target_include_directories(migraphx_py_${PYTHON_VERSION} PRIVATE include)
target_link_libraries(migraphx_py_${PYTHON_VERSION} PUBLIC migraphx) target_link_libraries(migraphx_py_${PYTHON_VERSION} PUBLIC migraphx)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment