tvm
greedy.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
25 #pragma once
26 #include <tvm/arith/analyzer.h>
27 #include <tvm/runtime/device_api.h>
28 #include <tvm/tir/builtin.h>
29 #include <tvm/tir/function.h>
30 #include <tvm/tir/stmt_functor.h>
31 #include <tvm/tir/usmp/utils.h>
32 
33 #include <unordered_map>
34 #include <vector>
35 
36 namespace tvm {
37 namespace tir {
38 namespace usmp {
39 namespace algo {
40 
45 class GreedyBase {
46  public:
52  virtual Map<BufferInfo, PoolAllocation> PlanMemory(const Array<BufferInfo>& buffer_info_arr) = 0;
53 
54  protected:
58  size_t round_up_to_byte_alignment(const size_t& non_aligned_byte_offset,
59  const int& byte_alignment);
60 
64  bool IsValidPlacement(const PoolInfo& candidate_pool, const size_t& next_offset,
65  const size_t& size_bytes);
66 
71  const BufferInfo& buf_info,
72  const std::unordered_map<PoolInfo, size_t, ObjectPtrHash, ObjectPtrEqual>& pool_offsets);
73 
79  const std::vector<BufferInfo>& buffer_info_vec);
80 };
81 
82 } // namespace algo
83 } // namespace usmp
84 } // namespace tir
85 } // namespace tvm
Algebra expression simplifications.
Base class for WorkspacePoolInfo and ConstantPoolInfo.
Definition: memory_pools.h:133
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics,...
Definition: map.h:1271
Definition: utils.h:120
This is the base class for Greedy Algorithms where the sorting is specialized in the extended classes...
Definition: greedy.h:45
virtual Map< BufferInfo, PoolAllocation > PlanMemory(const Array< BufferInfo > &buffer_info_arr)=0
This function should be implemented by the extended classes to sort the BufferInfo objects based on a...
PoolInfo SelectPlacementPool(const BufferInfo &buf_info, const std::unordered_map< PoolInfo, size_t, ObjectPtrHash, ObjectPtrEqual > &pool_offsets)
Selects a pool for placement in the given set of ordered pool candidates.
size_t round_up_to_byte_alignment(const size_t &non_aligned_byte_offset, const int &byte_alignment)
Rounds up the offset to satisfy the alignement requirement.
bool IsValidPlacement(const PoolInfo &candidate_pool, const size_t &next_offset, const size_t &size_bytes)
A helper function check whether a offset is valid given the constraints.
GreedyBase()
Definition: greedy.h:47
Map< BufferInfo, PoolAllocation > PostSortAllocation(const std::vector< BufferInfo > &buffer_info_vec)
This is the base allocation function that works on sorted BufferInfo objects based on the greedy heur...
Abstract device memory management API.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Functors for tir stmts utility functions to call common functors.
TIR builtin intrinsics.
TIR Function.
Utilities for Unified Static Memory Planner.