Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MetaSchedule] Add from-target Defaults for x86 VNNI Targets #13383

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/tvm/meta_schedule/mutator.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ class Mutator : public runtime::ObjectRef {
FApply f_apply, FClone f_clone, FAsString f_as_string);
/*! \brief Create default mutators for LLVM */
TVM_DLL static Map<Mutator, FloatImm, void> DefaultLLVM();
/*! \brief Create default mutators for x86 VNNI */
TVM_DLL static Map<Mutator, FloatImm, void> DefaultVNNI();
/*! \brief Create default mutators for CUDA */
TVM_DLL static Map<Mutator, FloatImm, void> DefaultCUDA();
/*! \brief Create default mutators for CUDA with TensorCore */
Expand Down
2 changes: 2 additions & 0 deletions include/tvm/meta_schedule/postproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ class Postproc : public runtime::ObjectRef {
TVM_DLL static Postproc RewriteLayout();
/*! \brief Create default postprocessors for LLVM */
TVM_DLL static Array<Postproc, void> DefaultLLVM();
/*! \brief Create default postprocessors for x86 VNNI */
TVM_DLL static Array<Postproc, void> DefaultVNNI();
/*! \brief Create default postprocessors for CUDA */
TVM_DLL static Array<Postproc, void> DefaultCUDA();
/*! \brief Create default postprocessors for CUDA with TensorCore */
Expand Down
2 changes: 2 additions & 0 deletions include/tvm/meta_schedule/schedule_rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ class ScheduleRule : public runtime::ObjectRef {

/*! \brief Create default schedule rules for LLVM */
TVM_DLL static Array<ScheduleRule, void> DefaultLLVM();
/*! \brief Create default schedule rules for x86 VNNI */
TVM_DLL static Array<ScheduleRule, void> DefaultVNNI();
/*! \brief Create default schedule rules for CUDA */
TVM_DLL static Array<ScheduleRule, void> DefaultCUDA();
/*! \brief Create default postprocessors for CUDA with TensorCore */
Expand Down
2 changes: 2 additions & 0 deletions src/meta_schedule/mutator/mutator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Map<Mutator, FloatImm> Mutator::DefaultLLVM() {
{Mutator::MutateParallel(/*max_jobs_per_core=*/16), FloatImm(DataType::Float(64), 0.02)}};
}

Map<Mutator, FloatImm> Mutator::DefaultVNNI() { return Mutator::DefaultLLVM(); }

Map<Mutator, FloatImm> Mutator::DefaultCUDA() {
return Map<Mutator, FloatImm>{
{Mutator::MutateTileSize(), FloatImm(DataType::Float(64), 0.9)},
Expand Down
8 changes: 8 additions & 0 deletions src/meta_schedule/postproc/postproc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ Array<Postproc> Postproc::DefaultLLVM() {
};
}

Array<Postproc> Postproc::DefaultVNNI() {
return Array<Postproc>{
Postproc::DisallowDynamicLoop(), Postproc::RewriteParallelVectorizeUnroll(),
Postproc::RewriteReductionBlock(), Postproc::RewriteTensorize(/*vectorize_init_loop=*/true),
Postproc::RewriteLayout(),
zxybazh marked this conversation as resolved.
Show resolved Hide resolved
};
}

Array<Postproc> Postproc::DefaultCUDA() {
return Array<Postproc>{
Postproc::DisallowDynamicLoop(),
Expand Down
45 changes: 45 additions & 0 deletions src/meta_schedule/schedule_rule/schedule_rule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,51 @@ Array<ScheduleRule> ScheduleRule::DefaultLLVM() {
};
}

Array<ScheduleRule> ScheduleRule::DefaultVNNI() {
return {
ScheduleRule::ApplyCustomRule(),
ScheduleRule::InlineConstantScalars(),
ScheduleRule::AutoInline(
zxybazh marked this conversation as resolved.
Show resolved Hide resolved
zxybazh marked this conversation as resolved.
Show resolved Hide resolved
/*into_producer=*/false,
/*into_consumer=*/true,
/*inline_const_tensor=*/true,
/*disallow_if_then_else=*/true,
/*require_injective=*/true,
/*require_ordered=*/true,
/*disallow_op=*/Array<String>{"tir.exp"}),
ScheduleRule::AddRFactor(
/*max_jobs_per_core=*/16,
/*max_innermost_factor=*/Integer(64)),
ScheduleRule::MultiLevelTilingWithIntrin(
zxybazh marked this conversation as resolved.
Show resolved Hide resolved
/*intrin_name=*/"dot_16x4_vnni",
/*structure=*/"SSRSRS",
/*tile_binds=*/NullOpt,
/*max_innermost_factor=*/Integer(64),
/*vector_load_lens=*/NullOpt,
/*reuse_read=*/NullOpt,
/*reuse_write=*/
Map<String, ObjectRef>{{"req", String("may")},
{"levels", Array<Integer>{1, 2}},
{"scope", String("global")}}),
ScheduleRule::MultiLevelTiling(
/*structure=*/"SSRSRS",
/*tile_binds=*/NullOpt,
/*max_innermost_factor=*/Integer(64),
/*vector_load_lens=*/NullOpt,
/*reuse_read=*/NullOpt,
/*reuse_write=*/
Map<String, ObjectRef>{{"req", String("may")},
{"levels", Array<Integer>{1, 2}},
{"scope", String("global")}}),
ScheduleRule::ParallelizeVectorizeUnroll(
/*max_jobs_per_core=*/16,
/*max_vectorize_extent=*/64,
/*unroll_max_steps=*/Array<Integer>{0, 16, 64, 512},
/*unroll_explicit=*/true),
ScheduleRule::RandomComputeLocation(),
};
}

Array<ScheduleRule> ScheduleRule::DefaultCUDA() {
return {
ScheduleRule::ApplyCustomRule(),
Expand Down
11 changes: 11 additions & 0 deletions src/meta_schedule/space_generator/space_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ namespace meta_schedule {

String GetRuleKindFromTarget(const Target& target) {
if (target->kind->name == "llvm") {
static const PackedFunc* f_check_vnni =
runtime::Registry::Get("tvm.topi.x86.utils.target_has_vnni");
ICHECK(*f_check_vnni != nullptr) << "The `target_has_vnni` func is not in tvm registry.";
if (target->GetAttr<String>("mcpu") &&
(*f_check_vnni)(target->GetAttr<String>("mcpu").value())) {
return "vnni";
}
return "llvm";
}
if (target->kind->name == "hexagon") {
Expand Down Expand Up @@ -79,6 +86,10 @@ void SpaceGeneratorNode::InitializeWithTuneContext(const TuneContext& context) {
default_sch_rules = ScheduleRule::DefaultHexagon();
default_postprocs = Postproc::DefaultHexagon();
default_mutator_probs = Mutator::DefaultHexagon();
} else if (kind == "vnni") {
default_sch_rules = ScheduleRule::DefaultVNNI();
default_postprocs = Postproc::DefaultVNNI();
default_mutator_probs = Mutator::DefaultVNNI();
} else {
LOG(FATAL) << "Unsupported kind: " << kind;
throw;
Expand Down