Skip to content

Commit 84cc0ac

Browse files
authored
[SYCLomatic] Migrate device ID and UUID (#732)
* [SYCLomatic] Migrate device ID and UUID Signed-off-by: Michael Aziz <[email protected]> * [SYCLomatic] Disable device info migration with option Signed-off-by: Michael Aziz <[email protected]> --------- Signed-off-by: Michael Aziz <[email protected]>
1 parent 54bae02 commit 84cc0ac

File tree

10 files changed

+170
-7
lines changed

10 files changed

+170
-7
lines changed

clang/lib/DPCT/ASTTraversal.cpp

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,7 +2020,7 @@ void TypeInDeclRule::registerMatcher(MatchFinder &MF) {
20202020
"cublasAtomicsMode_t", "CUmem_advise_enum", "CUmem_advise",
20212021
"thrust::tuple_element", "thrust::tuple_size", "cublasMath_t",
20222022
"cudaPointerAttributes", "thrust::zip_iterator",
2023-
"cusolverEigRange_t")
2023+
"cusolverEigRange_t", "cudaUUID_t")
20242024
)))))
20252025
.bind("cudaTypeDef"),
20262026
this);
@@ -3524,8 +3524,7 @@ void DeviceInfoVarRule::runRule(const MatchFinder::MatchResult &Result) {
35243524
emplaceTransformation(
35253525
new ReplaceToken(ME->getBeginLoc(), ME->getEndLoc(), "false"));
35263526
return;
3527-
} else if (MemberName == "pciDomainID" || MemberName == "pciBusID" ||
3528-
MemberName == "pciDeviceID") {
3527+
} else if (MemberName == "pciDomainID" || MemberName == "pciBusID") {
35293528
report(ME->getBeginLoc(), Diagnostics::UNCOMPATIBLE_DEVICE_PROP, false,
35303529
MemberName, "-1");
35313530
emplaceTransformation(
@@ -3565,6 +3564,13 @@ void DeviceInfoVarRule::runRule(const MatchFinder::MatchResult &Result) {
35653564
report(ME->getBeginLoc(), Diagnostics::MAX_GRID_SIZE, false);
35663565
}
35673566

3567+
if (!DpctGlobalInfo::useDeviceInfo() &&
3568+
(MemberName == "pciDeviceID" || MemberName == "uuid")) {
3569+
report(ME->getBeginLoc(), Diagnostics::UNMIGRATED_DEVICE_PROP, false,
3570+
MemberName);
3571+
return;
3572+
}
3573+
35683574
auto Search = PropNamesMap.find(MemberName);
35693575
if (Search == PropNamesMap.end()) {
35703576
return;
@@ -3589,6 +3595,15 @@ void DeviceInfoVarRule::runRule(const MatchFinder::MatchResult &Result) {
35893595
emplaceTransformation(new ReplaceText(BO->getOperatorLoc(), 1, "("));
35903596
emplaceTransformation(new InsertAfterStmt(BO, ")"));
35913597
}
3598+
} else if (auto *OCE = Parents[0].get<clang::CXXOperatorCallExpr>()) {
3599+
// migrate to set_XXX() for types with an overloaded = operator
3600+
if (OCE->getOperator() == clang::OverloadedOperatorKind::OO_Equal) {
3601+
requestFeature(PropToSetFeatureMap.at(MemberName), ME);
3602+
emplaceTransformation(
3603+
new RenameFieldInMemberExpr(ME, "set_" + Search->second));
3604+
emplaceTransformation(new ReplaceText(OCE->getOperatorLoc(), 1, "("));
3605+
emplaceTransformation(new InsertAfterStmt(OCE, ")"));
3606+
}
35923607
}
35933608
if ((Search->second.compare(0, 13, "major_version") == 0) ||
35943609
(Search->second.compare(0, 13, "minor_version") == 0)) {
@@ -15264,3 +15279,22 @@ void CudaExtentRule::runRule(
1526415279
}
1526515280

1526615281
REGISTER_RULE(CudaExtentRule, PassKind::PK_Analysis)
15282+
15283+
void CudaUuidRule::registerMatcher(ast_matchers::MatchFinder &MF) {
15284+
MF.addMatcher(memberExpr(hasObjectExpression(hasType(namedDecl(
15285+
hasAnyName("CUuuid_st", "cudaUUID_t")))),
15286+
member(hasName("bytes")))
15287+
.bind("UUID_bytes"),
15288+
this);
15289+
}
15290+
15291+
void CudaUuidRule::runRule(
15292+
const ast_matchers::MatchFinder::MatchResult &Result) {
15293+
if (auto ME = Result.Nodes.getNodeAs<MemberExpr>("UUID_bytes")) {
15294+
const auto SM = Result.SourceManager;
15295+
const auto Begin = SM->getSpellingLoc(ME->getOperatorLoc());
15296+
return emplaceTransformation(new ReplaceText(Begin, 6, ""));
15297+
}
15298+
}
15299+
15300+
REGISTER_RULE(CudaUuidRule, PassKind::PK_Analysis)

clang/lib/DPCT/ASTTraversal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,12 @@ class CudaExtentRule : public NamedMigrationRule<CudaExtentRule> {
583583
}
584584
};
585585

586+
class CudaUuidRule : public NamedMigrationRule<CudaUuidRule> {
587+
public:
588+
void registerMatcher(ast_matchers::MatchFinder &MF) override;
589+
void runRule(const ast_matchers::MatchFinder::MatchResult &Result);
590+
};
591+
586592
/// Migration rule for return types replacements.
587593
class ReturnTypeRule : public NamedMigrationRule<ReturnTypeRule> {
588594
public:

clang/lib/DPCT/CustomHelperFiles.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,10 @@ const std::unordered_map<std::string, HelperFeatureEnum> PropToGetFeatureMap = {
11281128
HelperFeatureEnum::Device_device_info_get_memory_clock_rate},
11291129
{"memoryBusWidth",
11301130
HelperFeatureEnum::Device_device_info_get_memory_bus_width},
1131+
{"pciDeviceID",
1132+
HelperFeatureEnum::Device_device_info_get_device_id},
1133+
{"uuid",
1134+
HelperFeatureEnum::Device_device_info_get_uuid},
11311135
};
11321136

11331137
const std::unordered_map<std::string, HelperFeatureEnum> PropToSetFeatureMap = {
@@ -1156,6 +1160,10 @@ const std::unordered_map<std::string, HelperFeatureEnum> PropToSetFeatureMap = {
11561160
HelperFeatureEnum::Device_device_info_set_memory_clock_rate},
11571161
{"memoryBusWidth",
11581162
HelperFeatureEnum::Device_device_info_set_memory_bus_width},
1163+
{"pciDeviceID",
1164+
HelperFeatureEnum::Device_device_info_set_device_id},
1165+
{"uuid",
1166+
HelperFeatureEnum::Device_device_info_set_uuid},
11591167
};
11601168

11611169
const std::unordered_map<std::string, HelperFeatureEnum>

clang/lib/DPCT/MapNames.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ void MapNames::setExplicitNamespaceMap() {
431431
{"cuda::std::complex", std::make_shared<TypeNameRule>("std::complex")},
432432
{"cuda::std::array", std::make_shared<TypeNameRule>("std::array")},
433433
{"cusolverEigRange_t", std::make_shared<TypeNameRule>("oneapi::mkl::rangev")},
434+
{"cudaUUID_t", std::make_shared<TypeNameRule>("std::array<unsigned char, 16>")},
434435
// ...
435436
};
436437

@@ -4228,6 +4229,8 @@ const MapNames::MapTy DeviceInfoVarRule::PropNamesMap{
42284229
{"maxThreadsDim", "max_work_item_sizes"},
42294230
{"memoryClockRate", "memory_clock_rate"},
42304231
{"memoryBusWidth", "memory_bus_width"},
4232+
{"pciDeviceID", "device_id"},
4233+
{"uuid", "uuid"},
42314234
// ...
42324235
};
42334236

clang/runtime/dpct-rt/include/device.hpp.inc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
// DPCT_CODE
4141
#include <sycl/sycl.hpp>
4242
#include <algorithm>
43+
#include <array>
4344
#include <cstring>
4445
#include <iostream>
4546
#include <mutex>
@@ -303,6 +304,20 @@ public:
303304
/// Returns the maximum bus width between device and memory in bits. If
304305
/// compiler does not support this API then returns default value 64 bits.
305306
unsigned int get_memory_bus_width() const { return _memory_bus_width; }
307+
// DPCT_LABEL_END
308+
// DPCT_LABEL_BEGIN|device_info_get_device_id|dpct
309+
// DPCT_DEPENDENCY_BEGIN
310+
// Device|device_info
311+
// DPCT_DEPENDENCY_END
312+
// DPCT_CODE
313+
uint32_t get_device_id() const { return _device_id; }
314+
// DPCT_LABEL_END
315+
// DPCT_LABEL_BEGIN|device_info_get_uuid|dpct
316+
// DPCT_DEPENDENCY_BEGIN
317+
// Device|device_info
318+
// DPCT_DEPENDENCY_END
319+
// DPCT_CODE
320+
std::array<unsigned char, 16> get_uuid() const { return _uuid; }
306321
// DPCT_LABEL_END
307322
// set interface
308323
// DPCT_LABEL_BEGIN|device_info_set_name|dpct
@@ -478,6 +493,26 @@ public:
478493
_max_register_size_per_work_group = max_register_size_per_work_group;
479494
}
480495
// DPCT_LABEL_END
496+
// DPCT_LABEL_BEGIN|device_info_set_device_id|dpct
497+
// DPCT_PARENT_FEATURE|device_info
498+
// DPCT_DEPENDENCY_BEGIN
499+
// Device|device_info
500+
// DPCT_DEPENDENCY_END
501+
// DPCT_CODE
502+
void set_device_id(uint32_t device_id) {
503+
_device_id = device_id;
504+
}
505+
// DPCT_LABEL_END
506+
// DPCT_LABEL_BEGIN|device_info_set_uuid|dpct
507+
// DPCT_PARENT_FEATURE|device_info
508+
// DPCT_DEPENDENCY_BEGIN
509+
// Device|device_info
510+
// DPCT_DEPENDENCY_END
511+
// DPCT_CODE
512+
void set_uuid(std::array<unsigned char, 16> uuid) {
513+
_uuid = std::move(uuid);
514+
}
515+
// DPCT_LABEL_END
481516
// DPCT_LABEL_BEGIN|device_info_1|dpct
482517
// DPCT_PARENT_FEATURE|device_info
483518
// DPCT_DEPENDENCY_BEGIN
@@ -506,6 +541,8 @@ private:
506541
size_t _local_mem_size;
507542
size_t _max_nd_range_size[3];
508543
int _max_nd_range_size_i[3];
544+
uint32_t _device_id;
545+
std::array<unsigned char, 16> _uuid;
509546
};
510547
// DPCT_LABEL_END
511548

@@ -769,6 +806,14 @@ public:
769806
prop.set_memory_bus_width(
770807
this->get_info<sycl::ext::intel::info::device::memory_bus_width>());
771808
}
809+
if (this->has(sycl::aspect::ext_intel_device_id)) {
810+
prop.set_device_id(
811+
this->get_info<sycl::ext::intel::info::device::device_id>());
812+
}
813+
if (this->has(sycl::aspect::ext_intel_device_info_uuid)) {
814+
prop.set_uuid(
815+
this->get_info<sycl::ext::intel::info::device::uuid>());
816+
}
772817
#elif defined(_MSC_VER) && !defined(__clang__)
773818
#pragma message("get_device_info: querying memory_clock_rate and \
774819
memory_bus_width are not supported by the compiler used. \

clang/test/dpct/device001.cu

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// UNSUPPORTED: cuda-8.0, cuda-9.1, cuda-9.2
2+
// UNSUPPORTED: v8.0, v9.1, v9.2
13
// RUN: dpct --format-range=none --usm-level=none -out-root %T/device001 %s --cuda-include-path="%cuda-path/include" --sycl-named-lambda -- -x cuda --cuda-host-only
24
// RUN: FileCheck %s --match-full-lines --input-file %T/device001/device001.dp.cpp
35

@@ -8,6 +10,16 @@ int main(int argc, char **argv) {
810
// CHECK: dpct::device_info deviceProp;
911
cudaDeviceProp deviceProp;
1012

13+
// CHECK: std::array<unsigned char, 16> uuid = deviceProp.get_uuid();
14+
cudaUUID_t uuid = deviceProp.uuid;
15+
// CHECK: deviceProp.set_uuid(uuid);
16+
deviceProp.uuid=uuid;
17+
18+
// CHECK: int device_id = deviceProp.get_device_id();
19+
int device_id = deviceProp.pciDeviceID;
20+
// CHECK: deviceProp.set_device_id(device_id);
21+
deviceProp.pciDeviceID=device_id;
22+
1123
// CHECK: /*
1224
// CHECK-NEXT: DPCT1035:{{[0-9]+}}: All SYCL devices can be used by the host to submit tasks. You may need to adjust this code.
1325
// CHECK-NEXT: */

clang/test/dpct/device004.cu

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// UNSUPPORTED: cuda-8.0, cuda-9.1, cuda-9.2
2+
// UNSUPPORTED: v8.0, v9.1, v9.2
3+
// RUN: dpct --no-dpcpp-extensions=device_info -out-root %T/device004 %s --cuda-include-path="%cuda-path/include" -- -x cuda --cuda-host-only
4+
// RUN: FileCheck %s --match-full-lines --input-file %T/device004/device004.dp.cpp
5+
6+
#include <cuda.h>
7+
#include <iostream>
8+
9+
int main() {
10+
cudaDeviceProp properties;
11+
cudaGetDeviceProperties(&properties, 0);
12+
13+
// CHECK: /*
14+
// CHECK-NEXT: DPCT1090:{{[0-9]+}}: SYCL does not support the device property that would be functionally compatible with pciDeviceID. It was not migrated. You need to rewrite the code.
15+
// CHECK-NEXT: */
16+
// CHECK-NEXT: const int id = properties.pciDeviceID;
17+
const int id = properties.pciDeviceID;
18+
// CHECK: /*
19+
// CHECK-NEXT: DPCT1090:{{[0-9]+}}: SYCL does not support the device property that would be functionally compatible with uuid. It was not migrated. You need to rewrite the code.
20+
// CHECK-NEXT: */
21+
// CHECK-NEXT: const std::array<unsigned char, 16> uuid = properties.uuid;
22+
const cudaUUID_t uuid = properties.uuid;
23+
// CHECK: /*
24+
// CHECK-NEXT: DPCT1090:{{[0-9]+}}: SYCL does not support the device property that would be functionally compatible with pciDeviceID. It was not migrated. You need to rewrite the code.
25+
// CHECK-NEXT: */
26+
// CHECK-NEXT: properties.pciDeviceID = id;
27+
properties.pciDeviceID = id;
28+
// CHECK: /*
29+
// CHECK-NEXT: DPCT1090:{{[0-9]+}}: SYCL does not support the device property that would be functionally compatible with uuid. It was not migrated. You need to rewrite the code.
30+
// CHECK-NEXT: */
31+
// CHECK-NEXT: properties.uuid = uuid;
32+
properties.uuid = uuid;
33+
}

clang/test/dpct/helper_files_ref/include/device.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <sycl/sycl.hpp>
1313
#include <algorithm>
14+
#include <array>
1415
#include <cstring>
1516
#include <iostream>
1617
#include <mutex>
@@ -125,6 +126,8 @@ class device_info {
125126
/// Returns the maximum bus width between device and memory in bits. If
126127
/// compiler does not support this API then returns default value 64 bits.
127128
unsigned int get_memory_bus_width() const { return _memory_bus_width; }
129+
uint32_t get_device_id() const { return _device_id; }
130+
std::array<unsigned char, 16> get_uuid() const { return _uuid; }
128131
// set interface
129132
void set_name(const char* name) {
130133
size_t length = strlen(name);
@@ -182,6 +185,12 @@ class device_info {
182185
set_max_register_size_per_work_group(int max_register_size_per_work_group) {
183186
_max_register_size_per_work_group = max_register_size_per_work_group;
184187
}
188+
void set_device_id(uint32_t device_id) {
189+
_device_id = device_id;
190+
}
191+
void set_uuid(std::array<unsigned char, 16> uuid) {
192+
_uuid = std::move(uuid);
193+
}
185194
private:
186195
char _name[256];
187196
sycl::id<3> _max_work_item_sizes;
@@ -204,6 +213,8 @@ class device_info {
204213
size_t _local_mem_size;
205214
size_t _max_nd_range_size[3];
206215
int _max_nd_range_size_i[3];
216+
uint32_t _device_id;
217+
std::array<unsigned char, 16> _uuid;
207218
};
208219

209220
/// dpct device extension
@@ -332,6 +343,14 @@ class device_ext : public sycl::device {
332343
prop.set_memory_bus_width(
333344
this->get_info<sycl::ext::intel::info::device::memory_bus_width>());
334345
}
346+
if (this->has(sycl::aspect::ext_intel_device_id)) {
347+
prop.set_device_id(
348+
this->get_info<sycl::ext::intel::info::device::device_id>());
349+
}
350+
if (this->has(sycl::aspect::ext_intel_device_info_uuid)) {
351+
prop.set_uuid(
352+
this->get_info<sycl::ext::intel::info::device::uuid>());
353+
}
335354
#elif defined(_MSC_VER) && !defined(__clang__)
336355
#pragma message("get_device_info: querying memory_clock_rate and \
337356
memory_bus_width are not supported by the compiler used. \

clang/test/dpct/test_api_level/Device/api_test6.cu

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@
55

66
// CHECK: 35
77
// TEST_FEATURE: Device_device_ext_get_device_info_return_info
8+
// TEST_FEATURE: Device_device_info_get_device_id
9+
// TEST_FEATURE: Device_device_info_set_device_id
10+
// TEST_FEATURE: Device_device_info_get_uuid
11+
// TEST_FEATURE: Device_device_info_set_uuid
812

913
int main() {
1014
cudaDeviceProp deviceProp;
1115
cudaGetDeviceProperties(&deviceProp, 0);
16+
deviceProp.uuid;
17+
deviceProp.pciDeviceID;
1218
return 0;
1319
}

clang/test/dpct/types001.cu

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,10 +548,7 @@ void fun3() {
548548
// CHECK-NEXT: /*
549549
// CHECK-NEXT: DPCT1051:{{[0-9]+}}: SYCL does not support a device property functionally compatible with pciBusID. It was migrated to -1. You may need to adjust the value of -1 for the specific device.
550550
// CHECK-NEXT: */
551-
// CHECK-NEXT: /*
552-
// CHECK-NEXT: DPCT1051:{{[0-9]+}}: SYCL does not support a device property functionally compatible with pciDeviceID. It was migrated to -1. You may need to adjust the value of -1 for the specific device.
553-
// CHECK-NEXT: */
554-
// CHECK-NEXT: sprintf(devstr, "pci %x:%x:%x", -1, -1, -1);
551+
// CHECK-NEXT: sprintf(devstr, "pci %x:%x:%x", -1, -1, deviceProp.get_device_id());
555552
// CHECK-NEXT: /*
556553
// CHECK-NEXT: DPCT1051:{{[0-9]+}}: SYCL does not support a device property functionally compatible with concurrentKernels. It was migrated to true. You may need to adjust the value of true for the specific device.
557554
// CHECK-NEXT: */

0 commit comments

Comments
 (0)