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 Dec 2, 2020
1 parent ce847d5 commit 2d5dfc6
Show file tree
Hide file tree
Showing 6 changed files with 642 additions and 8 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=address")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -lasan")

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/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "context.h"
#include "defer.h"
#include "tensor.h"
#include "defer.h"

namespace cppflow {

Expand Down
Loading

0 comments on commit 2d5dfc6

Please sign in to comment.