Skip to content

Commit 03a13bd

Browse files
committed
Move property determination
1 parent 31feaa2 commit 03a13bd

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

interfaces/cuda/Control.cu

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ void ConcreteAPI::setDevice(int deviceId) {
4040
cudaFree(nullptr);
4141
CHECK_ERR;
4242

43-
int result;
44-
cudaDeviceGetAttribute(&result, cudaDevAttrDirectManagedMemAccessFromHost, getDeviceId());
45-
usmDefault = result != 0;
46-
4743
status[StatusID::DeviceSelected] = true;
4844
}
4945

@@ -64,6 +60,9 @@ void ConcreteAPI::initialize() {
6460
CHECK_ERR;
6561
allowedConcurrentManagedAccess = result != 0;
6662

63+
cudaDeviceGetAttribute(&result, cudaDevAttrDirectManagedMemAccessFromHost, getDeviceId());
64+
usmDefault = result != 0;
65+
6766
cudaDeviceGetStreamPriorityRange(&priorityMin, &priorityMax);
6867
CHECK_ERR;
6968

interfaces/hip/Control.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,6 @@ void ConcreteAPI::setDevice(int deviceId) {
4040
hipFree(nullptr);
4141
CHECK_ERR;
4242

43-
hipDeviceProp_t properties{};
44-
hipGetDeviceProperties(&properties, deviceId);
45-
CHECK_ERR;
46-
47-
// NOTE: hipDeviceGetAttribute internally calls hipGetDeviceProperties; hence it doesn't make sense to use it here
48-
49-
if constexpr (HIP_VERSION >= 60200000) {
50-
// cf. https://rocm.docs.amd.com/en/docs-6.2.0/about/release-notes.html
51-
// (before 6.2.0, the flag hipDeviceAttributePageableMemoryAccessUsesHostPageTables had effectively the same effect)
52-
// (cf. https://github.com/ROCm/clr/commit/7d5b4a8f7a7d34f008d65277f8aae4c98a6da375#diff-596cd550f7fdef76b39f1b7b179b20128313dd9cc9ec662b2eae562efa2b7f33L405 )
53-
usmDefault = properties.integrated != 0;
54-
}
55-
else {
56-
usmDefault = properties.directManagedMemAccessFromHost != 0 && properties.pageableMemoryAccessUsesHostPageTables != 0;
57-
}
58-
59-
hipDeviceGetStreamPriorityRange(&priorityMin, &priorityMax);
60-
CHECK_ERR;
61-
6243
status[StatusID::DeviceSelected] = true;
6344
}
6445

@@ -74,6 +55,25 @@ void ConcreteAPI::initialize() {
7455
if (!status[StatusID::InterfaceInitialized]) {
7556
status[StatusID::InterfaceInitialized] = true;
7657
hipStreamCreateWithFlags(&defaultStream, hipStreamNonBlocking); CHECK_ERR;
58+
59+
hipDeviceProp_t properties{};
60+
hipGetDeviceProperties(&properties, deviceId);
61+
CHECK_ERR;
62+
63+
// NOTE: hipDeviceGetAttribute internally calls hipGetDeviceProperties; hence it doesn't make sense to use it here
64+
65+
if constexpr (HIP_VERSION >= 60200000) {
66+
// cf. https://rocm.docs.amd.com/en/docs-6.2.0/about/release-notes.html
67+
// (before 6.2.0, the flag hipDeviceAttributePageableMemoryAccessUsesHostPageTables had effectively the same effect)
68+
// (cf. https://github.com/ROCm/clr/commit/7d5b4a8f7a7d34f008d65277f8aae4c98a6da375#diff-596cd550f7fdef76b39f1b7b179b20128313dd9cc9ec662b2eae562efa2b7f33L405 )
69+
usmDefault = properties.integrated != 0;
70+
}
71+
else {
72+
usmDefault = properties.directManagedMemAccessFromHost != 0 && properties.pageableMemoryAccessUsesHostPageTables != 0;
73+
}
74+
75+
hipDeviceGetStreamPriorityRange(&priorityMin, &priorityMax);
76+
CHECK_ERR;
7777
}
7878
else {
7979
logWarning() << "Device Interface has already been initialized";

0 commit comments

Comments
 (0)