From 12847428fa8d9c90c717b09188ced9f15b5987ff Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Mon, 15 May 2017 15:22:30 +0700 Subject: [PATCH] samples: Install Tensorflow in HOME directory --- .gitignore | 7 +++++-- samples/tensorflow/README.md | 6 ++++-- samples/tensorflow/build.sh | 11 ++++++++--- samples/tensorflow/tensorflow.def | 1 - 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 392873a4aa0..fdef1767c6b 100644 --- a/.gitignore +++ b/.gitignore @@ -47,5 +47,8 @@ proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc # translator auto generated artifacts kotstd/ll -#test teamcity property: commitable only with -f -backend.native/tests/teamcity-test.property \ No newline at end of file +# test teamcity property: commitable only with -f +backend.native/tests/teamcity-test.property + +# Sample output +samples/**/*.kt.bc-build \ No newline at end of file diff --git a/samples/tensorflow/README.md b/samples/tensorflow/README.md index f12a5c03c76..0385b01791b 100644 --- a/samples/tensorflow/README.md +++ b/samples/tensorflow/README.md @@ -12,10 +12,12 @@ showing how a TensorFlow client in Kotlin/Native could look like. ./build.sh -will install [TensorFlow for C](https://www.tensorflow.org/versions/r1.1/install/install_c) into `/opt/local` (if not yet done) and build the example. +will install [TensorFlow for C](https://www.tensorflow.org/versions/r1.1/install/install_c) into +`$HOME/.konan/third-party/tensorflow` (if not yet done) and build the example. ./HelloTensorflow.kexe will then run the example. -You may need to specify `LD_LIBRARY_PATH` or `DYLD_LIBRARY_PATH` to `/opt/local/lib` if the TensorFlow dynamic library cannot be found. \ No newline at end of file +You may need to specify `LD_LIBRARY_PATH` or `DYLD_LIBRARY_PATH` to `$HOME/.konan/third-party/tensorflow/lib` +if the TensorFlow dynamic library cannot be found. \ No newline at end of file diff --git a/samples/tensorflow/build.sh b/samples/tensorflow/build.sh index de0fec41d8d..fcf0a41171e 100755 --- a/samples/tensorflow/build.sh +++ b/samples/tensorflow/build.sh @@ -2,9 +2,12 @@ PATH=../../dist/bin:../../bin:$PATH DIR=. -TF_TARGET_DIRECTORY="/opt/local" # If you change this, adapt compilerOpts in tensorflow.def accordingly +TF_TARGET_DIRECTORY="$HOME/.konan/third-party/tensorflow" TF_TYPE="cpu" # Change to "gpu" for GPU support +CFLAGS_macbook="-I${TF_TARGET_DIRECTORY}/include" +CFLAGS_linux="-I${TF_TARGET_DIRECTORY}/include" + if [ x$TARGET == x ]; then case "$OSTYPE" in darwin*) TARGET=macbook; TF_TARGET=darwin ;; @@ -22,12 +25,14 @@ COMPILER_ARGS=${!var} # add -opt for an optimized build. if [ ! -d $TF_TARGET_DIRECTORY/include/tensorflow ]; then echo "Installing TensorFlow into $TF_TARGET_DIRECTORY ..." - sudo mkdir -p $TF_TARGET_DIRECTORY + mkdir -p $TF_TARGET_DIRECTORY curl -s -L \ "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-${TF_TYPE}-${TF_TARGET}-x86_64-1.1.0.tar.gz" | - sudo tar -C $TF_TARGET_DIRECTORY -xz + tar -C $TF_TARGET_DIRECTORY -xz fi cinterop -def $DIR/tensorflow.def -copt "$CFLAGS" -target $TARGET -o tensorflow.kt.bc || exit 1 konanc $COMPILER_ARGS -target $TARGET $DIR/HelloTensorflow.kt -library tensorflow.kt.bc -o HelloTensorflow.kexe \ -linkerArgs "-L$TF_TARGET_DIRECTORY/lib -ltensorflow" || exit 1 + +echo "Note: You may need to specify LD_LIBRARY_PATH or DYLD_LIBRARY_PATH env variables to $TF_TARGET_DIRECTORY/lib if the TensorFlow dynamic library cannot be found." diff --git a/samples/tensorflow/tensorflow.def b/samples/tensorflow/tensorflow.def index d846d99a0ae..2f0566fd401 100644 --- a/samples/tensorflow/tensorflow.def +++ b/samples/tensorflow/tensorflow.def @@ -1,2 +1 @@ headers = tensorflow/c/c_api.h -compilerOpts = -I/opt/local/include -L/opt/local/lib