Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env bash
echo Building Native ops...
TF_INC=$(python3 -c 'import tensorflow as tf; print(tf.sysconfig.get_include())')
TF_CFLAGS=( $(python3 -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_compile_flags()))') )
TF_LFLAGS=( $(python3 -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_link_flags()))') )
# TODO: GPU support
#nvcc -std=c++11 -c -o count_sketch.cu.o count_sketch.cu.cc -I $TF_INC -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -D_MWAITXINTRIN_H_INCLUDED -g
#g++ -std=c++11 -shared -o count_sketch.so count_sketch.cc count_sketch.cu.o -fPIC -lcudart -I $TF_INC -D_GLIBCXX_USE_CXX11_ABI=0 -g

mkdir -p build
g++ -std=c++11 -shared -o build/count_sketch.so ops/count_sketch.cc -fPIC -I $TF_INC -D_GLIBCXX_USE_CXX11_ABI=0
g++ -std=c++11 -shared -o build/count_sketch.so ops/count_sketch.cc -fPIC -I $TF_INC -D_GLIBCXX_USE_CXX11_ABI=0 -fPIC ${TF_CFLAGS[@]} ${TF_LFLAGS[@]} -O2
8 changes: 6 additions & 2 deletions count_sketch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import tensorflow as tf
import pkg_resources

_sketch_op = tf.load_op_library('./build/count_sketch.so')
path = "./build/count_sketch.so"
filepath = pkg_resources.resource_filename(__name__, path)

_sketch_op = tf.load_op_library(filepath)

def count_sketch(probs, project_size):
""" Calculates count-min sketch of a tensor.
Expand Down Expand Up @@ -53,5 +57,5 @@ def bilinear_pool(x1, x2, output_size):
pc1 = tf.complex(p1, tf.zeros_like(p1))
pc2 = tf.complex(p2, tf.zeros_like(p2))

conved = tf.batch_ifft(tf.batch_fft(pc1) * tf.batch_fft(pc2))
conved = tf.ifft(tf.fft(pc1) * tf.fft(pc2))
return tf.real(conved)