diff --git a/tools/onnx_subgraph/include/partition.h b/tools/onnx_subgraph/include/partition.h new file mode 100644 index 00000000000..4de5b53678a --- /dev/null +++ b/tools/onnx_subgraph/include/partition.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed 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. + */ + +#ifndef __TOOLS_ONNX_SUBGRAPH_PARTITION_H__ +#define __TOOLS_ONNX_SUBGRAPH_PARTITION_H__ + +#include "onnx.pb.h" +#include "device.h" +#include "graph.h" + +// Priority setting when OPs can be supported by both CPU & NPU, and performance is same on both +enum PartitionStrategy +{ + SPILTE_CPU_STRUCTURE_FIRST, + SPILTE_NPU_STRUCTURE_FIRST, + AUTOMATIC_SEARCH +}; + +/** + * @brief Partition the ONNX graph into subgraphs and produce cutting instructions. + * + * @param [in] g The ONNX graph to be partitioned. + * @param [in] d The device information for partitioning. + * @param [in] strategy The partition strategy to be used (deprecated). + * @param [in] node_io_size The input/output size information for each node. + * @pre The ONNX graph should be valid and the device information should be properly set. + * @post The graph is partitioned into subgraphs, and the results are stored in Subgraphs and + * otherSubgraphs. + * @exception None + * @return None + */ +void PartitionGraph(const onnx::GraphProto &g, Device &d, PartitionStrategy strategy, + const std::unordered_map &node_io_size); + +#endif // __TOOLS_ONNX_SUBGRAPH_PARTITION_H__ diff --git a/tools/onnx_subgraph/src/lib/partition.cpp b/tools/onnx_subgraph/src/lib/partition.cpp new file mode 100644 index 00000000000..4159932e72d --- /dev/null +++ b/tools/onnx_subgraph/src/lib/partition.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed 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. + */ + +#include "partition.h" +#include +#include +#include + +#define MAX_DEPTH 1000 + +void PartitionGraph(const onnx::GraphProto &g, Device &d, PartitionStrategy strategy, + const std::unordered_map &node_io_size) +{ + return; +} diff --git a/tools/onnx_subgraph/src/main.cpp b/tools/onnx_subgraph/src/main.cpp index 1d41d9d72b7..39f2c5b6684 100644 --- a/tools/onnx_subgraph/src/main.cpp +++ b/tools/onnx_subgraph/src/main.cpp @@ -16,6 +16,7 @@ #include "graph.h" #include "device.h" +#include "partition.h" namespace fs = std::filesystem; @@ -79,6 +80,9 @@ int main(int argc, char *argv[]) Device target; target.updateOnnxFile(onnxFile); target.GetDeviceJson(confFile); + std::unordered_map node_io_size; + PartitionGraph(g, target, PartitionStrategy::SPILTE_CPU_STRUCTURE_FIRST, node_io_size); + std::cout << "PartitionGraph done." << std::endl; return 0; }