TensorRT/parsers/caffe/binaryProtoBlob.h源碼研讀
TensorRT/parsers/caffe/binaryProtoBlob.h
/*
* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TRT_CAFFE_PARSER_BINARY_PROTO_BLOB_H
#define TRT_CAFFE_PARSER_BINARY_PROTO_BLOB_H
#include <stdlib.h>
#include "NvCaffeParser.h"
#include "NvInfer.h"
namespace nvcaffeparser1
{
/*
class IBinaryProtoBlob
宣告於TensorRT/include/NvCaffeParser.h
class IBinaryProtoBlob
{
public:
virtual const void* getData() TRTNOEXCEPT = 0;
virtual nvinfer1::DimsNCHW getDimensions() TRTNOEXCEPT = 0;
virtual nvinfer1::DataType getDataType() TRTNOEXCEPT = 0;
virtual void destroy() TRTNOEXCEPT = 0;
protected:
virtual ~IBinaryProtoBlob() {}
};
Object used to store and query data extracted from a binaryproto file using the ICaffeParser.
用於儲存及查詢binaryproto檔裡抽取出來的數據
warning Do not inherit from this class, as doing so will break forward-compatibility of the API and ABI.
*/
/*
BinaryProtoBlob繼承自IBinaryProtoBlob,
用於儲存及查詢binaryproto檔裡抽取出來的數據,
並記錄它的metadata,如型別及維度。
*/
class BinaryProtoBlob : public IBinaryProtoBlob
{
public:
BinaryProtoBlob(void* memory, nvinfer1::DataType type, nvinfer1::DimsNCHW dimensions)
: mMemory(memory)
, mDataType(type)
, mDimensions(dimensions)
{
}
nvinfer1::DimsNCHW getDimensions() override
{
return mDimensions;
}
nvinfer1::DataType getDataType() override
{
return mDataType;
}
const void* getData() override
{
return mMemory;
}
//為何除了destructor還要定義這個函數?
void destroy() override
{
delete this;
}
~BinaryProtoBlob() override
{
free(mMemory);
}
void* mMemory;
nvinfer1::DataType mDataType;
nvinfer1::DimsNCHW mDimensions;
};
} // namespace nvcaffeparser1
#endif // TRT_CAFFE_PARSER_BINARY_PROTO_BLOB_H
BinaryProtoBlob
繼承自IBinaryProtoBlob
,用於儲存及查詢binaryproto檔裡抽取出來的數據,並記錄它的metadata,如型別及維度。
繼承IBinaryProtoBlob
IBinaryProtoBlob
裡的註釋寫說不要繼承該類別,但BinaryProtoBlob
卻繼承了?
delete this
destroy
中用到了delete this
,詳見C++ delete this。