Skip to content

Commit ceb8afb

Browse files
committed
Formatted the file
1 parent 271525b commit ceb8afb

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

core/runtime/TRTEngine.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ TRTEngine::TRTEngine(std::vector<std::string> serialized_info)
8686
static_cast<bool>(std::stoi(serialized_info[HW_COMPATIBLE_IDX])),
8787
static_cast<bool>(std::stoi(serialized_info[REQUIRES_OUTPUT_ALLOCATOR_IDX])),
8888
serialized_info[SERIALIZED_METADATA_IDX],
89-
(static_cast<bool>(std::stoi(serialized_info[RESOURCE_ALLOCATION_STRATEGY_IDX])) ? ResourceAllocationStrategy::kDynamic : ResourceAllocationStrategy::kStatic)) {}
89+
(static_cast<bool>(std::stoi(serialized_info[RESOURCE_ALLOCATION_STRATEGY_IDX]))
90+
? ResourceAllocationStrategy::kDynamic
91+
: ResourceAllocationStrategy::kStatic)) {}
9092

9193
TRTEngine::TRTEngine(
9294
const std::string& mod_name,
@@ -129,7 +131,9 @@ TRTEngine::TRTEngine(
129131
}
130132

131133
this->resource_allocation_strategy = resource_allocation_strategy;
132-
LOG_DEBUG("Resource allocation strategy: " << (this->resource_allocation_strategy == ResourceAllocationStrategy::kDynamic ? "Dynamic" : "Static"));
134+
LOG_DEBUG(
135+
"Resource allocation strategy: "
136+
<< (this->resource_allocation_strategy == ResourceAllocationStrategy::kDynamic ? "Dynamic" : "Static"));
133137
if (this->resource_allocation_strategy == ResourceAllocationStrategy::kDynamic) {
134138
this->exec_ctx =
135139
make_trt(cuda_engine->createExecutionContext(nvinfer1::ExecutionContextAllocationStrategy::kUSER_MANAGED));
@@ -472,7 +476,8 @@ std::vector<std::string> TRTEngine::serialize() {
472476
serialized_info[REQUIRES_OUTPUT_ALLOCATOR_IDX] = this->requires_output_allocator ? "1" : "0";
473477
serialized_info[SERIALIZED_METADATA_IDX] = this->serialized_metadata;
474478
serialized_info[TARGET_PLATFORM_IDX] = this->target_platform.serialize();
475-
serialized_info[RESOURCE_ALLOCATION_STRATEGY_IDX] = this->resource_allocation_strategy == ResourceAllocationStrategy::kDynamic ? "1" : "0";
479+
serialized_info[RESOURCE_ALLOCATION_STRATEGY_IDX] =
480+
this->resource_allocation_strategy == ResourceAllocationStrategy::kDynamic ? "1" : "0";
476481

477482
return serialized_info;
478483
}
@@ -486,11 +491,11 @@ void TRTEngine::set_resource_allocation_strategy(TRTEngine::ResourceAllocationSt
486491
this->resource_allocation_strategy = new_strategy;
487492
if (this->resource_allocation_strategy == TRTEngine::ResourceAllocationStrategy::kDynamic) {
488493
LOG_DEBUG("Setting resource allocation strategy to dynamic");
489-
this->exec_ctx = make_trt(cuda_engine->createExecutionContext(nvinfer1::ExecutionContextAllocationStrategy::kUSER_MANAGED));
494+
this->exec_ctx =
495+
make_trt(cuda_engine->createExecutionContext(nvinfer1::ExecutionContextAllocationStrategy::kUSER_MANAGED));
490496
} else {
491497
LOG_DEBUG("Setting resource allocation strategy to static");
492-
this->exec_ctx = make_trt(
493-
cuda_engine->createExecutionContext());
498+
this->exec_ctx = make_trt(cuda_engine->createExecutionContext());
494499
}
495500
}
496501
}

core/runtime/register_jit_hooks.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ static auto TORCHTRT_UNUSED TRTEngineTSRegistrtion =
109109
[](const c10::intrusive_ptr<TRTEngine>& self) -> std::vector<std::string> { return self->serialize(); },
110110
[](std::vector<std::string> serialized_info) -> c10::intrusive_ptr<TRTEngine> {
111111
serialized_info[ENGINE_IDX] = base64_decode(serialized_info[ENGINE_IDX]);
112-
LOG_DEBUG("Deserialized resource allocation strategy: " << (static_cast<bool>(std::stoi(serialized_info[RESOURCE_ALLOCATION_STRATEGY_IDX])) ? "Dynamic" : "Static"));
112+
LOG_DEBUG(
113+
"Deserialized resource allocation strategy: "
114+
<< (static_cast<bool>(std::stoi(serialized_info[RESOURCE_ALLOCATION_STRATEGY_IDX])) ? "Dynamic"
115+
: "Static"));
113116
TRTEngine::verify_serialization_fmt(serialized_info);
114117
return c10::make_intrusive<TRTEngine>(serialized_info);
115118
});

py/torch_tensorrt/dynamo/runtime/_ResourceAllocator.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ResourceAllocationStrategy(torch.nn.Module): # type: ignore[misc]
1414
def __init__(
1515
self,
1616
compiled_module: torch.nn.Module,
17-
dynamically_allocate_resources: bool = True
17+
dynamically_allocate_resources: bool = True,
1818
) -> None:
1919
super(ResourceAllocationStrategy, self).__init__()
2020
self.compiled_module = compiled_module
@@ -24,9 +24,13 @@ def __enter__(self) -> None:
2424
print("Entering resource allocator context")
2525
for name, submodule in self.compiled_module.named_modules():
2626
if "_run_on_acc" in name:
27-
submodule.use_dynamically_allocated_resources(dynamically_allocate_resources=self.dynamically_allocate_resources)
27+
submodule.use_dynamically_allocated_resources(
28+
dynamically_allocate_resources=self.dynamically_allocate_resources
29+
)
2830

2931
def __exit__(self, exc_type: Any, exc_value: Any, exc_tb: Any) -> None:
3032
for name, submodule in self.compiled_module.named_modules():
3133
if "_run_on_acc" in name:
32-
submodule.use_dynamically_allocated_resources(dynamically_allocate_resources=self.dynamically_allocate_resources)
34+
submodule.use_dynamically_allocated_resources(
35+
dynamically_allocate_resources=self.dynamically_allocate_resources
36+
)

0 commit comments

Comments
 (0)