Skip to content
Open
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
53 changes: 41 additions & 12 deletions include/common.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <CL/sycl.hpp>

#include <cstdlib>
#include <string>
#include <iostream>
#include <cassert>
Expand Down Expand Up @@ -132,19 +133,19 @@ class BenchmarkManager
};


class BenchmarkApp
{
BenchmarkArgs args;
cl::sycl::queue device_queue;
std::unordered_set<std::string> benchmark_names;

public:
BenchmarkApp(int argc, char** argv)
{
try{
args = BenchmarkCommandLine{argc, argv}.getBenchmarkArgs();
class BenchmarkApp {
public:
BenchmarkApp(int argc, char** argv) {
std::stringstream ss;
for(int i = 0; i < argc; ++i) {
ss << " " << argv[i];
}
catch(std::exception& e){
self_call = ss.str();
is_meta_run = getenv(run_env_var) == nullptr;

try {
args = BenchmarkCommandLine{argc, argv}.getBenchmarkArgs();
} catch(std::exception& e) {
std::cerr << "Error while parsing command lines: " << e.what() << std::endl;
}
}
Expand All @@ -169,6 +170,13 @@ class BenchmarkApp
throw std::runtime_error("Duplicate benchmark name");
}

if(is_meta_run) {
spawnBenchmark(name);
return;
} else if(!shouldRun(name)) {
return;
}

BenchmarkManager<Benchmark> mgr(args);

// Add hooks to benchmark manager, perhaps depending on command line
Expand All @@ -192,4 +200,25 @@ class BenchmarkApp
std::cerr << "Error: " << e.what() << std::endl;
}
}

private:
const char* run_env_var = "__SYCL_BENCH_RUN";
std::string self_call;
bool is_meta_run = false;

BenchmarkArgs args;
cl::sycl::queue device_queue;
std::unordered_set<std::string> benchmark_names;

void spawnBenchmark(const std::string& name) const {
std::stringstream cmd;
cmd << run_env_var << "=\"" << name << "\"";
cmd << self_call;
std::system(cmd.str().c_str());
}

bool shouldRun(const std::string& name) const {
assert(!is_meta_run);
return std::string(getenv(run_env_var)) == name;
}
};