Skip to content

Commit

Permalink
Enable building pymomentum on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongseok-meta committed Oct 3, 2024
1 parent 6d8f901 commit 486015b
Show file tree
Hide file tree
Showing 8 changed files with 406 additions and 544 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/ci_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ on:
- "**/website/**"

jobs:
build:
name: win
momentum:
name: momentum-win
runs-on: windows-latest
steps:
- name: Checkout
Expand All @@ -36,3 +36,17 @@ jobs:
--build momentum/examples/hello_world/build `
--config Release `
--parallel
pymomentum:
name: pymomentum-win
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up pixi
uses: prefix-dev/setup-pixi@v0.8.1
with:
cache: true
- name: Build PyMomentum
run: |
pixi run test_pymomentum
860 changes: 349 additions & 511 deletions pixi.lock

Large diffs are not rendered by default.

26 changes: 21 additions & 5 deletions pixi.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[project]
name = "momentum"
channels = ["conda-forge"]
channels = ["conda-forge", "pytorch"]
platforms = ["linux-64", "osx-64", "osx-arm64", "win-64"]
version = "0.1.0"
description = "A library providing foundational algorithms for human kinematic motion and numerical optimization solvers to apply human motion in various applications"
description = """
A library providing foundational algorithms for human kinematic motion and numerical optimization \
solvers to apply human motion in various applications
"""
license = "MIT"
readme = "README.md"
homepage = "https://facebookincubator.github.io/momentum/"
Expand All @@ -24,7 +27,6 @@ scipy = ">=1.13.0,<1.14"
setuptools = ">=69.5.1,<69.6"

[dependencies]
blas = ">=1.1,<3"
ceres-solver = ">=2.2.0,<2.3"
cli11 = ">=2.4.1,<2.5"
dispenso = ">=1.3.0,<1.4"
Expand Down Expand Up @@ -141,6 +143,8 @@ build_pymomentum = { cmd = "pip install -e ." }
#=========

[target.win-64.dependencies]
mkl-static = ">=2018" # Needed by pytorch::pytorch
pytorch = { version = ">=2.4.1,<2.5", channel = "pytorch" } # TODO: Migrate to conda-forge::pytorch once available on Windows

[target.win-64.tasks]
configure = { cmd = """
Expand All @@ -156,18 +160,30 @@ configure = { cmd = """
-DMOMENTUM_BUILD_TESTING=ON \
-DMOMENTUM_ENABLE_SIMD=%MOMENTUM_ENABLE_SIMD% \
-DMOMENTUM_USE_SYSTEM_GOOGLETEST=ON \
-DMOMENTUM_USE_SYSTEM_PYBIND11=ON \
-DMOMENTUM_USE_SYSTEM_PYBIND11=OFF \
-DMOMENTUM_USE_SYSTEM_RERUN_CPP_SDK=ON
""", env = { MOMENTUM_ENABLE_SIMD = "ON", MOMENTUM_BUILD_PYMOMENTUM = "OFF" } }
""", env = { MOMENTUM_ENABLE_SIMD = "ON", MOMENTUM_BUILD_PYMOMENTUM = "ON" } }
open_vs = { cmd = "cmd /c start build\\momentum.sln", depends_on = [
"configure",
] }
build = { cmd = "cmake --build build -j --config Release", depends_on = [
"configure",
] }
build_pymomentum = { cmd = "pip install -e ." }
test = { cmd = "ctest --test-dir build --output-on-failure --build-config Release", depends_on = [
"build",
] }
test_pymomentum = { cmd = """
pytest \
pymomentum/test/test_closest_points.py \
pymomentum/test/test_fbx.py \
pymomentum/test/test_parameter_transform.py \
pymomentum/test/test_quaternion.py \
pymomentum/test/test_skel_state.py \
pymomentum/test/test_skeleton.py
""", env = { MOMENTUM_MODELS_PATH = "momentum/" }, depends_on = [
"build_pymomentum",
] }
hello_world = { cmd = "build/Release/hello_world.exe", depends_on = ["build"] }
convert_model = { cmd = "build/Release/convert_model.exe", depends_on = [
"build",
Expand Down
30 changes: 13 additions & 17 deletions pymomentum/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,20 @@
# Find dependencies
#===============================================================================

set(ENV{NVTOOLSEXT_PATH} "$ENV{CONDA_PREFIX}/include")

find_package(ATen CONFIG REQUIRED
HINTS
$ENV{CONDA_PREFIX}/lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages/torch/
)

find_package(Torch CONFIG REQUIRED
HINTS
$ENV{CONDA_PREFIX}/lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages/torch/
)
if(MSVC)
set(torch_lib_path "$ENV{CONDA_PREFIX}/lib/site-packages/torch/")
set(nvtoolsext_path "$ENV{CONDA_PREFIX}/include")
string(REPLACE "\\" "/" torch_lib_path ${torch_lib_path})
string(REPLACE "\\" "/" nvtoolsext_path ${nvtoolsext_path})
else()
set(torch_lib_path "$ENV{CONDA_PREFIX}/lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages/torch/")
set(nvtoolsext_path "$ENV{CONDA_PREFIX}/include")
endif()

find_library(torch_python
NAMES torch_python
HINTS
$ENV{CONDA_PREFIX}/lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages/torch/lib/
REQUIRED
)
set(ENV{NVTOOLSEXT_PATH} "${nvtoolsext_path}")
find_package(ATen CONFIG REQUIRED HINTS "${torch_lib_path}")
find_package(Torch CONFIG REQUIRED HINTS "${torch_lib_path}")
find_library(torch_python NAMES torch_python HINTS "${torch_lib_path}/lib" REQUIRED)

#===============================================================================
# Find build dependencies
Expand Down
6 changes: 3 additions & 3 deletions pymomentum/geometry/momentum_geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ at::Tensor uniformRandomToModelParameters(

at::Tensor result = at::zeros({nBatch, nModelParam}, at::kFloat);

for (ssize_t iBatch = 0; iBatch < nBatch; ++iBatch) {
for (size_t iBatch = 0; iBatch < nBatch; ++iBatch) {
auto res_i = toEigenMap<float>(result.select(0, iBatch));
auto unif_i = toEigenMap<float>(unifNoise.select(0, iBatch));

Expand Down Expand Up @@ -1008,7 +1008,7 @@ std::tuple<MatrixX7f, MatrixX7f> jointParameterLimits(
py::array_t<float> getBindPose(const momentum::Character& character) {
const auto& inverseBindPose = character.inverseBindPose;
py::array_t<float> result = py::array_t<float>(
std::vector<ssize_t>{(ssize_t)inverseBindPose.size(), 4, 4});
std::vector<size_t>{(size_t)inverseBindPose.size(), 4, 4});
auto r = result.mutable_unchecked<3>(); // Will throw if ndim != 3 or
// flags.writable is false
for (py::ssize_t i = 0; i < inverseBindPose.size(); i++) {
Expand All @@ -1025,7 +1025,7 @@ py::array_t<float> getBindPose(const momentum::Character& character) {
py::array_t<float> getInverseBindPose(const momentum::Character& character) {
const auto& inverseBindPose = character.inverseBindPose;
py::array_t<float> result = py::array_t<float>(
std::vector<ssize_t>{(ssize_t)inverseBindPose.size(), 4, 4});
std::vector<size_t>{(size_t)inverseBindPose.size(), 4, 4});
auto r = result.mutable_unchecked<3>(); // Will throw if ndim != 3 or
// flags.writable is false
for (py::ssize_t i = 0; i < inverseBindPose.size(); i++) {
Expand Down
6 changes: 2 additions & 4 deletions pymomentum/tensor_momentum/tensor_skeleton_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ void computeSkelStateBackward(
for (int d = 0; d < momentum::kParametersPerJoint; ++d) {
Eigen::VectorX<JetType> jointParams_cur =
jointParameters
.template segment(
kParametersPerJoint * curJoint, kParametersPerJoint)
.segment(kParametersPerJoint * curJoint, kParametersPerJoint)
.template cast<JetType>();
jointParams_cur(d).v[0] = 1;

Expand Down Expand Up @@ -189,8 +188,7 @@ void computeLocalSkelStateBackward(
for (int d = 0; d < momentum::kParametersPerJoint; ++d) {
Eigen::VectorX<JetType> jointParams_cur =
jointParameters
.template segment(
kParametersPerJoint * iJoint, kParametersPerJoint)
.segment(kParametersPerJoint * iJoint, kParametersPerJoint)
.template cast<JetType>();
jointParams_cur(d).v[0] = 1;

Expand Down
2 changes: 1 addition & 1 deletion pymomentum/tensor_utility/tensor_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ std::string formatTensorSizes(const at::Tensor& tensor) {
return formatTensorSizes(sizes.begin(), sizes.end());
}

std::string formatTensorSizes(const std::vector<ssize_t>& sizes) {
std::string formatTensorSizes(const std::vector<size_t>& sizes) {
return formatTensorSizes(sizes.begin(), sizes.end());
}

Expand Down
2 changes: 1 addition & 1 deletion pymomentum/tensor_utility/tensor_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ template <typename T>
Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, 1>> toEigenMap(at::Tensor t);

std::string formatTensorSizes(const at::Tensor& tensor);
std::string formatTensorSizes(const std::vector<ssize_t>& dims);
std::string formatTensorSizes(const std::vector<size_t>& dims);

inline bool isEmpty(const at::Tensor& t) {
return (t.numel() == 0);
Expand Down

0 comments on commit 486015b

Please sign in to comment.