Commit 3fba1ac2 by Antonio Maiorano

Coroutine: allow a name to be passed in for routine generation

Add an optional parameter to Coroutine::finalize() to give the underlying routine a name. To support variadic args, we use a strongly-typed Name class. Note that giving a name to Coroutines is optional, but we may decide to force one to be given, as we do for Functions, as it's useful for debugging. - ReactorUnitTests Coroutine tests now pass in the test name - ComputeProgram now passes in "ComputeProgram" as a name Bug: b/174358505 Change-Id: I899e8aab5dfd5d461bc7de0e54bc0e2b72e4b4a9 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/50791 Kokoro-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarAntonio Maiorano <amaiorano@google.com>
parent 2195f7a8
......@@ -139,7 +139,7 @@ public:
// finalize() *must* be called explicitly on the same thread that
// instantiates the Coroutine instance if operator() is to be invoked on
// different threads.
inline void finalize(const Config::Edit &cfg = Config::Edit::None);
inline void finalize(const char *name = "coroutine", const Config::Edit &cfg = Config::Edit::None);
// Starts execution of the coroutine and returns a unique_ptr to a
// Stream<> that exposes the await() function for obtaining yielded
......@@ -170,11 +170,11 @@ Coroutine<Return(Arguments...)>::Coroutine()
}
template<typename Return, typename... Arguments>
void Coroutine<Return(Arguments...)>::finalize(const Config::Edit &cfg /* = Config::Edit::None */)
void Coroutine<Return(Arguments...)>::finalize(const char *name /*= "coroutine"*/, const Config::Edit &cfg /* = Config::Edit::None */)
{
if(core != nullptr)
{
routine = core->acquireCoroutine("coroutine", cfg);
routine = core->acquireCoroutine(name, cfg);
core.reset(nullptr);
}
}
......
......@@ -122,7 +122,7 @@ std::shared_ptr<sw::ComputeProgram> createProgram(vk::Device *device, const vk::
// TODO(b/119409619): use allocator.
auto program = std::make_shared<sw::ComputeProgram>(device, key.getShader(), key.getLayout(), descriptorSets);
program->generate();
program->finalize();
program->finalize("ComputeProgram");
return program;
}
......
......@@ -1907,6 +1907,7 @@ TEST(ReactorUnitTests, Coroutines_Fibonacci)
next = tmp;
}
}
function.finalize(testName().c_str());
auto coroutine = function();
......@@ -1936,6 +1937,7 @@ TEST(ReactorUnitTests, Coroutines_Parameters)
Yield(data[i]);
}
}
function.finalize(testName().c_str());
uint8_t data[] = { 10, 20, 30 };
auto coroutine = function(&data[0], 3);
......@@ -1976,6 +1978,7 @@ TEST(ReactorUnitTests, Coroutines_Vectors)
Int4 c{ 9, 10, 11, 12 };
Yield(rr::Extract(c, 1));
}
function.finalize(testName().c_str());
auto coroutine = function();
......@@ -2008,6 +2011,7 @@ TEST(ReactorUnitTests, Coroutines_NoYield)
Int a;
a = 4;
}
function.finalize(testName().c_str());
auto coroutine = function();
int out;
......@@ -2041,7 +2045,7 @@ TEST(ReactorUnitTests, Coroutines_Parallel)
}
// Must call on same thread that creates the coroutine
function.finalize();
function.finalize(testName().c_str());
std::vector<std::thread> threads;
const size_t numThreads = 100;
......@@ -2847,6 +2851,7 @@ TEST(ReactorUnitTests, Multithreaded_Coroutine)
Yield(a);
Yield(b);
}
function.finalize((testName() + "_thread" + std::to_string(t) + "_loop" + std::to_string(l)).c_str());
auto coroutine = function(t, l);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment