CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
142 lines
4.1 KiB
C++
142 lines
4.1 KiB
C++
//===-- reduce-chunk-list.cpp - Reduce a chunks list to its minimal size --===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// See the llvm-project/llvm/docs/ProgrammersManual.rst to see how to use this
|
|
// tool
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
#include "llvm/Support/IntegerInclusiveInterval.h"
|
|
#include "llvm/Support/Program.h"
|
|
|
|
using namespace llvm;
|
|
|
|
static cl::opt<std::string> ReproductionCmd(cl::Positional, cl::Required);
|
|
|
|
static cl::opt<std::string> StartChunks(cl::Positional, cl::Required);
|
|
|
|
static cl::opt<bool> Pessimist("pessimist", cl::init(false));
|
|
|
|
namespace {
|
|
|
|
bool isStillInteresting(ArrayRef<IntegerInclusiveInterval> Chunks) {
|
|
IntegerInclusiveIntervalUtils::IntervalList SimpleChunks =
|
|
IntegerInclusiveIntervalUtils::mergeAdjacentIntervals(Chunks);
|
|
|
|
std::string ChunkStr;
|
|
{
|
|
raw_string_ostream OS(ChunkStr);
|
|
IntegerInclusiveIntervalUtils::printIntervals(OS, SimpleChunks);
|
|
}
|
|
|
|
errs() << "Checking with: " << ChunkStr << "\n";
|
|
|
|
std::vector<StringRef> Argv;
|
|
Argv.push_back(ReproductionCmd);
|
|
Argv.push_back(ChunkStr);
|
|
|
|
std::string ErrMsg;
|
|
bool ExecutionFailed;
|
|
int Result = sys::ExecuteAndWait(Argv[0], Argv, std::nullopt, {}, 0, 0,
|
|
&ErrMsg, &ExecutionFailed);
|
|
if (ExecutionFailed) {
|
|
errs() << "failed to execute : " << Argv[0] << " : " << ErrMsg << "\n";
|
|
exit(1);
|
|
}
|
|
|
|
bool Res = Result != 0;
|
|
if (Res) {
|
|
errs() << "SUCCESS : Still Interesting\n";
|
|
} else {
|
|
errs() << "FAILURE : Not Interesting\n";
|
|
}
|
|
return Res;
|
|
}
|
|
|
|
bool increaseGranularity(IntegerInclusiveIntervalUtils::IntervalList &Chunks) {
|
|
errs() << "Increasing granularity\n";
|
|
IntegerInclusiveIntervalUtils::IntervalList NewChunks;
|
|
bool SplitOne = false;
|
|
|
|
for (auto &C : Chunks) {
|
|
if (C.getBegin() == C.getEnd()) {
|
|
NewChunks.push_back(C);
|
|
} else {
|
|
int64_t Half = (C.getBegin() + C.getEnd()) / 2;
|
|
NewChunks.push_back(IntegerInclusiveInterval(C.getBegin(), Half));
|
|
NewChunks.push_back(IntegerInclusiveInterval(Half + 1, C.getEnd()));
|
|
SplitOne = true;
|
|
}
|
|
}
|
|
if (SplitOne) {
|
|
Chunks = std::move(NewChunks);
|
|
}
|
|
return SplitOne;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main(int argc, char **argv) {
|
|
cl::ParseCommandLineOptions(argc, argv);
|
|
|
|
auto ExpectedChunks =
|
|
IntegerInclusiveIntervalUtils::parseIntervals(StartChunks, ',');
|
|
if (!ExpectedChunks) {
|
|
handleAllErrors(ExpectedChunks.takeError(), [](const StringError &E) {
|
|
errs() << "Error parsing chunks: " << E.getMessage() << "\n";
|
|
});
|
|
return 1;
|
|
}
|
|
IntegerInclusiveIntervalUtils::IntervalList CurrChunks =
|
|
std::move(*ExpectedChunks);
|
|
|
|
auto Program = sys::findProgramByName(ReproductionCmd);
|
|
if (!Program) {
|
|
errs() << "failed to find command : " << ReproductionCmd << "\n";
|
|
return 1;
|
|
}
|
|
ReproductionCmd.setValue(Program.get());
|
|
|
|
errs() << "Input Checking:\n";
|
|
if (!isStillInteresting(CurrChunks)) {
|
|
errs() << "starting chunks are not interesting\n";
|
|
return 1;
|
|
}
|
|
if (CurrChunks.size() == 1)
|
|
increaseGranularity(CurrChunks);
|
|
if (Pessimist)
|
|
while (increaseGranularity(CurrChunks))
|
|
/* empty body */;
|
|
while (1) {
|
|
for (int Idx = (CurrChunks.size() - 1); Idx >= 0; Idx--) {
|
|
if (CurrChunks.size() == 1)
|
|
break;
|
|
|
|
IntegerInclusiveInterval Testing = CurrChunks[Idx];
|
|
errs() << "Trying to remove : ";
|
|
Testing.print(errs());
|
|
errs() << "\n";
|
|
|
|
CurrChunks.erase(CurrChunks.begin() + Idx);
|
|
|
|
if (!isStillInteresting(CurrChunks))
|
|
CurrChunks.insert(CurrChunks.begin() + Idx, Testing);
|
|
}
|
|
bool HasSplit = increaseGranularity(CurrChunks);
|
|
if (!HasSplit)
|
|
break;
|
|
}
|
|
|
|
errs() << "Minimal Chunks = ";
|
|
IntegerInclusiveIntervalUtils::printIntervals(
|
|
llvm::errs(),
|
|
IntegerInclusiveIntervalUtils::mergeAdjacentIntervals(CurrChunks));
|
|
errs() << "\n";
|
|
}
|