This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Subgraph API for integrating accelerators with MXNet (#12157)
* Graph partitioner and subgraph op (#11251) Graph partitioner and subgraph op Fix duplicate entry bugs (#11767) Make subgraph var node name unique (#11876) [DO NOT REVIEW] Fix bug of eliminating cycles (#11907) * Fix cycle bug * Fix decycle bug * Fix comment [DO NOT REVIEW] Subgraph API (#12104) * Initial commit * Add unit tests * Fix lint * Fix lint * Clean up * Add graph partitiong to Bind * Add property name to graph partitioning c api * Fix unit test gpu context * Address cr * Move subgraph to attrs.subgraphs and fix the example * Fix lint * Add var version unit test * Address cr * Enable unit test that was flaky * Clean up * Clean up * Clean up * Change version return type in NDArray * Clean up * Add register or get for subgraph prop registry * Address cr * Remove unnecessary code * Handle var version issue in naive engine * Delete example * Remove registration of resource request for default subgraph op * Add doc string * Improve doc string
- Loading branch information
1 parent
32c9ca7
commit a64cf7d
Showing
19 changed files
with
2,059 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/*! | ||
* Copyright (c) 2018 by Contributors | ||
* \file c_api_test.h | ||
* \brief C API of mxnet for ease of testing backend in Python | ||
*/ | ||
#ifndef MXNET_C_API_TEST_H_ | ||
#define MXNET_C_API_TEST_H_ | ||
|
||
/*! \brief Inhibit C++ name-mangling for MXNet functions. */ | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif // __cplusplus | ||
|
||
#include <mxnet/c_api.h> | ||
|
||
/*! | ||
* \brief This API partitions a graph only by the operator names | ||
* provided by users. This will attach a DefaultSubgraphProperty | ||
* to the input graph for partitioning. This function should be | ||
* used only for the testing purpose. | ||
*/ | ||
MXNET_DLL int MXPartitionGraphByOpNames(SymbolHandle sym_handle, | ||
const char* prop_name, | ||
const mx_uint num_ops, | ||
const char** op_names, | ||
SymbolHandle* ret_sym_handle); | ||
|
||
/*! | ||
* \brief Given a subgraph property name, use the provided op names | ||
* as the op_names attribute for that subgraph property, instead of | ||
* the predefined one. This is only for the purpose of testing. | ||
*/ | ||
MXNET_DLL int MXSetSubgraphPropertyOpNames(const char* prop_name, | ||
const mx_uint num_ops, | ||
const char** op_names); | ||
|
||
/*! | ||
* \brief Given a subgraph property name, delete the op name set | ||
* in the SubgraphPropertyOpNameSet. | ||
*/ | ||
MXNET_DLL int MXRemoveSubgraphPropertyOpNames(const char* prop_name); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif // __cplusplus | ||
|
||
#endif // MXNET_C_API_TEST_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/*! | ||
* Copyright (c) 2018 by Contributors | ||
* \file c_api_test.cc | ||
* \brief C API of mxnet for the ease of testing backend in Python | ||
*/ | ||
#include <mxnet/c_api_test.h> | ||
#include <nnvm/pass.h> | ||
#include "./c_api_common.h" | ||
#include "../operator/subgraph/subgraph_property.h" | ||
|
||
int MXPartitionGraphByOpNames(SymbolHandle sym_handle, | ||
const char* prop_name, | ||
const mx_uint num_ops, | ||
const char** op_names, | ||
SymbolHandle* ret_sym_handle) { | ||
nnvm::Symbol* s = new nnvm::Symbol(); | ||
API_BEGIN(); | ||
std::unordered_set<std::string> op_name_set; | ||
for (size_t i = 0; i < num_ops; ++i) { | ||
op_name_set.emplace(op_names[i]); | ||
} | ||
nnvm::Symbol* sym = static_cast<nnvm::Symbol*>(sym_handle); | ||
*s = sym->Copy(); | ||
nnvm::Graph g; | ||
g.outputs = s->outputs; | ||
if (!op_name_set.empty()) { | ||
mxnet::op::SubgraphPropertyPtr property | ||
= mxnet::op::SubgraphPropertyRegistry::Get()->CreateSubgraphProperty(prop_name); | ||
property->SetAttr("op_names", op_name_set); | ||
g.attrs["subgraph_property"] = std::make_shared<nnvm::any>(std::move(property)); | ||
} | ||
g = nnvm::ApplyPass(std::move(g), "PartitionGraph"); | ||
s->outputs = g.outputs; | ||
*ret_sym_handle = s; | ||
API_END_HANDLE_ERROR(delete s); | ||
} | ||
|
||
int MXSetSubgraphPropertyOpNames(const char* prop_name, | ||
const mx_uint num_ops, | ||
const char** op_names) { | ||
API_BEGIN(); | ||
std::unordered_set<std::string> op_name_set; | ||
for (size_t i = 0; i < num_ops; ++i) { | ||
op_name_set.emplace(op_names[i]); | ||
} | ||
(*mxnet::op::SubgraphPropertyOpNameSet::Get())[prop_name] = op_name_set; | ||
API_END(); | ||
} | ||
|
||
int MXRemoveSubgraphPropertyOpNames(const char* prop_name) { | ||
API_BEGIN(); | ||
mxnet::op::SubgraphPropertyOpNameSet::Get()->erase(prop_name); | ||
API_END(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.