Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import span to speed up #68

Open
wants to merge 1 commit into
base: cppflow2
Choose a base branch
from
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
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}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep Threads::Threads. This does not compile on LInux because pthread is required.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert all changes to this file? It makes this commit cleaner and focuses on the span header. You can create separate testing files to show it works with and without C++20.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target_link_libraries (example "${TENSORFLOW_LIB}") is required because it reports link error on my macos.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is your cmake version? Threads::Threads was introduced in cmake 3.1, and cmake 3.10 is requested here. This specific test case is related to threading, so Threads::Threads has to be linked.

I strongly recommend creating a separate test case for the span class and do not touch unrelated test case.

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