Ai
1 Star 0 Fork 0

snowingbear/onnx-tensorrt

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ShapedWeights.cpp 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
Kevin Chen 提交于 2022-06-15 01:28 +08:00 . TensorRT 8.4 GA ONNX Parser Release (#851)
/*
* SPDX-License-Identifier: Apache-2.0
*/
#include "ShapedWeights.hpp"
#include "onnx2trt_utils.hpp"
#include "trt_utils.hpp"
#include <cstdint>
#include <cstring>
namespace onnx2trt
{
size_t ShapedWeights::count() const
{
assert(shape.nbDims >= 0);
size_t c = 1;
for (int i = 0; i < this->shape.nbDims; ++i)
{
c *= this->shape.d[i];
}
return c;
}
ShapedWeights ShapedWeights::empty(DataType type)
{
return ShapedWeights(type, nullptr, nvinfer1::Dims{1, {0}});
}
ShapedWeights::ShapedWeights(DataType type_, void* values_, nvinfer1::Dims shape_)
: type(type_)
, values(values_)
, shape(shape_)
{
// Note: this->shape.type[] is not used
}
size_t ShapedWeights::size_bytes() const
{
return this->count() * getDtypeSize(this->type);
}
ShapedWeights::operator bool() const
{
return (bool) this->values;
}
ShapedWeights::operator nvinfer1::Weights() const
{
nvinfer1::Weights w{};
w.values = this->values;
bool supported_type = convertDtype(this->type, &w.type);
(void) supported_type;
assert(supported_type);
w.count = this->count();
return w;
}
const char* ShapedWeights::getName() const
{
return this->name;
}
void ShapedWeights::setName(const char* n)
{
this->name = n;
}
} // namespace onnx2trt
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/snowingbear/onnx-tensorrt.git
git@gitee.com:snowingbear/onnx-tensorrt.git
snowingbear
onnx-tensorrt
onnx-tensorrt
main

搜索帮助