Skip to content

Commit a9050c4

Browse files
authored
Merge pull request vortexgpgpu#246 from vortexgpgpu/bug_fixes
extending divergence test coverage
2 parents 17ea1cd + c569e16 commit a9050c4

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

sim/common/util.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// limitations under the License.
1313

1414
#include "util.h"
15+
#include <fstream>
16+
#include <sstream>
1517
#include <string.h>
1618

1719
// return file extension
@@ -36,4 +38,21 @@ void aligned_free(void *ptr) {
3638
// retreive the stored unaligned address and use it to free the allocation
3739
void* unaligned_addr = ((void**)ptr)[-1];
3840
free(unaligned_addr);
41+
}
42+
43+
std::string vortex::resolve_file_path(const std::string& filename, const std::string& searchPaths) {
44+
std::ifstream ifs(filename);
45+
if (!ifs) {
46+
std::stringstream ss(searchPaths);
47+
std::string path;
48+
while (std::getline(ss, path, ',')) {
49+
if (!path.empty()) {
50+
std::string filePath = path + "/" + filename;
51+
std::ifstream ifs(filePath);
52+
if (ifs)
53+
return filePath;
54+
}
55+
}
56+
}
57+
return filename;
3958
}

sim/common/util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <algorithm>
1818
#include <assert.h>
1919
#include <bitmanip.h>
20+
#include <string>
2021

2122
template <typename... Args>
2223
void unused(Args&&...) {}
@@ -94,4 +95,6 @@ class VDataCast<R, W, typename std::enable_if<(W <= 8)>::type> {
9495
}
9596
};
9697

98+
std::string resolve_file_path(const std::string& filename, const std::string& searchPaths);
99+
97100
}

tests/regression/diverge/kernel.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55

66
// Parallel Selection sort
77

8+
struct key_t {
9+
uint32_t user = 0;
10+
};
11+
12+
static __attribute__((noinline)) void hacker(key_t* key, uint32_t task_id) {
13+
key->user = task_id;
14+
}
15+
816
void kernel_body(kernel_arg_t* __UNIFORM__ arg) {
917
int32_t* src_ptr = (int32_t*)arg->src_addr;
1018
int32_t* dst_ptr = (int32_t*)arg->dst_addr;
@@ -13,6 +21,15 @@ void kernel_body(kernel_arg_t* __UNIFORM__ arg) {
1321

1422
int value = src_ptr[task_id];
1523

24+
key_t key;
25+
uint32_t samples = arg->num_points;
26+
while (samples--) {
27+
hacker(&key, task_id);
28+
if ((key.user & 0x1) == 0) {
29+
value += 1;
30+
}
31+
}
32+
1633
// none taken
1734
if (task_id >= 0x7fffffff) {
1835
value = 0;

tests/regression/diverge/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ void gen_ref_data(std::vector<int>& ref_data, const std::vector<int>& src_data,
7878
for (int i = 0; i < (int)size; ++i) {
7979
int value = src_data.at(i);
8080

81+
key_t key;
82+
uint32_t samples = size;
83+
while (samples--) {
84+
if ((i & 0x1) == 0) {
85+
value += 1;
86+
}
87+
}
88+
8189
// none taken
8290
if (i >= 0x7fffffff) {
8391
value = 0;

0 commit comments

Comments
 (0)