Skip to content

Commit 703947f

Browse files
authored
Merge pull request #152 from xsacha/patch-2
Fix missing unistd.h on Windows
2 parents 02abcaa + 6346b1c commit 703947f

File tree

7 files changed

+151
-20
lines changed

7 files changed

+151
-20
lines changed

core/util/macros.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,27 @@
2525
#define LOG_ERROR_OWN(l,s) TRTORCH_LOG(l, core::util::logging::LogLevel::kERROR, s)
2626
#define LOG_INTERNAL_ERROR_OWN(l,s) TRTORCH_LOG(l, core::util::logging::LogLevel::kINTERNAL_ERROR, s)
2727

28+
#ifdef _MSC_VER
29+
30+
#define EXPAND( x ) x
31+
32+
#define LOG_GRAPH(...) EXPAND(GET_MACRO(__VA_ARGS__, LOG_GRAPH_OWN, LOG_GRAPH_GLOBAL)(__VA_ARGS__))
33+
#define LOG_DEBUG(...) EXPAND(GET_MACRO(__VA_ARGS__, LOG_DEBUG_OWN, LOG_DEBUG_GLOBAL)(__VA_ARGS__))
34+
#define LOG_INFO(...) EXPAND(GET_MACRO(__VA_ARGS__, LOG_INFO_OWN, LOG_INFO_GLOBAL)(__VA_ARGS__))
35+
#define LOG_WARNING(...) EXPAND(GET_MACRO(__VA_ARGS__, LOG_WARNING_OWN, LOG_WARNING_GLOBAL)(__VA_ARGS__))
36+
#define LOG_ERROR(...) EXPAND(GET_MACRO(__VA_ARGS__, LOG_ERROR_OWN, LOG_ERROR_GLOBAL)(__VA_ARGS__))
37+
#define LOG_INTERNAL_ERROR(...) EXPAND(GET_MACRO(__VA_ARGS__, LOG_INTERNAL_ERROR_OWN, LOG_INTERNAL_ERROR_GLOBAL)(__VA_ARGS__))
38+
39+
#else
40+
2841
#define LOG_GRAPH(...) GET_MACRO(__VA_ARGS__, LOG_GRAPH_OWN, LOG_GRAPH_GLOBAL)(__VA_ARGS__)
2942
#define LOG_DEBUG(...) GET_MACRO(__VA_ARGS__, LOG_DEBUG_OWN, LOG_DEBUG_GLOBAL)(__VA_ARGS__)
3043
#define LOG_INFO(...) GET_MACRO(__VA_ARGS__, LOG_INFO_OWN, LOG_INFO_GLOBAL)(__VA_ARGS__)
3144
#define LOG_WARNING(...) GET_MACRO(__VA_ARGS__, LOG_WARNING_OWN, LOG_WARNING_GLOBAL)(__VA_ARGS__)
3245
#define LOG_ERROR(...) GET_MACRO(__VA_ARGS__, LOG_ERROR_OWN, LOG_ERROR_GLOBAL)(__VA_ARGS__)
3346
#define LOG_INTERNAL_ERROR(...) GET_MACRO(__VA_ARGS__, LOG_INTERNAL_ERROR_OWN, LOG_INTERNAL_ERROR_GLOBAL)(__VA_ARGS__)
3447

48+
#endif
3549
// ----------------------------------------------------------------------------
3650
// Error reporting macros
3751
// ----------------------------------------------------------------------------

cpp/api/include/trtorch/trtorch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct TRTORCH_API ExtraInfo {
9090
* This class is compatable with c10::DataTypes (but will check for TRT support)
9191
* so there should not be a reason that you need to use this type explictly.
9292
*/
93-
class DataType {
93+
class TRTORCH_API DataType {
9494
public:
9595
/**
9696
* Underlying enum class to support the DataType Class

cpp/trtorchc/main.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
#include <iostream>
22
#include <sstream>
33
#include <stdlib.h>
4-
#include <unistd.h>
54

65
#ifdef linux
76
#include <linux/limits.h>
87
#else
98
#define PATH_MAX 260
109
#endif
1110

11+
#if defined(_WIN32)
12+
#include <direct.h>
13+
#define getcwd _getcwd
14+
#define realpath(N,R) _fullpath((R),(N),PATH_MAX)
15+
#else
16+
#include <unistd.h>
17+
#endif
18+
1219
#include "NvInfer.h"
1320
#include "third_party/args/args.hpp"
1421
#include "torch/torch.h"
@@ -366,4 +373,4 @@ int main(int argc, char** argv) {
366373
}
367374

368375
return 0;
369-
}
376+
}

third_party/cuda/BUILD

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,22 @@ config_setting(
88
],
99
)
1010

11+
config_setting(
12+
name = "windows",
13+
constraint_values = [
14+
"@platforms//os:windows",
15+
],
16+
)
17+
1118
cc_library(
1219
name = "cudart",
1320
srcs = select({
1421
":aarch64_linux": [
1522
"targets/aarch64-linux/lib/libcudart.so",
1623
],
24+
":windows": [
25+
"lib/x64/cudart.lib",
26+
],
1727
"//conditions:default": [
1828
"targets/x86_64-linux/lib/libcudart.so",
1929
],
@@ -32,6 +42,9 @@ cc_library(
3242
":aarch64_linux": [
3343
"targets/aarch64-linux/lib/libnvToolsExt.so.1",
3444
],
45+
":windows": [
46+
"bin/nvToolsExt64_1.dll",
47+
],
3548
"//conditions:default": [
3649
"targets/x86_64-linux/lib/libnvToolsExt.so.1",
3750
],
@@ -44,6 +57,9 @@ cc_library(
4457
":aarch64_linux": glob([
4558
"targets/aarch64-linux/lib/**/lib*.so",
4659
]),
60+
":windows": [
61+
"bin/*.dll",
62+
],
4763
"//conditions:default": glob([
4864
"targets/x86_64-linux/lib/**/lib*.so",
4965
]),
@@ -59,9 +75,17 @@ cc_library(
5975

6076
cc_library(
6177
name = "cublas",
62-
srcs = glob([
63-
"lib/**/*libcublas.so",
64-
]),
78+
srcs = select({
79+
":aarch64_linux": glob([
80+
"lib/**/*libcublas.so",
81+
]),
82+
":windows": glob([
83+
"lib/x64/cublas.lib",
84+
]),
85+
"//conditions:default": glob([
86+
"lib/**/*libcublas.so",
87+
]),
88+
}),
6589
hdrs = glob([
6690
"include/**/*cublas*.h",
6791
"include/**/*.hpp",

third_party/cudnn/local/BUILD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ config_setting(
88
],
99
)
1010

11+
config_setting(
12+
name = "windows",
13+
constraint_values = [
14+
"@platforms//os:windows",
15+
],
16+
)
17+
1118
cc_library(
1219
name = "cudnn_headers",
1320
hdrs = ["include/cudnn.h"] + glob(["include/cudnn+.h"]),
@@ -19,6 +26,7 @@ cc_import(
1926
name = "cudnn_lib",
2027
shared_library = select({
2128
":aarch64_linux": "lib/aarch64-linux-gnu/libcudnn.so",
29+
":windows": glob(["bin/cudnn64_*.dll"])[0],
2230
"//conditions:default": "lib/x86_64-linux-gnu/libcudnn.so",
2331
}),
2432
visibility = ["//visibility:private"],

third_party/libtorch/BUILD

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package(default_visibility = ["//visibility:public"])
22

3+
config_setting(
4+
name = "windows",
5+
constraint_values = [
6+
"@platforms//os:windows",
7+
],
8+
)
9+
310
cc_library(
411
name = "libtorch",
512
deps = [
@@ -18,12 +25,20 @@ cc_library(
1825
) + glob([
1926
'include/torch/csrc/api/include/**/*.h'
2027
]),
21-
srcs = [
22-
'lib/libtorch.so',
23-
'lib/libtorch_cuda.so',
24-
'lib/libtorch_cpu.so',
25-
'lib/libtorch_global_deps.so',
26-
],
28+
srcs = select({
29+
":windows": [
30+
'lib/torch.lib',
31+
'lib/torch_cuda.lib',
32+
'lib/torch_cpu.lib',
33+
'lib/torch_global_deps.dll',
34+
],
35+
"//conditions:default": [
36+
'lib/libtorch.so',
37+
'lib/libtorch_cuda.so',
38+
'lib/libtorch_cpu.so',
39+
'lib/libtorch_global_deps.so',
40+
],
41+
}),
2742
deps = [
2843
":ATen",
2944
":c10_cuda",
@@ -39,7 +54,10 @@ cc_library(
3954
hdrs = glob([
4055
'include/c10/**/*.h'
4156
]),
42-
srcs = ["lib/libc10_cuda.so"],
57+
srcs = select({
58+
":windows": ["lib/c10_cuda.lib"],
59+
"//conditions:default": ["lib/libc10_cuda.so"],
60+
}),
4361
strip_include_prefix = "include",
4462
deps = [
4563
":c10"
@@ -51,7 +69,10 @@ cc_library(
5169
hdrs = glob([
5270
'include/c10/**/*.h'
5371
]),
54-
srcs = ["lib/libc10.so"],
72+
srcs = select({
73+
":windows": ["lib/c10.lib"],
74+
"//conditions:default": ["lib/libc10.so"],
75+
}),
5576
strip_include_prefix = "include",
5677
)
5778

@@ -68,11 +89,18 @@ cc_library(
6889
hdrs = glob([
6990
'include/caffe2/**/*.h'
7091
]),
71-
srcs = [
72-
'lib/libcaffe2_nvrtc.so',
73-
'lib/libcaffe2_detectron_ops_gpu.so',
74-
'lib/libcaffe2_observers.so',
75-
'lib/libcaffe2_module_test_dynamic.so'
76-
],
92+
srcs = select({
93+
":windows": [
94+
'lib/caffe2_nvrtc.lib',
95+
'lib/caffe2_detectron_ops_gpu.lib',
96+
'lib/caffe2_module_test_dynamic.lib'
97+
],
98+
"//conditions:default": [
99+
'lib/libcaffe2_nvrtc.so',
100+
'lib/libcaffe2_detectron_ops_gpu.so',
101+
'lib/libcaffe2_observers.so',
102+
'lib/libcaffe2_module_test_dynamic.so'
103+
],
104+
}),
77105
strip_include_prefix = "include",
78106
)

0 commit comments

Comments
 (0)