Skip to content

Commit

Permalink
Merge pull request pytorch#152 from xsacha/patch-2
Browse files Browse the repository at this point in the history
Fix missing unistd.h on Windows
  • Loading branch information
narendasan authored Jul 29, 2020
2 parents 02abcaa + 6346b1c commit 703947f
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 20 deletions.
14 changes: 14 additions & 0 deletions core/util/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,27 @@
#define LOG_ERROR_OWN(l,s) TRTORCH_LOG(l, core::util::logging::LogLevel::kERROR, s)
#define LOG_INTERNAL_ERROR_OWN(l,s) TRTORCH_LOG(l, core::util::logging::LogLevel::kINTERNAL_ERROR, s)

#ifdef _MSC_VER

#define EXPAND( x ) x

#define LOG_GRAPH(...) EXPAND(GET_MACRO(__VA_ARGS__, LOG_GRAPH_OWN, LOG_GRAPH_GLOBAL)(__VA_ARGS__))
#define LOG_DEBUG(...) EXPAND(GET_MACRO(__VA_ARGS__, LOG_DEBUG_OWN, LOG_DEBUG_GLOBAL)(__VA_ARGS__))
#define LOG_INFO(...) EXPAND(GET_MACRO(__VA_ARGS__, LOG_INFO_OWN, LOG_INFO_GLOBAL)(__VA_ARGS__))
#define LOG_WARNING(...) EXPAND(GET_MACRO(__VA_ARGS__, LOG_WARNING_OWN, LOG_WARNING_GLOBAL)(__VA_ARGS__))
#define LOG_ERROR(...) EXPAND(GET_MACRO(__VA_ARGS__, LOG_ERROR_OWN, LOG_ERROR_GLOBAL)(__VA_ARGS__))
#define LOG_INTERNAL_ERROR(...) EXPAND(GET_MACRO(__VA_ARGS__, LOG_INTERNAL_ERROR_OWN, LOG_INTERNAL_ERROR_GLOBAL)(__VA_ARGS__))

#else

#define LOG_GRAPH(...) GET_MACRO(__VA_ARGS__, LOG_GRAPH_OWN, LOG_GRAPH_GLOBAL)(__VA_ARGS__)
#define LOG_DEBUG(...) GET_MACRO(__VA_ARGS__, LOG_DEBUG_OWN, LOG_DEBUG_GLOBAL)(__VA_ARGS__)
#define LOG_INFO(...) GET_MACRO(__VA_ARGS__, LOG_INFO_OWN, LOG_INFO_GLOBAL)(__VA_ARGS__)
#define LOG_WARNING(...) GET_MACRO(__VA_ARGS__, LOG_WARNING_OWN, LOG_WARNING_GLOBAL)(__VA_ARGS__)
#define LOG_ERROR(...) GET_MACRO(__VA_ARGS__, LOG_ERROR_OWN, LOG_ERROR_GLOBAL)(__VA_ARGS__)
#define LOG_INTERNAL_ERROR(...) GET_MACRO(__VA_ARGS__, LOG_INTERNAL_ERROR_OWN, LOG_INTERNAL_ERROR_GLOBAL)(__VA_ARGS__)

#endif
// ----------------------------------------------------------------------------
// Error reporting macros
// ----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion cpp/api/include/trtorch/trtorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct TRTORCH_API ExtraInfo {
* This class is compatable with c10::DataTypes (but will check for TRT support)
* so there should not be a reason that you need to use this type explictly.
*/
class DataType {
class TRTORCH_API DataType {
public:
/**
* Underlying enum class to support the DataType Class
Expand Down
11 changes: 9 additions & 2 deletions cpp/trtorchc/main.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <unistd.h>

#ifdef linux
#include <linux/limits.h>
#else
#define PATH_MAX 260
#endif

#if defined(_WIN32)
#include <direct.h>
#define getcwd _getcwd
#define realpath(N,R) _fullpath((R),(N),PATH_MAX)
#else
#include <unistd.h>
#endif

#include "NvInfer.h"
#include "third_party/args/args.hpp"
#include "torch/torch.h"
Expand Down Expand Up @@ -366,4 +373,4 @@ int main(int argc, char** argv) {
}

return 0;
}
}
30 changes: 27 additions & 3 deletions third_party/cuda/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ config_setting(
],
)

config_setting(
name = "windows",
constraint_values = [
"@platforms//os:windows",
],
)

cc_library(
name = "cudart",
srcs = select({
":aarch64_linux": [
"targets/aarch64-linux/lib/libcudart.so",
],
":windows": [
"lib/x64/cudart.lib",
],
"//conditions:default": [
"targets/x86_64-linux/lib/libcudart.so",
],
Expand All @@ -32,6 +42,9 @@ cc_library(
":aarch64_linux": [
"targets/aarch64-linux/lib/libnvToolsExt.so.1",
],
":windows": [
"bin/nvToolsExt64_1.dll",
],
"//conditions:default": [
"targets/x86_64-linux/lib/libnvToolsExt.so.1",
],
Expand All @@ -44,6 +57,9 @@ cc_library(
":aarch64_linux": glob([
"targets/aarch64-linux/lib/**/lib*.so",
]),
":windows": [
"bin/*.dll",
],
"//conditions:default": glob([
"targets/x86_64-linux/lib/**/lib*.so",
]),
Expand All @@ -59,9 +75,17 @@ cc_library(

cc_library(
name = "cublas",
srcs = glob([
"lib/**/*libcublas.so",
]),
srcs = select({
":aarch64_linux": glob([
"lib/**/*libcublas.so",
]),
":windows": glob([
"lib/x64/cublas.lib",
]),
"//conditions:default": glob([
"lib/**/*libcublas.so",
]),
}),
hdrs = glob([
"include/**/*cublas*.h",
"include/**/*.hpp",
Expand Down
8 changes: 8 additions & 0 deletions third_party/cudnn/local/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ config_setting(
],
)

config_setting(
name = "windows",
constraint_values = [
"@platforms//os:windows",
],
)

cc_library(
name = "cudnn_headers",
hdrs = ["include/cudnn.h"] + glob(["include/cudnn+.h"]),
Expand All @@ -19,6 +26,7 @@ cc_import(
name = "cudnn_lib",
shared_library = select({
":aarch64_linux": "lib/aarch64-linux-gnu/libcudnn.so",
":windows": glob(["bin/cudnn64_*.dll"])[0],
"//conditions:default": "lib/x86_64-linux-gnu/libcudnn.so",
}),
visibility = ["//visibility:private"],
Expand Down
56 changes: 42 additions & 14 deletions third_party/libtorch/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package(default_visibility = ["//visibility:public"])

config_setting(
name = "windows",
constraint_values = [
"@platforms//os:windows",
],
)

cc_library(
name = "libtorch",
deps = [
Expand All @@ -18,12 +25,20 @@ cc_library(
) + glob([
'include/torch/csrc/api/include/**/*.h'
]),
srcs = [
'lib/libtorch.so',
'lib/libtorch_cuda.so',
'lib/libtorch_cpu.so',
'lib/libtorch_global_deps.so',
],
srcs = select({
":windows": [
'lib/torch.lib',
'lib/torch_cuda.lib',
'lib/torch_cpu.lib',
'lib/torch_global_deps.dll',
],
"//conditions:default": [
'lib/libtorch.so',
'lib/libtorch_cuda.so',
'lib/libtorch_cpu.so',
'lib/libtorch_global_deps.so',
],
}),
deps = [
":ATen",
":c10_cuda",
Expand All @@ -39,7 +54,10 @@ cc_library(
hdrs = glob([
'include/c10/**/*.h'
]),
srcs = ["lib/libc10_cuda.so"],
srcs = select({
":windows": ["lib/c10_cuda.lib"],
"//conditions:default": ["lib/libc10_cuda.so"],
}),
strip_include_prefix = "include",
deps = [
":c10"
Expand All @@ -51,7 +69,10 @@ cc_library(
hdrs = glob([
'include/c10/**/*.h'
]),
srcs = ["lib/libc10.so"],
srcs = select({
":windows": ["lib/c10.lib"],
"//conditions:default": ["lib/libc10.so"],
}),
strip_include_prefix = "include",
)

Expand All @@ -68,11 +89,18 @@ cc_library(
hdrs = glob([
'include/caffe2/**/*.h'
]),
srcs = [
'lib/libcaffe2_nvrtc.so',
'lib/libcaffe2_detectron_ops_gpu.so',
'lib/libcaffe2_observers.so',
'lib/libcaffe2_module_test_dynamic.so'
],
srcs = select({
":windows": [
'lib/caffe2_nvrtc.lib',
'lib/caffe2_detectron_ops_gpu.lib',
'lib/caffe2_module_test_dynamic.lib'
],
"//conditions:default": [
'lib/libcaffe2_nvrtc.so',
'lib/libcaffe2_detectron_ops_gpu.so',
'lib/libcaffe2_observers.so',
'lib/libcaffe2_module_test_dynamic.so'
],
}),
strip_include_prefix = "include",
)
Loading

0 comments on commit 703947f

Please sign in to comment.