Skip to content

Commit 48115d2

Browse files
authored
[SYCLomatic] Migrate the cudaCpuDeviceId defined macro. (#2725)
Signed-off-by: Chen, Sheng S <sheng.s.chen@intel.com>
1 parent 0db898c commit 48115d2

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

clang/lib/DPCT/RuleInfra/MapNames.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ void MapNames::setExplicitNamespaceMap(
290290
{"CubDebugExit",
291291
MacroMigrationRule("dpct_build_in_macro_rule", RulePriority::Fallback,
292292
"CubDebugExit", MapNames::getCheckErrorMacroName())},
293+
{"cudaCpuDeviceId",
294+
MacroMigrationRule("cudaCpuDeviceId", RulePriority::Fallback,
295+
"cudaCpuDeviceId",
296+
getDpctNamespace() + "get_cpu_device_id()")},
293297
//...
294298
};
295299
// Type names mapping.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,10 @@ static inline unsigned int get_device_id(const sycl::device &dev){
953953
return dev_mgr::instance().get_device_id(dev);
954954
}
955955

956+
static inline unsigned int get_cpu_device_id() {
957+
return get_device_id(cpu_device());
958+
}
959+
956960
/// Util function to do implicit sync among queues of the same device then
957961
/// insert a synchronize barrier in the queue. For USM, If the queue is the
958962
/// default in-order queue, try to sync with all queues available in the current

clang/test/dpct/memory_management_restricted.cu

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ int main(){
9292
// CHECK: MY_ERROR_CHECKER(DPCT_CHECK_ERROR(dpct::cpu_device().in_order_queue().prefetch(a,100)));
9393
MY_ERROR_CHECKER(cudaMemPrefetchAsync(a, 100, cudaCpuDeviceId, nullptr));
9494

95+
// CHECK: int dev_id = dpct::get_cpu_device_id();
96+
int dev_id = cudaCpuDeviceId;
97+
9598
//CHECK: stream_array[0]->memcpy(h_A, d_A, size2);
9699
cudaMemcpyAsync(h_A, d_A, size2, cudaMemcpyDeviceToHost, stream_array[0]);
97100

0 commit comments

Comments
 (0)