Skip to content

Commit 668a50b

Browse files
committed
[SYCLomatic] Support migration of 3 runtime Surface APIs.
Signed-off-by: Tang, Jiajun [email protected]
1 parent 739cce7 commit 668a50b

File tree

6 files changed

+63
-4
lines changed

6 files changed

+63
-4
lines changed

clang/lib/DPCT/RuleInfra/MapNames.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,13 @@ void MapNames::setExplicitNamespaceMap(
554554
"ext::oneapi::experimental::sampled_image_handle"
555555
: getDpctNamespace() + "image_wrapper_base_p",
556556
HelperFeatureEnum::device_ext)},
557+
{"cudaSurfaceObject_t",
558+
std::make_shared<TypeNameRule>(
559+
DpctGlobalInfo::useExtBindlessImages()
560+
? getClNamespace() +
561+
"ext::oneapi::experimental::sampled_image_handle"
562+
: getDpctNamespace() + "image_wrapper_base_p",
563+
HelperFeatureEnum::device_ext)},
557564
{"textureReference",
558565
std::make_shared<TypeNameRule>(getDpctNamespace() + "image_wrapper_base",
559566
HelperFeatureEnum::device_ext)},
@@ -868,6 +875,7 @@ void MapNames::setExplicitNamespaceMap(
868875
"cudaTextureDesc",
869876
"cudaResourceDesc",
870877
"cudaTextureObject_t",
878+
"cudaSurfaceObject_t",
871879
"textureReference",
872880
"cudaTextureAddressMode",
873881
"cudaTextureFilterMode",

clang/lib/DPCT/RulesLang/APINamesTexture.inc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY(
6464
"experimental::destroy_bindless_image",
6565
ARG(0), QUEUESTR)),
6666
DELETER_FACTORY_ENTRY("cuTexObjectDestroy", ARG(0))))
67+
ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY(
68+
UseExtBindlessImages,
69+
CALL_FACTORY_ENTRY("cudaDestroySurfaceObject",
70+
CALL(MapNames::getDpctNamespace() +
71+
"experimental::destroy_bindless_image",
72+
ARG(0), QUEUESTR)),
73+
DELETER_FACTORY_ENTRY("cudaDestroySurfaceObject", ARG(0))))
6774

6875
CONDITIONAL_FACTORY_ENTRY(
6976
UseExtBindlessImages,
@@ -104,6 +111,15 @@ CONDITIONAL_FACTORY_ENTRY(
104111
"cuTexObjectGetTextureDesc", DEREF(0),
105112
MEMBER_CALL(ARG(1), true,
106113
"get_sampling_info")))))
114+
CONDITIONAL_FACTORY_ENTRY(
115+
UseExtBindlessImages,
116+
ASSIGNABLE_FACTORY(ASSIGN_FACTORY_ENTRY(
117+
"cudaGetSurfaceObjectResourceDesc", DEREF(0),
118+
CALL(MapNames::getDpctNamespace() + "experimental::get_data", ARG(1)))),
119+
FEATURE_REQUEST_FACTORY(HelperFeatureEnum::device_ext,
120+
ASSIGNABLE_FACTORY(ASSIGN_FACTORY_ENTRY(
121+
"cudaGetSurfaceObjectResourceDesc", DEREF(0),
122+
MEMBER_CALL(ARG(1), true, "get_data")))))
107123

108124
FEATURE_REQUEST_FACTORY(HelperFeatureEnum::device_ext,
109125
ENTRY_TEXTURE("tex1D", 0x01, 1))
@@ -184,6 +200,16 @@ FEATURE_REQUEST_FACTORY(HelperFeatureEnum::device_ext,
184200
"create_image_wrapper",
185201
DEREF(1), DEREF(2)))))
186202

203+
FEATURE_REQUEST_FACTORY(HelperFeatureEnum::device_ext,
204+
ASSIGNABLE_FACTORY(ASSIGN_FACTORY_ENTRY(
205+
"cudaCreateSurfaceObject", DEREF(0),
206+
CALL(DpctGlobalInfo::useExtBindlessImages()
207+
? MapNames::getDpctNamespace() +
208+
"experimental::create_bindless_image"
209+
: MapNames::getDpctNamespace() +
210+
"create_image_wrapper",
211+
DEREF(1)))))
212+
187213
ENTRY_UNSUPPORTED("cudaGetTextureObjectResourceViewDesc",
188214
Diagnostics::API_NOT_MIGRATED)
189215

clang/lib/DPCT/RulesLang/RulesLang.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9698,6 +9698,12 @@ void TextureRule::registerMatcher(MatchFinder &MF) {
96989698
)
96999699
.bind("tex"),
97009700
this);
9701+
MF.addMatcher(
9702+
typeLoc(
9703+
loc(qualType(hasDeclaration(typedefDecl(hasAnyName(
9704+
"cudaTextureObject_t", "cudaSurfaceObject_t", "CUtexObject"))))))
9705+
.bind("texObj"),
9706+
this);
97019707
MF.addMatcher(typeLoc(loc(qualType(hasDeclaration(typedefDecl(hasAnyName(
97029708
"cudaTextureObject_t", "CUtexObject"))))))
97039709
.bind("texObj"),
@@ -9761,6 +9767,9 @@ void TextureRule::registerMatcher(MatchFinder &MF) {
97619767
"cudaGetTextureObjectResourceDesc",
97629768
"cudaGetTextureObjectTextureDesc",
97639769
"cudaGetTextureObjectResourceViewDesc",
9770+
"cudaCreateSurfaceObject",
9771+
"cudaDestroySurfaceObject",
9772+
"cudaGetSurfaceObjectResourceDesc",
97649773
"cuArray3DCreate_v2",
97659774
"cuArrayCreate_v2",
97669775
"cuArrayDestroy",

clang/lib/DPCT/SrcAPI/APINames.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,9 @@ ENTRY(cudaGetTextureObjectResourceViewDesc, cudaGetTextureObjectResourceViewDesc
379379
ENTRY(cudaGetTextureObjectTextureDesc, cudaGetTextureObjectTextureDesc, true, NO_FLAG, P4, "Successful")
380380

381381
// low level texture surface management functions of runtime API
382-
ENTRY(cudaCreateSurfaceObject, cudaCreateSurfaceObject, false, NO_FLAG, P0, "comment")
383-
ENTRY(cudaDestroySurfaceObject, cudaDestroySurfaceObject, false, NO_FLAG, P0, "comment")
384-
ENTRY(cudaGetSurfaceObjectResourceDesc, cudaGetSurfaceObjectResourceDesc, false, NO_FLAG, P4, "comment")
382+
ENTRY(cudaCreateSurfaceObject, cudaCreateSurfaceObject, true, NO_FLAG, P0, "Successful")
383+
ENTRY(cudaDestroySurfaceObject, cudaDestroySurfaceObject, true, NO_FLAG, P0, "Successful")
384+
ENTRY(cudaGetSurfaceObjectResourceDesc, cudaGetSurfaceObjectResourceDesc, true, NO_FLAG, P4, "Successful")
385385

386386
// Version Management
387387
ENTRY(cudaDriverGetVersion, cudaDriverGetVersion, true, NO_FLAG, P0, "DPCT1043")

clang/runtime/dpct-rt/include/dpct/bindless_images.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ inline void unmap_resources(int count, external_mem_wrapper **handles,
844844
/// \param [in] q The queue where the image creation be executed.
845845
/// \returns The sampled image handle of created bindless image.
846846
static inline sycl::ext::oneapi::experimental::sampled_image_handle
847-
create_bindless_image(image_data data, sampling_info info,
847+
create_bindless_image(image_data data, sampling_info info = {},
848848
sycl::queue q = get_default_queue()) {
849849
auto samp = sycl::ext::oneapi::experimental::bindless_image_sampler(
850850
info.get_addressing_mode(), info.get_coordinate_normalization_mode(),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: dpct --format-range=none --use-experimental-features=bindless_images -out-root %T/texture/surface_object_bindless_image %s --cuda-include-path="%cuda-path/include" -- -x cuda --cuda-host-only -std=c++14
2+
// RUN: FileCheck --input-file %T/texture/surface_object_bindless_image/surface_object_bindless_image.dp.cpp --match-full-lines %s
3+
// RUN: %if build_lit %{icpx -c -fsycl %T/texture/surface_object_bindless_image/surface_object_bindless_image.dp.cpp -o %T/texture/surface_object_bindless_image/surface_object_bindless_image.dp.o %}
4+
5+
int main() {
6+
// CHECK: sycl::ext::oneapi::experimental::sampled_image_handle surf;
7+
cudaSurfaceObject_t surf;
8+
// CHECK: dpct::image_data resDesc;
9+
cudaResourceDesc resDesc;
10+
// CHECK: surf = dpct::experimental::create_bindless_image(resDesc);
11+
cudaCreateSurfaceObject(&surf, &resDesc);
12+
// CHECK: dpct::experimental::destroy_bindless_image(surf, dpct::get_in_order_queue());
13+
cudaDestroySurfaceObject(surf);
14+
// CHECK: resDesc = dpct::experimental::get_data(surf);
15+
cudaGetSurfaceObjectResourceDesc(&resDesc, surf);
16+
}

0 commit comments

Comments
 (0)