Skip to content

Commit de3682a

Browse files
author
Deepak Raj H R
authored
[SYCLomatic] Add migration support for cuMemGetAllocationPropertiesFromHandle (#2623)
1 parent 17aae2d commit de3682a

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed

clang/lib/DPCT/RulesLang/APINamesMemory.inc

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,21 @@ CONDITIONAL_FACTORY_ENTRY(
717717
UNSUPPORT_FACTORY_ENTRY("cuMemCreate",
718718
Diagnostics::TRY_EXPERIMENTAL_FEATURE,
719719
ARG("cuMemCreate"),
720-
ARG("--use-experimental-features=virtual_memory")))
720+
ARG("--use-experimental-features=virtual_mem")))
721+
722+
CONDITIONAL_FACTORY_ENTRY(
723+
UseExpVirtualMemory,
724+
ASSIGNABLE_FACTORY(FEATURE_REQUEST_FACTORY(
725+
HelperFeatureEnum::device_ext,
726+
ASSIGN_FACTORY_ENTRY(
727+
"cuMemGetAllocationPropertiesFromHandle",
728+
MEMBER_EXPR(DEREF(0), false, LITERAL("location.id")),
729+
CALL(MapNames::getDpctNamespace() + "get_device_id",
730+
MEMBER_CALL(ARG(1), true, "get_device"))))),
731+
UNSUPPORT_FACTORY_ENTRY("cuMemGetAllocationPropertiesFromHandle",
732+
Diagnostics::TRY_EXPERIMENTAL_FEATURE,
733+
ARG("cuMemGetAllocationPropertiesFromHandle"),
734+
ARG("--use-experimental-features=virtual_mem")))
721735

722736
CONDITIONAL_FACTORY_ENTRY(
723737
UseExpVirtualMemory,
@@ -734,7 +748,7 @@ CONDITIONAL_FACTORY_ENTRY(
734748
UNSUPPORT_FACTORY_ENTRY("cuMemAddressReserve",
735749
Diagnostics::TRY_EXPERIMENTAL_FEATURE,
736750
ARG("cuMemAddressReserve"),
737-
ARG("--use-experimental-features=virtual_memory")))
751+
ARG("--use-experimental-features=virtual_mem")))
738752

739753
CONDITIONAL_FACTORY_ENTRY(
740754
UseExpVirtualMemory,
@@ -750,7 +764,7 @@ CONDITIONAL_FACTORY_ENTRY(
750764
UNSUPPORT_FACTORY_ENTRY("cuMemAddressFree",
751765
Diagnostics::TRY_EXPERIMENTAL_FEATURE,
752766
ARG("cuMemAddressFree"),
753-
ARG("--use-experimental-features=virtual_memory")))
767+
ARG("--use-experimental-features=virtual_mem")))
754768

755769
CONDITIONAL_FACTORY_ENTRY(
756770
UseExpVirtualMemory,
@@ -770,7 +784,7 @@ CONDITIONAL_FACTORY_ENTRY(
770784
UNSUPPORT_FACTORY_ENTRY("cuMemGetAllocationGranularity",
771785
Diagnostics::TRY_EXPERIMENTAL_FEATURE,
772786
ARG("cuMemGetAllocationGranularity"),
773-
ARG("--use-experimental-features=virtual_memory")))
787+
ARG("--use-experimental-features=virtual_mem")))
774788

775789
CONDITIONAL_FACTORY_ENTRY(
776790
UseExpVirtualMemory,
@@ -780,7 +794,7 @@ CONDITIONAL_FACTORY_ENTRY(
780794
UNSUPPORT_FACTORY_ENTRY("cuMemRelease",
781795
Diagnostics::TRY_EXPERIMENTAL_FEATURE,
782796
ARG("cuMemRelease"),
783-
ARG("--use-experimental-features=virtual_memory")))
797+
ARG("--use-experimental-features=virtual_mem")))
784798

785799
CONDITIONAL_FACTORY_ENTRY(
786800
UseExpVirtualMemory,
@@ -795,7 +809,7 @@ CONDITIONAL_FACTORY_ENTRY(
795809
ARG(2)))),
796810
UNSUPPORT_FACTORY_ENTRY("cuMemMap", Diagnostics::TRY_EXPERIMENTAL_FEATURE,
797811
ARG("cuMemMap"),
798-
ARG("--use-experimental-features=virtual_memory")))
812+
ARG("--use-experimental-features=virtual_mem")))
799813

800814
CONDITIONAL_FACTORY_ENTRY(
801815
UseExpVirtualMemory,
@@ -810,7 +824,7 @@ CONDITIONAL_FACTORY_ENTRY(
810824
"get_current_device().get_context()"))))),
811825
UNSUPPORT_FACTORY_ENTRY("cuMemUnmap", Diagnostics::TRY_EXPERIMENTAL_FEATURE,
812826
ARG("cuMemUnmap"),
813-
ARG("--use-experimental-features=virtual_memory")))
827+
ARG("--use-experimental-features=virtual_mem")))
814828

815829
CONDITIONAL_FACTORY_ENTRY(
816830
UseExpVirtualMemory,
@@ -828,7 +842,7 @@ CONDITIONAL_FACTORY_ENTRY(
828842
UNSUPPORT_FACTORY_ENTRY("cuMemSetAccess",
829843
Diagnostics::TRY_EXPERIMENTAL_FEATURE,
830844
ARG("cuMemSetAccess"),
831-
ARG("--use-experimental-features=virtual_memory")))
845+
ARG("--use-experimental-features=virtual_mem")))
832846

833847
CONDITIONAL_FACTORY_ENTRY(
834848
UsePeerAccess(),

clang/lib/DPCT/RulesLang/RulesLang.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8055,7 +8055,8 @@ void VirtualMemRule::registerMatcher(ast_matchers::MatchFinder &MF) {
80558055
auto virtualmemoryAPI = [&]() {
80568056
return hasAnyName("cuMemCreate", "cuMemAddressReserve", "cuMemMap",
80578057
"cuMemUnmap", "cuMemAddressFree", "cuMemRelease",
8058-
"cuMemSetAccess", "cuMemGetAllocationGranularity");
8058+
"cuMemSetAccess", "cuMemGetAllocationGranularity",
8059+
"cuMemGetAllocationPropertiesFromHandle");
80598060
};
80608061
auto virtualmemoryType = [&]() {
80618062
return hasAnyName("CUmemAllocationProp", "CUmemGenericAllocationHandle",

clang/lib/DPCT/SrcAPI/APINames.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,7 @@ ENTRY(cuMemCreate, cuMemCreate, true, NO_FLAG, P4, "comment")
17251725
ENTRY(cuMemExportToShareableHandle, cuMemExportToShareableHandle, false, NO_FLAG, P4, "comment")
17261726
ENTRY(cuMemGetAccess, cuMemGetAccess, false, NO_FLAG, P4, "comment")
17271727
ENTRY(cuMemGetAllocationGranularity, cuMemGetAllocationGranularity, true, NO_FLAG, P4, "comment")
1728-
ENTRY(cuMemGetAllocationPropertiesFromHandle, cuMemGetAllocationPropertiesFromHandle, false, NO_FLAG, P4, "comment")
1728+
ENTRY(cuMemGetAllocationPropertiesFromHandle, cuMemGetAllocationPropertiesFromHandle, true, NO_FLAG, P4, "Successful")
17291729
ENTRY(cuMemImportFromShareableHandle, cuMemImportFromShareableHandle, false, NO_FLAG, P4, "comment")
17301730
ENTRY(cuMemMap, cuMemMap, true, NO_FLAG, P4, "comment")
17311731
ENTRY(cuMemMapArrayAsync, cuMemMapArrayAsync, false, NO_FLAG, P7, "comment")

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,14 +677,14 @@ namespace experimental {
677677
typedef sycl::ext::oneapi::experimental::physical_mem *physical_mem_ptr;
678678

679679
struct mem_location {
680-
int id;
681-
int type; // Location type. Value 1 means device location, and thus, id is a
682-
// device id.
680+
int id = 0;
681+
// Location type. Value 1 means device location, and thus, id is a device id.
682+
int type = 1;
683683
};
684684

685685
struct mem_prop {
686686
mem_location location;
687-
int type; // Memory type. Value 1 means default device memory.
687+
int type = 1; // Memory type. Value 1 means default device memory.
688688
};
689689

690690
struct mem_access_desc {

clang/test/dpct/virtual_memory.cu

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,17 @@ int main() {
3838
cuMemCreate(&allocHandle, POOL_SIZE, &prop, 0);
3939
cuMemMap(reserved_addr, POOL_SIZE, 0, allocHandle, 0);
4040

41+
// CHECK: prop.location.id = dpct::get_device_id(allocHandle->get_device());
42+
cuMemGetAllocationPropertiesFromHandle(&prop, allocHandle);
43+
4144
// CHECK: dpct::experimental::mem_access_desc accessDesc = {};
4245
// CHECK: accessDesc.location.type = 1;
43-
// CHECK: accessDesc.location.id = device;
46+
// CHECK: accessDesc.location.id = prop.location.id;
4447
// CHECK: accessDesc.flags = sycl::ext::oneapi::experimental::address_access_mode::read_write;
4548
// CHECK: sycl::ext::oneapi::experimental::set_access_mode(reserved_addr, POOL_SIZE, accessDesc.flags, dpct::get_device(accessDesc.location.id).get_context());
4649
CUmemAccessDesc accessDesc = {};
4750
accessDesc.location.type = CU_MEM_LOCATION_TYPE_DEVICE;
48-
accessDesc.location.id = device;
51+
accessDesc.location.id = prop.location.id;
4952
accessDesc.flags = CU_MEM_ACCESS_FLAGS_PROT_READWRITE;
5053
cuMemSetAccess(reserved_addr, POOL_SIZE, &accessDesc, 1);
5154
int* host_data = new int[SIZE];

0 commit comments

Comments
 (0)