Skip to content

Virtual memory "address_access_mode::read" access doesn't work #19189

Open
@AllanZyne

Description

@AllanZyne

Describe the bug

It seems virtual memory readonly access doesn't work

To reproduce

#include <sycl/detail/core.hpp>

#include <sycl/ext/oneapi/virtual_mem/physical_mem.hpp>
#include <sycl/ext/oneapi/virtual_mem/virtual_mem.hpp>

namespace syclext = sycl::ext::oneapi::experimental;

int main() {
  sycl::queue Q;
  auto Dev = Q.get_device();
  auto Ctx = Q.get_context();

  size_t Size = syclext::get_mem_granularity(Dev, Ctx);
  syclext::physical_mem PhysicalMem{Dev, Ctx, Size};

  uintptr_t VirtualMemoryPtr = syclext::reserve_virtual_mem(Size, Ctx);

  void *MappedPtr = PhysicalMem.map(VirtualMemoryPtr, Size,
                                    syclext::address_access_mode::read_write);

  char *DataPtr = reinterpret_cast<char *>(MappedPtr);

  Q.memset(DataPtr, 42, Size).wait_and_throw();

  std::vector<char> Host1(Size);
  Q.memcpy(Host1.data(), DataPtr, Size).wait_and_throw();

  for (size_t i = 0; i < Size; ++i) {
    if (Host1[i] != 42) {
      std::cerr << "Host1 mismatch at index " << i << ": "
                << static_cast<int>(Host1[i]) << " != 42" << std::endl;
      return 1;
    }
  }

  syclext::set_access_mode(MappedPtr, Size, syclext::address_access_mode::read,
                           Ctx);

  Q.parallel_for(sycl::range<1>(Size), [=](sycl::id<1> Idx) {
     DataPtr[Idx] = Idx;
   }).wait_and_throw();

  std::vector<char> Host2(Size);
  Q.memcpy(Host2.data(), DataPtr, Size).wait_and_throw();

  for (size_t i = 0; i < Size; ++i) {
    if (Host2[i] != 42) {
      std::cerr << "Host2 mismatch at index " << i << ": "
                << static_cast<int>(Host2[i]) << " != 42" << std::endl;
      return 1;
    }
  }

  return 0;
}
$ clang++ -fsycl test.cpp
$ ./a.out
Host2 mismatch at index 0: 0 != 42

Environment

<LOADER>[INFO]: The adapter 'libur_adapter_level_zero_v2.so.0' is skipped because UR_LOADER_USE_LEVEL_ZERO_V2 or SYCL_UR_USE_LEVEL_ZERO_V2 is not set.
<LOADER>[INFO]: failed to load adapter 'libur_adapter_cuda.so.0' with error: libur_adapter_cuda.so.0: cannot open shared object file: No such file or directory
<LOADER>[INFO]: failed to load adapter '/localdisk3/yzhao/sycl_ws/builds/prod/lib/libur_adapter_cuda.so.0' with error: /localdisk3/yzhao/sycl_ws/builds/prod/lib/libur_adapter_cuda.so.0: cannot open shared object file: No such file or directory
<LOADER>[INFO]: failed to load adapter 'libur_adapter_hip.so.0' with error: libur_adapter_hip.so.0: cannot open shared object file: No such file or directory
<LOADER>[INFO]: failed to load adapter '/localdisk3/yzhao/sycl_ws/builds/prod/lib/libur_adapter_hip.so.0' with error: /localdisk3/yzhao/sycl_ws/builds/prod/lib/libur_adapter_hip.so.0: cannot open shared object file: No such file or directory
<LOADER>[INFO]: loaded adapter 0x0x620b9ee86190 (libur_adapter_level_zero.so.0) from /localdisk3/yzhao/sycl_ws/builds/prod/lib/libur_adapter_level_zero.so.0
<LOADER>[INFO]: failed to load adapter 'libur_adapter_native_cpu.so.0' with error: libur_adapter_native_cpu.so.0: cannot open shared object file: No such file or directory
<LOADER>[INFO]: failed to load adapter '/localdisk3/yzhao/sycl_ws/builds/prod/lib/libur_adapter_native_cpu.so.0' with error: /localdisk3/yzhao/sycl_ws/builds/prod/lib/libur_adapter_native_cpu.so.0: cannot open shared object file: No such file or directory
<LOADER>[INFO]: failed to load adapter 'libur_adapter_offload.so.0' with error: libur_adapter_offload.so.0: cannot open shared object file: No such file or directory
<LOADER>[INFO]: failed to load adapter '/localdisk3/yzhao/sycl_ws/builds/prod/lib/libur_adapter_offload.so.0' with error: /localdisk3/yzhao/sycl_ws/builds/prod/lib/libur_adapter_offload.so.0: cannot open shared object file: No such file or directory
<LOADER>[INFO]: loaded adapter 0x0x620b9ee89900 (libur_adapter_opencl.so.0) from /localdisk3/yzhao/sycl_ws/builds/prod/lib/libur_adapter_opencl.so.0
[level_zero:gpu][level_zero:0] Intel(R) oneAPI Unified Runtime over Level-Zero, Intel(R) Data Center GPU Max 1100 12.60.7 [1.6.31740+14]
[opencl:cpu][opencl:0] Intel(R) OpenCL, Intel(R) Xeon(R) Platinum 8480+ OpenCL 3.0 (Build 0) [2025.19.3.0.17_230222]

Platforms: 2
Platform [#1]:
    Version  : 1.6
    Name     : Intel(R) oneAPI Unified Runtime over Level-Zero
    Vendor   : Intel(R) Corporation
    Devices  : 1
        Device [#0]:
        Type              : gpu
        Version           : 12.60.7
        Name              : Intel(R) Data Center GPU Max 1100
        Vendor            : Intel(R) Corporation
        Driver            : 1.6.31740+14
        UUID              : 8680da0b-2f00-0000-aa00-000000000000
        DeviceID          : 3034
        Num SubDevices    : 0
        Num SubSubDevices : 0
        Aspects           : gpu fp16 fp64 online_compiler online_linker queue_profiling usm_device_allocations usm_host_allocations usm_shared_allocations ext_intel_pci_address ext_intel_gpu_eu_count ext_intel_gpu_eu_simd_width ext_intel_gpu_slices ext_intel_gpu_subslices_per_slice ext_intel_gpu_eu_count_per_subslice atomic64 ext_intel_device_info_uuid ext_intel_gpu_hw_threads_per_eu ext_intel_free_memory ext_intel_device_id ext_intel_memory_clock_rate ext_intel_memory_bus_width ext_oneapi_external_memory_import ext_intel_esimd ext_oneapi_ballot_group ext_oneapi_fixed_size_group ext_oneapi_opportunistic_group ext_oneapi_tangle_group ext_intel_matrix ext_oneapi_limited_graph ext_oneapi_private_alloca ext_oneapi_bindless_sampled_image_fetch_1d_usm ext_oneapi_bindless_sampled_image_fetch_1d ext_oneapi_bindless_sampled_image_fetch_2d_usm ext_oneapi_bindless_sampled_image_fetch_2d ext_oneapi_bindless_sampled_image_fetch_3d ext_oneapi_queue_profiling_tag ext_oneapi_virtual_mem ext_oneapi_image_array ext_oneapi_virtual_functions ext_intel_spill_memory_size ext_intel_current_clock_throttle_reasons ext_intel_power_limits ext_oneapi_async_memory_alloc
        info::device::sub_group_sizes: 16 32
        Architecture: intel_gpu_pvc
Platform [#2]:
    Version  : OpenCL 3.0 LINUX
    Name     : Intel(R) OpenCL
    Vendor   : Intel(R) Corporation
    Devices  : 1
        Device [#0]:
        Type              : cpu
        Version           : OpenCL 3.0 (Build 0)
        Name              : Intel(R) Xeon(R) Platinum 8480+
        Vendor            : Intel(R) Corporation
        Driver            : 2025.19.3.0.17_230222
        UUID              : 8680f606-0800-fffb-fe7f-fffbebbf0000
        DeviceID          : 526070
        Num SubDevices    : 2
        Num SubSubDevices : 0
        Aspects           : cpu fp16 fp64 online_compiler online_linker queue_profiling usm_device_allocations usm_host_allocations usm_shared_allocations usm_system_allocations ext_intel_gpu_slices ext_intel_gpu_subslices_per_slice ext_intel_gpu_eu_count_per_subslice usm_atomic_host_allocations usm_atomic_shared_allocations atomic64 ext_intel_device_info_uuid ext_oneapi_srgb ext_oneapi_native_assert ext_intel_gpu_hw_threads_per_eu ext_intel_device_id ext_intel_legacy_image ext_oneapi_ballot_group ext_oneapi_fixed_size_group ext_oneapi_opportunistic_group ext_oneapi_tangle_group ext_intel_matrix ext_oneapi_private_alloca ext_oneapi_atomic16 ext_oneapi_virtual_functions
        info::device::sub_group_sizes: 4 8 16 32 64
        Architecture: intel_cpu_spr
default_selector()      : gpu, Intel(R) oneAPI Unified Runtime over Level-Zero, Intel(R) Data Center GPU Max 1100 12.60.7 [1.6.31740+14]
accelerator_selector()  : No device of requested type available.
cpu_selector()          : cpu, Intel(R) OpenCL, Intel(R) Xeon(R) Platinum 8480+ OpenCL 3.0 (Build 0) [2025.19.3.0.17_230222]
gpu_selector()          : gpu, Intel(R) oneAPI Unified Runtime over Level-Zero, Intel(R) Data Center GPU Max 1100 12.60.7 [1.6.31740+14]
custom_selector(gpu)    : gpu, Intel(R) oneAPI Unified Runtime over Level-Zero, Intel(R) Data Center GPU Max 1100 12.60.7 [1.6.31740+14]
custom_selector(cpu)    : cpu, Intel(R) OpenCL, Intel(R) Xeon(R) Platinum 8480+ OpenCL 3.0 (Build 0) [2025.19.3.0.17_230222]
custom_selector(acc)    : No device of requested type available.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions