SWDEV-494149 - Improve hipGet/Set Device

Change-Id: If8975687a3ba9caadafc48a0066f19a4ebaab9e2
This commit is contained in:
Saleel Kudchadker
2024-11-05 22:52:57 +00:00
والد 2ca644cf22
کامیت 6611cc015d
3فایلهای تغییر یافته به همراه25 افزوده شده و 17 حذف شده
@@ -656,16 +656,17 @@ int ihipGetDevice() {
hipError_t hipGetDevice(int* deviceId) {
HIP_INIT_API(hipGetDevice, deviceId);
if (deviceId != nullptr) {
int dev = ihipGetDevice();
if (dev == -1) {
HIP_RETURN(hipErrorNoDevice);
}
*deviceId = dev;
HIP_RETURN(hipSuccess, *deviceId);
} else {
if (deviceId == nullptr) {
HIP_RETURN(hipErrorInvalidValue);
}
Device* device = hip::getCurrentDevice();
if (device == nullptr) {
HIP_RETURN(hipErrorNoDevice);
}
*deviceId = device->deviceId();
HIP_RETURN(hipSuccess, *deviceId);
}
hipError_t hipGetDeviceCount(int* count) {
@@ -685,6 +686,12 @@ hipError_t hipGetDeviceFlags(unsigned int* flags) {
hipError_t hipSetDevice(int device) {
HIP_INIT_API_NO_RETURN(hipSetDevice, device);
// Check if the device is already set
if (hip::tls.device_ != nullptr && hip::tls.device_->deviceId() == device) {
HIP_RETURN(hipSuccess);
}
if (static_cast<unsigned int>(device) < g_devices.size()) {
hip::setCurrentDevice(device);