Skip to content

Commit

Permalink
Samples refresh and bugfixes
Browse files Browse the repository at this point in the history
Signed-off-by: Rajeev Rao <[email protected]>
  • Loading branch information
rajeevsrao committed Apr 12, 2021
1 parent 80e2473 commit c4dbccc
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion samples/common/sampleEngines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ ICudaEngine* networkToEngine(const BuildOptions& build, const SystemOptions& sys
{
elemCount.push_back(volume(profileCalib->getDimensions(input->getName(), OptProfileSelector::kOPT)));
}
else if (profile)
else if (profile && (profile->getDimensions(input->getName(), OptProfileSelector::kOPT).nbDims >= 0))
{
elemCount.push_back(volume(profile->getDimensions(input->getName(), OptProfileSelector::kOPT)));
}
Expand Down
20 changes: 16 additions & 4 deletions samples/common/sampleOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ nvinfer1::DataType stringToValue<nvinfer1::DataType>(const std::string& option)
const std::unordered_map<std::string, nvinfer1::DataType> strToDT{{"fp32", nvinfer1::DataType::kFLOAT},
{"fp16", nvinfer1::DataType::kHALF}, {"int8", nvinfer1::DataType::kINT8},
{"int32", nvinfer1::DataType::kINT32}};
const auto dt = strToDT.find(option);
const auto& dt = strToDT.find(option);
if (dt == strToDT.end())
{
throw std::invalid_argument("Invalid DataType " + option);
Expand All @@ -109,11 +109,12 @@ nvinfer1::TensorFormats stringToValue<nvinfer1::TensorFormats>(const std::string
{"chw2", nvinfer1::TensorFormat::kCHW2}, {"chw4", nvinfer1::TensorFormat::kCHW4},
{"hwc8", nvinfer1::TensorFormat::kHWC8}, {"chw16", nvinfer1::TensorFormat::kCHW16},
{"chw32", nvinfer1::TensorFormat::kCHW32}, {"dhwc8", nvinfer1::TensorFormat::kDHWC8},
{"hwc", nvinfer1::TensorFormat::kHWC}};
{"hwc", nvinfer1::TensorFormat::kHWC}, {"dla_linear", nvinfer1::TensorFormat::kDLA_LINEAR},
{"dla_hwc4", nvinfer1::TensorFormat::kDLA_HWC4}};
nvinfer1::TensorFormats formats{};
for (auto f : optionStrings)
{
const auto tf = strToFmt.find(f);
const auto& tf = strToFmt.find(f);
if (tf == strToFmt.end())
{
throw std::invalid_argument(std::string("Invalid TensorFormat ") + f);
Expand Down Expand Up @@ -988,6 +989,16 @@ std::ostream& operator<<(std::ostream& os, const IOFormat& format)
os << "hwc";
break;
}
case nvinfer1::TensorFormat::kDLA_LINEAR:
{
os << "dla_linear";
break;
}
case nvinfer1::TensorFormat::kDLA_HWC4:
{
os << "dla_hwc4";
break;
}
}
}
}
Expand Down Expand Up @@ -1061,7 +1072,8 @@ std::ostream& operator<<(std::ostream& os, const SystemOptions& options)
(options.DLACore != -1 && options.fallback ? "(With GPU fallback)" : "") << std::endl;
// clang-format on
os << "Plugins:";
for (const auto p : options.plugins)

for (const auto& p : options.plugins)
{
os << " " << p;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 1993-2020 NVIDIA Corporation. All rights reserved.
Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.

NOTICE TO LICENSEE:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 1993-2020 NVIDIA Corporation. All rights reserved.
Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.

NOTICE TO LICENSEE:

Expand Down
2 changes: 1 addition & 1 deletion samples/opensource/sampleNMT/get_newstest2015.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

# Copyright 2017 Google Inc.
# Modifications Copyright (c) 2020 Nvidia
# Modifications Copyright (c) 2021, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <cudnn.h>
#include <iostream>
#include <map>
#include <string.h>
#include <unordered_map>
#include <vector>

Expand Down Expand Up @@ -586,7 +587,7 @@ class UffPoolPluginV2 : public IPluginV2IOExt
template <typename T>
T read(const char*& buffer) const
{
T val;
T val{};
std::memcpy(&val, buffer, sizeof(T));
buffer += sizeof(T);
return val;
Expand Down
14 changes: 14 additions & 0 deletions samples/opensource/trtexec/trtexec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ int main(int argc, char** argv)
if ((options.reporting.profile || !options.reporting.exportProfile.empty()) && !options.inference.rerun)
{
iEnv.profiler.reset(new Profiler);
if (options.inference.graph)
{
options.inference.graph = false;
sample::gLogWarning << "Profiler does not work when CUDA graph is enabled. Ignored --useCudaGraph flag "
"and disabled CUDA graph."
<< std::endl;
}
}

if (!setUpInference(iEnv, options.inference))
Expand All @@ -201,6 +208,13 @@ int main(int argc, char** argv)
auto* profiler = new Profiler;
iEnv.profiler.reset(profiler);
iEnv.context.front()->setProfiler(profiler);
if (options.inference.graph)
{
options.inference.graph = false;
sample::gLogWarning << "Profiler does not work when CUDA graph is enabled. Ignored --useCudaGraph flag "
"and disabled CUDA graph in the second run with the profiler."
<< std::endl;
}
runInference(options.inference, iEnv, options.system.device, trace);
}
printPerformanceProfile(options.reporting, iEnv, sample::gLogInfo);
Expand Down

0 comments on commit c4dbccc

Please sign in to comment.