Skip to content

Commit

Permalink
Add compilation of libuv for windows. Remove non exported classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
HGuillemet committed Jun 13, 2024
1 parent c7c374d commit 0e74675
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 115 deletions.
23 changes: 23 additions & 0 deletions pytorch/cppbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ mkdir -p "$PLATFORM$EXTENSION"
cd "$PLATFORM$EXTENSION"
INSTALL_PATH=`pwd`

# Distributed needs libuv on Windows (on other platforms, it's included
# in tensorpipe)
if [[ $PLATFORM == windows* ]]; then
if [[ ! -d libuv ]]; then
mkdir libuv
cd libuv
download https://dist.libuv.org/dist/v1.39.0/libuv-v1.39.0.tar.gz libuv.tgz
tar xfz libuv.tgz
mkdir build
cd build
cmake ../libuv-v1.39.0 -DBUILD_TESTING=OFF
cmake --install . --config Release --prefix=../dist
cd ../..
fi
export libuv_ROOT=`pwd`/libuv/dist
fi

if [[ ! -d pytorch ]]; then
git clone https://github.com/pytorch/pytorch
fi
Expand Down Expand Up @@ -189,6 +206,9 @@ sedinplace 's/const std::string& interface)/const std::string\& interface_name)/
"$PYTHON_BIN_PATH" setup.py build

rm -Rf ../lib
if [[ ! -e torch/include/gloo ]]; then
ln -sf ../../third_party/gloo/gloo torch/include
fi
ln -sf ../../third_party/gloo/gloo torch/include
ln -sf pytorch/torch/include ../include
ln -sf pytorch/torch/lib ../lib
Expand All @@ -202,6 +222,9 @@ case $PLATFORM in
install_name_tool -id @rpath/libiomp5.dylib ../lib/libiomp5.dylib
install_name_tool -change @rpath/libomp.dylib @rpath/libiomp5.dylib ../lib/libtorch_cpu.dylib
;;
windows-*)
cp libuv/dist/lib/Release/* lib
;;
esac

cd ../..
30 changes: 0 additions & 30 deletions pytorch/src/gen/java/org/bytedeco/pytorch/global/gloo.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,33 +136,6 @@ public class gloo extends org.bytedeco.pytorch.presets.gloo {
// namespace gloo


// Parsed from gloo/context.h

/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

// #pragma once

// #include <chrono>
// #include <memory>
// #include <vector>

// #include <gloo/transport/pair.h>

// There is no need to materialize all transport types here.

// Targeting ../gloo/Context.java



// namespace gloo


// Parsed from gloo/common/common.h

/**
Expand Down Expand Up @@ -248,9 +221,6 @@ public class gloo extends org.bytedeco.pytorch.presets.gloo {
@Namespace("gloo") @MemberGetter public static native @Cast("const uint8_t") byte kBroadcastSlotPrefix();
@Namespace("gloo") @MemberGetter public static native @Cast("const uint8_t") byte kBarrierSlotPrefix();
@Namespace("gloo") @MemberGetter public static native @Cast("const uint8_t") byte kAlltoallSlotPrefix();
// Targeting ../gloo/Slot.java


@Namespace("gloo") public static native @ByVal float16 cpu_float2half_rn(float f);
@Namespace("gloo") public static native float cpu_half2float(@ByVal float16 h);
// Targeting ../gloo/float16.java
Expand Down
52 changes: 0 additions & 52 deletions pytorch/src/gen/java/org/bytedeco/pytorch/gloo/Context.java

This file was deleted.

30 changes: 0 additions & 30 deletions pytorch/src/gen/java/org/bytedeco/pytorch/gloo/Slot.java

This file was deleted.

6 changes: 5 additions & 1 deletion pytorch/src/main/java/org/bytedeco/pytorch/presets/gloo.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ public void map(InfoMap infoMap) {
.put(new Info("gloo::transport::Context").pointerTypes("TransportContext"))
;

//// Not exported
infoMap
.put(new Info("gloo::Slot").skip())
;

infoMap
.put(new Info("__CUDA_ARCH__").define(false))
;

infoMap.put(new Info("gloo::kOnDeviceThreshold").javaText("public static final long kOnDeviceThreshold = 256 * 1024;"));

new torch.PointerInfo("gloo::Context").makeShared(infoMap);
new torch.PointerInfo("gloo::transport::Context").javaBaseName("TransportContext").makeShared(infoMap);
new torch.PointerInfo("gloo::transport::Device").makeShared(infoMap);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
@Platform(
value = {"linux", "macosx", "windows"},
compiler = "cpp17",
// __WINSOCKAPI_ fixes compilation error on windows due to
// inclusion of both V1 and V2 of winsock API.
define = {"SHARED_PTR_NAMESPACE std", "UNIQUE_PTR_NAMESPACE std", "USE_C10D_GLOO", "_WINSOCKAPI_"},
include = {
"torch/torch.h",
Expand All @@ -76,7 +78,11 @@
"torch/csrc/jit/serialization/storage_context.h",

"datasets.h",
"pytorch_adapters.h"
"pytorch_adapters.h",

// Fix link error on Windows:
"gloo/common/logging.cc"

},
exclude = {"openblas_config.h", "cblas.h", "lapacke_config.h", "lapacke_mangling.h", "lapack.h", "lapacke.h", "lapacke_utils.h"},
link = {"c10", "torch_cpu", "torch"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "gloo/transport/buffer.h"
#include "gloo/transport/unbound_buffer.h"
#include "gloo/transport/pair.h"
#include "gloo/context.h"
//#include "gloo/context.h"
#include "gloo/common/common.h"
#include "gloo/types.h"
#include "gloo/math.h"
Expand Down

0 comments on commit 0e74675

Please sign in to comment.