Commit eb173aaa authored by Artur Wojcik's avatar Artur Wojcik
Browse files

Python bindings - default ON on Linux, UNAVAILABLE on Windows

parent 3b3fcc16
......@@ -274,6 +274,9 @@ target_link_libraries(migraphx INTERFACE $<BUILD_INTERFACE:msgpackc-cxx>)
add_library(migraphx_all_targets INTERFACE)
include(CMakeDependentOption)
cmake_dependent_option(MIGRAPHX_ENABLE_PYTHON "Enable python bindings" ON "WIN32" OFF)
set(PACKAGE_DEPENDS)
add_subdirectory(api)
......
......@@ -49,7 +49,11 @@ rocm_clang_tidy_check(driver)
file(STRINGS "${CMAKE_SOURCE_DIR}/test/onnx/.onnxrt-commit" String_output)
target_compile_definitions(driver PUBLIC MIGRAPHX_ORT_SHA1="${String_output}")
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(
TARGETS driver
......
......@@ -32,7 +32,9 @@
#include <migraphx/tf.hpp>
#include <migraphx/onnx.hpp>
#ifdef MIGRAPHX_ENABLE_PYTHON
#include <migraphx/py.hpp>
#endif
#include <migraphx/stringutils.hpp>
#include <migraphx/convert_to_json.hpp>
#include <migraphx/load_save.hpp>
......@@ -282,10 +284,12 @@ struct loader
options.format = "json";
p = migraphx::load(file, options);
}
#ifdef MIGRAPHX_ENABLE_PYTHON
else if(file_type == "py")
{
p = migraphx::load_py(file);
}
#endif
else if(file_type == "migraphx")
{
p = migraphx::load(file);
......
......@@ -47,7 +47,9 @@ struct MIGRAPHX_EXPORT dynamic_loader
static fs::path path(void* address);
#endif
#ifdef MIGRAPHX_ENABLE_PYTHON
static optional<dynamic_loader> try_load(const fs::path& p);
#endif
dynamic_loader() = default;
......
......@@ -68,7 +68,14 @@ struct convert : unary<convert>
auto y = x;
shape::visit(type, [&](auto as) {
// 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();
}
......
......@@ -22,22 +22,22 @@
# THE SOFTWARE.
#####################################################################################
option(MIGRAPHX_ENABLE_PYTHON "Enable python bindings" ON)
add_library(migraphx_py py_loader.cpp)
migraphx_generate_export_header(migraphx_py)
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)
include(PythonModules)
add_compile_definitions($<$<COMPILE_LANGUAGE:CXX,C>:MIGRAPHX_ENABLE_PYTHON>)
add_library(migraphx_py py_loader.cpp)
migraphx_generate_export_header(migraphx_py)
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})
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)
rocm_install_targets(TARGETS migraphx_pybind_${PYTHON_VERSION})
add_dependencies(migraphx_py migraphx_pybind_${PYTHON_VERSION})
add_library(migraphx_py_${PYTHON_VERSION} py.cpp)
target_include_directories(migraphx_py_${PYTHON_VERSION} PRIVATE include)
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