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(); // test sources REQUIRE(nodes[0]->is_source() == false); REQUIRE(nodes[1]->is_source() == true); REQUIRE(nodes[2]->is_source() == false); REQUIRE(nodes[3]->is_source() == true); // test sinks
* (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())); } /* * gpu <-> gpu * (0, 1) -> (0, 0) * (0, 0) -> (0, 1) */ SECTION("gpu <-> gpu") { Blob* twos_gpu1 = g.create("twos_gpu1", rank, 0, {1, 10, 10, 10}); Blob* twos_gpu2 = g.create("twos_gpu2", rank, 1, {1, 10, 10, 10}); Copy* cp = g.createAny<Copy>("cp", Copy::param_tuple());