Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function(add_sycl_sample)

target_include_directories(${SYCL_SAMPLE_TARGET} PRIVATE ${SYCL_SAMPLE_INCLUDES})

target_compile_options(${SYCL_SAMPLE_TARGET} PRIVATE -fsycl -fsycl-unnamed-lambda)
target_compile_options(${SYCL_SAMPLE_TARGET} PRIVATE -fsycl -fsycl-unnamed-lambda -fsycl-range-rounding=disable)
target_compile_options(${SYCL_SAMPLE_TARGET} PRIVATE ${SYCL_SAMPLE_ADDITIONAL_COMPILE_OPTIONS})

# Passing -fsycl via target_link_libraries for older versions of CMake:
Expand Down
10 changes: 10 additions & 0 deletions samples/dpcpp/usm/00_hellousm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2026 Ben Ashbaugh
#
# SPDX-License-Identifier: MIT

add_sycl_sample(
TEST
NUMBER 00
TARGET hellousm
CATEGORY usm
SOURCES main.cpp)
16 changes: 16 additions & 0 deletions samples/dpcpp/usm/00_hellousm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# hellousm

## Sample Purpose

This is an equivalent of the hellosycl sample, rewritten to use USM.

It uses device USM, so it should be able to run on many devices.
Because it uses device USM, though, it needs to explicitly copy memory between the host and the device.

## Key APIs and Concepts

This sample demonstrates how to allocate, write, and copy USM memory.

## Command Line Options

None.
41 changes: 41 additions & 0 deletions samples/dpcpp/usm/00_hellousm/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
// Copyright (c) 2026 Ben Ashbaugh
//
// SPDX-License-Identifier: MIT
*/

#include <sycl/sycl.hpp>
#include <iostream>

int main()
{
const size_t array_size = 16;

sycl::queue q{sycl::property::queue::in_order()};

std::cout << "Hello from SYCL, with USM!\n";
std::cout << "Running on default SYCL device " << q.get_device().get_info<sycl::info::device::name>() << std::endl;

if (q.get_device().has(sycl::aspect::usm_device_allocations)) {
std::cout << "This device supports aspect::usm_device_allocations.\n";
} else {
std::cerr << "This device does not support aspect::usm_device_allocations. Exiting.\n";
return -1;
}

int* d_data = sycl::malloc_device<int>(array_size, q);
q.parallel_for(sycl::range<1>{array_size}, [=](sycl::id<1> i) {
d_data[i] = i.get(0);
});

int h_data[array_size];
q.copy(d_data, h_data, array_size);
q.wait();

for( int i = 0; i < array_size; i++ )
{
std::cout << "data[" << i << "] = " << h_data[i] << std::endl;
}

return 0;
}
1 change: 1 addition & 0 deletions samples/dpcpp/usm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: MIT

add_subdirectory( 00_hellousm )
add_subdirectory( 00_usmqueries )

add_subdirectory( 100_dmemhelloworld )
Expand Down