Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies = ["numpy>=1.21", "scipy>=1.8"]

[tool.scikit-build]
build-dir = "build/{wheel_tag}"
cmake.version = ">=3.20"
cmake.version = ">=3.21"
cmake.build-type = "Release"
wheel.packages = ["python/cupdlpx"]
sdist.include = ["tests/**", "pyproject.toml", "README.md", "LICENSE"]
Expand Down
13 changes: 12 additions & 1 deletion python/cupdlpx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import platform

# Windows only: register CUDA bin for dependent DLL loading.
if platform.system() == "Windows":
cuda_path = os.environ.get("CUDA_PATH")
if cuda_path:
bin_path = os.path.join(cuda_path, "bin")
if os.path.isdir(bin_path):
os.add_dll_directory(bin_path)

from .model import Model
from . import PDLP

Expand All @@ -23,4 +34,4 @@
try:
__version__ = version("cupdlpx")
except PackageNotFoundError:
__version__ = "0.0.0"
__version__ = "0.0.0"
23 changes: 17 additions & 6 deletions python_bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# python_bindings/CMakeLists.txt

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.21)

# sources
set(PYBIND_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/_core_bindings.cpp)
Expand All @@ -13,11 +13,13 @@ target_link_libraries(_cupdlpx_core PRIVATE
)

# set rpath so that the module can find the shared libraries at runtime
set_target_properties(_cupdlpx_core PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH "$ORIGIN/../lib"
BUILD_RPATH "$ORIGIN/../lib"
)
if(NOT WIN32)
set_target_properties(_cupdlpx_core PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH "$ORIGIN/../lib"
BUILD_RPATH "$ORIGIN/../lib"
)
endif()

# better error messages from pybind11
target_compile_definitions(_cupdlpx_core PRIVATE PYBIND11_DETAILED_ERROR_MESSAGES=1)
Expand All @@ -34,3 +36,12 @@ install(TARGETS _cupdlpx_core
RUNTIME DESTINATION cupdlpx
ARCHIVE DESTINATION cupdlpx
)

if(WIN32)
# Install runtime DLL dependencies next to the extension module so Python can
# resolve them without additional os.add_dll_directory(...) calls.
install(FILES $<TARGET_RUNTIME_DLLS:_cupdlpx_core>
DESTINATION cupdlpx
OPTIONAL
)
endif()
2 changes: 1 addition & 1 deletion python_bindings/_core_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ static py::dict solve_once(py::object A,
auto xb = x.request(), yb = y.request(), rcb = rc.request();
std::memcpy(xb.ptr, res->primal_solution, sizeof(double) * n_out);
std::memcpy(yb.ptr, res->dual_solution, sizeof(double) * m_out);
std::memcpy(rcb.ptr, res->reduced_costs, sizeof(double) * n_out);
std::memcpy(rcb.ptr, res->reduced_cost, sizeof(double) * n_out);
}
// build info dict
py::dict info;
Expand Down