Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SYCL Sanitizer: Allow unknown host pointers #15630

Open
al42and opened this issue Oct 8, 2024 · 0 comments
Open

SYCL Sanitizer: Allow unknown host pointers #15630

al42and opened this issue Oct 8, 2024 · 0 comments
Labels
confirmed enhancement New feature or request

Comments

@al42and
Copy link
Contributor

al42and commented Oct 8, 2024

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

$ cat test-sanitizer-unknown.cpp 
#include <iostream>
#include <sycl/sycl.hpp>

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

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

    int *d = sycl::malloc_device<int>(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)
@al42and al42and added the enhancement New feature or request label Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants