Skip to content

Commit 43a96f8

Browse files
committed
VGG example working well. see bottom of cmake file.
1 parent a534ee8 commit 43a96f8

File tree

5 files changed

+58
-7
lines changed

5 files changed

+58
-7
lines changed

CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,6 @@ target_link_options(TorchBridge
159159
${LIBTORCH_LIBS_LINKER_ARGS}
160160
--ldflags "-Wl,-rpath,${LIBTORCH_DIR}/lib"
161161
)
162-
# chpl test/tiny/layer_test.chpl -M lib bridge/include/bridge.h build/CMakeFiles/bridge.dir/bridge/lib/bridge.cpp.o -L libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps --ldflags "-Wl,-rpath,libtorch/lib"
163-
164-
# chpl --fast -o vgg test.chpl -M ../../lib /Users/iainmoncrief/Documents/Github/ChAI/bridge/include/bridge.h /Users/iainmoncrief/Documents/Github/ChAI/build/CMakeFiles/bridge.dir/bridge/lib/bridge.cpp.o -L /Users/iainmoncrief/Documents/Github/ChAI/libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps --ldflags "-Wl,-rpath,/Users/iainmoncrief/Documents/Github/ChAI/libtorch/lib"
165162

166163

167164

@@ -181,4 +178,11 @@ target_link_options(TinyLayerTest
181178
-L ${LIBTORCH_DIR}/lib
182179
${LIBTORCH_LIBS_LINKER_ARGS}
183180
--ldflags "-Wl,-rpath,${LIBTORCH_DIR}/lib"
184-
)
181+
)
182+
# chpl test/tiny/layer_test.chpl -M lib bridge/include/bridge.h build/CMakeFiles/bridge.dir/bridge/lib/bridge.cpp.o -L libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps --ldflags "-Wl,-rpath,libtorch/lib"
183+
184+
# chpl --fast -o vgg test.chpl -M ../../lib /Users/iainmoncrief/Documents/Github/ChAI/bridge/include/bridge.h /Users/iainmoncrief/Documents/Github/ChAI/build/CMakeFiles/bridge.dir/bridge/lib/bridge.cpp.o -L /Users/iainmoncrief/Documents/Github/ChAI/libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps --ldflags "-Wl,-rpath,/Users/iainmoncrief/Documents/Github/ChAI/libtorch/lib"
185+
186+
# chpl -o vgg test.chpl $(../../embed_libtorch.sh .)
187+
# chpl --fast -o vgg test.chpl $(../../embed_libtorch.sh .)
188+

bridge/lib/bridge.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ extern "C" bridge_tensor_t conv2d(
8080
int stride,
8181
int padding
8282
) {
83-
84-
printf("Hello from conv2d!\n");
8583
auto t_input = bridge_to_torch(input);
8684
auto t_kernel = bridge_to_torch(kernel);
8785
auto t_bias = bridge_to_torch(bias);

embed_libtorch.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env sh
2+
3+
#
4+
# This script prints the flags required by the Chapel compiler to embed Python
5+
# code in a Chapel program. It is intended to be used by consumers of the
6+
# 'Python' module. See https://chapel-lang.org/docs/modules/packages/Python.html
7+
#
8+
9+
# get the chpl home directory
10+
# chpl_home=$(cd $(dirname $0) ; cd ..; cd ..; pwd)
11+
# chpl_python=$("$chpl_home/util/config/find-python.sh")
12+
13+
cd "$(dirname "$0")"
14+
15+
mkdir -p build
16+
cd build
17+
cmake .. > /dev/null
18+
make -j4 > /dev/null
19+
cd ..
20+
21+
SOURCE_DIR=$(pwd)
22+
BRIDGE_LIB=$SOURCE_DIR/build/CMakeFiles/bridge.dir/bridge/lib/bridge.cpp.o
23+
LIBTORCH_DIR=$SOURCE_DIR/libtorch
24+
25+
26+
echo "-M $SOURCE_DIR/lib $SOURCE_DIR/bridge/include/bridge.h $BRIDGE_LIB -I $SOURCE_DIR/bridge/include -L $LIBTORCH_DIR/lib --ldflags -Wl,-rpath,$SOURCE_DIR/libtorch/lib"
27+
28+
# PYTHON_INCLUDE_DIR=$($chpl_python -c "import sysconfig; print(sysconfig.get_paths()['include'])")
29+
# PYTHON_LIB_DIR=$($chpl_python -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))")
30+
# PYTHON_LDVERSION=$($chpl_python -c "import sysconfig; print(sysconfig.get_config_var('LDVERSION'))")
31+
32+
# DISABLE_WARNINGS=""
33+
# # some older python's don't use `#ifndef` when they should
34+
# # so we disable redefinition warnings for clean testing
35+
# DISABLE_WARNINGS="$DISABLE_WARNINGS --ccflags -Wno-macro-redefined"
36+
37+
# echo "--ccflags -isystem$PYTHON_INCLUDE_DIR -L$PYTHON_LIB_DIR --ldflags -Wl,-rpath,$PYTHON_LIB_DIR -lpython$PYTHON_LDVERSION $DISABLE_WARNINGS"

examples/vgg/test.chpl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,16 @@ proc confidence(x: []): [] {
2626
// returns (top k indicies, top k condiences)
2727
proc run(model: borrowed, file: string) {
2828
const img = Tensor.load(file):real(32);
29-
const output = model(img);
29+
30+
writeln("Loaded image: ", file);
31+
writeln("Image shape: ", img.shape());
32+
33+
var output = model(img);
34+
35+
for i in 0..10 do
36+
output = model(img);
37+
38+
writeln("Output shape: ", output.shape());
3039

3140
const top = output.topk(k);
3241
var topArr = top.tensorize(1).array.data;
@@ -40,6 +49,7 @@ proc main(args: [] string) {
4049
const labels = getLabels();
4150
const vgg = new VGG16(real(32));
4251
vgg.loadPyTorchDump("models/vgg16/", false);
52+
writeln("Loaded VGG16 model.");
4353

4454

4555
var files = args[1..];

lib/Bridge.chpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
module Bridge {
2+
// require "bridge.h";
3+
require "-ltorch", "-ltorch_cpu", "-lc10", "-ltorch_global_deps";
24

35
import Utilities as util;
46
use Utilities.Standard;

0 commit comments

Comments
 (0)