[polly] [clang] [llvm] [polly][ScheduleOptimizer] Fix long compile time(hang) reported in polly (PR #75141)
https://github.com/kartcq updated https://github.com/llvm/llvm-project/pull/75141 >From 98745d850c588eaf9b5d2ac6f71c79873107501f Mon Sep 17 00:00:00 2001 From: kartcq Date: Mon, 11 Dec 2023 05:22:33 -0800 Subject: [PATCH 1/3] [polly][ScheduleOptimizer] Bail out on exceeding Schedule compute's ISL quota There is no upper cap set on current Schedule Optimizer to compute schedule. In some cases a very long compile time taken to compute the schedule resulting in hang kind of behavior. This patch introduces a flag 'polly-schedule-computeout' to pass the cap which is initialized to 30. This patch handles the compute out cases by bailing out and exiting gracefully. Change-Id: Id506832df4ae8d3f140579ba10cf570e18efac62 --- polly/lib/Transform/ScheduleOptimizer.cpp | 25 + .../ScheduleOptimizer/schedule_computeout.ll | 97 +++ 2 files changed, 122 insertions(+) create mode 100644 polly/test/ScheduleOptimizer/schedule_computeout.ll diff --git a/polly/lib/Transform/ScheduleOptimizer.cpp b/polly/lib/Transform/ScheduleOptimizer.cpp index 35a0a4def0403d..8ee2b66339adbc 100644 --- a/polly/lib/Transform/ScheduleOptimizer.cpp +++ b/polly/lib/Transform/ScheduleOptimizer.cpp @@ -96,6 +96,13 @@ static cl::opt cl::desc("Maximize the band depth (yes/no)"), cl::Hidden, cl::init("yes"), cl::cat(PollyCategory)); +static cl::opt +ScheduleComputeOut("polly-schedule-computeout", + cl::desc("Bound the scheduler by maximal amount" +"of computational steps. "), + cl::Hidden, cl::init(30), cl::ZeroOrMore, + cl::cat(PollyCategory)); + static cl::opt GreedyFusion("polly-loopfusion-greedy", cl::desc("Aggressively try to fuse everything"), cl::Hidden, @@ -860,7 +867,25 @@ static void runIslScheduleOptimizer( SC = SC.set_proximity(Proximity); SC = SC.set_validity(Validity); SC = SC.set_coincidence(Validity); + +// Save error handling behavior +long MaxOperations = isl_ctx_get_max_operations(Ctx); +isl_ctx_set_max_operations(Ctx, ScheduleComputeOut); Schedule = SC.compute_schedule(); +bool ScheduleQuota = false; +if (isl_ctx_last_error(Ctx) == isl_error_quota) { + isl_ctx_reset_error(Ctx); + LLVM_DEBUG( + dbgs() << "Schedule optimizer calculation exceeds ISL quota\n"); + ScheduleQuota = true; +} +isl_options_set_on_error(Ctx, ISL_ON_ERROR_ABORT); +isl_ctx_reset_operations(Ctx); +isl_ctx_set_max_operations(Ctx, MaxOperations); + +if (ScheduleQuota) + return; + isl_options_set_on_error(Ctx, OnErrorStatus); ScopsRescheduled++; diff --git a/polly/test/ScheduleOptimizer/schedule_computeout.ll b/polly/test/ScheduleOptimizer/schedule_computeout.ll new file mode 100644 index 00..3e768e02c8a740 --- /dev/null +++ b/polly/test/ScheduleOptimizer/schedule_computeout.ll @@ -0,0 +1,97 @@ +; RUN: opt -S -polly-optree -polly-delicm -polly-opt-isl -polly-schedule-computeout=10 -debug-only="polly-opt-isl" < %s 2>&1 | FileCheck %s +; Bailout if the computations of schedule compute exceeds the max scheduling quota. +; Max compute out is initialized to 30, Here it is set to 10 for test purpose. + +target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" +target triple = "aarch64-unknown-linux-gnu" + +@a = dso_local local_unnamed_addr global ptr null, align 8 +@b = dso_local local_unnamed_addr global ptr null, align 8 +@c = dso_local local_unnamed_addr global ptr null, align 8 + +define dso_local void @foo(i32 noundef %I, i32 noundef %J, i32 noundef %K1, i32 noundef %K2, i32 noundef %L1, i32 noundef %L2) local_unnamed_addr { +entry: + %j = alloca i32, align 4 + store volatile i32 0, ptr %j, align 4 + %j.0.j.0.j.0.54 = load volatile i32, ptr %j, align 4 + %cmp55 = icmp slt i32 %j.0.j.0.j.0.54, %J + br i1 %cmp55, label %for.body.lr.ph, label %for.cond.cleanup + +for.body.lr.ph: ; preds = %entry + %0 = load ptr, ptr @a, align 8 + %1 = load ptr, ptr @b, align 8 + %2 = load ptr, ptr %1, align 8 + %cmp352 = icmp slt i32 %L1, %L2 + %cmp750 = icmp slt i32 %K1, %K2 + %3 = sext i32 %K1 to i64 + %4 = sext i32 %L1 to i64 + br label %for.body + +for.cond.cleanup: ; preds = %for.cond.cleanup4, %entry + ret void + +for.body: ; preds = %for.cond.cleanup4, %for.body.lr.ph + br i1 %cmp352, label %for.cond6.preheader.preheader, label %for.cond.cleanup4 + +for.cond6.preheader.preheader:; preds = %for.body + %wide.trip.count66 = sext i32 %L2 to i64 + br label %for.cond6.preheader + +for.cond6.preheader: ; preds = %for.cond.cleanup8, %for.cond6.preheader.preheader + %indvars.iv61 = phi i64 [ %4, %for.cond6.preheader.preheader ], [ %indvars.iv.next62, %fo
[polly] [clang] [llvm] [polly][ScheduleOptimizer] Fix long compile time(hang) reported in polly (PR #75141)
https://github.com/kartcq updated https://github.com/llvm/llvm-project/pull/75141 >From 98745d850c588eaf9b5d2ac6f71c79873107501f Mon Sep 17 00:00:00 2001 From: kartcq Date: Mon, 11 Dec 2023 05:22:33 -0800 Subject: [PATCH 1/2] [polly][ScheduleOptimizer] Bail out on exceeding Schedule compute's ISL quota There is no upper cap set on current Schedule Optimizer to compute schedule. In some cases a very long compile time taken to compute the schedule resulting in hang kind of behavior. This patch introduces a flag 'polly-schedule-computeout' to pass the cap which is initialized to 30. This patch handles the compute out cases by bailing out and exiting gracefully. Change-Id: Id506832df4ae8d3f140579ba10cf570e18efac62 --- polly/lib/Transform/ScheduleOptimizer.cpp | 25 + .../ScheduleOptimizer/schedule_computeout.ll | 97 +++ 2 files changed, 122 insertions(+) create mode 100644 polly/test/ScheduleOptimizer/schedule_computeout.ll diff --git a/polly/lib/Transform/ScheduleOptimizer.cpp b/polly/lib/Transform/ScheduleOptimizer.cpp index 35a0a4def0403d..8ee2b66339adbc 100644 --- a/polly/lib/Transform/ScheduleOptimizer.cpp +++ b/polly/lib/Transform/ScheduleOptimizer.cpp @@ -96,6 +96,13 @@ static cl::opt cl::desc("Maximize the band depth (yes/no)"), cl::Hidden, cl::init("yes"), cl::cat(PollyCategory)); +static cl::opt +ScheduleComputeOut("polly-schedule-computeout", + cl::desc("Bound the scheduler by maximal amount" +"of computational steps. "), + cl::Hidden, cl::init(30), cl::ZeroOrMore, + cl::cat(PollyCategory)); + static cl::opt GreedyFusion("polly-loopfusion-greedy", cl::desc("Aggressively try to fuse everything"), cl::Hidden, @@ -860,7 +867,25 @@ static void runIslScheduleOptimizer( SC = SC.set_proximity(Proximity); SC = SC.set_validity(Validity); SC = SC.set_coincidence(Validity); + +// Save error handling behavior +long MaxOperations = isl_ctx_get_max_operations(Ctx); +isl_ctx_set_max_operations(Ctx, ScheduleComputeOut); Schedule = SC.compute_schedule(); +bool ScheduleQuota = false; +if (isl_ctx_last_error(Ctx) == isl_error_quota) { + isl_ctx_reset_error(Ctx); + LLVM_DEBUG( + dbgs() << "Schedule optimizer calculation exceeds ISL quota\n"); + ScheduleQuota = true; +} +isl_options_set_on_error(Ctx, ISL_ON_ERROR_ABORT); +isl_ctx_reset_operations(Ctx); +isl_ctx_set_max_operations(Ctx, MaxOperations); + +if (ScheduleQuota) + return; + isl_options_set_on_error(Ctx, OnErrorStatus); ScopsRescheduled++; diff --git a/polly/test/ScheduleOptimizer/schedule_computeout.ll b/polly/test/ScheduleOptimizer/schedule_computeout.ll new file mode 100644 index 00..3e768e02c8a740 --- /dev/null +++ b/polly/test/ScheduleOptimizer/schedule_computeout.ll @@ -0,0 +1,97 @@ +; RUN: opt -S -polly-optree -polly-delicm -polly-opt-isl -polly-schedule-computeout=10 -debug-only="polly-opt-isl" < %s 2>&1 | FileCheck %s +; Bailout if the computations of schedule compute exceeds the max scheduling quota. +; Max compute out is initialized to 30, Here it is set to 10 for test purpose. + +target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" +target triple = "aarch64-unknown-linux-gnu" + +@a = dso_local local_unnamed_addr global ptr null, align 8 +@b = dso_local local_unnamed_addr global ptr null, align 8 +@c = dso_local local_unnamed_addr global ptr null, align 8 + +define dso_local void @foo(i32 noundef %I, i32 noundef %J, i32 noundef %K1, i32 noundef %K2, i32 noundef %L1, i32 noundef %L2) local_unnamed_addr { +entry: + %j = alloca i32, align 4 + store volatile i32 0, ptr %j, align 4 + %j.0.j.0.j.0.54 = load volatile i32, ptr %j, align 4 + %cmp55 = icmp slt i32 %j.0.j.0.j.0.54, %J + br i1 %cmp55, label %for.body.lr.ph, label %for.cond.cleanup + +for.body.lr.ph: ; preds = %entry + %0 = load ptr, ptr @a, align 8 + %1 = load ptr, ptr @b, align 8 + %2 = load ptr, ptr %1, align 8 + %cmp352 = icmp slt i32 %L1, %L2 + %cmp750 = icmp slt i32 %K1, %K2 + %3 = sext i32 %K1 to i64 + %4 = sext i32 %L1 to i64 + br label %for.body + +for.cond.cleanup: ; preds = %for.cond.cleanup4, %entry + ret void + +for.body: ; preds = %for.cond.cleanup4, %for.body.lr.ph + br i1 %cmp352, label %for.cond6.preheader.preheader, label %for.cond.cleanup4 + +for.cond6.preheader.preheader:; preds = %for.body + %wide.trip.count66 = sext i32 %L2 to i64 + br label %for.cond6.preheader + +for.cond6.preheader: ; preds = %for.cond.cleanup8, %for.cond6.preheader.preheader + %indvars.iv61 = phi i64 [ %4, %for.cond6.preheader.preheader ], [ %indvars.iv.next62, %fo
[polly] [clang] [llvm] [polly][ScheduleOptimizer] Fix long compile time(hang) reported in polly (PR #75141)
https://github.com/kartcq edited https://github.com/llvm/llvm-project/pull/75141 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits