GetCompiledGraphSummary

Description

Queries the summary about the compiled graph. The summary information includes the feature memory size, const memory size, number of streams and events, and whether the memory can be updated. You can allocate memory based on the information, and set the base addresses of the feature memory and Const memory by calling the following APIs:

  • SetGraphConstMemoryBase: sets the base address of Const memory. The memory size is obtained from GetCompiledGraphSummary > GetConstMemorySize.
  • UpdateGraphFeatureMemoryBase: updates the base address of feature memory. The memory size is obtained from GetCompiledGraphSummary > GetFeatureMemorySize.
  • SetGraphFixedFeatureMemoryBase: sets the base address of fixed feature memory. The memory size is obtained from GetCompiledGraphSummary > GetFixedFeatureMemorySize.
  • SetGraphFixedFeatureMemoryBaseWithType: sets the base addresses of fixed feature memory with a different memory type of a graph. The memory size is obtained from GetCompiledGraphSummary > GetAllFeatureMemoryTypeSize.
  • UpdateGraphRefreshableFeatureMemoryBase: updates the base addresses of feature memory that can be refreshed except the fixed memory. The memory size is obtained from GetCompiledGraphSummary > GetRefreshableFeatureMemorySize.

Prototype

CompiledGraphSummaryPtr GetCompiledGraphSummary(uint32_t graph_id);

Parameters

Parameter

Input/Output

Description

graph_id

Input

Subgraph ID.

Returns

Parameter

Type

Description

-

CompiledGraphSummaryPtr

share_ptr of CompiledGraphSummary.

The structure of CompiledGraphSummary is as follows:

class GE_FUNC_VISIBILITY CompiledGraphSummary {
 public:
  class Builder;
  class SummaryData;
  ~CompiledGraphSummary();
  CompiledGraphSummary &operator=(const CompiledGraphSummary &) & = delete;
  CompiledGraphSummary(const CompiledGraphSummary &) = delete;
   // Return whether the graph is statically compiled. The subsequent APIs (except GetFixedFeatureMemorySize and GetAllFeatureMemoryTypeSize) for obtaining the summary information can be used only in static compilation mode.
  bool IsStatic() const;
   // Obtain the size of const memory after compilation.
  Status GetConstMemorySize(size_t &size) const;
   // Obtain the size of the full feature memory (including the fixed memory) after compilation.
  Status GetFeatureMemorySize(size_t &size) const;
   // Obtain whether the feature base address can be updated.
  Status GetFeatureMemoryBaseRefreshable (bool &v) const;
   // Obtain the input index and output index pairs of the graph with the same logical address after compilation.
  Status GetIOIndexesWithSameAddr(std::vector<std::pair<uint32_t, uint32_t>> &io_indexes) const;
 
   // Obtain the number of streams.
  Status GetStreamNum(size_t &num) const;
   // Obtain the number of events.
  Status GetEventNum(size_t &num) const;
   // This API applies only to static shape graphs to obtain the output shape for graph build. The output shape can be used to calculate the memory size occupied by outputs. For dynamic multi-profile graphs, it obtains the output shape of the maximum profile.
  Status GetOutputShapes(std::vector<ge::Shape> &shapes) const;
   // Obtain the output Dtypes of graph compilation.
  Status GetOutputDtypes(std::vector<ge::DataType> &dtypes) const;
   // Obtain the sharding information of the input (refdata) on each device.
  Status GetInputShardMethod(std::map<std::string, std::map<int32_t, std::vector<std::pair<int64_t, int64_t>>>>&device_id_to_tensor_deployment) const;

   // Obtain the total fixed memory size (applicable to static and dynamic shape graphs).
  Status GetFixedFeatureMemorySize(size_t &size) const;
   // Obtain the total size of the memory that can be refreshed except fixed memory.
  Status GetRefreshableFeatureMemorySize(size_t &sizes) const;
   // Obtain the feature memory list of all memory types. Currently, only fixed memory is included (applicable to static and dynamic shape graphs).
  std::vector<FeatureMemoryPtr> GetAllFeatureMemoryTypeSize() const;

 private:
  CompiledGraphSummary() = default;
  std::shared_ptr<SummaryData> data_{nullptr};
};

The return values of Status are as follows:

  • SUCCESS: The API is called successfully.
  • FAILED: The API fails to be called.

The return value of GetAllFeatureMemoryTypeSize is shared_ptr of feature memory in the compilation result.

The structure of FeatureMemory is as follows:

class GE_FUNC_VISIBILITY FeatureMemory {
 public:
  class Builder;
  class FeatureMemoryData;
  ~FeatureMemory();
  FeatureMemory &operator=(const FeatureMemory &) & = delete;
  FeatureMemory(const FeatureMemory &) = delete;

   // Memory Type
  MemoryType GetType() const;

   // Memory size
  size_t GetSize() const;

   // Whether the memory is fixed
  bool IsFixed() const;

 private:
  FeatureMemory() = default;
  std::shared_ptr<FeatureMemoryData> data_{nullptr};
};

Restrictions

Before calling this API, you must call CompileGraph to compile the graph.