Fixing ubsan discovery in topology tests on large machines.
Possibly: hard to test without 128 cores. I did try turning the topology
mask into a uint8_t on my 64 core machine and it passed --config=ubsan.
diff --git a/build_tools/bazel/iree.bazelrc b/build_tools/bazel/iree.bazelrc
index 368e262..693841e 100644
--- a/build_tools/bazel/iree.bazelrc
+++ b/build_tools/bazel/iree.bazelrc
@@ -188,6 +188,15 @@
build:tsan --cc_output_directory_tag=tsan
build:tsan --copt=-DTHREAD_SANITIZER
+# UBSAN (undefined behavior sanitizer)
+# https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
+build:ubsan --config=sanitizer
+build:ubsan --features=ubsan
+build:ubsan --copt=-fsanitize=undefined
+build:ubsan --linkopt=-fsanitize=undefined
+build:ubsan --linkopt=-lubsan
+build:ubsan --cc_output_directory_tag=ubsan
+
# Don't strip debug info
build:sanitizer --strip=never
# Ignore settings of `linkopts = ["-static"]` which can screw up the sanitizer.
diff --git a/iree/task/topology.c b/iree/task/topology.c
index f20f2ac..f8646ac 100644
--- a/iree/task/topology.c
+++ b/iree/task/topology.c
@@ -190,7 +190,10 @@
uint64_t mask = 0;
for (uint32_t processor_i = 0; processor_i < cache->processor_count;
++processor_i) {
- mask |= 1ull << (cache->processor_start + processor_i);
+ uint32_t i = cache->processor_start + processor_i;
+ if (i < IREE_TASK_TOPOLOGY_GROUP_BIT_COUNT) {
+ mask |= 1ull << i;
+ }
}
return mask;
}
@@ -299,6 +302,7 @@
void iree_task_topology_initialize_from_physical_cores_with_filter(
iree_task_topology_core_filter_t filter_fn, uintptr_t filter_fn_data,
iree_host_size_t max_core_count, iree_task_topology_t* out_topology) {
+ max_core_count = iree_min(max_core_count, IREE_TASK_TOPOLOGY_GROUP_BIT_COUNT);
if (!iree_task_topology_is_cpuinfo_available()) {
iree_task_topology_initialize_fallback(max_core_count, out_topology);
return;
diff --git a/iree/task/topology.h b/iree/task/topology.h
index 8a06b76..35c1820 100644
--- a/iree/task/topology.h
+++ b/iree/task/topology.h
@@ -32,6 +32,8 @@
typedef uint64_t iree_task_topology_group_mask_t;
#define IREE_TASK_TOPOLOGY_GROUP_MASK_ALL UINT64_MAX
+#define IREE_TASK_TOPOLOGY_GROUP_BIT_COUNT \
+ (sizeof(iree_task_topology_group_mask_t) * 8)
// Information about a particular group within the topology.
// Groups may be of varying levels of granularity even within the same topology