Skip to content

Commit 270f4fd

Browse files
authored
[CINN]Change flat_hash_map of absl to the flat_hash_map of paddle (#72465)
* [CINN]optimize CUDA launch bounds calculation and usage * [CINN]Change flat_hash_map of absl to the flat_hash_map of paddle
1 parent 6a0f5ce commit 270f4fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+198
-206
lines changed

cmake/cinn/external/absl.cmake

+2-4
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ ExternalProject_Add(
5050
BUILD_BYPRODUCTS ${ABSL_INSTALL_DIR}/lib/libabsl_throw_delegate.a
5151
BUILD_BYPRODUCTS ${ABSL_INSTALL_DIR}/lib/libabsl_bad_any_cast_impl.a
5252
BUILD_BYPRODUCTS ${ABSL_INSTALL_DIR}/lib/libabsl_bad_optional_access.a
53-
BUILD_BYPRODUCTS ${ABSL_INSTALL_DIR}/lib/libabsl_bad_variant_access.a
54-
BUILD_BYPRODUCTS ${ABSL_INSTALL_DIR}/lib/libabsl_raw_hash_set.a)
53+
BUILD_BYPRODUCTS ${ABSL_INSTALL_DIR}/lib/libabsl_bad_variant_access.a)
5554

5655
# It may be more convenient if we just include all absl libs
5756
set(ABSL_LIB_NAMES
@@ -65,8 +64,7 @@ set(ABSL_LIB_NAMES
6564
throw_delegate
6665
bad_any_cast_impl
6766
bad_optional_access
68-
bad_variant_access
69-
raw_hash_set)
67+
bad_variant_access)
7068
set(ABSL_LIBS "")
7169

7270
if(WITH_ROCM)

paddle/cinn/ast_gen_ius/tensor_group.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ void TensorGroup::MarkShareMemBuffer(const ir::Tensor& tensor,
183183
GetShareMemRootName(tensor->name);
184184
}
185185

186-
absl::flat_hash_map<std::string, ir::Tensor> TensorGroup::AllocateBuffers() {
186+
paddle::flat_hash_map<std::string, ir::Tensor> TensorGroup::AllocateBuffers() {
187187
std::unordered_set<std::string> allocated_roots;
188188
for (auto& name_tensor : name_to_tensor_) {
189189
std::string root_name = GetShareMemRootName(name_tensor.first);

paddle/cinn/ast_gen_ius/tensor_group.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
#pragma once
16-
#include <absl/container/flat_hash_map.h>
1716

1817
#include <set>
1918
#include <string>
@@ -25,7 +24,7 @@
2524
#include "paddle/cinn/ir/ir_base.h"
2625
#include "paddle/cinn/ir/tensor.h"
2726
#include "paddle/cinn/poly/stage.h"
28-
27+
#include "paddle/utils/flat_hash_map.h"
2928
namespace cinn {
3029
namespace ast_gen_ius {
3130

@@ -103,7 +102,7 @@ class TensorGroup {
103102
* Allocate buffers for Tensors in TensorGroup, it handles the shared memory
104103
* using Union-Find set algorithm.
105104
*/
106-
absl::flat_hash_map<std::string, ir::Tensor> AllocateBuffers();
105+
paddle::flat_hash_map<std::string, ir::Tensor> AllocateBuffers();
107106

108107
/**
109108
* Returns tensors in topological order and remove those args
@@ -118,7 +117,7 @@ class TensorGroup {
118117
std::set<std::string> output_tensor_names_;
119118

120119
/** collection of all tensors in this TensorGroup */
121-
absl::flat_hash_map<std::string, ir::Tensor> name_to_tensor_;
120+
paddle::flat_hash_map<std::string, ir::Tensor> name_to_tensor_;
122121

123122
/** Stores vector of tensor names, which the key tensor depends on */
124123
std::unordered_map<std::string, std::unordered_set<std::string>> ctrl_dep_;

paddle/cinn/backends/codegen_device_util.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
#pragma once
1616

17-
#include <absl/container/flat_hash_map.h>
18-
1917
#include <string>
2018
#include <tuple>
2119
#include <vector>
@@ -36,6 +34,7 @@
3634
#include "paddle/cinn/ir/utils/stmt_converter.h"
3735
#include "paddle/cinn/runtime/flags.h"
3836
#include "paddle/common/enforce.h"
37+
#include "paddle/utils/flat_hash_map.h"
3938
namespace cinn {
4039
namespace backends {
4140

paddle/cinn/backends/extern_func_emitter.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
*/
1919

2020
#pragma once
21-
#include <absl/container/flat_hash_map.h>
2221

2322
#include <memory>
2423
#include <string>
2524
#include <utility>
2625

2726
#include "paddle/cinn/backends/extern_func_protos.h"
2827
#include "paddle/cinn/ir/ir.h"
28+
#include "paddle/utils/flat_hash_map.h"
2929

3030
namespace cinn {
3131
namespace backends {
@@ -127,7 +127,7 @@ class ExternFunctionEmitterRegistry {
127127
const std::string& Lookup(const ExternFuncID& name) const;
128128

129129
private:
130-
absl::flat_hash_map<ExternFuncID, std::string> data_;
130+
paddle::flat_hash_map<ExternFuncID, std::string> data_;
131131

132132
ExternFunctionEmitterRegistry();
133133
CINN_DISALLOW_COPY_AND_ASSIGN(ExternFunctionEmitterRegistry);

paddle/cinn/backends/function_prototype.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ FunctionProto *FunctionProtoRegistry::Lookup(const std::string &name) {
142142
return nullptr;
143143
}
144144

145-
FunctionProto *FunctionProtoRegistry::Register(absl::string_view name,
145+
FunctionProto *FunctionProtoRegistry::Register(std::string name,
146146
FunctionProto *x) {
147147
#ifdef CINN_WITH_DEBUG
148148
if (FLAGS_verbose_function_register) {

paddle/cinn/backends/function_prototype.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#pragma once
1616

17-
#include <absl/container/flat_hash_map.h>
1817
#include <absl/strings/string_view.h>
1918

2019
#include <memory>
@@ -23,6 +22,7 @@
2322

2423
#include "paddle/cinn/common/common.h"
2524
#include "paddle/cinn/ir/ir.h"
25+
#include "paddle/utils/flat_hash_map.h"
2626

2727
namespace cinn {
2828
namespace backends {
@@ -118,14 +118,14 @@ struct FunctionProto {
118118

119119
class FunctionProtoRegistry {
120120
public:
121-
FunctionProto* Register(absl::string_view name, FunctionProto* x);
121+
FunctionProto* Register(std::string name, FunctionProto* x);
122122

123123
FunctionProto* Lookup(const std::string& name);
124124

125125
std::string debug_string() const;
126126

127127
private:
128-
absl::flat_hash_map<std::string, std::unique_ptr<FunctionProto>> data_;
128+
paddle::flat_hash_map<std::string, std::unique_ptr<FunctionProto>> data_;
129129
};
130130

131131
} // namespace backends

paddle/cinn/backends/llvm/codegen_llvm.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#pragma once
1616

17-
#include <absl/container/flat_hash_map.h>
1817
#include <absl/strings/string_view.h>
1918
#include <llvm/IR/Constants.h>
2019
#include <llvm/IR/Function.h>
@@ -35,6 +34,7 @@
3534
#include "paddle/cinn/ir/ir_visitor.h"
3635
#include "paddle/cinn/ir/lowered_func.h"
3736
#include "paddle/cinn/ir/module.h"
37+
#include "paddle/utils/flat_hash_map.h"
3838

3939
namespace cinn {
4040
namespace backends {
@@ -93,7 +93,7 @@ class SymbolTable {
9393
size_t num_scopes() const { return scopes_.size(); }
9494

9595
private:
96-
std::vector<absl::flat_hash_map<std::string, llvm::Value *>> scopes_;
96+
std::vector<paddle::flat_hash_map<std::string, llvm::Value *>> scopes_;
9797

9898
SymbolTable(const SymbolTable &) = delete;
9999
};
@@ -272,7 +272,7 @@ class CodeGenLLVM : public LLVMIRVisitor, public IrBuilderMixin<CodeGenLLVM> {
272272

273273
std::unique_ptr<llvm::MDBuilder> md_builder_;
274274

275-
// std::shared_ptr<absl::flat_hash_map<std::string, llvm::Value *>>
275+
// std::shared_ptr<paddle::flat_hash_map<std::string, llvm::Value *>>
276276
// named_vars_;
277277
std::shared_ptr<SymbolTable> symbol_table_;
278278
std::unordered_set<ir::_Var_ *> alias_vars_;

paddle/cinn/backends/llvm/codegen_x86.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include "paddle/cinn/backends/llvm/codegen_x86.h"
1616

17-
#include <absl/container/flat_hash_map.h>
1817
#include <llvm/IR/LLVMContext.h>
1918

2019
#include <algorithm>
@@ -31,6 +30,7 @@
3130
#include "paddle/cinn/ir/utils/ir_nodes_collector.h"
3231
#include "paddle/cinn/runtime/intrinsic.h"
3332
#include "paddle/common/enforce.h"
33+
#include "paddle/utils/flat_hash_map.h"
3434
namespace cinn::backends {
3535

3636
CodeGenX86::CodeGenX86(llvm::Module* m,

paddle/cinn/backends/llvm/codegen_x86.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414

1515
#pragma once
1616

17-
#include <absl/container/flat_hash_map.h>
1817
#include <llvm/IR/IRBuilder.h>
1918

2019
#include <memory>
2120
#include <string>
2221
#include <vector>
2322

2423
#include "paddle/cinn/backends/llvm/codegen_llvm.h"
24+
#include "paddle/utils/flat_hash_map.h"
2525

2626
namespace cinn::backends {
2727

paddle/cinn/backends/llvm/llvm_intrin_rule.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#pragma once
1616

17-
#include <absl/container/flat_hash_map.h>
1817
#include <glog/logging.h>
1918
#include <llvm/IR/Intrinsics.h>
2019

@@ -27,6 +26,7 @@
2726
#include "paddle/cinn/ir/registry.h"
2827
#include "paddle/cinn/lang/packed_func.h"
2928
#include "paddle/common/enforce.h"
29+
#include "paddle/utils/flat_hash_map.h"
3030
namespace cinn {
3131
namespace codegen {
3232

paddle/cinn/common/context.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct NameGenerator {
4646
}
4747

4848
private:
49-
absl::flat_hash_map<std::string, uint32_t> name_hint_idx_;
49+
paddle::flat_hash_map<std::string, uint32_t> name_hint_idx_;
5050
mutable std::mutex mutex_;
5151
};
5252

@@ -62,7 +62,7 @@ struct PrettyNamer {
6262
NameGenerator& GetNameGenerator() { return name_generator_; }
6363

6464
private:
65-
absl::flat_hash_map<size_t, std::string> pretty_names_;
65+
paddle::flat_hash_map<size_t, std::string> pretty_names_;
6666
NameGenerator name_generator_;
6767
};
6868

paddle/cinn/common/graph_utils.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ std::string Graph::Visualize() const {
176176
}
177177

178178
void Graph::ClearUnlinkedNodes(
179-
absl::flat_hash_map<std::string, std::vector<int>> *shape_dict,
180-
absl::flat_hash_map<std::string, Type> *type_dict,
181-
absl::flat_hash_map<std::string, std::string> *layout_dict) {
179+
paddle::flat_hash_map<std::string, std::vector<int>> *shape_dict,
180+
paddle::flat_hash_map<std::string, Type> *type_dict,
181+
paddle::flat_hash_map<std::string, std::string> *layout_dict) {
182182
PADDLE_ENFORCE_NOT_NULL(
183183
shape_dict,
184184
::common::errors::InvalidArgument(

paddle/cinn/common/graph_utils.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#pragma once
1616
//! \file This file contains the utilities of graph.
1717

18-
#include <absl/container/flat_hash_map.h>
1918
#include <glog/logging.h>
2019

2120
#include <algorithm>
@@ -32,6 +31,7 @@
3231
#include "paddle/cinn/common/shared.h"
3332
#include "paddle/cinn/common/type.h"
3433
#include "paddle/common/enforce.h"
34+
#include "paddle/utils/flat_hash_map.h"
3535
namespace cinn {
3636
namespace common {
3737

@@ -300,9 +300,9 @@ class Graph {
300300
std::string Visualize() const;
301301

302302
void ClearUnlinkedNodes(
303-
absl::flat_hash_map<std::string, std::vector<int>>* shape_dict,
304-
absl::flat_hash_map<std::string, cinn::common::Type>* type_dict,
305-
absl::flat_hash_map<std::string, std::string>* layout_dict);
303+
paddle::flat_hash_map<std::string, std::vector<int>>* shape_dict,
304+
paddle::flat_hash_map<std::string, cinn::common::Type>* type_dict,
305+
paddle::flat_hash_map<std::string, std::string>* layout_dict);
306306

307307
size_t num_nodes() const { return nodes_.size(); }
308308

paddle/cinn/common/info_registry.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
// limitations under the License.
1414

1515
#pragma once
16-
#include <absl/container/flat_hash_map.h>
1716
#include <absl/types/any.h>
1817

1918
#include <string>
20-
19+
#include "paddle/utils/flat_hash_map.h"
2120
namespace cinn {
2221
namespace common {
2322

@@ -34,7 +33,7 @@ class InfoRegistry {
3433
void Clear() { data_.clear(); }
3534

3635
private:
37-
absl::flat_hash_map<std::string, absl::any> data_;
36+
paddle::flat_hash_map<std::string, absl::any> data_;
3837
};
3938

4039
template <typename T>

paddle/cinn/common/integer_set.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -771,10 +771,10 @@ std::optional<bool> SingleIntervalIntSet::ProveSuperSet(
771771

772772
ir::Expr EnhancedSimplifyModExpr(
773773
ir::Expr e,
774-
const absl::flat_hash_map<std::string, CasInterval>& var_intervals) {
774+
const paddle::flat_hash_map<std::string, CasInterval>& var_intervals) {
775775
struct Mutator : public ir::IRMutator<ir::Expr*> {
776776
explicit Mutator(
777-
const absl::flat_hash_map<std::string, CasInterval>& var_intervals)
777+
const paddle::flat_hash_map<std::string, CasInterval>& var_intervals)
778778
: var_intervals_(var_intervals), analyzer_(var_intervals_) {}
779779

780780
void operator()(ir::Expr* expr) { Visit(expr); }
@@ -789,7 +789,7 @@ ir::Expr EnhancedSimplifyModExpr(
789789
}
790790

791791
private:
792-
const absl::flat_hash_map<std::string, CasInterval>& var_intervals_;
792+
const paddle::flat_hash_map<std::string, CasInterval>& var_intervals_;
793793
SymbolicExprAnalyzer analyzer_;
794794
};
795795

paddle/cinn/common/integer_set.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct CasInterval {
5555
friend std::ostream& operator<<(std::ostream& os, const CasInterval& i);
5656
};
5757

58-
using cas_intervals_t = absl::flat_hash_map<std::string, CasInterval>;
58+
using cas_intervals_t = paddle::flat_hash_map<std::string, CasInterval>;
5959

6060
cas_intervals_t CollectVarIntervalsOfExprs(const std::vector<ir::Expr>& exprs,
6161
bool is_lower_bound_zero = true);
@@ -146,7 +146,7 @@ cas_intervals_t MergeVarIntervals(const SingleIntervalIntSet& a,
146146

147147
ir::Expr EnhancedSimplifyModExpr(
148148
ir::Expr e,
149-
const absl::flat_hash_map<std::string, CasInterval>& var_intervals);
149+
const paddle::flat_hash_map<std::string, CasInterval>& var_intervals);
150150

151151
} // namespace common
152152
} // namespace cinn

paddle/cinn/common/ir_util.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ Expr or_all(const std::vector<Expr> &conds) {
311311
void CheckTensorUniqueInExpr(Expr expr) {
312312
auto tensor_uniq = ir::ir_utils::CollectIRNodes(
313313
expr, [](const Expr *x) { return x->as_tensor(); });
314-
absl::flat_hash_map<std::string, const ir::_Tensor_ *> tensor_names;
314+
paddle::flat_hash_map<std::string, const ir::_Tensor_ *> tensor_names;
315315
for (auto &t : tensor_uniq) {
316316
auto *tp = t.as_tensor();
317317
if (!tensor_names.count(tp->name)) {

paddle/cinn/common/ir_util.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
#pragma once
16-
#include <absl/container/flat_hash_map.h>
1716

1817
#include <map>
1918
#include <memory>
@@ -24,6 +23,7 @@
2423
#include "paddle/cinn/common/float16.h"
2524
#include "paddle/cinn/common/integer_set.h"
2625
#include "paddle/cinn/ir/ir.h"
26+
#include "paddle/utils/flat_hash_map.h"
2727

2828
namespace cinn {
2929
namespace common {

0 commit comments

Comments
 (0)