| 61 | |
| 62 | #if CUDA_VERSION >= 10020 |
| 63 | TEST(TestProfiler, Conv) { |
| 64 | REQUIRE_GPU(1); |
| 65 | auto cn = CompNode::load("gpu0"); |
| 66 | cn.activate(); |
| 67 | REQUIRE_CUDA_COMPUTE_CAPABILITY_EQ(7, 5); |
| 68 | auto ctx = make_ctx(); |
| 69 | |
| 70 | HostTensorGenerator<dtype::Int8> gen; |
| 71 | auto graph = ComputingGraph::make(); |
| 72 | graph->options().graph_opt_level = 0; |
| 73 | auto mkvar = [&](const char* name, const TensorShape& shp, const DType& dtype) { |
| 74 | return opr::TypeCvt::make( |
| 75 | opr::Host2DeviceCopy::make(*graph, gen(shp, cn)).rename(name), dtype); |
| 76 | }; |
| 77 | auto mkcvar = [&](const char* name, const TensorShape& shp, const DType& dtype) { |
| 78 | return opr::TypeCvt::make( |
| 79 | opr::SharedDeviceTensor::make(*graph, *gen(shp, cn)).rename(name), |
| 80 | dtype); |
| 81 | }; |
| 82 | auto x = |
| 83 | mkvar("x", {64, 48, 14, 14}, |
| 84 | dtype::Quantized4Asymm(2.5f, static_cast<uint8_t>(4))); |
| 85 | auto w1 = mkcvar("w1", {48, 48, 3, 3}, dtype::QuantizedS4(2.5f)); |
| 86 | auto b1 = mkcvar("b1", {1, 48, 1, 1}, dtype::QuantizedS32(6.25f)); |
| 87 | opr::ConvBias::Param param; |
| 88 | param.format = opr::ConvBias::Param::Format::NCHW; |
| 89 | param.nonlineMode = opr::ConvBias::Param::NonlineMode::IDENTITY; |
| 90 | param.stride_h = param.stride_w = 1; |
| 91 | param.pad_h = param.pad_w = 1; |
| 92 | auto c1 = opr::ConvBias::make( |
| 93 | x, w1, b1, param, {}, |
| 94 | OperatorNodeConfig( |
| 95 | dtype::Quantized4Asymm(12.345f, static_cast<uint8_t>(5)))); |
| 96 | x = opr::TypeCvt::make(c1, dtype::QuantizedS8(12.345f)); |
| 97 | auto w2 = mkcvar("w2", {48, 48, 3, 3}, dtype::QuantizedS8(2.5f)); |
| 98 | auto b2 = mkcvar("b2", {1, 48, 1, 1}, dtype::QuantizedS32(12.345f * 2.5f)); |
| 99 | auto c2 = opr::ConvBias::make( |
| 100 | x, w2, b2, param, {}, OperatorNodeConfig(dtype::QuantizedS8(2.5f))); |
| 101 | |
| 102 | using S = opr::mixin::AlgoChooserHelper::ExecutionPolicy::Strategy; |
| 103 | S strategy = S::PROFILE; |
| 104 | gopt::modify_opr_algo_strategy_inplace({c2}, strategy); |
| 105 | SubGraphExtractor extractor(ctx->opr_list()); |
| 106 | auto partitions = extractor.extract({c2}); |
| 107 | ASSERT_EQ(partitions.size(), 1u); |
| 108 | Problem problem(partitions[0], *ctx); |
| 109 | auto profiler = ProfilerBase::make_profiler(); |
| 110 | auto rst = profiler->profile(problem); |
| 111 | const auto& opr_rst = rst.opr_record; |
| 112 | const auto& var_rst = rst.var_record; |
| 113 | EXPECT_TRUE(opr_rst.count(c1.node()->owner_opr()) > 0); |
| 114 | EXPECT_TRUE(opr_rst.count(c2.node()->owner_opr()) > 0); |
| 115 | EXPECT_TRUE(opr_rst.count(x.node()->owner_opr()) > 0); |
| 116 | EXPECT_TRUE(var_rst.count(w1.node()) == 0); |
| 117 | EXPECT_TRUE(var_rst.count(b1.node()) == 0); |
| 118 | EXPECT_TRUE(var_rst.count(w2.node()) == 0); |
| 119 | EXPECT_TRUE(var_rst.count(b2.node()) == 0); |
| 120 | } |
nothing calls this directly
no test coverage detected