Skip to content

Commit 1bafe0f

Browse files
ivanallenliufeng27
authored and
liufeng27
committed
import span to speed up
1 parent 8db5b32 commit 1bafe0f

File tree

5 files changed

+642
-5
lines changed

5 files changed

+642
-5
lines changed

examples/eager_op_multithread/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ find_package(Threads REQUIRED)
66

77
set(CMAKE_CXX_STANDARD 17)
88

9+
910
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=thread")
1011
#set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=thread")
1112

1213
add_executable(example main.cpp)
1314
target_include_directories(example PRIVATE ../../include $ENV{HOME}/libtensorflow2/include)
15+
target_link_libraries (example "${TENSORFLOW_LIB}")
1416
target_link_libraries(example "${TENSORFLOW_LIB}" Threads::Threads)

examples/tensor_span/CMakeLists.txt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(example)
3+
4+
find_library(TENSORFLOW_LIB tensorflow HINT $ENV{HOME}/libtensorflow2/lib)
5+
find_package(Threads REQUIRED)
6+
7+
#set(CMAKE_CXX_STANDARD 20)
8+
set(CMAKE_CXX_STANDARD 17)
9+
10+
11+
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=thread")
12+
#set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=thread")
13+
14+
add_executable(example main.cpp)
15+
target_include_directories(example PRIVATE ../../include $ENV{HOME}/libtensorflow2/include)
16+
target_link_libraries (example "${TENSORFLOW_LIB}")

examples/tensor_span/main.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <thread>
2+
#include <cmath>
3+
#include <vector>
4+
#include <iostream>
5+
#include <cassert>
6+
7+
#include "cppflow/cppflow.h"
8+
9+
template<typename T>
10+
void test(const std::initializer_list<T>& input) {
11+
std::vector<T> values = input;
12+
cppflow::tensor t(input);
13+
auto span_result = t.get_data<T>();
14+
15+
assert(span_result.size() == values.size());
16+
for(size_t i = 0; i < span_result.size(); i++) {
17+
assert(std::abs(values[i]/span_result[i]-1.0f) < 1e-6);
18+
}
19+
}
20+
21+
int main() {
22+
test({10, 20, 30});
23+
test({10.0, 20.1, 30.3});
24+
return 0;
25+
}

0 commit comments

Comments
 (0)