Skip to content

[NFC][SYCL] Cache aspects that call has_extension #18546

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

Merged
merged 5 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
327 changes: 0 additions & 327 deletions sycl/source/detail/device_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,333 +312,6 @@ ur_native_handle_t device_impl::getNative() const {
return Handle;
}

bool device_impl::has(aspect Aspect) const {
switch (Aspect) {
case aspect::host:
// Deprecated
return false;
case aspect::cpu:
return is_cpu();
case aspect::gpu:
return is_gpu();
case aspect::accelerator:
return is_accelerator();
case aspect::custom:
return false;
// TODO: Implement this for FPGA emulator.
case aspect::emulated:
return false;
case aspect::host_debuggable:
return false;
case aspect::fp16:
return has_extension("cl_khr_fp16");
case aspect::fp64:
return has_extension("cl_khr_fp64");
case aspect::int64_base_atomics:
return has_extension("cl_khr_int64_base_atomics");
case aspect::int64_extended_atomics:
return has_extension("cl_khr_int64_extended_atomics");
case aspect::atomic64:
return get_info<info::device::atomic64>();
case aspect::image:
return get_info<info::device::image_support>();
case aspect::online_compiler:
return get_info<info::device::is_compiler_available>();
case aspect::online_linker:
return get_info<info::device::is_linker_available>();
case aspect::queue_profiling:
return get_info<info::device::queue_profiling>();
case aspect::usm_device_allocations:
return get_info<info::device::usm_device_allocations>();
case aspect::usm_host_allocations:
return get_info<info::device::usm_host_allocations>();
case aspect::ext_intel_mem_channel:
return get_info<info::device::ext_intel_mem_channel>();
case aspect::ext_oneapi_cuda_cluster_group:
return get_info<info::device::ext_oneapi_cuda_cluster_group>();
case aspect::usm_atomic_host_allocations:
return (get_info_impl<UR_DEVICE_INFO_USM_HOST_SUPPORT>() &
UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ATOMIC_CONCURRENT_ACCESS);
case aspect::usm_shared_allocations:
return get_info<info::device::usm_shared_allocations>();
case aspect::usm_atomic_shared_allocations:
return (get_info_impl<UR_DEVICE_INFO_USM_SINGLE_SHARED_SUPPORT>() &
UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ATOMIC_CONCURRENT_ACCESS);
case aspect::usm_restricted_shared_allocations:
return get_info<info::device::usm_restricted_shared_allocations>();
case aspect::usm_system_allocations:
return get_info<info::device::usm_system_allocations>();
case aspect::ext_intel_device_id:
return has_info_desc(UR_DEVICE_INFO_DEVICE_ID);
case aspect::ext_intel_pci_address:
return has_info_desc(UR_DEVICE_INFO_PCI_ADDRESS);
case aspect::ext_intel_gpu_eu_count:
return has_info_desc(UR_DEVICE_INFO_GPU_EU_COUNT);
case aspect::ext_intel_gpu_eu_simd_width:
return has_info_desc(UR_DEVICE_INFO_GPU_EU_SIMD_WIDTH);
case aspect::ext_intel_gpu_slices:
return has_info_desc(UR_DEVICE_INFO_GPU_EU_SLICES);
case aspect::ext_intel_gpu_subslices_per_slice:
return has_info_desc(UR_DEVICE_INFO_GPU_SUBSLICES_PER_SLICE);
case aspect::ext_intel_gpu_eu_count_per_subslice:
return has_info_desc(UR_DEVICE_INFO_GPU_EU_COUNT_PER_SUBSLICE);
case aspect::ext_intel_gpu_hw_threads_per_eu:
return has_info_desc(UR_DEVICE_INFO_GPU_HW_THREADS_PER_EU);
case aspect::ext_intel_free_memory:
return has_info_desc(UR_DEVICE_INFO_GLOBAL_MEM_FREE);
case aspect::ext_intel_memory_clock_rate:
return has_info_desc(UR_DEVICE_INFO_MEMORY_CLOCK_RATE);
case aspect::ext_intel_memory_bus_width:
return has_info_desc(UR_DEVICE_INFO_MEMORY_BUS_WIDTH);
case aspect::ext_intel_device_info_uuid:
return has_info_desc(UR_DEVICE_INFO_UUID);
case aspect::ext_intel_max_mem_bandwidth:
// currently not supported
return false;
case aspect::ext_intel_current_clock_throttle_reasons:
return has_info_desc(UR_DEVICE_INFO_CURRENT_CLOCK_THROTTLE_REASONS);
case aspect::ext_intel_fan_speed:
return has_info_desc(UR_DEVICE_INFO_FAN_SPEED);
case aspect::ext_intel_power_limits:
return has_info_desc(UR_DEVICE_INFO_MIN_POWER_LIMIT) &&
has_info_desc(UR_DEVICE_INFO_MAX_POWER_LIMIT);
case aspect::ext_oneapi_srgb:
return get_info<info::device::ext_oneapi_srgb>();
case aspect::ext_oneapi_native_assert:
return get_info_impl<UR_DEVICE_INFO_USE_NATIVE_ASSERT>();
case aspect::ext_oneapi_cuda_async_barrier: {
return get_info_impl_nocheck<UR_DEVICE_INFO_ASYNC_BARRIER>().value_or(0);
}
case aspect::ext_intel_legacy_image: {
return get_info_impl_nocheck<UR_DEVICE_INFO_IMAGE_SUPPORT>().value_or(0);
}
case aspect::ext_oneapi_bindless_images: {
return get_info_impl_nocheck<UR_DEVICE_INFO_BINDLESS_IMAGES_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_bindless_images_shared_usm: {
return get_info_impl_nocheck<
UR_DEVICE_INFO_BINDLESS_IMAGES_SHARED_USM_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_bindless_images_1d_usm: {
return get_info_impl_nocheck<
UR_DEVICE_INFO_BINDLESS_IMAGES_1D_USM_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_bindless_images_2d_usm: {
return get_info_impl_nocheck<
UR_DEVICE_INFO_BINDLESS_IMAGES_2D_USM_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_external_memory_import: {
return get_info_impl_nocheck<
UR_DEVICE_INFO_EXTERNAL_MEMORY_IMPORT_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_external_semaphore_import: {
return get_info_impl_nocheck<
UR_DEVICE_INFO_EXTERNAL_SEMAPHORE_IMPORT_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_mipmap: {
return get_info_impl_nocheck<UR_DEVICE_INFO_MIPMAP_SUPPORT_EXP>().value_or(
0);
}
case aspect::ext_oneapi_mipmap_anisotropy: {
return get_info_impl_nocheck<UR_DEVICE_INFO_MIPMAP_ANISOTROPY_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_mipmap_level_reference: {
return get_info_impl_nocheck<
UR_DEVICE_INFO_MIPMAP_LEVEL_REFERENCE_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_bindless_sampled_image_fetch_1d_usm: {
return get_info_impl_nocheck<
UR_DEVICE_INFO_BINDLESS_SAMPLED_IMAGE_FETCH_1D_USM_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_bindless_sampled_image_fetch_1d: {
return get_info_impl_nocheck<
UR_DEVICE_INFO_BINDLESS_SAMPLED_IMAGE_FETCH_1D_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_bindless_sampled_image_fetch_2d_usm: {
return get_info_impl_nocheck<
UR_DEVICE_INFO_BINDLESS_SAMPLED_IMAGE_FETCH_2D_USM_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_bindless_sampled_image_fetch_2d: {
return get_info_impl_nocheck<
UR_DEVICE_INFO_BINDLESS_SAMPLED_IMAGE_FETCH_2D_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_bindless_sampled_image_fetch_3d: {
return get_info_impl_nocheck<
UR_DEVICE_INFO_BINDLESS_SAMPLED_IMAGE_FETCH_3D_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_bindless_images_gather: {
return get_info_impl_nocheck<
UR_DEVICE_INFO_BINDLESS_IMAGES_GATHER_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_cubemap: {
return get_info_impl_nocheck<UR_DEVICE_INFO_CUBEMAP_SUPPORT_EXP>().value_or(
0);
}
case aspect::ext_oneapi_cubemap_seamless_filtering: {
return get_info_impl_nocheck<
UR_DEVICE_INFO_CUBEMAP_SEAMLESS_FILTERING_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_image_array: {
return get_info_impl_nocheck<UR_DEVICE_INFO_IMAGE_ARRAY_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_unique_addressing_per_dim: {
return get_info_impl_nocheck<
UR_DEVICE_INFO_BINDLESS_UNIQUE_ADDRESSING_PER_DIM_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_bindless_images_sample_1d_usm: {
return get_info_impl_nocheck<
UR_DEVICE_INFO_BINDLESS_SAMPLE_1D_USM_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_bindless_images_sample_2d_usm: {
return get_info_impl_nocheck<
UR_DEVICE_INFO_BINDLESS_SAMPLE_2D_USM_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_intel_esimd: {
return get_info_impl_nocheck<UR_DEVICE_INFO_ESIMD_SUPPORT>().value_or(0);
}
case aspect::ext_oneapi_ballot_group:
case aspect::ext_oneapi_fixed_size_group:
case aspect::ext_oneapi_opportunistic_group: {
return (this->getBackend() == backend::ext_oneapi_level_zero) ||
(this->getBackend() == backend::opencl) ||
(this->getBackend() == backend::ext_oneapi_cuda);
}
case aspect::ext_oneapi_tangle_group: {
// TODO: tangle_group is not currently supported for CUDA devices. Add when
// implemented.
return (this->getBackend() == backend::ext_oneapi_level_zero) ||
(this->getBackend() == backend::opencl);
}
case aspect::ext_intel_matrix: {
using arch = sycl::ext::oneapi::experimental::architecture;
const arch supported_archs[] = {
arch::intel_cpu_spr, arch::intel_cpu_gnr,
arch::intel_cpu_dmr, arch::intel_gpu_pvc,
arch::intel_gpu_dg2_g10, arch::intel_gpu_dg2_g11,
arch::intel_gpu_dg2_g12, arch::intel_gpu_bmg_g21,
arch::intel_gpu_lnl_m, arch::intel_gpu_arl_h,
arch::intel_gpu_ptl_h, arch::intel_gpu_ptl_u,
};
try {
return std::any_of(
std::begin(supported_archs), std::end(supported_archs),
[=](const arch a) { return this->extOneapiArchitectureIs(a); });
} catch (const sycl::exception &) {
// If we're here it means the device does not support architecture
// querying
return false;
}
}
case aspect::ext_oneapi_is_composite: {
auto components = get_info<
sycl::ext::oneapi::experimental::info::device::component_devices>();
// Any device with ext_oneapi_is_composite aspect will have at least two
// constituent component devices.
return components.size() >= 2;
}
case aspect::ext_oneapi_is_component: {
return get_info_impl_nocheck<UR_DEVICE_INFO_COMPOSITE_DEVICE>().value_or(
nullptr) != nullptr;
}
case aspect::ext_oneapi_graph: {
ur_device_command_buffer_update_capability_flags_t UpdateCapabilities;
bool CallSuccessful =
getAdapter()->call_nocheck<UrApiKind::urDeviceGetInfo>(
MDevice, UR_DEVICE_INFO_COMMAND_BUFFER_UPDATE_CAPABILITIES_EXP,
sizeof(UpdateCapabilities), &UpdateCapabilities,
nullptr) == UR_RESULT_SUCCESS;
if (!CallSuccessful) {
return false;
}

/* The kernel handle update capability is not yet required for the
* ext_oneapi_graph aspect */
ur_device_command_buffer_update_capability_flags_t RequiredCapabilities =
UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_KERNEL_ARGUMENTS |
UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_LOCAL_WORK_SIZE |
UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_GLOBAL_WORK_SIZE |
UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_GLOBAL_WORK_OFFSET |
UR_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_KERNEL_HANDLE;

return has(aspect::ext_oneapi_limited_graph) &&
(UpdateCapabilities & RequiredCapabilities) == RequiredCapabilities;
}
case aspect::ext_oneapi_limited_graph: {
bool SupportsCommandBuffers = false;
bool CallSuccessful =
getAdapter()->call_nocheck<UrApiKind::urDeviceGetInfo>(
MDevice, UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP,
sizeof(SupportsCommandBuffers), &SupportsCommandBuffers,
nullptr) == UR_RESULT_SUCCESS;
if (!CallSuccessful) {
return false;
}

return SupportsCommandBuffers;
}
case aspect::ext_oneapi_private_alloca: {
// Extension only supported on SPIR-V targets.
backend be = getBackend();
return be == sycl::backend::ext_oneapi_level_zero ||
be == sycl::backend::opencl;
}
case aspect::ext_oneapi_queue_profiling_tag: {
return get_info_impl_nocheck<
UR_DEVICE_INFO_TIMESTAMP_RECORDING_SUPPORT_EXP>()
.value_or(0);
}
case aspect::ext_oneapi_virtual_mem: {
return get_info_impl_nocheck<UR_DEVICE_INFO_VIRTUAL_MEMORY_SUPPORT>()
.value_or(0);
}
case aspect::ext_intel_fpga_task_sequence: {
return is_accelerator();
}
case aspect::ext_oneapi_atomic16: {
// Likely L0 doesn't check it properly. Need to double-check.
return has_extension("cl_ext_float_atomics");
}
case aspect::ext_oneapi_virtual_functions: {
// TODO: move to UR like e.g. aspect::ext_oneapi_virtual_mem
backend BE = getBackend();
bool isCompatibleBE = BE == sycl::backend::ext_oneapi_level_zero ||
BE == sycl::backend::opencl;
return (is_cpu() || is_gpu()) && isCompatibleBE;
}
case aspect::ext_intel_spill_memory_size: {
backend BE = getBackend();
bool isCompatibleBE = BE == sycl::backend::ext_oneapi_level_zero;
return is_gpu() && isCompatibleBE;
}
case aspect::ext_oneapi_async_memory_alloc: {
return get_info_impl_nocheck<
UR_DEVICE_INFO_ASYNC_USM_ALLOCATIONS_SUPPORT_EXP>()
.value_or(0);
}
}

return false; // This device aspect has not been implemented yet.
}

// On the first call this function queries for device timestamp
// along with host synchronized timestamp and stores it in member variable
// MDeviceHostBaseTime. Subsequent calls to this function would just retrieve
Expand Down
Loading