// Copyright Lin Min 2014
#include "catch/catch.hpp"
#include "dispatch/runnable.hpp"
#include "composite/layers/concat_layer.hpp"
#include "composite/layers/split_layer.hpp"

using namespace purine;

TEST_CASE("TestConcat", "[Concat]") {
  Runnable run(0, 0);
  Blob* data = run.create("data", { 32, 32, 32, 32 });
  Blob* data_diff = run.create("data_diff", { 32, 32, 32, 32 });
  Blob* data1 = run.create("data1", { 32, 32, 32, 32 });
  Blob* data1_diff = run.create("data1_diff", { 32, 32, 32, 32 });
  Blob* data2 = run.create("data2", { 32, 32, 32, 32 });
  Blob* data2_diff = run.create("data2_diff", { 32, 32, 32, 32 });
  ConcatLayer* concat = run.createGraph<ConcatLayer>("concat",
      ConcatLayer::param_tuple(Split::CHANNELS));
  vector<Blob*>{ data, data1, data2, data_diff, data1_diff, data2_diff }
  >> *concat;
  vector<Blob*> top = concat->top();
  REQUIRE(top[0]->tensor()->size() == Size(32, 96, 32, 32));
  REQUIRE(top[1]->tensor()->size() == Size(32, 96, 32, 32));
  REQUIRE(top[0]->tensor()->stride() == Stride(98304, 1024, 32, 1));
  REQUIRE(top[1]->tensor()->stride() == Stride(98304, 1024, 32, 1));
  REQUIRE(data->tensor()->stride() == Stride(98304, 1024, 32, 1));
  REQUIRE(data1->tensor()->stride() == Stride(98304, 1024, 32, 1));
  REQUIRE(data2->tensor()->stride() == Stride(98304, 1024, 32, 1));
  REQUIRE(data_diff->tensor()->stride() == Stride(98304, 1024, 32, 1));
  REQUIRE(data1_diff->tensor()->stride() == Stride(98304, 1024, 32, 1));
  REQUIRE(data2_diff->tensor()->stride() == Stride(98304, 1024, 32, 1));
 * device: -1, 0, 1    -1, 0, 1
 */
TEST_CASE("TestCopy", "[Copy]") {
    Runnable g;
    SECTION("Single Copy") {
        SECTION("Within rank") {
            int rank = current_rank();
            /**
             * cpu <-> gpu
             * (0, -1) -> (0, 0)
             * (0, 0) -> (0, -1)
             */
            SECTION("cpu <-> gpu") {
                Op<Constant>* c = g.create<Constant>("constant", rank, -1, "main",
                                                     Constant::param_tuple(2.));
                Blob* twos_cpu = g.create("twos_cpu", rank, -1, {1, 10, 10, 10});
                Blob* twos_gpu = g.create("twos_gpu", rank, 0, {1, 10, 10, 10});
                Blob* dest_cpu = g.create("dest_cpu", rank, -1, {1, 10, 10, 10});
                Copy* cp = g.createAny<Copy>("cp", Copy::param_tuple());
                Copy* cp2 = g.createAny<Copy>("cp2", Copy::param_tuple());

                *c >> B{ twos_cpu } >> *cp >> B{ twos_gpu } >> *cp2 >> B{ dest_cpu };

                REQUIRE(cp->nodes().size() == 1);
                REQUIRE(cp2->nodes().size() == 1);
                REQUIRE(g.nodes().size() == 6);

                g.run();
                REQUIRE(caffe::purine_cpu_compare(twos_cpu->tensor()->cpu_data(),
                                                  dest_cpu->tensor()->cpu_data(),
                                                  twos_cpu->tensor()->shape().Count()));
Beispiel #3
0
#include "operations/include/eltwise.hpp"
#include "operations/include/mem_copy.hpp"
#include "dispatch/graph_template.hpp"
#include "dispatch/op_template.hpp"
#include "dispatch/runnable.hpp"
#include "composite/layers/conv_layer.hpp"

using namespace purine;

typedef vector<Blob*> B;

TEST_CASE("TestGraph", "[Graph]") {
  Runnable test_graph;
  Op<Conv>* o = test_graph.create<Conv>("conv", "main",
      Conv::param_tuple(2, 2, 1, 1));
  Blob* bottom = test_graph.create("bottom", 0, 0, {1, 3, 10, 10});
  Blob* top = test_graph.create("top", 0, 0, {1, 3, 10, 10});
  Blob* weight = test_graph.create("weight", 0, 0, {3, 3, 5, 5});
  B{ bottom, weight } >> (*o) >> B{ top };

  SECTION("graph node number test") {
    vector<Node*> nodes = test_graph.nodes();
    int node_size = test_graph.nodes().size();
    int source_size = test_graph.sources().size();
    int sink_size = test_graph.sinks().size();
    REQUIRE(node_size == 4);
    REQUIRE(source_size == 2);
    REQUIRE(sink_size == 1);
  }
  SECTION("graph sources and sinks test") {
    vector<Node*>&& nodes = test_graph.nodes();
Beispiel #4
0
#include "operations/include/mpi.hpp"
#include "dispatch/op_template.hpp"
#include "dispatch/graph_template.hpp"
#include "dispatch/runnable.hpp"
#include "dispatch/blob.hpp"

using namespace purine;
using namespace std;

typedef vector<Blob*> B;

TEST_CASE("TestMPI", "[MPI][Thread]") {
  Runnable g;
  SECTION("Isend and Irecv") {
    int rank = current_rank();
    Blob* src = g.create("src", 0, -1, {1, 3, 10, 10});
    Blob* dest = g.create("dest", 1, -1, {1, 3, 10, 10});
    Op<Constant>* c = g.create<Constant>("constant", 0, -1, "main",
        Constant::param_tuple(1.));
    Op<Isend>* send = g.create<Isend>("send", 0, -1, "main",
        Isend::param_tuple(0, dest->rank()));
    Op<Irecv>* recv = g.create<Irecv>("recv", 1, -1, "main",
        Irecv::param_tuple(0, src->rank()));
    // connect
    *c >> B{ src };
    B{ src } >> *send;
    *recv >> B{ dest };
    // run
    g.run();
    Tensor* t = dest->tensor();
    if (current_rank() == 1) {