Skip to content

Commit 2d46302

Browse files
committed
fix alignment of embedded tensor weight blobs
1 parent 4cf03f1 commit 2d46302

3 files changed

Lines changed: 53 additions & 3 deletions

File tree

.github/workflows/internal.ci.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,16 @@ jobs:
958958
artifact-path: build install deps
959959
cmd: scripts/build.py install --full -D OIDN_SANITIZER=Thread
960960

961+
build-macos-arm-ubsan:
962+
secrets: inherit
963+
uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/macos.yml@main
964+
with:
965+
project: oidn
966+
runs-on: '[ "macOS", "ARM64", "build" ]'
967+
artifact-out: build-macos-arm-ubsan
968+
artifact-path: build install deps
969+
cmd: scripts/build.py install --full -D OIDN_SANITIZER=Undefined
970+
961971
build-ios-arm:
962972
secrets: inherit
963973
uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/macos.yml@main
@@ -1076,6 +1086,21 @@ jobs:
10761086
export TBB_ENABLE_SANITIZERS=1
10771087
scripts/test.py --device cpu --minimal --log test.log
10781088
1089+
test-macos-arm-ubsan:
1090+
needs: build-macos-arm-ubsan
1091+
secrets: inherit
1092+
uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/macos.yml@main
1093+
with:
1094+
project: oidn
1095+
runs-on: '[ "macOS", "ARM64", "build" ]' # match the build job due to UBSAN
1096+
artifact-in: build-macos-arm-ubsan
1097+
artifact-out: test-macos-arm-ubsan
1098+
artifact-path: test.log
1099+
artifact-on-failure: true
1100+
cmd: |
1101+
export TBB_ENABLE_SANITIZERS=1
1102+
scripts/test.py --device cpu --minimal --log test.log
1103+
10791104
test-macos-arm-metal:
10801105
needs: build-macos-arm
10811106
secrets: inherit
@@ -1158,6 +1183,21 @@ jobs:
11581183
export TBB_ENABLE_SANITIZERS=1
11591184
scripts/test.py --device metal --minimal --log test.log
11601185
1186+
test-macos-arm-ubsan-metal:
1187+
needs: build-macos-arm-ubsan
1188+
secrets: inherit
1189+
uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/macos.yml@main
1190+
with:
1191+
project: oidn
1192+
runs-on: '[ "macOS", "ARM64", "build" ]' # match the build job due to UBSAN
1193+
artifact-in: build-macos-arm-ubsan
1194+
artifact-out: test-macos-arm-ubsan-metal
1195+
artifact-path: test.log
1196+
artifact-on-failure: true
1197+
cmd: |
1198+
export TBB_ENABLE_SANITIZERS=1
1199+
scripts/test.py --device metal --minimal --log test.log
1200+
11611201
build-macos:
11621202
secrets: inherit
11631203
uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/macos.yml@main

apps/oidnTest.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,14 @@ TEST_CASE("buffer creation", "[buffer]")
334334
}
335335
#endif
336336

337+
#if !defined(OIDN_SANITIZER)
338+
// Passing an invalid enum value is a false positive for UBSan
337339
SECTION("invalid buffer storage")
338340
{
339341
BufferRef buffer = device.newBuffer(bufferSize, static_cast<Storage>(-42));
340342
REQUIRE(device.getError() == Error::InvalidArgument);
341343
}
344+
#endif
342345

343346
SECTION("device released before buffer")
344347
{
@@ -632,9 +635,12 @@ TEST_CASE("single filter", "[single_filter][minimal]")
632635
setFilterImage(filter, nullptr, input);
633636
REQUIRE(device.getError() == Error::InvalidArgument);
634637

635-
// Try setting an image with invalid format
638+
#if !defined(OIDN_SANITIZER)
639+
// Try setting an image with invalid format (passing an invalid enum value is a false positive for
640+
// UBSan)
636641
filter.setImage("color", input->getBuffer(), static_cast<Format>(-1), W, H);
637642
REQUIRE(device.getError() == Error::InvalidArgument);
643+
#endif
638644

639645
// Try setting an image with buffer overflow
640646
filter.setImage("color", input->getBuffer(), input->getFormat(), W+1, H);

scripts/blob_to_cpp.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import argparse
99
from array import array
1010

11+
# Alignment of the generated blob in bytes. This ensures that data stored at aligned offsets within
12+
# the blob ends up at correctly aligned absolute addresses.
13+
BLOB_ALIGNMENT = 64
14+
1115
def is_git_lfs_pointer(data):
1216
HEADER = array('B', b'version https://git-lfs.github.com/spec/')
1317
return data[:len(HEADER)] == HEADER
@@ -50,7 +54,7 @@ def generate(in_path, cpp_path, hpp_path, namespace):
5054
write_prologue(cpp_file, in_name)
5155
write_namespace_begin(cpp_file, scopes)
5256

53-
cpp_file.write('extern const unsigned char %s[%d] = {' % (var_name, in_size))
57+
cpp_file.write('alignas(%d) extern const unsigned char %s[%d] = {' % (BLOB_ALIGNMENT, var_name, in_size))
5458
line_length = 1000
5559
for i in range(in_size):
5660
c = in_data[i]
@@ -69,7 +73,7 @@ def generate(in_path, cpp_path, hpp_path, namespace):
6973
with open(hpp_path, 'w') as hpp_file:
7074
write_prologue(hpp_file, in_name)
7175
write_namespace_begin(hpp_file, scopes)
72-
hpp_file.write('extern const unsigned char %s[%d];\n' % (var_name, in_size))
76+
hpp_file.write('alignas(%d) extern const unsigned char %s[%d];\n' % (BLOB_ALIGNMENT, var_name, in_size))
7377
write_namespace_end(hpp_file, scopes)
7478

7579
if __name__ == '__main__':

0 commit comments

Comments
 (0)