Skip to content

Commit

Permalink
Introduce expression API (#4)
Browse files Browse the repository at this point in the history
* Introduce expression API

Co-authored-by: Liubov Batanina  <[email protected]>
  • Loading branch information
TolyaTalamanov and l-bat authored Mar 6, 2021
1 parent 9e30e88 commit 6f26df3
Show file tree
Hide file tree
Showing 17 changed files with 156 additions and 32 deletions.
6 changes: 0 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ project(deepworks)
########################################
set(CMAKE_CXX_STANDARD 17)

########################################
# Define include directories
########################################
set(COMMON_INCLUDES ${PROJECT_SOURCE_DIR}/include)
include_directories(${COMMON_INCLUDES})

########################################
# Define output paths
########################################
Expand Down
10 changes: 0 additions & 10 deletions include/deepworks.hpp

This file was deleted.

5 changes: 5 additions & 0 deletions include/deepworks/deepworks.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <deepworks/placeholder.hpp>
#include <deepworks/shape.hpp>
#include <deepworks/tensor.hpp>
24 changes: 24 additions & 0 deletions include/deepworks/placeholder.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <memory> // shared_ptr

#include <deepworks/shape.hpp>

namespace deepworks {

class Call;
class Placeholder {
public:
explicit Placeholder(const deepworks::Shape& shape);

const Shape& shape() const;

// NB: Public for test, but not available for user,
// because Impl isn't exported to public API.
Placeholder(const deepworks::Shape& shape, Call call);
struct Impl;
const Impl& impl() const;
std::shared_ptr<Impl> m_impl;
};

} // namespace deepworks
9 changes: 9 additions & 0 deletions include/deepworks/shape.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <vector>

namespace deepworks {

using Shape = std::vector<int>;

} // namespace deepworks;
3 changes: 2 additions & 1 deletion include/tensor.hpp → include/deepworks/tensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
#include <vector>
#include <memory>

#include <deepworks/shape.hpp>

namespace deepworks {

using Shape = std::vector<int>;
using Strides = std::vector<size_t>;

class Tensor {
Expand Down
14 changes: 13 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/src/*.cpp)
set(SRC_FILES
${CMAKE_CURRENT_LIST_DIR}/placeholder.cpp
${CMAKE_CURRENT_LIST_DIR}/call.cpp
${CMAKE_CURRENT_LIST_DIR}/tensor.cpp
)

set(DeepWorks_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include/")

add_library(${PROJECT_NAME} SHARED ${SRC_FILES})

# Set public API
target_include_directories(${PROJECT_NAME}
PUBLIC ${DeepWorks_INCLUDE_DIR}
PRIVATE "${PROJECT_NAME}/src"
)

if (WITH_EIGEN)
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
target_link_libraries(${PROJECT_NAME} PRIVATE Eigen3::Eigen)
Expand Down
20 changes: 20 additions & 0 deletions src/call.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <deepworks/placeholder.hpp>

#include "call.hpp"
#include "call_impl.hpp"

deepworks::Call::Call(deepworks::LayerInfo&& info)
: m_impl(new Call::Impl{std::move(info)}) {
}

void deepworks::Call::pass(std::vector<deepworks::Placeholder>&& args) {
m_impl->args = std::move(args);
}

deepworks::Placeholder deepworks::Call::create(const deepworks::Shape& shape) {
return deepworks::Placeholder{shape, *this};
};

const deepworks::Call::Impl& deepworks::Call::impl() const {
return *m_impl;
}
23 changes: 23 additions & 0 deletions src/call.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <memory> // shared_ptr

#include "layer_info.hpp"

namespace deepworks {

class Placeholder;
struct Call {
Call() = default;
explicit Call(LayerInfo&&);

void pass(std::vector<Placeholder>&& args);

Placeholder create(const Shape& shape);

struct Impl;
const Impl& impl() const;
std::shared_ptr<Impl> m_impl;
};

} // namespace deepworks
10 changes: 10 additions & 0 deletions src/call_impl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "call.hpp"

namespace deepworks {

struct Call::Impl {
deepworks::LayerInfo info;
std::vector<Placeholder> args;
};

} // namespace deepworks
5 changes: 0 additions & 5 deletions src/deepworks.cpp

This file was deleted.

10 changes: 10 additions & 0 deletions src/layer_info.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

namespace deepworks {

struct LayerInfo {
std::string name;
std::string type;
};

} // namespace deepworks
21 changes: 21 additions & 0 deletions src/placeholder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <deepworks/placeholder.hpp>

#include "call.hpp"
#include "placeholder_impl.hpp"

deepworks::Placeholder::Placeholder(const deepworks::Shape& shape,
deepworks::Call call)
: m_impl(new deepworks::Placeholder::Impl{shape, call}) {
}

deepworks::Placeholder::Placeholder(const deepworks::Shape& shape)
: m_impl(new deepworks::Placeholder::Impl{shape, {}}) {
}

const deepworks::Shape& deepworks::Placeholder::shape() const {
return m_impl->shape;
}

const deepworks::Placeholder::Impl& deepworks::Placeholder::impl() const {
return *m_impl;
}
15 changes: 15 additions & 0 deletions src/placeholder_impl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <optional>

#include "call.hpp"

namespace deepworks {

struct Placeholder::Impl {
deepworks::Shape shape;
// NB: The creator, empty optional if it's input.
std::optional<Call> call;
};

} // namespace deepworks
3 changes: 2 additions & 1 deletion src/tensor.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <tensor.hpp>
#include <deepworks/tensor.hpp>

#include <numeric>
#include <algorithm>

Expand Down
6 changes: 0 additions & 6 deletions tests/unit/foo_tests.cpp

This file was deleted.

4 changes: 2 additions & 2 deletions tests/unit/test_tensor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <deepworks.hpp>
#include <gtest/gtest.h>
#include <tensor.hpp>

#include <deepworks/tensor.hpp>

TEST(TensorTest, Allocate) {
deepworks::Tensor src_tensor;
Expand Down

0 comments on commit 6f26df3

Please sign in to comment.