From aaeb7ba644088ec605e6650eebe904db919559c9 Mon Sep 17 00:00:00 2001 From: tinebp Date: Sat, 3 May 2025 21:34:10 -0700 Subject: [PATCH] extending divergence test coverage --- sim/common/util.cpp | 19 +++++++++++++++++++ sim/common/util.h | 3 +++ tests/regression/diverge/kernel.cpp | 17 +++++++++++++++++ tests/regression/diverge/main.cpp | 8 ++++++++ 4 files changed, 47 insertions(+) diff --git a/sim/common/util.cpp b/sim/common/util.cpp index 8cd67bb33..ff22817b9 100644 --- a/sim/common/util.cpp +++ b/sim/common/util.cpp @@ -12,6 +12,8 @@ // limitations under the License. #include "util.h" +#include +#include #include // return file extension @@ -36,4 +38,21 @@ void aligned_free(void *ptr) { // retreive the stored unaligned address and use it to free the allocation void* unaligned_addr = ((void**)ptr)[-1]; free(unaligned_addr); +} + +std::string vortex::resolve_file_path(const std::string& filename, const std::string& searchPaths) { + std::ifstream ifs(filename); + if (!ifs) { + std::stringstream ss(searchPaths); + std::string path; + while (std::getline(ss, path, ',')) { + if (!path.empty()) { + std::string filePath = path + "/" + filename; + std::ifstream ifs(filePath); + if (ifs) + return filePath; + } + } + } + return filename; } \ No newline at end of file diff --git a/sim/common/util.h b/sim/common/util.h index fd234d279..c4b47ac49 100644 --- a/sim/common/util.h +++ b/sim/common/util.h @@ -17,6 +17,7 @@ #include #include #include +#include template void unused(Args&&...) {} @@ -94,4 +95,6 @@ public: } }; +std::string resolve_file_path(const std::string& filename, const std::string& searchPaths); + } \ No newline at end of file diff --git a/tests/regression/diverge/kernel.cpp b/tests/regression/diverge/kernel.cpp index 70b27fa79..522a31b23 100644 --- a/tests/regression/diverge/kernel.cpp +++ b/tests/regression/diverge/kernel.cpp @@ -5,6 +5,14 @@ // Parallel Selection sort +struct key_t { + uint32_t user = 0; +}; + +static __attribute__((noinline)) void hacker(key_t* key, uint32_t task_id) { + key->user = task_id; +} + void kernel_body(kernel_arg_t* __UNIFORM__ arg) { int32_t* src_ptr = (int32_t*)arg->src_addr; int32_t* dst_ptr = (int32_t*)arg->dst_addr; @@ -13,6 +21,15 @@ void kernel_body(kernel_arg_t* __UNIFORM__ arg) { int value = src_ptr[task_id]; + key_t key; + uint32_t samples = arg->num_points; + while (samples--) { + hacker(&key, task_id); + if ((key.user & 0x1) == 0) { + value += 1; + } + } + // none taken if (task_id >= 0x7fffffff) { value = 0; diff --git a/tests/regression/diverge/main.cpp b/tests/regression/diverge/main.cpp index d858b1729..bca9a1fc0 100644 --- a/tests/regression/diverge/main.cpp +++ b/tests/regression/diverge/main.cpp @@ -78,6 +78,14 @@ void gen_ref_data(std::vector& ref_data, const std::vector& src_data, for (int i = 0; i < (int)size; ++i) { int value = src_data.at(i); + key_t key; + uint32_t samples = size; + while (samples--) { + if ((i & 0x1) == 0) { + value += 1; + } + } + // none taken if (i >= 0x7fffffff) { value = 0;