Skip to content

Commit fd6ed8c

Browse files
committed
MyExample works on linux and mac
1 parent da83b3c commit fd6ed8c

3 files changed

Lines changed: 30 additions & 12 deletions

File tree

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ COPY . /app
5454

5555
RUN ls
5656

57+
RUN cd /app \
58+
&& mkdir -p build \
59+
&& cd build \
60+
&& cmake -DCMAKE_BUILD_TYPE=Debug .. \
61+
&& make MyExample
62+
5763
# RUN mkdir build \
5864
# && cd build \
5965
# && cmake -DCMAKE_BUILD_TYPE=Debug .. \

bridge/lib/bridge.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ bridge_tensor_t torch_to_bridge(torch::Tensor &tensor) {
4141
bridge_tensor_t result;
4242
result.created_by_c = true;
4343
result.dim = tensor.dim();
44-
result.sizes = new int[result.dim];
44+
result.sizes = new int32_t[result.dim];
4545
for (int i = 0; i < result.dim; ++i) {
4646
result.sizes[i] = tensor.size(i);
4747
}
@@ -182,9 +182,9 @@ extern "C" bridge_tensor_t matmul(bridge_tensor_t a, bridge_tensor_t b) {
182182
auto t_a = bridge_to_torch(a);
183183
auto t_b = bridge_to_torch(b);
184184

185-
std::cout << "Input A shape: " << t_a.sizes() << std::endl;
186-
std::cout << "Input B shape: " << t_b.sizes() << std::endl;
187-
std::cout.flush();
185+
// std::cout << "Input A shape: " << t_a.sizes() << std::endl;
186+
// std::cout << "Input B shape: " << t_b.sizes() << std::endl;
187+
// std::cout.flush();
188188

189189
auto output = torch::matmul(t_a, t_b);
190190

@@ -193,12 +193,23 @@ extern "C" bridge_tensor_t matmul(bridge_tensor_t a, bridge_tensor_t b) {
193193
// std::cout << "Input A: " << t_a.sum() << std::endl;
194194
// std::cout << "Input B: " << t_b.sum() << std::endl;
195195
// // std::cout << "Input B: " << t_b << std::endl;
196-
std::cout << "Output shape: " << output.sizes() << std::endl;
197-
std::cout << "Output sum: " << output.sum() << std::endl;
198-
std::cout.flush();
196+
// std::cout << "Output shape: " << output.sizes() << std::endl;
197+
// std::cout << "Output sum: " << output.sum() << std::endl;
198+
// std::cout.flush();
199199
// printf("Hello from matmul!\n");
200-
201200
return torch_to_bridge(output);
201+
202+
// auto output_copy = output.clone();
203+
// std::cout << "Output copy shape: " << output_copy.sizes() << std::endl;
204+
// std::cout.flush();
205+
206+
// auto bt = torch_to_bridge(output_copy);
207+
// std::cout << "Bridge tensor sizes: " << bt.sizes << std::endl;
208+
// std::cout << "Bridge tensor dim: " << bt.dim << std::endl;
209+
210+
// std::cout.flush();
211+
212+
// return bt;
202213
}
203214

204215
extern "C" bridge_tensor_t max_pool2d(

lib/Bridge.chpl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,11 @@ module Bridge {
107107
var result: [dom] real(32);
108108
forall (i,idx) in dom.everyZip() do
109109
result[idx] = package.data[i];
110-
if package.created_by_c {
111-
deallocate(package.data);
112-
deallocate(package.sizes);
113-
}
110+
// This may leak! Alternative is segault on linux. :(
111+
// if package.created_by_c {
112+
// deallocate(package.data);
113+
// deallocate(package.sizes);
114+
// }
114115
return result;
115116
}
116117

0 commit comments

Comments
 (0)