Skip to content

Commit

Permalink
import span to speed up
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanallen authored and liufeng27 committed Nov 5, 2020
1 parent 8db5b32 commit 0e56399
Show file tree
Hide file tree
Showing 6 changed files with 641 additions and 5 deletions.
2 changes: 2 additions & 0 deletions examples/eager_op_multithread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ find_package(Threads REQUIRED)

set(CMAKE_CXX_STANDARD 17)


#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=thread")
#set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=thread")

add_executable(example main.cpp)
target_include_directories(example PRIVATE ../../include $ENV{HOME}/libtensorflow2/include)
target_link_libraries (example "${TENSORFLOW_LIB}")
target_link_libraries(example "${TENSORFLOW_LIB}" Threads::Threads)
16 changes: 16 additions & 0 deletions examples/tensor_span/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.10)
project(example)

find_library(TENSORFLOW_LIB tensorflow HINT $ENV{HOME}/libtensorflow2/lib)
find_package(Threads REQUIRED)

#set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 17)


#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=thread")
#set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=thread")

add_executable(example main.cpp)
target_include_directories(example PRIVATE ../../include $ENV{HOME}/libtensorflow2/include)
target_link_libraries (example "${TENSORFLOW_LIB}")
23 changes: 23 additions & 0 deletions examples/tensor_span/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <cmath>
#include <vector>
#include <cassert>

#include "cppflow/cppflow.h"

template<typename T>
void test(const std::initializer_list<T>& input) {
std::vector<T> values = input;
cppflow::tensor t(input);
auto span_result = t.get_data<T>();

assert(span_result.size() == values.size());
for(size_t i = 0; i < span_result.size(); i++) {
assert(std::abs(values[i]/span_result[i]-1.0f) < 1e-6);
}
}

int main() {
test({10, 20, 30});
test({10.0, 20.1, 30.3});
return 0;
}
1 change: 1 addition & 0 deletions include/cppflow/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define CPPFLOW2_CONTEXT_H

#include <memory>
#include <stdexcept>
#include <utility>

#include <tensorflow/c/c_api.h>
Expand Down
Loading

0 comments on commit 0e56399

Please sign in to comment.