Skip to content

Commit

Permalink
Cppkg update, renames, and age generalization (#26)
Browse files Browse the repository at this point in the history
* renames, cleanups, and updates

* update cppkg version

* make age opmap more general

* separate type conversion from opera

* update docs
  • Loading branch information
raggledodo committed Feb 1, 2019
1 parent 2d29920 commit 7e5cdca
Show file tree
Hide file tree
Showing 149 changed files with 1,729 additions and 615 deletions.
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ BWD_TEST := //bwd:test

COVERAGE_IGNORE := 'external/*' '**/test/*' 'testutil/*' '**/genfiles/*' 'dbg/*'

COVERAGE_PIPE := ./scripts/merge_cov.sh $(COVERAGE_INFO_FILE)
COVERAGE_PIPE := ./bazel-bin/external/com_github_mingkaic_cppkg/merge_cov $(COVERAGE_INFO_FILE)

TMP_LOGFILE := /tmp/tenncor-test.log

Expand All @@ -22,7 +22,10 @@ cover_bwd:
$(COVER) $(BWD_TEST)


lcov: coverage
merge_cov:
bazel build @com_github_mingkaic_cppkg//:merge_cov

lcov: merge_cov coverage
rm -f $(TMP_LOGFILE)
cat bazel-testlogs/ade/test/test.log >> $(TMP_LOGFILE)
cat bazel-testlogs/bwd/test/test.log >> $(TMP_LOGFILE)
Expand All @@ -31,12 +34,12 @@ lcov: coverage
rm -f $(TMP_LOGFILE)
lcov --list $(COVERAGE_INFO_FILE)

lcov_ade: cover_ade
lcov_ade: merge_cov cover_ade
cat bazel-testlogs/ade/test/test.log | $(COVERAGE_PIPE)
lcov --remove $(COVERAGE_INFO_FILE) $(COVERAGE_IGNORE) -o $(COVERAGE_INFO_FILE)
lcov --list $(COVERAGE_INFO_FILE)

lcov_bwd: cover_bwd
lcov_bwd: merge_cov over_bwd
rm -f $(TMP_LOGFILE)
cat bazel-testlogs/bwd/test/test.log | $(COVERAGE_PIPE)
lcov --remove $(COVERAGE_INFO_FILE) $(COVERAGE_IGNORE) 'ade/*' -o $(COVERAGE_INFO_FILE)
Expand Down
48 changes: 28 additions & 20 deletions ade/mtens.hpp → ade/funcarg.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
///
/// funcarg.hpp
/// ade
///
/// Purpose:
/// Define functor argument wrapper to carryover shape and coordinate mappers
///

#include "ade/itensor.hpp"
#include "ade/coord.hpp"

#ifndef ADE_MTENS_HPP
#define ADE_MTENS_HPP
#ifndef ADE_FUNCARG_HPP
#define ADE_FUNCARG_HPP

namespace ade
{

/// Coordinate mapper and tensor pair
struct MappedTensor final
struct FuncArg final
{
/// Construct MappedTensor auto deducing coorder_ and map_io_ flag
MappedTensor (TensptrT tensor, CoordptrT shaper) :
/// Construct FuncArg auto deducing coorder_ and map_io_ flag
FuncArg (TensptrT tensor, CoordptrT shaper) :
tensor_(tensor), shaper_(shaper)
{
if (tensor_ == nullptr)
Expand All @@ -29,8 +37,8 @@ struct MappedTensor final
}
}

/// Construct MappedTensor with specific coorder_ and map_io_ flag
MappedTensor (TensptrT tensor, CoordptrT shaper,
/// Construct FuncArg with specific coorder_ and map_io_ flag
FuncArg (TensptrT tensor, CoordptrT shaper,
bool map_io, CoordptrT coorder) :
tensor_(tensor), shaper_(shaper),
map_io_(map_io), coorder_(coorder)
Expand Down Expand Up @@ -102,36 +110,36 @@ struct MappedTensor final
CoordptrT coorder_;
};

/// Return MappedTensor that identity maps input tensor
MappedTensor identity_map (TensptrT tensor);
/// Return FuncArg that identity maps input tensor
FuncArg identity_map (TensptrT tensor);

/// Return MappedTensor that reduces input tensor at
/// Return FuncArg that reduces input tensor at
/// rank then snip the dimension at rank
/// E.g.: tensor w/ shape [2, 3, 4], rank = 1 gets mapped to [2, 4]
MappedTensor reduce_1d_map (TensptrT tensor, uint8_t rank);
FuncArg reduce_1d_map (TensptrT tensor, uint8_t rank);

/// Return MappedTensor that reduces input tensor by
/// Return FuncArg that reduces input tensor by
/// units in reduction vector after specified rank
/// E.g.: tensor w/ shape [2, 3, 4], rank = 0, red = [2, 3]
/// gets mapped to [1, 1, 4]
MappedTensor reduce_map (TensptrT tensor,
FuncArg reduce_map (TensptrT tensor,
uint8_t rank, std::vector<DimT> red);

/// Return MappedTensor that extends input tensor by
/// Return FuncArg that extends input tensor by
/// rank and extension vector
/// E.g.: tensor w/ shape [2, 1, 1], rank = 1, red = [3, 4]
/// gets mapped to [2, 3, 4]
MappedTensor extend_map (TensptrT tensor,
FuncArg extend_map (TensptrT tensor,
uint8_t rank, std::vector<DimT> ext);

/// Return MappedTensor that permutes input tensor by order
/// Return FuncArg that permutes input tensor by order
/// E.g.: tensor w/ shape [2, 3, 4], order = [1, 2, 0]
/// gets mapped to [3, 4, 2]
MappedTensor permute_map (TensptrT tensor, std::vector<uint8_t> order);
FuncArg permute_map (TensptrT tensor, std::vector<uint8_t> order);

/// Return MappedTensor that flips input tensor along dimension
MappedTensor flip_map (TensptrT tensor, uint8_t dim);
/// Return FuncArg that flips input tensor along dimension
FuncArg flip_map (TensptrT tensor, uint8_t dim);

}

#endif // ADE_MTENS_HPP
#endif // ADE_FUNCARG_HPP
18 changes: 18 additions & 0 deletions ade/functor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ struct Functor final : public iFunctor
return new Functor(opcode, shape, args);
}

static Functor* get (const Functor& other)
{
return new Functor(other);
}

static Functor* get (Functor&& other)
{
return new Functor(std::move(other));
}

Functor& operator = (const Functor& other) = delete;

Functor& operator = (Functor&& other) = delete;

/// Implementation of iTensor
const Shape& shape (void) const override
{
Expand Down Expand Up @@ -68,6 +82,10 @@ struct Functor final : public iFunctor
Functor (Opcode opcode, Shape shape, ArgsT args) :
opcode_(opcode), shape_(shape), args_(args) {}

Functor (const Functor& other) = default;

Functor (Functor&& other) = default;

/// Operation encoding
Opcode opcode_;

Expand Down
4 changes: 2 additions & 2 deletions ade/ifunctor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// Define functor nodes of an equation graph
///

#include "ade/mtens.hpp"
#include "ade/funcarg.hpp"

#ifndef ADE_IFUNCTOR_HPP
#define ADE_IFUNCTOR_HPP
Expand All @@ -15,7 +15,7 @@ namespace ade
{

/// Type of functor arguments
using ArgsT = std::vector<MappedTensor>;
using ArgsT = std::vector<FuncArg>;

/// Encoding of operation
struct Opcode final
Expand Down
49 changes: 49 additions & 0 deletions ade/src/funcarg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "ade/funcarg.hpp"

#ifdef ADE_FUNCARG_HPP

namespace ade
{

FuncArg identity_map (TensptrT tensor)
{
return FuncArg(tensor, identity);
}

FuncArg reduce_1d_map (TensptrT tensor, uint8_t rank)
{
Shape shape = tensor->shape();
std::vector<DimT> indices(rank_cap);
auto bt = indices.begin();
auto it = bt + rank;
std::iota(bt, it, 0);
std::iota(it, indices.end(), rank + 1);
indices[rank_cap - 1] = rank;
return FuncArg(tensor, CoordptrT(
reduce(rank, {shape.at(rank)})->
connect(*permute(indices))));
}

FuncArg reduce_map (TensptrT tensor, uint8_t rank, std::vector<DimT> red)
{
return FuncArg(tensor, reduce(rank, red));
}

FuncArg extend_map (TensptrT tensor, uint8_t rank, std::vector<DimT> ext)
{
return FuncArg(tensor, extend(rank, ext));
}

FuncArg permute_map (TensptrT tensor, std::vector<uint8_t> order)
{
return FuncArg(tensor, permute(order));
}

FuncArg flip_map (TensptrT tensor, uint8_t dim)
{
return FuncArg(tensor, flip(dim));
}

}

#endif
49 changes: 0 additions & 49 deletions ade/src/mtens.cpp

This file was deleted.

12 changes: 6 additions & 6 deletions ade/test/test_mtens.cpp → ade/test/test_funcarg.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#ifndef DISABLE_MTENS_TEST
#ifndef DISABLE_FUNCARG_TEST


#include "gtest/gtest.h"
Expand All @@ -8,10 +8,10 @@

#include "ade/test/common.hpp"

#include "ade/mtens.hpp"
#include "ade/funcarg.hpp"


struct MTENS : public ::testing::Test
struct FUNCARG : public ::testing::Test
{
virtual void TearDown (void)
{
Expand All @@ -21,7 +21,7 @@ struct MTENS : public ::testing::Test
};


TEST_F(MTENS, Reduce1d)
TEST_F(FUNCARG, Reduce1d)
{
size_t rank = 5;
ade::CoordT fwd_out;
Expand All @@ -32,7 +32,7 @@ TEST_F(MTENS, Reduce1d)
ade::Shape shape({223, 35, 7, 25, 19, 214, 72, 7});
ade::TensptrT tens = std::make_shared<MockTensor>(shape);

ade::MappedTensor redtens = ade::reduce_1d_map(tens, rank);
ade::FuncArg redtens = ade::reduce_1d_map(tens, rank);
ade::Shape rshaped = redtens.shape();

std::vector<ade::DimT> expect_shape = {223, 35, 7, 25,
Expand All @@ -53,4 +53,4 @@ TEST_F(MTENS, Reduce1d)
}


#endif // DISABLE_MTENS_TEST
#endif // DISABLE_FUNCARG_TEST
10 changes: 5 additions & 5 deletions ade/test/test_tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "ade/test/common.hpp"

#include "ade/mtens.hpp"
#include "ade/funcarg.hpp"


struct TENSOR : public ::testing::Test
Expand All @@ -21,18 +21,18 @@ struct TENSOR : public ::testing::Test
};


TEST_F(TENSOR, MappedTensor)
TEST_F(TENSOR, FuncArg)
{
std::vector<ade::DimT> slist = {2, 81};

size_t dim = 1;
ade::TensptrT tens(new MockTensor(ade::Shape(slist)));
ade::MappedTensor mt = ade::flip_map(tens, dim);
ade::FuncArg mt = ade::flip_map(tens, dim);

ade::Shape shape = mt.shape();
EXPECT_ARREQ(slist, shape);

ade::MappedTensor mt2(tens, ade::CoordptrT(new ade::CoordMap(
ade::FuncArg mt2(tens, ade::CoordptrT(new ade::CoordMap(
[](ade::MatrixT m)
{
for (size_t i = 0; i < ade::mat_dim; ++i)
Expand All @@ -48,7 +48,7 @@ TEST_F(TENSOR, MappedTensor)
EXPECT_FATAL(ade::identity_map(nullptr),
"cannot map a null tensor");

EXPECT_FATAL(ade::MappedTensor(nullptr, ade::reduce(3, {4}),
EXPECT_FATAL(ade::FuncArg(nullptr, ade::reduce(3, {4}),
false, ade::extend(3, {4})),
"cannot map a null tensor");
}
Expand Down
2 changes: 1 addition & 1 deletion age/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ genrule(
"generated/capi.cpp",
"generated/codes.hpp",
"generated/codes.cpp",
"generated/data.hpp",
"generated/grader.hpp",
"generated/grader.cpp",
"generated/opmap.hpp",
"generated/opmap.cpp",
],
tools = ["//age:cagen"],
cmd = "$(location //age:cagen) " +
Expand Down
Loading

0 comments on commit 7e5cdca

Please sign in to comment.