Skip to content

Commit a9ff0ed

Browse files
isaacaulthjabirdDBDuncanprzemektmaloncppchedy
authored andcommitted
[SYCL][Bindless][2/4] Add experimental implementation of SYCL bindless images extension (#10112)
# Experimental Implementation of SYCL Bindless Images Extension This commit stands as the second commit of four to make code review easier, implementing revision 4 of the [bindless images extension proposal](intel/llvm#9842). ## Scope This PR covers changes made to the PI and the UR. This includes - Extending PI with extension functions - Updating UR FetchContent commit and implementing [UR bindless images experimental features](https://oneapi-src.github.io/unified-runtime/core/EXP-BINDLESS-IMAGES.html) on the CUDA adaptor ## Following Split PRs - [3/4] Implement the user-facing SYCL extension - [4/4] Add tests ## Authors Co-authored-by: Isaac Ault <[email protected]> Co-authored-by: Hugh Bird <[email protected]> Co-authored-by: Duncan Brawley <[email protected]> Co-authored-by: Przemek Malon <[email protected]> Co-authored-by: Chedy Najjar <[email protected]> Co-authored-by: Sean Stirling <[email protected]> Co-authored-by: Peter Zuzek <[email protected]>
1 parent 3696b20 commit a9ff0ed

File tree

11 files changed

+1246
-9
lines changed

11 files changed

+1246
-9
lines changed

common.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,29 @@ ur_result_t checkErrorUR(CUresult Result, const char *Function, int Line,
6262
throw mapErrorUR(Result);
6363
}
6464

65+
ur_result_t checkErrorUR(ur_result_t Result, const char *Function, int Line,
66+
const char *File) {
67+
if (Result == UR_RESULT_SUCCESS) {
68+
return UR_RESULT_SUCCESS;
69+
}
70+
71+
if (std::getenv("SYCL_PI_SUPPRESS_ERROR_MESSAGE") == nullptr) {
72+
std::stringstream SS;
73+
SS << "\nUR ERROR:"
74+
<< "\n\tValue: " << Result
75+
<< "\n\tFunction: " << Function << "\n\tSource Location: " << File
76+
<< ":" << Line << "\n"
77+
<< std::endl;
78+
std::cerr << SS.str();
79+
}
80+
81+
if (std::getenv("PI_CUDA_ABORT") != nullptr) {
82+
std::abort();
83+
}
84+
85+
throw Result;
86+
}
87+
6588
std::string getCudaVersionString() {
6689
int driver_version = 0;
6790
cuDriverGetVersion(&driver_version);

common.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ ur_result_t mapErrorUR(CUresult Result);
2222
ur_result_t checkErrorUR(CUresult Result, const char *Function, int Line,
2323
const char *File);
2424

25+
ur_result_t checkErrorUR(ur_result_t Result, const char *Function, int Line,
26+
const char *File);
27+
2528
#define UR_CHECK_ERROR(Result) \
2629
checkErrorUR(Result, __func__, __LINE__, __FILE__)
2730

device.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,89 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
871871
case UR_DEVICE_INFO_MAX_COMPUTE_QUEUE_INDICES: {
872872
return ReturnValue(int32_t{1});
873873
}
874+
case UR_DEVICE_INFO_BINDLESS_IMAGES_SUPPORT_EXP: {
875+
// On CUDA bindless images are supported.
876+
return ReturnValue(true);
877+
}
878+
case UR_DEVICE_INFO_BINDLESS_IMAGES_SHARED_USM_SUPPORT_EXP: {
879+
// On CUDA bindless images can be backed by shared (managed) USM.
880+
return ReturnValue(true);
881+
}
882+
case UR_DEVICE_INFO_BINDLESS_IMAGES_1D_USM_SUPPORT_EXP: {
883+
// On CUDA 1D bindless image USM is not supported.
884+
// More specifically, linear filtering is not supported.
885+
return ReturnValue(false);
886+
}
887+
case UR_DEVICE_INFO_BINDLESS_IMAGES_2D_USM_SUPPORT_EXP: {
888+
// On CUDA 2D bindless image USM is supported.
889+
return ReturnValue(true);
890+
}
891+
case UR_DEVICE_INFO_IMAGE_PITCH_ALIGN_EXP: {
892+
int32_t tex_pitch_align = 0;
893+
detail::ur::assertion(
894+
cuDeviceGetAttribute(&tex_pitch_align,
895+
CU_DEVICE_ATTRIBUTE_TEXTURE_PITCH_ALIGNMENT,
896+
hDevice->get()) == CUDA_SUCCESS);
897+
return ReturnValue(tex_pitch_align);
898+
}
899+
case UR_DEVICE_INFO_MAX_IMAGE_LINEAR_WIDTH_EXP: {
900+
int32_t tex_max_linear_width = 0;
901+
detail::ur::assertion(
902+
cuDeviceGetAttribute(&tex_max_linear_width,
903+
CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_WIDTH,
904+
hDevice->get()) == CUDA_SUCCESS);
905+
return ReturnValue(tex_max_linear_width);
906+
}
907+
case UR_DEVICE_INFO_MAX_IMAGE_LINEAR_HEIGHT_EXP: {
908+
int32_t tex_max_linear_height = 0;
909+
detail::ur::assertion(
910+
cuDeviceGetAttribute(
911+
&tex_max_linear_height,
912+
CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_HEIGHT,
913+
hDevice->get()) == CUDA_SUCCESS);
914+
return ReturnValue(tex_max_linear_height);
915+
}
916+
case UR_DEVICE_INFO_MAX_IMAGE_LINEAR_PITCH_EXP: {
917+
int32_t tex_max_linear_pitch = 0;
918+
detail::ur::assertion(
919+
cuDeviceGetAttribute(&tex_max_linear_pitch,
920+
CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_PITCH,
921+
hDevice->get()) == CUDA_SUCCESS);
922+
return ReturnValue(tex_max_linear_pitch);
923+
}
924+
case UR_DEVICE_INFO_MIPMAP_SUPPORT_EXP: {
925+
// CUDA supports mipmaps.
926+
return ReturnValue(true);
927+
}
928+
case UR_DEVICE_INFO_MIPMAP_ANISOTROPY_SUPPORT_EXP: {
929+
// CUDA supports anisotropic filtering.
930+
return ReturnValue(true);
931+
}
932+
case UR_DEVICE_INFO_MIPMAP_MAX_ANISOTROPY_EXP: {
933+
// CUDA has no query for this, but documentation states max value is 16.
934+
return ReturnValue(16.f);
935+
}
936+
case UR_DEVICE_INFO_MIPMAP_LEVEL_REFERENCE_SUPPORT_EXP: {
937+
// CUDA supports creation of images from individual mipmap levels.
938+
return ReturnValue(true);
939+
}
940+
941+
case UR_DEVICE_INFO_INTEROP_MEMORY_IMPORT_SUPPORT_EXP: {
942+
// CUDA supports importing external memory.
943+
return ReturnValue(true);
944+
}
945+
case UR_DEVICE_INFO_INTEROP_MEMORY_EXPORT_SUPPORT_EXP: {
946+
// CUDA does not support exporting it's own device memory.
947+
return ReturnValue(false);
948+
}
949+
case UR_DEVICE_INFO_INTEROP_SEMAPHORE_IMPORT_SUPPORT_EXP: {
950+
// CUDA supports importing external semaphores.
951+
return ReturnValue(true);
952+
}
953+
case UR_DEVICE_INFO_INTEROP_SEMAPHORE_EXPORT_SUPPORT_EXP: {
954+
// CUDA does not support exporting semaphores or events.
955+
return ReturnValue(false);
956+
}
874957
case UR_DEVICE_INFO_DEVICE_ID: {
875958
int Value = 0;
876959
detail::ur::assertion(

enqueue.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===-----------------------------------------------------------------===//
88

9+
#include "enqueue.hpp"
910
#include "common.hpp"
1011
#include "context.hpp"
1112
#include "event.hpp"

enqueue.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===--------- enqueue.hpp - CUDA Adapter ----------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===-----------------------------------------------------------------===//
8+
#pragma once
9+
10+
#include <cassert>
11+
#include <cuda.h>
12+
#include <ur_api.h>
13+
14+
ur_result_t enqueueEventsWait(ur_queue_handle_t CommandQueue, CUstream Stream,
15+
uint32_t NumEventsInWaitList,
16+
const ur_event_handle_t *EventWaitList);

0 commit comments

Comments
 (0)