-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
import span to speed up & fix memory leak
- Loading branch information
Showing
8 changed files
with
680 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
#include <functional> | ||
|
||
namespace cppflow { | ||
|
||
class defer { | ||
public: | ||
typedef std::function<void ()> Func; | ||
|
||
explicit defer(const Func& func) : _func(func) {} | ||
~defer() { | ||
// maybe throw exception | ||
_func(); | ||
} | ||
|
||
defer(const defer&) = delete; | ||
defer(defer&&) = delete; | ||
defer& operator=(const defer&) = delete; | ||
void* operator new (size_t) = delete; | ||
void operator delete (void*) = delete; | ||
|
||
private: | ||
Func _func; | ||
}; | ||
|
||
} // namespace cppflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.