Skip to content

Commit 771e67b

Browse files
committed
refactor(serde): Address PR comments
Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
1 parent 9327cce commit 771e67b

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

core/runtime/CudaDevice.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ CudaDevice::CudaDevice(int64_t gpu_id, nvinfer1::DeviceType device_type) {
3434
// Set Device name
3535
this->device_name = device_name;
3636

37-
// Set Device name len for serialization/deserialization
38-
this->device_name_len = device_name.size();
39-
4037
// Set Device Type
4138
this->device_type = device_type;
4239
}
@@ -70,14 +67,20 @@ CudaDevice::CudaDevice(std::string device_info) {
7067
}
7168

7269
std::string CudaDevice::serialize() {
70+
std::vector<std::string> content;
71+
content.resize(DEVICE_NAME_IDX + 1);
72+
73+
content[ID_IDX] = std::to_string(id);
74+
content[SM_MAJOR_IDX] = std::to_string(major);
75+
content[SM_MINOR_IDX] = std::to_string(minor);
76+
content[DEVICE_TYPE_IDX] = std::to_string((int64_t) device_type);
77+
content[DEVICE_NAME_IDX] = device_name;
78+
7379
std::stringstream ss;
74-
// clang-format off
75-
ss << id << DEVICE_INFO_DELIM \
76-
<< major << DEVICE_INFO_DELIM \
77-
<< minor << DEVICE_INFO_DELIM \
78-
<< (int64_t) device_type << DEVICE_INFO_DELIM
79-
<< device_name;
80-
// clang-format on
80+
for(size_t i = 0; i < content.size() - 1; i++) {
81+
ss << content[i] << DEVICE_INFO_DELIM;
82+
}
83+
ss << content[DEVICE_NAME_IDX];
8184

8285
std::string serialized_device_info = ss.str();
8386

core/runtime/register_trt_op.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,17 @@ bool is_switch_required(const CudaDevice& curr_device, const CudaDevice& conf_de
2727
if (curr_device.device_name != conf_device.device_name) {
2828
LOG_WARNING(
2929
"Program compiled for " << conf_device.device_name << " but current CUDA device is " << curr_device
30-
<< ". Switching the device context");
30+
<< ". Attempting to switch device context for better compatibility");
3131
return true;
3232
}
3333
}
3434

35-
// REVIEW: This shouldnt be a reason to switch GPU
36-
// if (curr_device.id != conf_device.id) {
37-
// LOG_WARNING(
38-
// "Configured Device ID: " << conf_device.id << " is different that current device ID: " << curr_device.id
39-
// << ". Switching context");
40-
// return true;
41-
// }
35+
if (curr_device.id != conf_device.id) {
36+
LOG_WARNING(
37+
"Configured Device ID: " << conf_device.id << " is different that current device ID: " << curr_device.id
38+
<< ". Moving input tensors to device: " << conf_device.id);
39+
return true;
40+
}
4241

4342
return false;
4443
}

core/runtime/runtime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void set_cuda_device(CudaDevice& cuda_device) {
1313
}
1414

1515
CudaDevice get_current_device() {
16-
int device = 0;
16+
int device = -1;
1717
TRTORCH_CHECK(
1818
(cudaGetDevice(reinterpret_cast<int*>(&device)) == cudaSuccess),
1919
"Unable to get current device (runtime.get_current_device)");

core/runtime/runtime.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ struct CudaDevice {
1818
int64_t major; // CUDA compute major version
1919
int64_t minor; // CUDA compute minor version
2020
nvinfer1::DeviceType device_type;
21-
size_t device_name_len;
2221
std::string device_name;
2322

2423
CudaDevice();

0 commit comments

Comments
 (0)