Shortcuts

DLA

DLA NVIDIA深度学习加速器是一个针对深度学习操作的固定功能加速引擎。DLA旨在对卷积神经网络进行全硬件加速。DLA支持各种层,如卷积、反卷积、全连接、激活、池化、批量归一化等。torch_tensorrt支持在NVIDIA嵌入式平台上可用的DLA硬件上编译TorchScript模块和部署管道。

注意:DLA仅支持fp16和int8精度。

使用DLA与torchtrtc

torchtrtc [input_file_path] [output_file_path] [input_shapes...] -p f16 -d dla {OPTIONS}

在C++应用程序中使用DLA

std::vector<std::vector<int64_t>> input_shape = {{32, 3, 32, 32}};
auto compile_spec = torch_tensorrt::CompileSpec({input_shape});

# Set a precision. DLA supports fp16 or int8 only
compile_spec.enabled_precisions = {torch::kF16};
compile_spec.device.device_type = torch_tensorrt::CompileSpec::DeviceType::kDLA;

# Make sure the gpu id is set to Xavier id for DLA
compile_spec.device.gpu_id = 0;

# Set the DLA core id
compile_spec.device.dla_core = 1;

# If a layer fails to run on DLA it will fallback to GPU
compile_spec.device.allow_gpu_fallback = true;

在Python应用程序中使用DLA

compile_spec = {
    "inputs": [torch_tensorrt.Input(self.input.shape)],
    "device": torch_tensorrt.Device("dla:0", allow_gpu_fallback=True),
    "enabled_precisions": {torch.half},
}

trt_mod = torch_tensorrt.compile(self.scripted_model, compile_spec)