Skip to content

Commit a585c5c

Browse files
committed
Add makefile to bridge folder. Working now.
1 parent d65f528 commit a585c5c

9 files changed

Lines changed: 147 additions & 119 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ test/correspondence/gh.out
3737
modules/build
3838
!bridge/*
3939
bridge/build
40+
bridge/libtorch
4041
# pytorch/

bridge/.DS_Store

6 KB
Binary file not shown.

bridge/Bridge

1.28 MB
Binary file not shown.

bridge/CMakeLists.txt

Lines changed: 108 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -27,87 +27,87 @@ include(ExternalProject)
2727
# ------------------------------------------------------------------------------
2828

2929
# Where to place PyTorch after installation
30-
set(PYTORCH_INSTALL_DIR "${PROJECT_BINARY_DIR}/pytorch-install")
31-
set(PYTORCH_BUILD_DIR "${PROJECT_BINARY_DIR}/pytorch-prefix/src/pytorch-build")
30+
# set(PYTORCH_INSTALL_DIR "${PROJECT_BINARY_DIR}/pytorch-install")
31+
# set(PYTORCH_BUILD_DIR "${PROJECT_BINARY_DIR}/pytorch-prefix/src/pytorch-build")
3232

33-
set(PYTORCH_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/pytorch-install-prefix")
33+
# set(PYTORCH_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/pytorch-install-prefix")
3434
# file(MAKE_DIRECTORY "${PYTORCH_INSTALL_PREFIX}")
3535

3636
# ExternalProject_Add can fetch from Git, a local path, or a release tarball.
3737
# Here, for simplicity, we'll fetch from Git. In practice, you might want
3838
# a fixed commit or a release tarball for reproducible builds.
3939

40-
ExternalProject_Add(
41-
pytorch
42-
GIT_REPOSITORY https://github.com/pytorch/pytorch.git
43-
GIT_TAG v2.6.0 # Example: specify a particular release
44-
UPDATE_COMMAND "" # Don’t auto-run 'git pull'
45-
PATCH_COMMAND "" # No custom patch step
40+
# ExternalProject_Add(
41+
# pytorch
42+
# GIT_REPOSITORY https://github.com/pytorch/pytorch.git
43+
# GIT_TAG v2.6.0 # Example: specify a particular release
44+
# UPDATE_COMMAND "" # Don’t auto-run 'git pull'
45+
# PATCH_COMMAND "" # No custom patch step
4646

47-
# DOWNLOAD_DIR "${CMAKE_BINARY_DIR}/pytorch-download" # Where to download the repo
48-
49-
# We need all PyTorch submodules. By default, ExternalProject won't do submodule init.
50-
# So we can do that in a separate step if we want a full build. For a minimal CPU build,
51-
# you might not need them all, but let's be safe:
52-
STEP_TARGETS clone
53-
# After 'clone', run "git submodule update --init --recursive"
54-
# to fetch all submodules.
55-
# We can use a little trick with COMMAND.
56-
# PATCH_COMMAND "git submodule update --init --recursive"
57-
58-
# CMAKE_ARGS
59-
# -DBUILD_SHARED_LIBS=OFF # Build static libraries
60-
# -DBUILD_PYTHON=OFF # Don’t build Python bindings
61-
# -DBUILD_TEST=OFF # Don’t build tests
62-
# -DUSE_CUDA=OFF # Disable CUDA
63-
# -DUSE_CUDNN=OFF # Disable cuDNN
64-
# -DUSE_MKLDNN=OFF # Disable MKLDNN for simplicity
65-
# # -DBUILD_BINARY=ON
66-
# # -DUSE_DISTRIBUTED=ON
67-
# # -DBUILD_STATIC_RUNTIME_BENCHMARK=ON
68-
# # -DBUILD_LITE_INTERPRETER=ON
69-
# # -DUSE_STATIC_MKL=ON
70-
# # -DSTATIC_DISPATCH_BACKEND=ON
71-
# # -DCAFFE2_USE_MSVC_STATIC_RUNTIME=ON
72-
# # -DUSE_DISTRIBUTED=ON
73-
# # -DCMAKE_BUILD_TYPE=Release
74-
# -DCMAKE_INSTALL_PREFIX=${PYTORCH_INSTALL_DIR}
75-
# # -DCMAKE_POLICY_VERSION_MINIMUM=3.5
76-
CMAKE_ARGS
77-
-DBUILD_SHARED_LIBS=OFF # Build static libraries
78-
-DBUILD_PYTHON=OFF # Don’t build Python bindings
79-
-DBUILD_TEST=OFF # Don’t build tests
80-
-DUSE_CUDA=OFF # Disable CUDA
81-
-DUSE_CUDNN=OFF # Disable cuDNN
82-
-DUSE_MKLDNN=OFF # Disable MKLDNN for simplicity
83-
-DCMAKE_BUILD_TYPE=Release
84-
-DCMAKE_INSTALL_PREFIX=${PYTORCH_INSTALL_DIR}
47+
# # DOWNLOAD_DIR "${CMAKE_BINARY_DIR}/pytorch-download" # Where to download the repo
48+
49+
# # We need all PyTorch submodules. By default, ExternalProject won't do submodule init.
50+
# # So we can do that in a separate step if we want a full build. For a minimal CPU build,
51+
# # you might not need them all, but let's be safe:
52+
# STEP_TARGETS clone
53+
# # After 'clone', run "git submodule update --init --recursive"
54+
# # to fetch all submodules.
55+
# # We can use a little trick with COMMAND.
56+
# # PATCH_COMMAND "git submodule update --init --recursive"
57+
58+
# # CMAKE_ARGS
59+
# # -DBUILD_SHARED_LIBS=OFF # Build static libraries
60+
# # -DBUILD_PYTHON=OFF # Don’t build Python bindings
61+
# # -DBUILD_TEST=OFF # Don’t build tests
62+
# # -DUSE_CUDA=OFF # Disable CUDA
63+
# # -DUSE_CUDNN=OFF # Disable cuDNN
64+
# # -DUSE_MKLDNN=OFF # Disable MKLDNN for simplicity
65+
# # # -DBUILD_BINARY=ON
66+
# # # -DUSE_DISTRIBUTED=ON
67+
# # # -DBUILD_STATIC_RUNTIME_BENCHMARK=ON
68+
# # # -DBUILD_LITE_INTERPRETER=ON
69+
# # # -DUSE_STATIC_MKL=ON
70+
# # # -DSTATIC_DISPATCH_BACKEND=ON
71+
# # # -DCAFFE2_USE_MSVC_STATIC_RUNTIME=ON
72+
# # # -DUSE_DISTRIBUTED=ON
73+
# # # -DCMAKE_BUILD_TYPE=Release
74+
# # -DCMAKE_INSTALL_PREFIX=${PYTORCH_INSTALL_DIR}
75+
# # # -DCMAKE_POLICY_VERSION_MINIMUM=3.5
76+
# CMAKE_ARGS
77+
# -DBUILD_SHARED_LIBS=OFF # Build static libraries
78+
# -DBUILD_PYTHON=OFF # Don’t build Python bindings
79+
# -DBUILD_TEST=OFF # Don’t build tests
80+
# -DUSE_CUDA=OFF # Disable CUDA
81+
# -DUSE_CUDNN=OFF # Disable cuDNN
82+
# -DUSE_MKLDNN=OFF # Disable MKLDNN for simplicity
83+
# -DCMAKE_BUILD_TYPE=Release
84+
# -DCMAKE_INSTALL_PREFIX=${PYTORCH_INSTALL_DIR}
8585

86-
INSTALL_DIR ${PYTORCH_INSTALL_DIR} # Where to install
87-
88-
# LOG_DOWNLOAD ON
89-
# LOG_UPDATE ON
90-
# LOG_PATCH ON
91-
# LOG_CONFIGURE ON
92-
# LOG_BUILD ON
93-
# LOG_INSTALL ON
86+
# INSTALL_DIR ${PYTORCH_INSTALL_DIR} # Where to install
87+
88+
# # LOG_DOWNLOAD ON
89+
# # LOG_UPDATE ON
90+
# # LOG_PATCH ON
91+
# # LOG_CONFIGURE ON
92+
# # LOG_BUILD ON
93+
# # LOG_INSTALL ON
9494

95-
)
96-
95+
# )
9796

98-
file(GLOB_RECURSE PYTORCH_INCLUDES "${PYTORCH_INSTALL_DIR}/include" "*.h")
99-
file(GLOB_RECURSE PYTORCH_LIBS "${PYTORCH_INSTALL_DIR}/lib" "*.a")
97+
set(PYTORCH_INSTALL_DIR "${PROJECT_ROOT_DIR}/libtorch")
98+
# file(GLOB_RECURSE PYTORCH_INCLUDES "${PYTORCH_INSTALL_DIR}/include" "*.h")
99+
# file(GLOB_RECURSE PYTORCH_LIBS "${PYTORCH_INSTALL_DIR}/lib" "*.a")
100100

101101

102-
set(PYTORCH_LIBS_LINKER_ARGS "") # Will hold the list of "-l..." flags.
103-
foreach(lib_path IN LISTS PYTORCH_LIBS)
104-
# Get just the filename without the directory or extension
105-
get_filename_component(lib_name "${lib_path}" NAME_WE)
106-
# If it starts with "lib", strip that off
107-
string(REGEX REPLACE "^lib" "" lib_name "${lib_name}")
108-
# Now prepend "-l" to the actual library name
109-
list(APPEND MY_LIBS "-l${lib_name}")
110-
endforeach()
102+
# set(PYTORCH_LIBS_LINKER_ARGS "-L/Users/jade/Development/libtorch/libtorch/lib") # Will hold the list of "-l..." flags.
103+
# foreach(lib_path IN LISTS PYTORCH_LIBS)
104+
# # Get just the filename without the directory or extension
105+
# get_filename_component(lib_name "${lib_path}" NAME_WE)
106+
# # If it starts with "lib", strip that off
107+
# string(REGEX REPLACE "^lib" "" lib_name "${lib_name}")
108+
# # Now prepend "-l" to the actual library name
109+
# list(APPEND MY_LIBS "-l${lib_name}")
110+
# endforeach()
111111

112112

113113
find_package(chpl REQUIRED HINTS ${PROJECT_ROOT_DIR}/cmake/chapel)
@@ -123,60 +123,61 @@ project(MyProject LANGUAGES CXX C CHPL)
123123
# We'll create a dummy target that depends on 'pytorch' so that
124124
# building your own code will first build/install PyTorch.
125125

126-
add_library(torch_interface INTERFACE)
126+
# add_library(torch_interface INTERFACE)
127127

128-
# Ensure that our 'torch_interface' target isn't used until PyTorch is built
129-
add_dependencies(torch_interface pytorch)
128+
# # Ensure that our 'torch_interface' target isn't used until PyTorch is built
129+
# # add_dependencies(torch_interface pytorch)
130130

131-
# Include directories for PyTorch
132-
target_include_directories(torch_interface INTERFACE
133-
"${PYTORCH_INSTALL_DIR}/include"
134-
"${PYTORCH_INSTALL_DIR}/include/torch/csrc/api/include"
135-
# "${PYTORCH_BUILD_DIR}/aten/src/include"
136-
)
131+
# # Include directories for PyTorch
132+
# target_include_directories(torch_interface INTERFACE
133+
# "${PYTORCH_INSTALL_DIR}/include"
134+
# "${PYTORCH_INSTALL_DIR}/include/torch/csrc/api/include"
135+
# # "${PYTORCH_BUILD_DIR}/aten/src/include"
136+
# )
137137

138-
# Link the relevant static libraries. For a minimal CPU-only build,
139-
# you'll likely need at least these (names can vary by version).
140-
# The exact set can differ depending on which components got built.
138+
# # Link the relevant static libraries. For a minimal CPU-only build,
139+
# # you'll likely need at least these (names can vary by version).
140+
# # The exact set can differ depending on which components got built.
141141

142-
target_link_libraries(torch_interface INTERFACE
143-
"${PYTORCH_INSTALL_DIR}/lib/libtorch.a"
144-
"${PYTORCH_INSTALL_DIR}/lib/libtorch_cpu.a"
145-
"${PYTORCH_INSTALL_DIR}/lib/libc10.a"
142+
# target_link_libraries(torch_interface INTERFACE
143+
# "${PYTORCH_INSTALL_DIR}/lib/libtorch.a"
144+
# "${PYTORCH_INSTALL_DIR}/lib/libtorch_cpu.a"
145+
# "${PYTORCH_INSTALL_DIR}/lib/libc10.a"
146146

147-
${PYTORCH_LIBS}
147+
# # ${PYTORCH_LIBS}
148148

149-
# System libraries often needed:
150-
pthread
151-
dl
152-
rt
153-
)
149+
# # System libraries often needed:
150+
# pthread
151+
# dl
152+
# rt
153+
# )
154154

155155

156156

157157
add_executable(CHPLTest lib/CHPLTest.chpl)
158158

159159

160-
add_library(torchbridge STATIC "${PROJECT_ROOT_DIR}/lib/bridge.cpp" "${PROJECT_ROOT_DIR}/include/bridge.h")
161-
add_dependencies(torchbridge torch_interface)
160+
add_library(torchbridge OBJECT "${PROJECT_ROOT_DIR}/lib/bridge.cpp" "${PROJECT_ROOT_DIR}/include/bridge.h")
161+
# add_dependencies(torchbridge torch_interface)
162162

163163
target_include_directories(torchbridge PRIVATE
164164
"${PYTORCH_INSTALL_DIR}/include"
165165
"${PYTORCH_INSTALL_DIR}/include/torch/csrc/api/include"
166166
"${PROJECT_ROOT_DIR}/include"
167-
# "${PYTORCH_BUILD_DIR}/aten/src/include"
167+
# # "${PYTORCH_BUILD_DIR}/aten/src/include"
168168
)
169169
# target_link_directories(torchbridge PUBLIC
170170
# "${PYTORCH_INSTALL_DIR}/lib"
171171
# )
172-
target_link_libraries(torchbridge
173-
PRIVATE
174-
torch_interface
175-
${PYTORCH_LIBS}
176-
pthread
177-
dl
178-
rt
179-
)
172+
# target_link_libraries(torchbridge
173+
# PRIVATE
174+
# # torch_interface
175+
# # ${PYTORCH_LIBS}
176+
177+
# pthread
178+
# dl
179+
# rt
180+
# )
180181

181182

182183

@@ -190,17 +191,17 @@ target_link_options(Bridge
190191
PRIVATE
191192
"${PROJECT_ROOT_DIR}/include/bridge.h"
192193
"-L${PROJECT_BINARY_DIR}"
193-
"-ltorchbridge"
194-
-L.
194+
# "-ltorchbridge"
195+
# -L.
195196
"-ltorchbridge"
196197
# "-I${PROJECT_BINARY_DIR}"
197-
# "-L${PYTORCH_INSTALL_DIR}/lib"
198+
"-L${PYTORCH_INSTALL_DIR}/lib"
198199
# "-I${PYTORCH_INSTALL_DIR}/include"
199200
# "-I${PYTORCH_INSTALL_DIR}/include/torch/csrc/api/include"
200-
# "-ltorch"
201-
# "-ltorch_cpu"
201+
"-ltorch"
202+
"-ltorch_cpu"
202203
# "-lcpuinfo"
203-
# "-lc10"
204+
"-lc10"
204205
# "-lsleef"
205206
# "-lclog"
206207
# "-lprotoc"

bridge/Fix.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
https://github.com/pytorch/pytorch/issues/20030
3+
4+
install_name_tool -add_rpath /opt/homebrew/opt/libomp/lib /Users/iainmoncrief/Documents/Github/ChAI/bridge/libtorch/lib/libtorch_cpu.dylib

bridge/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
3+
bridge.o: lib/bridge.cpp include/bridge.h
4+
g++ -c lib/bridge.cpp -I include -o bridge.o -I /Users/iainmoncrief/Documents/Github/ChAI/bridge/libtorch/include/torch/csrc/api/include -I /Users/iainmoncrief/Documents/Github/ChAI/bridge/libtorch/include --std=c++17
5+
6+
Bridge: bridge.o lib/Bridge.chpl
7+
chpl lib/Bridge.chpl include/bridge.h bridge.o -L /Users/iainmoncrief/Documents/Github/ChAI/bridge/libtorch/lib -ltorch -ltorch_cpu -lc10 --ldflags "-Wl,-rpath,/Users/iainmoncrief/Documents/Github/ChAI/bridge/libtorch/lib" --print-commands
8+
9+
clean:
10+
rm -f bridge.o
11+
rm -f Bridge
12+
13+
14+

bridge/bridge.o

158 KB
Binary file not shown.

bridge/jade.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
3+
4+
5+
6+
7+

bridge/lib/bridge.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@
88

99
void secret() {
1010
std::cout << "Secret function called!" << std::endl;
11-
torch::Tensor tensor = torch::eye(3);
12-
// std::cout << "Tensor: " << tensor << std::endl;
11+
auto x = torch::randn({5, 3});
12+
// torch::Tensor tensor = torch::eye(3);
13+
std::cout << "Tensor: " << x << std::endl;
1314

1415
// std::cout << "Secret function called! Tensor: " << tensor << std::endl;
1516
}
1617

1718
extern "C" int baz(void) {
1819
printf("Hello from baz!\n");
1920
secret();
20-
// auto x = torch::randn({5, 3});
21-
// return x.size(0);
21+
auto x = torch::randn({5, 3});
22+
return x.size(0);
2223
}
2324

2425

@@ -38,18 +39,18 @@ extern "C" float sumArray(float* arr, int* sizes, int dim) {
3839

3940
printf("sumArray called with arr: %p, sizes: %p, dim: %d\n", arr, sizes, dim);
4041

41-
// std::vector<int64_t> sizes_vec(sizes, sizes + dim);
42-
// std::cout << sizes_vec << std::endl;
42+
std::vector<int64_t> sizes_vec(sizes, sizes + dim);
43+
std::cout << sizes_vec << std::endl;
4344

44-
// auto shape = at::IntArrayRef(sizes_vec);
45-
// std::cout << shape << std::endl;
45+
auto shape = at::IntArrayRef(sizes_vec);
46+
std::cout << shape << std::endl;
4647

47-
// auto t = torch::from_blob(arr, shape, torch::kFloat);
48-
// std::cout << t << std::endl;
48+
auto t = torch::from_blob(arr, shape, torch::kFloat);
49+
std::cout << t << std::endl;
4950

50-
// return t.sum().item<float>();
51+
return t.sum().item<float>();
5152

52-
return 0.0f;
53+
// return 0.0f;
5354

5455
// float sum = 0.0f;
5556
// for (int i = 0; i < size; ++i) {

0 commit comments

Comments
 (0)