Skip to content

Commit

Permalink
make kernels depend each other, use original variables and access order
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmetyusufoglu committed Nov 11, 2024
1 parent 8fefd70 commit 80a0840
Show file tree
Hide file tree
Showing 2 changed files with 322 additions and 124 deletions.
66 changes: 54 additions & 12 deletions benchmarks/babelstream/src/babelStreamCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,44 @@ namespace
// To prevent timeouts in CI, a smaller default value is used.
[[maybe_unused]] auto arraySizeMain = 1024 * 1024;


// Minimum array size to be used.
[[maybe_unused]] constexpr auto minArrSize = 1024 * 128;

// Scalar value for Mul and Triad kernel parameters.
[[maybe_unused]] constexpr auto scalarVal = 2.0f;
[[maybe_unused]] constexpr double scalarVal = 0.4;

// Block thread extent for DotKernel test work division parameters.
[[maybe_unused]] constexpr auto blockThreadExtentMain = 1024;
[[maybe_unused]] constexpr auto dotGridBlockExtent = 256;

// Number of runs for each kernel, can be changed by command line arguments.
// At least 100 runs are recommended for good benchmarking.
// To prevent timeouts in CI, a small value is used.
[[maybe_unused]] auto numberOfRuns = 2;

// Data input value for babelstream.
[[maybe_unused]] constexpr auto valA = 1.0f;
// Data input values for babelstream.
[[maybe_unused]] constexpr double valA = 0.1;
[[maybe_unused]] constexpr double valB = 0.2;
// Change this if triad kernel is going to be run alone
[[maybe_unused]] constexpr double valC = 0.0;

//! Values corresponding to the command line argument run-kernels
enum class KernelsToRun
{
All, // init, add, copy, mul, triad
Triad, // only init and triad
NStream // only init and nstream
};

[[maybe_unused]] KernelsToRun kernelsToBeExecuted{KernelsToRun::All};

//! handleCustomArguments Gets custom cmd line arguments from the all arguments.
//! Namely gets --array-size=1234 and --number-runs=1234 and keeps the others which are
//! command line args for Catch2 session.
[[maybe_unused]] static void handleCustomArguments(int& argc, char* argv[])
{
std::vector<char*> newArgv;
newArgv.push_back(argv[0]); // Keep the program name
std::vector<char*> newArgv({argv[0]}); // keep program name

for(int i = 1; i < argc; ++i)
{
Expand Down Expand Up @@ -79,6 +93,26 @@ namespace
std::cout << "Using default number of runs: " << numberOfRuns << std::endl;
}
}
else if(arg.rfind("--run-kernels=", 0) == 0)
{
auto const kernelsString = std::string(arg.substr(14)); // Convert to integer
if(kernelsString == "nstream")
{
std::cout << "Only nstream kernel will be executed." << std::endl;
kernelsToBeExecuted = KernelsToRun::NStream;
}
else if(kernelsString == "triad")
{
kernelsToBeExecuted = KernelsToRun::Triad;
std::cout << "Only triad kernel will be executed." << std::endl;
}
else if(kernelsString == "all")
{
// The variable kernelsToBeExecuted default value is "all";
kernelsToBeExecuted = KernelsToRun::All;
std::cout << "All 5 babelstream kernels are going to be executed." << std::endl;
}
}
else
{
// If it's not a custom argument, keep it for Catch2
Expand All @@ -89,6 +123,10 @@ namespace
std::cout << "Usage of custom arguments (arguments which are not Catch2): --array-size=33554432 and "
"--number-runs=100"
<< std::endl;
std::cout << "If you want to run only nstream kernel or triad kernel use --run-kernels=nstream or "
"--run-kernels=triad. Otherwise all 5 standar kernels will be run. Init, Copy, Mul, Add, "
"Triad. (and Dot kernel, if multi-threaded acc is used.)"
<< std::endl;
}
}

Expand All @@ -111,7 +149,7 @@ namespace
{
if constexpr(std::is_floating_point_v<T>)
{
return std::fabs(a - b) < std::numeric_limits<T>::epsilon() * static_cast<T>(100.0);
return std::fabs(a - b) < (std::numeric_limits<T>::epsilon() * static_cast<T>(100.0));
}
else if constexpr(std::is_integral_v<T>)
{
Expand Down Expand Up @@ -219,6 +257,7 @@ namespace
WorkDivTriad,
WorkDivMult,
WorkDivDot,
WorkDivNStream,
DeviceName,
TimeUnit,
KernelNames,
Expand Down Expand Up @@ -279,6 +318,8 @@ namespace
return "WorkDivMult ";
case BMInfoDataType::WorkDivDot:
return "WorkDivDot ";
case BMInfoDataType::WorkDivNStream:
return "WorkDivNStream";
default:
return "";
}
Expand Down Expand Up @@ -353,11 +394,13 @@ namespace
{
std::stringstream ss;
// define lambda to add values to a string stream created already
auto addItemValue = [&, this](BMInfoDataType item) {
ss << "\n" << typeToTypeStr(item) << ":" << metaDataMap.at(item);
auto addItemValue = [&, this](BMInfoDataType item)
{
if(metaDataMap.count(item) != 0)
ss << "\n" << typeToTypeStr(item) << ":" << metaDataMap.at(item);
};

// Initially chose some data to serialize
// Initially chose some data to serialize from the meta-data map to add to string stream
ss << "\n";
addItemValue(BMInfoDataType::AcceleratorType);
addItemValue(BMInfoDataType::NumRuns);
Expand All @@ -369,9 +412,8 @@ namespace
addItemValue(BMInfoDataType::WorkDivMult);
addItemValue(BMInfoDataType::WorkDivAdd);
addItemValue(BMInfoDataType::WorkDivTriad);
if(metaDataMap.count(BMInfoDataType::WorkDivDot) != 0)
addItemValue(BMInfoDataType::WorkDivDot);

addItemValue(BMInfoDataType::WorkDivDot);
addItemValue(BMInfoDataType::WorkDivNStream);
auto getItemFromStrList = [this](BMInfoDataType item, int index) -> std::string
{
std::string const str = metaDataMap.at(item);
Expand Down
Loading

0 comments on commit 80a0840

Please sign in to comment.