MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / test_free_memory_in_weight_preprocess

Function test_free_memory_in_weight_preprocess

src/core/test/graph/misc.cpp:1914–1989  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1912}
1913
1914void test_free_memory_in_weight_preprocess(int record_level, CompNode cn) {
1915 HostTensorGenerator<> gen;
1916 auto graph = ComputingGraph::make();
1917#if MGB_ENABLE_JSON
1918 std::unique_ptr<GraphProfiler> profiler;
1919 if (!record_level) {
1920 profiler = std::make_unique<GraphProfiler>(graph.get());
1921 }
1922#endif
1923 graph->options().graph_opt.weight_preprocess = true;
1924 graph->options().comp_node_seq_record_level = record_level;
1925 auto mkvar = [&](const char* name, const TensorShape& shp) {
1926 return opr::Host2DeviceCopy::make(*graph, gen(shp, cn)).rename(name);
1927 };
1928 auto mkcvar = [&](const char* name, const TensorShape& shp) {
1929 return opr::SharedDeviceTensor::make_const(*graph, *gen(shp, cn)).rename(name);
1930 };
1931 auto x = mkvar("x", {1, 32, 16, 16});
1932 // ConvBias test dense
1933 opr::ConvBias::Param param_conv_bias;
1934 param_conv_bias.pad_h = param_conv_bias.pad_w = 0;
1935 param_conv_bias.sparse = opr::ConvBias::Param::Sparse::DENSE;
1936 auto w1 = mkcvar("w1", {32, 32, 1, 1}), b1 = mkcvar("b1", {1, 32, 1, 1});
1937 auto conv1 = opr::ConvBias::make(x, w1, b1, param_conv_bias);
1938 Maybe<bool> wp1, wp2;
1939 conv1.node()->owner_opr()->cast_final_safe<opr::ConvBias>().setup_algo_chooser(
1940 [&](const cg::OperatorNodeBase* opr) {
1941 return try_find_any_weight_preprocess_algo(
1942 opr->cast_final_safe<opr::ConvBias>().megdnn_opr(),
1943 opr->cname(), wp1, opr->input(0)->layout(),
1944 opr->input(1)->layout(), opr->input(2)->layout(),
1945 TensorLayout{}, opr->output(0)->layout());
1946 });
1947 // Convolution
1948 opr::Convolution::Param param_conv;
1949 param_conv.pad_h = param_conv.pad_w = 0;
1950 param_conv.sparse = opr::Convolution::Param::Sparse::DENSE;
1951 auto w2 = mkcvar("w2", {32, 32, 1, 1});
1952 auto y = opr::Convolution::make(conv1, w2, param_conv);
1953 y.node()->owner_opr()->cast_final_safe<opr::Convolution>().setup_algo_chooser(
1954 [&](const cg::OperatorNodeBase* opr) {
1955 return try_find_any_weight_preprocess_algo(
1956 opr->cast_final_safe<opr::Convolution>().megdnn_opr(),
1957 opr->cname(), wp2, opr->input(0)->layout(),
1958 opr->input(1)->layout(), opr->output(0)->layout());
1959 });
1960
1961 HostTensorND host_y;
1962 auto func = graph->compile({make_callback_copy(y, host_y)});
1963 //! flag the no need memory of var
1964 func->execute();
1965 //! free the no need memory of var
1966 func->execute();
1967 auto check = [&](SymbolVar v) {
1968 ASSERT_TRUE(v.node()->contain_flag(VarNode::Flag::MEMORY_NO_NEED));
1969 ASSERT_TRUE(v.node()->dev_tensor().empty());
1970 ASSERT_TRUE(v.node()->owner_opr()
1971 ->cast_final_safe<opr::SharedDeviceTensor>()

Callers 1

TESTFunction · 0.85

Calls 15

make_constFunction · 0.85
make_callback_copyFunction · 0.85
output_fileFunction · 0.85
renameMethod · 0.80
setup_algo_chooserMethod · 0.80
get_dev_tensorMethod · 0.80
to_json_fullMethod · 0.80
makeFunction · 0.70
genFunction · 0.50
checkFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected