if (src_layout_ == dst_layout_)
return true;
+ /* raw layout */
+ if (src_layout_ == DATA_LAYOUT_RAW || dst_layout_ == DATA_LAYOUT_RAW)
+ return true;
+
/* standard -> trinity */
if ((src_layout_ == DATA_LAYOUT_NHWC || src_layout_ == DATA_LAYOUT_NCHW) &&
(dst_layout_ == DATA_LAYOUT_TRIV || dst_layout_ == DATA_LAYOUT_TRIV2))
}
/**
+ * @brief check layout conversion is required
+ * @return true if required. otherwise false
+ */
+bool
+DataConverter::needLayoutConversion () {
+ /* don't care about DATA_LAYOUT_RAW */
+ if (to_npu_ && dst_layout_ == DATA_LAYOUT_RAW)
+ return false;
+
+ if (!to_npu_ && src_layout_ == DATA_LAYOUT_RAW)
+ return false;
+
+ return src_layout_ != dst_layout_;
+}
+
+/**
* @brief convert data format, copying the converted source data to destination.
* @return the number of bytes copied
*/
DataConverter::perform () {
/* check parameters first */
if (!src_ || !dst_ || size_ == 0 || !dims_) {
- logwarn (TAG, "Skip data conversion: Invalid parameter detected");
+ logerr (TAG, "Invalid parameter detected");
return 0;
}
if (!checkCapability ()) {
- logwarn (TAG, "Skip data conversion: Unsupported layout detected");
+ logerr (TAG, "Unable to pass capability check");
return 0;
}
- /* trinity device assumes the NHWC-based layout */
- uint32_t batch = dims_[0];
- uint32_t height = dims_[1];
- uint32_t width = dims_[2];
- uint32_t depth = dims_[3];
+ DECLARE_QUANTIZER (src_type_, dst_type_);
- uint32_t src_data_size = get_data_size (src_type_);
- uint32_t dst_data_size = get_data_size (dst_type_);
- uint32_t npu_data_size;
- if (to_npu_)
- npu_data_size = dst_data_size;
- else
- npu_data_size = src_data_size;
+ if (needLayoutConversion ()) {
+ /* trinity device assumes the NHWC-based layout */
+ uint32_t batch = dims_[0];
+ uint32_t height = dims_[1];
+ uint32_t width = dims_[2];
+ uint32_t depth = dims_[3];
- uint32_t granularity = DATA_GRANULARITY;
- uint32_t granularity_div = 1;
+ uint32_t src_data_size = get_data_size (src_type_);
+ uint32_t dst_data_size = get_data_size (dst_type_);
+ uint32_t npu_data_size;
+ if (to_npu_)
+ npu_data_size = dst_data_size;
+ else
+ npu_data_size = src_data_size;
- if (npu_tops_ == 2)
- granularity_div *= 2;
- if (npu_data_size == 2)
- granularity_div *= 2;
+ uint32_t granularity = DATA_GRANULARITY;
+ uint32_t granularity_div = 1;
- granularity /= granularity_div;
+ if (npu_tops_ == 2)
+ granularity_div *= 2;
+ if (npu_data_size == 2)
+ granularity_div *= 2;
- DECLARE_QUANTIZER (src_type_, dst_type_);
+ granularity /= granularity_div;
- if (src_layout_ != dst_layout_) {
uint32_t MPA_L = granularity;
uint32_t src_offset;
uint32_t dst_offset;
Model::updateDataInfo () {
for (uint32_t idx = 0; idx < in_.num_info; idx++) {
if (in_.info[idx].layout == DATA_LAYOUT_MODEL) {
- if (meta_->getVersion () < 3)
+ if (meta_->getVersion () >= 3) {
+ if (meta_->getInputSegmentLayout (idx) != DATA_LAYOUT_NONE)
+ in_.info[idx].layout = meta_->getInputSegmentLayout (idx);
+ else
+ in_.info[idx].layout = DATA_LAYOUT_TRIV2;
+ } else {
in_.info[idx].layout = DATA_LAYOUT_TRIV;
- else
- in_.info[idx].layout = DATA_LAYOUT_TRIV2;
+ }
}
if (in_.info[idx].type == DATA_TYPE_MODEL)
in_.info[idx].type = meta_->getInputQuantType (idx);
for (uint32_t idx = 0; idx < out_.num_info; idx++) {
if (out_.info[idx].layout == DATA_LAYOUT_MODEL) {
- if (meta_->getVersion () < 3)
+ if (meta_->getVersion () >= 3) {
+ if (meta_->getOutputSegmentLayout (idx) != DATA_LAYOUT_NONE)
+ out_.info[idx].layout = meta_->getOutputSegmentLayout (idx);
+ else
+ out_.info[idx].layout = DATA_LAYOUT_TRIV2;
+ } else {
out_.info[idx].layout = DATA_LAYOUT_TRIV;
- else
- out_.info[idx].layout = DATA_LAYOUT_TRIV2;
+ }
}
if (out_.info[idx].type == DATA_TYPE_MODEL)
out_.info[idx].type = meta_->getOutputQuantType (idx);
int version = getMetadata ()->getVersion ();
for (uint32_t idx = 0; idx < input_num; idx++) {
if (in_.info[idx].layout == DATA_LAYOUT_MODEL) {
- if (version >= 3)
- in_.info[idx].layout = DATA_LAYOUT_TRIV2;
- else
- in_.info[idx].layout = DATA_LAYOUT_SRNPU;
+ if (version >= 3) {
+ if (meta_->getInputSegmentLayout (idx) != DATA_LAYOUT_NONE)
+ in_.info[idx].layout = meta_->getInputSegmentLayout (idx);
+ else
+ in_.info[idx].layout = DATA_LAYOUT_TRIV2;
+ } else {
+ in_.info[idx].layout = DATA_LAYOUT_TRIV;
+ }
}
if (in_.info[idx].type == DATA_TYPE_MODEL) {
if (version >= 3)
for (uint32_t idx = 0; idx < output_num; idx++) {
if (out_.info[idx].layout == DATA_LAYOUT_MODEL) {
- if (version >= 3)
- out_.info[idx].layout = DATA_LAYOUT_TRIV2;
- else
- out_.info[idx].layout = DATA_LAYOUT_SRNPU;
+ if (version >= 3) {
+ if (meta_->getOutputSegmentLayout (idx) != DATA_LAYOUT_NONE)
+ out_.info[idx].layout = meta_->getOutputSegmentLayout (idx);
+ else
+ out_.info[idx].layout = DATA_LAYOUT_TRIV2;
+ } else {
+ out_.info[idx].layout = DATA_LAYOUT_TRIV;
+ }
}
if (out_.info[idx].type == DATA_TYPE_MODEL) {
if (version >= 3)