Skip to content

Conversation

@mayuyuace
Copy link

In before code, I get a pointer from virtual memory, but sycl::get_pointer_type will return unknown if check this pointer.
In oneCCL, I want to remove this memory type check to avoid throwing runtime error directly.

#include <sycl/sycl.hpp>

using namespace sycl::ext::oneapi::experimental;

int main(){

    sycl::queue q(sycl::default_selector_v, sycl::property::queue::enable_profiling{});
    auto device = q.get_device();
    std::cout << "Running on device: " << device.get_info<sycl::info::device::name>() << std::endl;

    auto mini = granularity_mode::minimum;
    auto reco = granularity_mode::recommended;

    auto syclContext = sycl::context(q.get_device());
    auto syclDevice = sycl::device(q.get_device());

    size_t mini_mem_granularity = get_mem_granularity(syclDevice, syclContext, mini);
    size_t reco_mem_granularity = get_mem_granularity(syclDevice, syclContext, reco);

    std::cout << "Minimum memory granularity: " << mini_mem_granularity << " bytes" << std::endl;
    std::cout << "Recommended memory granularity: " << reco_mem_granularity << " bytes" << std::endl;

    uintptr_t test_malloc1 = reserve_virtual_mem(mini_mem_granularity, syclContext);

    auto p_type = sycl::get_pointer_type(reinterpret_cast<void*>(test_malloc1), syclContext);
    std::cout << "is_unknown?:" << (p_type == sycl::usm::alloc::unknown) << std::endl;

    return 0;
}

Output:

Running on device: Intel(R) Graphics [0xe211]
Minimum memory granularity: 65536 bytes
Recommended memory granularity: 65536 bytes
is_unknown?:1

@nikitaxgusev
Copy link
Contributor

@mayuyuace
I have a few questions to better understand the intended usage and safe behavior for oneCCL when sycl::get_pointer_type returns unknown:

  1. It is not clear what behavior is expected from oneCCL when the pointer type is unknown. Should oneCCL proceed as if the pointer is valid for any device, or restrict its use somehow? When get_pointer_type returns unknown, is it your intention that oneCCL should treat these pointers as host (CPU) memory, device (GPU) memory, or something else? Could you clarify?

  2. Removing the memory type check may lead to undefined or unsafe behavior if the pointer is not actually usable by the device (especially on GPU backends). How do you expect oneCCL to handle such scenarios?

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants