intel / intel/llvm

SYCL Sanitizer: Allow unknown host pointers

Open
#15,630 0 comments 0 reactions 0 assignees View on GitHub
confirmed enhancement
Dominant language
LLVM
Stars
1.5k
Forks
854
Avg merge
3d 17h
Merged PRs (30d)
137

Description

### Is your feature request related to a problem? Please describe

`sycl::memcpy` and its friends can work fine with non-USM host pointers. This could be sub-optimal, but is fully legal:

> `void memcpy(void* dest, const void* src, size_t numBytes)`
>
> Copies `numBytes` of data from the pointer `src` to the pointer `dest`. The `dest` and `src` parameters must each either be a host pointer or a pointer within a USM allocation that is accessible on the handler’s device.
>
> Source: Table 132 in SYCL 2020 spec rev. 9

However, currently, running the code using non-USM pointers with SYCL Sanitizer produces fatal errors.

I suggest adding a way to either instrument and check non-USM memory allocations, or at least add a flag to `sycl-sanitizer` to make such errors non-fatal.

### Describe the solution you would like

A `sycl-sanitize` flag to allow the calls to SYCL API with unknown pointers. `--allow-unknown-pointers`?

### Describe alternatives you have considered

- Keep things as they are. Not great, valid SYCL programs will fail under `sycl-sanitizer`.
- Allow unknown pointers by default. Might miss some errors, but those would likely segfault anyway?
- Also instrument non-USM host memory allocations and track stack state, thus making all pointers known. The best solution for users, but perhaps more overhead/complexity?

### Additional context

```console
$ cat test-sanitizer-unknown.cpp
#include
#include

int main() {
for (const auto &dev :
sycl::device::get_devices(sycl::info::device_type::gpu)) {
std::cout << dev.get_info() << std::endl;
sycl::queue q{dev};

int stack = 1;
int *heap = static_cast(malloc(sizeof(int)));
*heap = 2;
int *host = sycl::malloc_host(1, q);
*host = 3;

int *d = sycl::malloc_device(3, q);
q.memcpy(d + 0, &stack, sizeof(int));
q.memcpy(d + 1, heap, sizeof(int));
q.memcpy(d + 2, host, sizeof(int));
q.wait();
sycl::free(d, q);
free(heap);
sycl::free(host, q);
}
std::cout << "Done!" << std::endl;
}

$ clang++ -g -fsycl test-sanitizer-unknown.cpp && ONEAPI_DEVICE_SELECTOR=level_zero:gpu ./a.out
ZE_LOADER_DEBUG_TRACE:Using Loader Library Path:
ZE_LOADER_DEBUG_TRACE:Tracing Layer Library Path: libze_tracing_layer.so.1
Intel(R) Arc(TM) A770 Graphics
Intel(R) UHD Graphics 770
Done!

$ clang++ -g -fsycl test-sanitizer-unknown.cpp && ONEAPI_DEVICE_SELECTOR=level_zero:gpu sycl-sanitize ./a.out
ZE_LOADER_DEBUG_TRACE:Using Loader Library Path:
ZE_LOADER_DEBUG_TRACE:Tracing Layer Library Path: libze_tracing_layer.so.1
Intel(R) Arc(TM) A770 Graphics

[USM] Function uses unknown USM pointer (could be already released or not allocated as USM) as source memory block.
| memcpy location: function main at test-sanitizer-unknown.cpp:17
terminate called without an active exception
Aborted (core dumped)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.