summaryrefslogtreecommitdiff
path: root/src/ml
diff options
context:
space:
mode:
authorSangjung Woo <sangjung.woo@samsung.com>2023-04-07 17:51:01 +0900
committerSangjung Woo <sangjung.woo@samsung.com>2023-04-11 20:25:47 +0900
commitc2a010b067f1e564418889f156c355ea25f5c7a2 (patch)
tree1639513e851c92ef9a487ad38f83442beb16d1cd /src/ml
parent98eac70955c377a91ecc69a1f1948c9e0dd6fa08 (diff)
downloadwebapi-plugins-c2a010b067f1e564418889f156c355ea25f5c7a2.tar.gz
webapi-plugins-c2a010b067f1e564418889f156c355ea25f5c7a2.tar.bz2
webapi-plugins-c2a010b067f1e564418889f156c355ea25f5c7a2.zip
[ML] Fix the value of ML_TENSOR_RANK_LIMITaccepted/tizen/unified/20230413.123721
To support the higher rank of the ML model, the ML_TENSOR_RANK_LIMIT of the ML API was changed from 4 to 16. However, the webapi-plugins assume that ML_TENSOR_RANK_LIMIT is 4 and it causes the build break issue. This patch fixes this issue and update related test cases. Change-Id: I05ab7fa0a5ba28476f38170d9f9c4e7396d35981 Signed-off-by: Sangjung Woo <sangjung.woo@samsung.com> Signed-off-by: Piotr Kosko/Tizen API (PLT) /SRPOL/Engineer/Samsung Electronics <p.kosko@samsung.com>
Diffstat (limited to 'src/ml')
-rw-r--r--src/ml/ml_instance.cc43
-rw-r--r--src/ml/ml_tensors_data_manager.cc32
-rw-r--r--src/ml/ml_tensors_data_manager.h16
-rw-r--r--src/ml/ml_tensors_info_manager.cc46
-rw-r--r--src/ml/ml_tensors_info_manager.h11
-rw-r--r--src/ml/ml_utils.cc33
-rw-r--r--src/ml/ml_utils.h17
-rw-r--r--src/ml/ut/tensor_raw_data.cc164
8 files changed, 211 insertions, 151 deletions
diff --git a/src/ml/ml_instance.cc b/src/ml/ml_instance.cc
index eec6ca72..da94a250 100644
--- a/src/ml/ml_instance.cc
+++ b/src/ml/ml_instance.cc
@@ -23,9 +23,10 @@
#include "common/tools.h"
#include "ml_utils.h"
-static_assert(ML_TENSOR_RANK_LIMIT == 4,
- "This implementation requires different ML_TENSOR_RANK_LIMIT. "
- "Please fix the code.");
+static_assert(
+ ML_TENSOR_RANK_LIMIT >= 4,
+ "This implementation requires different util::kWebApiMLTensorRankLimit. "
+ "Please fix the code.");
namespace extension {
namespace ml {
@@ -328,7 +329,7 @@ void MlInstance::MLTensorsInfoAddTensorInfo(const picojson::value& args,
LoggerD("name: %s", name.c_str());
}
- unsigned int dimensions[ML_TENSOR_RANK_LIMIT] = {};
+ unsigned int dimensions[util::kWebApiMLTensorRankLimit] = {};
auto dim = args.get(kDimensions).get<picojson::array>();
result = util::GetDimensionsFromJsonArray(dim, dimensions);
if (!result) {
@@ -365,14 +366,14 @@ void MlInstance::MLTensorsInfoGetDimensions(const picojson::value& args,
return;
}
int index = static_cast<int>(args.get(kIndex).get<double>());
- unsigned int dim[ML_TENSOR_RANK_LIMIT];
+ unsigned int dim[util::kWebApiMLTensorRankLimit];
PlatformResult result = tensorsInfo->NativeGetTensorDimensions(index, dim);
if (!result) {
LogAndReportError(result, &out);
return;
}
picojson::array array = picojson::array{};
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
if (0 == dim[i]) {
break;
}
@@ -400,7 +401,7 @@ void MlInstance::MLTensorsInfoSetDimensions(const picojson::value& args,
return;
}
- unsigned int dimensions[ML_TENSOR_RANK_LIMIT] = {};
+ unsigned int dimensions[util::kWebApiMLTensorRankLimit] = {};
auto dim = args.get(kDimensions).get<picojson::array>();
PlatformResult result = util::GetDimensionsFromJsonArray(dim, dimensions);
if (!result) {
@@ -745,7 +746,7 @@ void MlInstance::MLTensorsDataGetTensorRawData(const picojson::value& args,
return;
}
- unsigned int location[ML_TENSOR_RANK_LIMIT] = {};
+ unsigned int location[util::kWebApiMLTensorRankLimit] = {};
PlatformResult result = util::GetLocationFromJsonArray(
args.get(kLocation).get<picojson::array>(), location);
if (!result) {
@@ -753,7 +754,7 @@ void MlInstance::MLTensorsDataGetTensorRawData(const picojson::value& args,
return;
}
- unsigned int dimensions[ML_TENSOR_RANK_LIMIT] = {};
+ unsigned int dimensions[util::kWebApiMLTensorRankLimit] = {};
result = tensors_data->GetTensorsInfo()->NativeGetTensorDimensions(
index, dimensions);
if (!result) {
@@ -761,7 +762,7 @@ void MlInstance::MLTensorsDataGetTensorRawData(const picojson::value& args,
return;
}
- unsigned int size[ML_TENSOR_RANK_LIMIT] = {};
+ unsigned int size[util::kWebApiMLTensorRankLimit] = {};
result = util::GetSizeFromJsonArray(args.get(kSize).get<picojson::array>(),
location, dimensions, size);
if (!result) {
@@ -783,7 +784,7 @@ void MlInstance::MLTensorsDataGetTensorRawData(const picojson::value& args,
out[kType] = picojson::value(raw_data.type_str);
picojson::array shape = picojson::array{};
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
shape.push_back(picojson::value{static_cast<double>(raw_data.shape[i])});
}
out[kShape] = picojson::value{shape};
@@ -814,7 +815,7 @@ void MlInstance::MLTensorsDataGetTensorRawDataBinary(
return;
}
- unsigned int location[ML_TENSOR_RANK_LIMIT] = {};
+ unsigned int location[util::kWebApiMLTensorRankLimit] = {};
PlatformResult result = util::GetLocationFromJsonArray(
args.get(kLocation).get<picojson::array>(), location);
if (!result) {
@@ -823,7 +824,7 @@ void MlInstance::MLTensorsDataGetTensorRawDataBinary(
return;
}
- unsigned int dimensions[ML_TENSOR_RANK_LIMIT] = {};
+ unsigned int dimensions[util::kWebApiMLTensorRankLimit] = {};
result = tensors_data->GetTensorsInfo()->NativeGetTensorDimensions(
index, dimensions);
if (!result) {
@@ -832,7 +833,7 @@ void MlInstance::MLTensorsDataGetTensorRawDataBinary(
return;
}
- unsigned int size[ML_TENSOR_RANK_LIMIT] = {};
+ unsigned int size[util::kWebApiMLTensorRankLimit] = {};
result = util::GetSizeFromJsonArray(args.get(kSize).get<picojson::array>(),
location, dimensions, size);
if (!result) {
@@ -854,7 +855,7 @@ void MlInstance::MLTensorsDataGetTensorRawDataBinary(
out_json[kType] = picojson::value(raw_data.type_str);
picojson::array shape = picojson::array{};
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
shape.push_back(picojson::value{static_cast<double>(raw_data.shape[i])});
}
out_json[kShape] = picojson::value{shape};
@@ -937,7 +938,7 @@ void MlInstance::MLTensorsDataSetTensorRawData(const picojson::value& args,
return;
}
- unsigned int location[ML_TENSOR_RANK_LIMIT] = {};
+ unsigned int location[util::kWebApiMLTensorRankLimit] = {};
PlatformResult result = util::GetLocationFromJsonArray(
args.get(kLocation).get<picojson::array>(), location);
if (!result) {
@@ -945,7 +946,7 @@ void MlInstance::MLTensorsDataSetTensorRawData(const picojson::value& args,
return;
}
- unsigned int dimensions[ML_TENSOR_RANK_LIMIT] = {};
+ unsigned int dimensions[util::kWebApiMLTensorRankLimit] = {};
result = tensors_data->GetTensorsInfo()->NativeGetTensorDimensions(
index, dimensions);
if (!result) {
@@ -953,7 +954,7 @@ void MlInstance::MLTensorsDataSetTensorRawData(const picojson::value& args,
return;
}
- unsigned int size[ML_TENSOR_RANK_LIMIT] = {};
+ unsigned int size[util::kWebApiMLTensorRankLimit] = {};
result = util::GetSizeFromJsonArray(args.get(kSize).get<picojson::array>(),
location, dimensions, size);
if (!result) {
@@ -1032,7 +1033,7 @@ void MlInstance::MLTensorsDataSetTensorRawDataBinary(const char* data,
return;
}
- unsigned int location[ML_TENSOR_RANK_LIMIT] = {};
+ unsigned int location[util::kWebApiMLTensorRankLimit] = {};
PlatformResult result = util::GetLocationFromJsonArray(
args.get(kLocation).get<picojson::array>(), location);
if (!result) {
@@ -1040,7 +1041,7 @@ void MlInstance::MLTensorsDataSetTensorRawDataBinary(const char* data,
return;
}
- unsigned int dimensions[ML_TENSOR_RANK_LIMIT] = {};
+ unsigned int dimensions[util::kWebApiMLTensorRankLimit] = {};
result = tensors_data->GetTensorsInfo()->NativeGetTensorDimensions(
index, dimensions);
if (!result) {
@@ -1048,7 +1049,7 @@ void MlInstance::MLTensorsDataSetTensorRawDataBinary(const char* data,
return;
}
- unsigned int size[ML_TENSOR_RANK_LIMIT] = {};
+ unsigned int size[util::kWebApiMLTensorRankLimit] = {};
result = util::GetSizeFromJsonArray(args.get(kSize).get<picojson::array>(),
location, dimensions, size);
if (!result) {
diff --git a/src/ml/ml_tensors_data_manager.cc b/src/ml/ml_tensors_data_manager.cc
index c8276b55..2870b2e4 100644
--- a/src/ml/ml_tensors_data_manager.cc
+++ b/src/ml/ml_tensors_data_manager.cc
@@ -73,9 +73,10 @@ ml_tensor_type_e TensorsData::GetTensorType(int index) {
return tensor_type_enum;
}
-PlatformResult TensorsData::GetTensorRawData(int index, unsigned int location[ML_TENSOR_RANK_LIMIT],
- unsigned int size[ML_TENSOR_RANK_LIMIT],
- TensorRawData* tensor_raw_data) {
+PlatformResult TensorsData::GetTensorRawData(
+ int index, unsigned int location[util::kWebApiMLTensorRankLimit],
+ unsigned int size[util::kWebApiMLTensorRankLimit],
+ TensorRawData* tensor_raw_data) {
ScopeLogger("id_: %d, index: %d", id_, index);
if (nullptr == tensor_raw_data) {
@@ -92,9 +93,9 @@ PlatformResult TensorsData::GetTensorRawData(int index, unsigned int location[ML
uint8_t* data = static_cast<uint8_t*>(void_data);
// Dimensions of whole tensor
- unsigned int dim[ML_TENSOR_RANK_LIMIT];
+ unsigned int dim[util::kWebApiMLTensorRankLimit];
// Dimensions of expected tensors relative to location coordiantes
- unsigned int size_rel[ML_TENSOR_RANK_LIMIT];
+ unsigned int size_rel[util::kWebApiMLTensorRankLimit];
result = tensors_info_->NativeGetTensorDimensions(index, dim);
if (!result) {
@@ -103,7 +104,7 @@ PlatformResult TensorsData::GetTensorRawData(int index, unsigned int location[ML
// Check if update is partial due to location change
bool partial = false;
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
if (location[i] >= dim[i]) {
// Input data starts outside of current data
LoggerE("Requested data location is invalid on [%d]: %u", i, location[i]);
@@ -118,7 +119,7 @@ PlatformResult TensorsData::GetTensorRawData(int index, unsigned int location[ML
// Check if data will fit in TensorData and calculate dimensions
// of returned part, also check if update is partial due to size change
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
size_rel[i] = location[i] + size[i];
if (size_rel[i] < dim[i]) {
partial = true;
@@ -166,7 +167,7 @@ PlatformResult TensorsData::GetTensorRawData(int index, unsigned int location[ML
tensor_raw_data->size_in_bytes = data_size;
}
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
tensor_raw_data->shape[i] = size_rel[i] - location[i];
}
@@ -178,9 +179,10 @@ PlatformResult TensorsData::GetTensorRawData(int index, unsigned int location[ML
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult TensorsData::SetTensorRawData(int index, unsigned int location[ML_TENSOR_RANK_LIMIT],
- unsigned int size[ML_TENSOR_RANK_LIMIT],
- TensorRawData& tensor_raw_data) {
+PlatformResult TensorsData::SetTensorRawData(
+ int index, unsigned int location[util::kWebApiMLTensorRankLimit],
+ unsigned int size[util::kWebApiMLTensorRankLimit],
+ TensorRawData& tensor_raw_data) {
ScopeLogger("id_: %d, index: %d, tensor_raw_data.size_in_bytes: %zu, immutable_: %s", id_, index,
tensor_raw_data.size_in_bytes, immutable_ ? "true" : "false");
@@ -189,9 +191,9 @@ PlatformResult TensorsData::SetTensorRawData(int index, unsigned int location[ML
}
// Dimensions of whole tensor
- unsigned int dim[ML_TENSOR_RANK_LIMIT];
+ unsigned int dim[util::kWebApiMLTensorRankLimit];
// Dimensions of updated tensors relative to location coordiantes
- unsigned int size_rel[ML_TENSOR_RANK_LIMIT];
+ unsigned int size_rel[util::kWebApiMLTensorRankLimit];
PlatformResult result = tensors_info_->NativeGetTensorDimensions(index, dim);
if (!result) {
@@ -201,7 +203,7 @@ PlatformResult TensorsData::SetTensorRawData(int index, unsigned int location[ML
// Check if update is partial due to location change
bool partial = false;
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
if (location[i] >= dim[i]) {
// Input data starts outside of current data
LoggerE("Input data location is invalid on [%d]: %u", i, location[i]);
@@ -214,7 +216,7 @@ PlatformResult TensorsData::SetTensorRawData(int index, unsigned int location[ML
// Check if data will fit in TensorData and calculate dimensions
// of modified part, also check if update is partial due to size change
size_t data_to_be_updated_size = bytes_per_element;
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
size_rel[i] = location[i] + size[i];
if (size_rel[i] > dim[i]) {
LoggerE("Input data will not fit in TensorData [%d]: %u > %u", i, size_rel[i], dim[i]);
diff --git a/src/ml/ml_tensors_data_manager.h b/src/ml/ml_tensors_data_manager.h
index b1d6c039..5b168580 100644
--- a/src/ml/ml_tensors_data_manager.h
+++ b/src/ml/ml_tensors_data_manager.h
@@ -57,7 +57,7 @@ struct TensorRawData {
uint8_t* data = nullptr;
size_t size_in_bytes = 0;
std::string type_str;
- unsigned int shape[ML_TENSOR_RANK_LIMIT];
+ unsigned int shape[util::kWebApiMLTensorRankLimit];
private:
bool has_ownership_ = false;
@@ -75,12 +75,14 @@ class TensorsData {
int Count();
bool DisposableFromJS();
ml_tensor_type_e GetTensorType(int index);
- PlatformResult GetTensorRawData(int index, unsigned int location[ML_TENSOR_RANK_LIMIT],
- unsigned int size[ML_TENSOR_RANK_LIMIT],
- TensorRawData* tensor_raw_data);
- PlatformResult SetTensorRawData(int index, unsigned int location[ML_TENSOR_RANK_LIMIT],
- unsigned int size[ML_TENSOR_RANK_LIMIT],
- TensorRawData& tensor_raw_data);
+ PlatformResult GetTensorRawData(
+ int index, unsigned int location[util::kWebApiMLTensorRankLimit],
+ unsigned int size[util::kWebApiMLTensorRankLimit],
+ TensorRawData* tensor_raw_data);
+ PlatformResult SetTensorRawData(
+ int index, unsigned int location[util::kWebApiMLTensorRankLimit],
+ unsigned int size[util::kWebApiMLTensorRankLimit],
+ TensorRawData& tensor_raw_data);
TensorsInfo* GetTensorsInfo();
PlatformResult NativeDestroy();
diff --git a/src/ml/ml_tensors_info_manager.cc b/src/ml/ml_tensors_info_manager.cc
index 431b20df..b9d9e6f6 100644
--- a/src/ml/ml_tensors_info_manager.cc
+++ b/src/ml/ml_tensors_info_manager.cc
@@ -55,8 +55,9 @@ int TensorsInfo::Count() {
return this->count_;
}
-PlatformResult TensorsInfo::AddTensorInfo(std::string name, ml_tensor_type_e type,
- unsigned int dim[ML_TENSOR_RANK_LIMIT]) {
+PlatformResult TensorsInfo::AddTensorInfo(
+ std::string name, ml_tensor_type_e type,
+ unsigned int dim[util::kWebApiMLTensorRankLimit]) {
ScopeLogger("id_: %d", id_);
if (Count() >= ML_TENSOR_SIZE_LIMIT) {
return (PlatformResult(ErrorCode::ABORT_ERR, "Maximum size of tensors info reached."));
@@ -133,12 +134,13 @@ bool TensorsInfo::Equals(TensorsInfo* other) {
return false;
}
- unsigned int dim1[ML_TENSOR_RANK_LIMIT], dim2[ML_TENSOR_RANK_LIMIT];
+ unsigned int dim1[util::kWebApiMLTensorRankLimit],
+ dim2[util::kWebApiMLTensorRankLimit];
if ((!this->NativeGetTensorDimensions(i, dim1) || !other->NativeGetTensorDimensions(i, dim2))) {
LoggerD("Tensors dimensions getters error");
return false;
}
- for (int j = 0; j < ML_TENSOR_RANK_LIMIT; j++) {
+ for (int j = 0; j < util::kWebApiMLTensorRankLimit; j++) {
if (dim1[j] != dim2[j]) {
LoggerD("Tensors dimensions not equal at index %d, [%d][%u - %u]", i, j, dim1[j], dim2[j]);
return false;
@@ -186,24 +188,48 @@ PlatformResult TensorsInfo::NativeSetCount(unsigned int count) {
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult TensorsInfo::NativeGetTensorDimensions(int index,
- unsigned int dim[ML_TENSOR_RANK_LIMIT]) {
+PlatformResult TensorsInfo::NativeGetTensorDimensions(
+ int index, unsigned int dim[util::kWebApiMLTensorRankLimit]) {
+ guint i, rank;
+ ml_tensor_dimension dimension;
+
ScopeLogger("id_: %d, index: %d", id_, index);
- int ret = ml_tensors_info_get_tensor_dimension(handle_, index, dim);
+ int ret = ml_tensors_info_get_tensor_dimension(handle_, index, dimension);
if (ML_ERROR_NONE != ret) {
LoggerE("ml_tensors_info_get_tensor_dimension failed: %d (%s)", ret, get_error_message(ret));
return util::ToPlatformResult(ret, "Failed to get tensor dimension");
}
+ // ML API supports max rank 16, we should compare max rank between web-api and ML.
+ rank = MIN (ML_TENSOR_RANK_LIMIT, util::kWebApiMLTensorRankLimit);
+ for (i = 0; i < rank; i++) {
+ dim[i] = dimension[i];
+ }
+ for (i = rank; i < util::kWebApiMLTensorRankLimit; i++) {
+ dim[i] = 1;
+ }
+
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult TensorsInfo::NativeSetTensorDimensions(int index,
- unsigned int dim[ML_TENSOR_RANK_LIMIT]) {
+PlatformResult TensorsInfo::NativeSetTensorDimensions(
+ int index, unsigned int dim[util::kWebApiMLTensorRankLimit]) {
+ guint i, rank;
+ ml_tensor_dimension dimension;
+
ScopeLogger("id_: %d, index: %d", id_, index);
- int ret = ml_tensors_info_set_tensor_dimension(handle_, index, dim);
+ // ML API supports max rank 16, we should compare max rank between web-api and ML.
+ rank = MIN (ML_TENSOR_RANK_LIMIT, util::kWebApiMLTensorRankLimit);
+ for (i = 0; i < rank; i++) {
+ dimension[i] = dim[i];
+ }
+ for (i = rank; i < ML_TENSOR_RANK_LIMIT; i++) {
+ dimension[i] = 1;
+ }
+
+ int ret = ml_tensors_info_set_tensor_dimension(handle_, index, dimension);
if (ML_ERROR_NONE != ret) {
LoggerE("ml_tensors_info_set_tensor_dimension failed: %d (%s)", ret, get_error_message(ret));
return util::ToPlatformResult(ret, "Failed to set tensor dimension");
diff --git a/src/ml/ml_tensors_info_manager.h b/src/ml/ml_tensors_info_manager.h
index 38a03b17..90795a45 100644
--- a/src/ml/ml_tensors_info_manager.h
+++ b/src/ml/ml_tensors_info_manager.h
@@ -43,8 +43,9 @@ class TensorsInfo {
int Id();
int Count();
- PlatformResult AddTensorInfo(std::string name, ml_tensor_type_e type,
- unsigned int dim[ML_TENSOR_RANK_LIMIT]);
+ PlatformResult AddTensorInfo(
+ std::string name, ml_tensor_type_e type,
+ unsigned int dim[util::kWebApiMLTensorRankLimit]);
std::shared_ptr<TensorsInfo> CreateClone(int cloneId);
bool Equals(TensorsInfo* other);
@@ -52,8 +53,10 @@ class TensorsInfo {
PlatformResult NativeDestroy();
PlatformResult NativeGetCount(unsigned int* count);
PlatformResult NativeSetCount(unsigned int count);
- PlatformResult NativeGetTensorDimensions(int index, unsigned int dim[ML_TENSOR_RANK_LIMIT]);
- PlatformResult NativeSetTensorDimensions(int index, unsigned int dim[ML_TENSOR_RANK_LIMIT]);
+ PlatformResult NativeGetTensorDimensions(
+ int index, unsigned int dim[util::kWebApiMLTensorRankLimit]);
+ PlatformResult NativeSetTensorDimensions(
+ int index, unsigned int dim[util::kWebApiMLTensorRankLimit]);
PlatformResult NativeGetTensorName(int index, std::string* name);
PlatformResult NativeSetTensorName(int index, const std::string& name);
PlatformResult NativeGetTensorType(int index, ml_tensor_type_e* type);
diff --git a/src/ml/ml_utils.cc b/src/ml/ml_utils.cc
index ab437c29..f8ffbefe 100644
--- a/src/ml/ml_utils.cc
+++ b/src/ml/ml_utils.cc
@@ -187,15 +187,16 @@ bool CheckNNFWAvailability(const std::string& nnfw, const std::string& hw,
}
PlatformResult GetDimensionsFromJsonArray(
- const picojson::array& dim, unsigned int dimensions[ML_TENSOR_RANK_LIMIT]) {
+ const picojson::array& dim,
+ unsigned int dimensions[util::kWebApiMLTensorRankLimit]) {
ScopeLogger();
bool foundValidValue = false;
- unsigned int validDimensions[ML_TENSOR_RANK_LIMIT];
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ unsigned int validDimensions[util::kWebApiMLTensorRankLimit];
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
validDimensions[i] = 1;
}
- int dimSize = ML_TENSOR_RANK_LIMIT;
- if (dim.size() <= ML_TENSOR_RANK_LIMIT) {
+ int dimSize = util::kWebApiMLTensorRankLimit;
+ if (dim.size() <= util::kWebApiMLTensorRankLimit) {
dimSize = dim.size();
} else {
LoggerD("Provided dimensions array is bigger than supported");
@@ -232,15 +233,16 @@ PlatformResult GetDimensionsFromJsonArray(
"dimensions array contains invalid values");
}
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
dimensions[i] = validDimensions[i];
}
return PlatformResult(ErrorCode::NO_ERROR);
}
PlatformResult GetLocationFromJsonArray(
- const picojson::array& array, unsigned int location[ML_TENSOR_RANK_LIMIT]) {
- if (array.size() > ML_TENSOR_RANK_LIMIT) {
+ const picojson::array& array,
+ unsigned int location[util::kWebApiMLTensorRankLimit]) {
+ if (array.size() > util::kWebApiMLTensorRankLimit) {
LoggerD("Provided size array is bigger than supported");
}
int i = 0;
@@ -257,7 +259,7 @@ PlatformResult GetLocationFromJsonArray(
}
location[i] = static_cast<unsigned int>(num);
i++;
- if (i == ML_TENSOR_RANK_LIMIT) {
+ if (i == util::kWebApiMLTensorRankLimit) {
break;
}
}
@@ -265,10 +267,11 @@ PlatformResult GetLocationFromJsonArray(
}
PlatformResult GetSizeFromJsonArray(
- const picojson::array& array, unsigned int location[ML_TENSOR_RANK_LIMIT],
- unsigned int dimensions[ML_TENSOR_RANK_LIMIT],
- unsigned int size[ML_TENSOR_RANK_LIMIT]) {
- if (array.size() > ML_TENSOR_RANK_LIMIT) {
+ const picojson::array& array,
+ unsigned int location[util::kWebApiMLTensorRankLimit],
+ unsigned int dimensions[util::kWebApiMLTensorRankLimit],
+ unsigned int size[util::kWebApiMLTensorRankLimit]) {
+ if (array.size() > util::kWebApiMLTensorRankLimit) {
LoggerD("Provided size array is bigger than supported");
}
int i = 0;
@@ -289,11 +292,11 @@ PlatformResult GetSizeFromJsonArray(
size[i] = dimensions[i] - location[i];
}
i++;
- if (i == ML_TENSOR_RANK_LIMIT) {
+ if (i == util::kWebApiMLTensorRankLimit) {
break;
}
}
- for (; i < ML_TENSOR_RANK_LIMIT; i++) {
+ for (; i < util::kWebApiMLTensorRankLimit; i++) {
size[i] = dimensions[i] - location[i];
}
return PlatformResult(ErrorCode::NO_ERROR);
diff --git a/src/ml/ml_utils.h b/src/ml/ml_utils.h
index 3b06b097..075b47f8 100644
--- a/src/ml/ml_utils.h
+++ b/src/ml/ml_utils.h
@@ -58,6 +58,10 @@ extern const PlatformEnum<ml_train_dataset_mode_e> DatasetModeEnum;
} // namespace types
namespace util {
+// below constexpr is a hardcoded value of util::kWebApiMLTensorRankLimit
+// constant used in native API. since tizen 7.5 it was changed to 16, so to keep
+// the behaviours of webapi, its usage was replaced with below contant
+constexpr int kWebApiMLTensorRankLimit = 4;
PlatformResult ToPlatformResult(int ml_error_code,
const std::string& error_message);
@@ -66,14 +70,17 @@ bool CheckNNFWAvailability(const std::string& nnfw, const std::string& hw,
const optional<std::string> customRequirement);
PlatformResult GetDimensionsFromJsonArray(
- const picojson::array& dim, unsigned int dimensions[ML_TENSOR_RANK_LIMIT]);
+ const picojson::array& dim,
+ unsigned int dimensions[util::kWebApiMLTensorRankLimit]);
PlatformResult GetLocationFromJsonArray(
- const picojson::array& array, unsigned int location[ML_TENSOR_RANK_LIMIT]);
+ const picojson::array& array,
+ unsigned int location[util::kWebApiMLTensorRankLimit]);
PlatformResult GetSizeFromJsonArray(
- const picojson::array& array, unsigned int location[ML_TENSOR_RANK_LIMIT],
- unsigned int dimensions[ML_TENSOR_RANK_LIMIT],
- unsigned int size[ML_TENSOR_RANK_LIMIT]);
+ const picojson::array& array,
+ unsigned int location[util::kWebApiMLTensorRankLimit],
+ unsigned int dimensions[util::kWebApiMLTensorRankLimit],
+ unsigned int size[util::kWebApiMLTensorRankLimit]);
} // namespace util
} // namespace ml
diff --git a/src/ml/ut/tensor_raw_data.cc b/src/ml/ut/tensor_raw_data.cc
index abf49770..dd43d357 100644
--- a/src/ml/ut/tensor_raw_data.cc
+++ b/src/ml/ut/tensor_raw_data.cc
@@ -44,17 +44,18 @@ class MlTensorRawDataTest : public testing::Test {
TEST_F(MlTensorRawDataTest, GetTensorRawDataFull) {
ScopeLogger("GetTensorRawDataFull");
auto tensors_info = tensors_info_manager_.CreateTensorsInfo();
- unsigned int dim[] = {3, 2, 2, 1};
+ unsigned int dim[util::kWebApiMLTensorRankLimit] = {3, 2, 2, 1};
tensors_info->AddTensorInfo("", ML_TENSOR_TYPE_UINT8, dim);
auto tensors_data = tensors_info_manager_.CreateTensorsData(tensors_info);
- unsigned int location[] = {0, 0, 0, 0};
+ unsigned int location[util::kWebApiMLTensorRankLimit] = {0, 0, 0, 0};
TensorRawData raw_data;
PlatformResult res = tensors_data->GetTensorRawData(0, location, dim, &raw_data);
ASSERT_TRUE(res) << "GetTensorRawData failed";
+ // Expected dimension with rank 4 (Old rank limit of ml-tensors-info)
unsigned int expected_dim[] = {3, 2, 2, 1};
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
EXPECT_EQ(raw_data.shape[i], expected_dim[i]) << "Invalid value on dim " << i;
}
size_t expected_size = 12;
@@ -75,26 +76,28 @@ TEST_F(MlTensorRawDataTest, GetTensorRawDataFull) {
TEST_F(MlTensorRawDataTest, SetTensorRawDataFull) {
ScopeLogger("SetTensorRawDataFull");
auto tensors_info = tensors_info_manager_.CreateTensorsInfo();
- unsigned int dim[] = {3, 2, 2, 1};
+ unsigned int dim[util::kWebApiMLTensorRankLimit] = {3, 2, 2, 1};
tensors_info->AddTensorInfo("", ML_TENSOR_TYPE_UINT8, dim);
auto tensors_data = tensors_info_manager_.CreateTensorsData(tensors_info);
- unsigned int location[] = {0, 0, 0, 0};
- unsigned int size[] = {3, 2, 2, 1};
+ unsigned int location[util::kWebApiMLTensorRankLimit] = {0, 0, 0, 0};
+ unsigned int size[util::kWebApiMLTensorRankLimit] = {3, 2, 2, 1};
uint8_t arr_in[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
TensorRawData raw_data_set{arr_in, 12};
PlatformResult res = tensors_data->SetTensorRawData(0, location, size, raw_data_set);
ASSERT_TRUE(res) << "SetTensorRawData failed";
TensorRawData raw_data_get;
- unsigned int location_get[] = {0, 0, 0, 0};
+ unsigned int location_get[util::kWebApiMLTensorRankLimit] = {0, 0, 0, 0};
res = tensors_data->GetTensorRawData(0, location_get, dim, &raw_data_get);
ASSERT_TRUE(res) << "GetTensorRawData failed";
- unsigned int expected_dim[] = {3, 2, 2, 1};
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ // Expected dimension with rank 4 (Old rank limit of ml-tensors-info)
+ unsigned int expected_dim[] = {3, 2, 2, 1};
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
EXPECT_EQ(raw_data_get.shape[i], expected_dim[i]) << "Invalid value on dim " << i;
}
+
size_t expected_size = 12;
EXPECT_EQ(raw_data_get.size_in_bytes, expected_size);
uint8_t expected_arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
@@ -113,27 +116,29 @@ TEST_F(MlTensorRawDataTest, SetTensorRawDataFull) {
TEST_F(MlTensorRawDataTest, SetTensorRawData1) {
ScopeLogger("SetTensorRawData1");
auto tensors_info = tensors_info_manager_.CreateTensorsInfo();
- unsigned int dim[] = {3, 2, 2, 1};
+ unsigned int dim[util::kWebApiMLTensorRankLimit] = {3, 2, 2, 1};
tensors_info->AddTensorInfo("", ML_TENSOR_TYPE_UINT8, dim);
auto tensors_data = tensors_info_manager_.CreateTensorsData(tensors_info);
- unsigned int location[] = {0, 0, 0, 0};
- unsigned int size[] = {3, 2, 1, 1};
+ unsigned int location[util::kWebApiMLTensorRankLimit] = {0, 0, 0, 0};
+ unsigned int size[util::kWebApiMLTensorRankLimit] = {3, 2, 1, 1};
uint8_t arr_in[] = {1, 2, 3, 4, 5, 6};
TensorRawData raw_data_set{arr_in, 6};
PlatformResult res = tensors_data->SetTensorRawData(0, location, size, raw_data_set);
ASSERT_TRUE(res) << "SetTensorRawData failed";
TensorRawData raw_data_get;
- unsigned int location_get[] = {0, 0, 0, 0};
+ unsigned int location_get[util::kWebApiMLTensorRankLimit] = {0, 0, 0, 0};
res = tensors_data->GetTensorRawData(0, location_get, dim, &raw_data_get);
ASSERT_TRUE(res) << "GetTensorRawData failed";
- unsigned int expected_dim[] = {3, 2, 2, 1};
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ // Expected dimension with rank 4 (Old rank limit of ml-tensors-info)
+ unsigned int expected_dim[] = {3, 2, 2, 1};
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
EXPECT_EQ(raw_data_get.shape[i], expected_dim[i]) << "Invalid value on dim " << i;
}
+
size_t expected_size = 12;
EXPECT_EQ(raw_data_get.size_in_bytes, expected_size);
uint8_t expected_arr[] = {1, 2, 3, 4, 5, 6, 0, 0, 0, 0, 0, 0};
@@ -152,12 +157,12 @@ TEST_F(MlTensorRawDataTest, SetTensorRawData1) {
TEST_F(MlTensorRawDataTest, SetTensorRawData2) {
ScopeLogger("SetTensorRawData2");
auto tensors_info = tensors_info_manager_.CreateTensorsInfo();
- unsigned int dim[] = {3, 2, 2, 1};
+ unsigned int dim[util::kWebApiMLTensorRankLimit] = {3, 2, 2, 1};
tensors_info->AddTensorInfo("", ML_TENSOR_TYPE_UINT8, dim);
auto tensors_data = tensors_info_manager_.CreateTensorsData(tensors_info);
- unsigned int location[] = {0, 0, 1, 0};
- unsigned int size[] = {3, 2, 1, 1};
+ unsigned int location[util::kWebApiMLTensorRankLimit] = {0, 0, 1, 0};
+ unsigned int size[util::kWebApiMLTensorRankLimit] = {3, 2, 1, 1};
uint8_t arr_in[] = {1, 2, 3, 4, 5, 6};
TensorRawData raw_data_set{arr_in, 6};
PlatformResult res = tensors_data->SetTensorRawData(0, location, size, raw_data_set);
@@ -165,15 +170,17 @@ TEST_F(MlTensorRawDataTest, SetTensorRawData2) {
TensorRawData raw_data_get;
- unsigned int location_get[] = {0, 0, 0, 0};
+ unsigned int location_get[util::kWebApiMLTensorRankLimit] = {0, 0, 0, 0};
res = tensors_data->GetTensorRawData(0, location_get, dim, &raw_data_get);
ASSERT_TRUE(res) << "GetTensorRawData failed";
- unsigned int expected_dim[] = {3, 2, 2, 1};
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ // Expected dimension with rank 4 (Old rank limit of ml-tensors-info)
+ unsigned int expected_dim[] = {3, 2, 2, 1};
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
EXPECT_EQ(raw_data_get.shape[i], expected_dim[i]) << "Invalid value on dim " << i;
}
+
size_t expected_size = 12;
EXPECT_EQ(raw_data_get.size_in_bytes, expected_size);
uint8_t expected_arr[] = {0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6};
@@ -192,12 +199,12 @@ TEST_F(MlTensorRawDataTest, SetTensorRawData2) {
TEST_F(MlTensorRawDataTest, SetTensorRawData3) {
ScopeLogger("SetTensorRawData3");
auto tensors_info = tensors_info_manager_.CreateTensorsInfo();
- unsigned int dim[] = {3, 2, 2, 1};
+ unsigned int dim[util::kWebApiMLTensorRankLimit] = {3, 2, 2, 1};
tensors_info->AddTensorInfo("", ML_TENSOR_TYPE_UINT8, dim);
auto tensors_data = tensors_info_manager_.CreateTensorsData(tensors_info);
- unsigned int location[] = {1, 1, 0, 0};
- unsigned int size[] = {2, 1, 1, 1};
+ unsigned int location[util::kWebApiMLTensorRankLimit] = {1, 1, 0, 0};
+ unsigned int size[util::kWebApiMLTensorRankLimit] = {2, 1, 1, 1};
uint8_t arr_in[] = {1, 2};
TensorRawData raw_data_set{arr_in, 2};
raw_data_set.data = arr_in;
@@ -206,15 +213,16 @@ TEST_F(MlTensorRawDataTest, SetTensorRawData3) {
ASSERT_TRUE(res) << "SetTensorRawData failed";
TensorRawData raw_data_get;
- unsigned int location_get[] = {0, 0, 0, 0};
+ unsigned int location_get[util::kWebApiMLTensorRankLimit] = {0, 0, 0, 0};
res = tensors_data->GetTensorRawData(0, location_get, dim, &raw_data_get);
ASSERT_TRUE(res) << "GetTensorRawData failed";
+ // Expected dimension with rank 4 (Old rank limit of ml-tensors-info)
unsigned int expected_dim[] = {3, 2, 2, 1};
-
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
EXPECT_EQ(raw_data_get.shape[i], expected_dim[i]) << "Invalid value on dim " << i;
}
+
size_t expected_size = 12;
EXPECT_EQ(raw_data_get.size_in_bytes, expected_size);
uint8_t expected_arr[] = {0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0};
@@ -239,27 +247,28 @@ TEST_F(MlTensorRawDataTest, SetTensorRawData3) {
TEST_F(MlTensorRawDataTest, SetTensorRawData4) {
ScopeLogger("SetTensorRawData4");
auto tensors_info = tensors_info_manager_.CreateTensorsInfo();
- unsigned int dim[] = {3, 2, 2, 2};
+ unsigned int dim[util::kWebApiMLTensorRankLimit] = {3, 2, 2, 2};
tensors_info->AddTensorInfo("", ML_TENSOR_TYPE_UINT8, dim);
auto tensors_data = tensors_info_manager_.CreateTensorsData(tensors_info);
- unsigned int location[] = {1, 0, 1, 1};
- unsigned int size[] = {1, 2, 1, 1};
+ unsigned int location[util::kWebApiMLTensorRankLimit] = {1, 0, 1, 1};
+ unsigned int size[util::kWebApiMLTensorRankLimit] = {1, 2, 1, 1};
uint8_t arr_in[] = {1, 2};
TensorRawData raw_data_set{arr_in, 2};
PlatformResult res = tensors_data->SetTensorRawData(0, location, size, raw_data_set);
ASSERT_TRUE(res) << "SetTensorRawData failed";
TensorRawData raw_data_get;
- unsigned int location_get[] = {0, 0, 0, 0};
+ unsigned int location_get[util::kWebApiMLTensorRankLimit] = {0, 0, 0, 0};
res = tensors_data->GetTensorRawData(0, location_get, dim, &raw_data_get);
ASSERT_TRUE(res) << "GetTensorRawData failed";
+ // Expected dimension with rank 4 (Old rank limit of ml-tensors-info)
unsigned int expected_dim[] = {3, 2, 2, 2};
-
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
EXPECT_EQ(raw_data_get.shape[i], expected_dim[i]) << "Invalid value on dim " << i;
}
+
size_t expected_size = 24;
EXPECT_EQ(raw_data_get.size_in_bytes, expected_size);
uint8_t expected_arr[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0};
@@ -284,27 +293,28 @@ TEST_F(MlTensorRawDataTest, SetTensorRawData4) {
TEST_F(MlTensorRawDataTest, SetTensorRawData5) {
ScopeLogger("SetTensorRawData5");
auto tensors_info = tensors_info_manager_.CreateTensorsInfo();
- unsigned int dim[] = {3, 2, 2, 2};
+ unsigned int dim[util::kWebApiMLTensorRankLimit] = {3, 2, 2, 2};
tensors_info->AddTensorInfo("", ML_TENSOR_TYPE_INT32, dim);
auto tensors_data = tensors_info_manager_.CreateTensorsData(tensors_info);
- unsigned int location[] = {2, 1, 1, 1};
- unsigned int size[] = {1, 1, 1, 1};
+ unsigned int location[util::kWebApiMLTensorRankLimit] = {2, 1, 1, 1};
+ unsigned int size[util::kWebApiMLTensorRankLimit] = {1, 1, 1, 1};
int arr_in[] = {-34};
TensorRawData raw_data_set{(uint8_t*)arr_in, 4};
PlatformResult res = tensors_data->SetTensorRawData(0, location, size, raw_data_set);
ASSERT_TRUE(res) << "SetTensorRawData failed";
TensorRawData raw_data_get;
- unsigned int location_get[] = {0, 0, 0, 0};
+ unsigned int location_get[util::kWebApiMLTensorRankLimit] = {0, 0, 0, 0};
res = tensors_data->GetTensorRawData(0, location_get, dim, &raw_data_get);
ASSERT_TRUE(res) << "GetTensorRawData failed";
+ // Expected dimension with rank 4 (Old rank limit of ml-tensors-info)
unsigned int expected_dim[] = {3, 2, 2, 2};
-
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
EXPECT_EQ(raw_data_get.shape[i], expected_dim[i]) << "Invalid value on dim " << i;
}
+
size_t expected_size = 96;
EXPECT_EQ(raw_data_get.size_in_bytes, expected_size);
int expected_arr[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -34};
@@ -319,12 +329,12 @@ TEST_F(MlTensorRawDataTest, SetTensorRawData5) {
TEST_F(MlTensorRawDataTest, SetTensorRawData6) {
ScopeLogger("SetTensorRawData6");
auto tensors_info = tensors_info_manager_.CreateTensorsInfo();
- unsigned int dim[] = {3, 2, 2, 2};
+ unsigned int dim[util::kWebApiMLTensorRankLimit] = {3, 2, 2, 2};
tensors_info->AddTensorInfo("", ML_TENSOR_TYPE_UINT8, dim);
auto tensors_data = tensors_info_manager_.CreateTensorsData(tensors_info);
- unsigned int location[] = {4, 0, 0, 0};
- unsigned int size[] = {1, 1, 1, 1};
+ unsigned int location[util::kWebApiMLTensorRankLimit] = {4, 0, 0, 0};
+ unsigned int size[util::kWebApiMLTensorRankLimit] = {1, 1, 1, 1};
uint8_t arr_in[1] = {};
TensorRawData raw_data_set{arr_in, 1};
PlatformResult res = tensors_data->SetTensorRawData(0, location, size, raw_data_set);
@@ -336,12 +346,12 @@ TEST_F(MlTensorRawDataTest, SetTensorRawData6) {
TEST_F(MlTensorRawDataTest, SetTensorRawData7) {
ScopeLogger("SetTensorRawData7");
auto tensors_info = tensors_info_manager_.CreateTensorsInfo();
- unsigned int dim[] = {3, 2, 2, 2};
+ unsigned int dim[util::kWebApiMLTensorRankLimit] = {3, 2, 2, 2};
tensors_info->AddTensorInfo("", ML_TENSOR_TYPE_UINT8, dim);
auto tensors_data = tensors_info_manager_.CreateTensorsData(tensors_info);
- unsigned int location[] = {0, 0, 0, 0};
- unsigned int size[] = {2, 1, 1, 1};
+ unsigned int location[util::kWebApiMLTensorRankLimit] = {0, 0, 0, 0};
+ unsigned int size[util::kWebApiMLTensorRankLimit] = {2, 1, 1, 1};
uint8_t arr_in[1] = {};
TensorRawData raw_data_set{arr_in, 1};
PlatformResult res = tensors_data->SetTensorRawData(0, location, size, raw_data_set);
@@ -353,12 +363,12 @@ TEST_F(MlTensorRawDataTest, SetTensorRawData7) {
TEST_F(MlTensorRawDataTest, SetTensorRawData8) {
ScopeLogger("SetTensorRawData8");
auto tensors_info = tensors_info_manager_.CreateTensorsInfo();
- unsigned int dim[] = {3, 2, 2, 2};
+ unsigned int dim[util::kWebApiMLTensorRankLimit] = {3, 2, 2, 2};
tensors_info->AddTensorInfo("", ML_TENSOR_TYPE_UINT8, dim);
auto tensors_data = tensors_info_manager_.CreateTensorsData(tensors_info);
- unsigned int location[] = {0, 0, 0, 0};
- unsigned int size[] = {1, 1, 1, 1};
+ unsigned int location[util::kWebApiMLTensorRankLimit] = {0, 0, 0, 0};
+ unsigned int size[util::kWebApiMLTensorRankLimit] = {1, 1, 1, 1};
uint8_t arr_in[400] = {};
TensorRawData raw_data_set{arr_in, 400};
PlatformResult res = tensors_data->SetTensorRawData(0, location, size, raw_data_set);
@@ -372,22 +382,22 @@ class MlTensorRawDataTestGet : public testing::Test {
}
virtual void SetUp() override {
auto tensors_info = tensors_info_manager_.CreateTensorsInfo();
- unsigned int dim[] = {3, 2, 2, 2};
+ unsigned int dim[util::kWebApiMLTensorRankLimit] = {3, 2, 2, 2};
tensors_info->AddTensorInfo("", ML_TENSOR_TYPE_UINT8, dim);
- unsigned int dim_big[] = {5, 4, 3, 2};
+ unsigned int dim_big[util::kWebApiMLTensorRankLimit] = {5, 4, 3, 2};
tensors_info->AddTensorInfo("", ML_TENSOR_TYPE_UINT8, dim_big);
tensors_data_ = tensors_info_manager_.CreateTensorsData(tensors_info);
- unsigned int location[] = {0, 0, 0, 0};
- unsigned int size[] = {3, 2, 2, 2};
+ unsigned int location[util::kWebApiMLTensorRankLimit] = {0, 0, 0, 0};
+ unsigned int size[util::kWebApiMLTensorRankLimit] = {3, 2, 2, 2};
uint8_t arr_in[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24};
TensorRawData raw_data_set{arr_in, 24};
PlatformResult res = tensors_data_->SetTensorRawData(0, location, size, raw_data_set);
ASSERT_TRUE(res) << "SetTensorRawData failed";
- unsigned int location_big[] = {0, 0, 0, 0};
- unsigned int size_big[] = {5, 4, 3, 2};
+ unsigned int location_big[util::kWebApiMLTensorRankLimit] = {0, 0, 0, 0};
+ unsigned int size_big[util::kWebApiMLTensorRankLimit] = {5, 4, 3, 2};
uint8_t arr_in_big[120] = {};
for (int i = 0; i < 120; i++) {
@@ -423,8 +433,8 @@ class MlTensorRawDataTestGet : public testing::Test {
TEST_F(MlTensorRawDataTestGet, GetTensorRawData1) {
ScopeLogger("GetTensorRawData1");
- unsigned int location_get[4] = {0, 0, 0, 0};
- unsigned int size_get[4] = {1, 1, 1, 1};
+ unsigned int location_get[util::kWebApiMLTensorRankLimit] = {0, 0, 0, 0};
+ unsigned int size_get[util::kWebApiMLTensorRankLimit] = {1, 1, 1, 1};
unsigned int expected_dim[4] = {1, 1, 1, 1};
size_t expected_size = 1;
uint8_t expected_arr[1] = {1};
@@ -433,7 +443,8 @@ TEST_F(MlTensorRawDataTestGet, GetTensorRawData1) {
PlatformResult res = tensors_data_->GetTensorRawData(0, location_get, size_get, &raw_data_get);
ASSERT_TRUE(res) << "GetTensorRawData failed";
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ // Expected dimension with rank 4 (Old rank limit of ml-tensors-info)
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
EXPECT_EQ(raw_data_get.shape[i], expected_dim[i]) << "Invalid value at dim " << i;
}
EXPECT_EQ(raw_data_get.size_in_bytes, expected_size);
@@ -445,8 +456,8 @@ TEST_F(MlTensorRawDataTestGet, GetTensorRawData1) {
TEST_F(MlTensorRawDataTestGet, GetTensorRawData2) {
ScopeLogger("GetTensorRawData2");
- unsigned int location_get[4] = {0, 0, 1, 0};
- unsigned int size_get[4] = {3, 2, 2, 2};
+ unsigned int location_get[util::kWebApiMLTensorRankLimit] = {0, 0, 1, 0};
+ unsigned int size_get[util::kWebApiMLTensorRankLimit] = {3, 2, 2, 2};
unsigned int expected_dim[4] = {3, 2, 1, 2};
size_t expected_size = 12;
uint8_t expected_arr[12] = {7, 8, 9, 10, 11, 12, 19, 20, 21, 22, 23, 24};
@@ -455,7 +466,8 @@ TEST_F(MlTensorRawDataTestGet, GetTensorRawData2) {
PlatformResult res = tensors_data_->GetTensorRawData(0, location_get, size_get, &raw_data_get);
ASSERT_TRUE(res) << "GetTensorRawData failed";
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ // Expected dimension with rank 4 (Old rank limit of ml-tensors-info)
+ for (int i = 0; i < 4; i++) {
EXPECT_EQ(raw_data_get.shape[i], expected_dim[i]) << "Invalid value at dim " << i;
}
EXPECT_EQ(raw_data_get.size_in_bytes, expected_size);
@@ -467,8 +479,8 @@ TEST_F(MlTensorRawDataTestGet, GetTensorRawData2) {
TEST_F(MlTensorRawDataTestGet, GetTensorRawData3) {
ScopeLogger("GetTensorRawData3");
- unsigned int location_get[4] = {1, 1, 1, 1};
- unsigned int size_get[4] = {2, 2, 2, 2};
+ unsigned int location_get[util::kWebApiMLTensorRankLimit] = {1, 1, 1, 1};
+ unsigned int size_get[util::kWebApiMLTensorRankLimit] = {2, 2, 2, 2};
unsigned int expected_dim[4] = {2, 1, 1, 1};
size_t expected_size = 2;
uint8_t expected_arr[2] = {23, 24};
@@ -477,7 +489,8 @@ TEST_F(MlTensorRawDataTestGet, GetTensorRawData3) {
PlatformResult res = tensors_data_->GetTensorRawData(0, location_get, size_get, &raw_data_get);
ASSERT_TRUE(res) << "GetTensorRawData failed";
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ // Expected dimension with rank 4 (Old rank limit of ml-tensors-info)
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
EXPECT_EQ(raw_data_get.shape[i], expected_dim[i]) << "Invalid value at dim " << i;
}
EXPECT_EQ(raw_data_get.size_in_bytes, expected_size);
@@ -489,8 +502,8 @@ TEST_F(MlTensorRawDataTestGet, GetTensorRawData3) {
TEST_F(MlTensorRawDataTestGet, GetTensorRawData4) {
ScopeLogger("GetTensorRawData4");
- unsigned int location_get[4] = {2, 1, 0, 1};
- unsigned int size_get[4] = {3, 2, 2, 2};
+ unsigned int location_get[util::kWebApiMLTensorRankLimit] = {2, 1, 0, 1};
+ unsigned int size_get[util::kWebApiMLTensorRankLimit] = {3, 2, 2, 2};
unsigned int expected_dim[4] = {1, 1, 2, 1};
size_t expected_size = 2;
uint8_t expected_arr[2] = {18, 24};
@@ -499,7 +512,8 @@ TEST_F(MlTensorRawDataTestGet, GetTensorRawData4) {
PlatformResult res = tensors_data_->GetTensorRawData(0, location_get, size_get, &raw_data_get);
ASSERT_TRUE(res) << "GetTensorRawData failed";
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ // Expected dimension with rank 4 (Old rank limit of ml-tensors-info)
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
EXPECT_EQ(raw_data_get.shape[i], expected_dim[i]) << "Invalid value at dim " << i;
}
EXPECT_EQ(raw_data_get.size_in_bytes, expected_size);
@@ -511,8 +525,8 @@ TEST_F(MlTensorRawDataTestGet, GetTensorRawData4) {
TEST_F(MlTensorRawDataTestGet, GetTensorRawData5) {
ScopeLogger("GetTensorRawData5");
- unsigned int location_get[4] = {3, 2, 1, 0};
- unsigned int size_get[4] = {1, 1, 2, 2};
+ unsigned int location_get[util::kWebApiMLTensorRankLimit] = {3, 2, 1, 0};
+ unsigned int size_get[util::kWebApiMLTensorRankLimit] = {1, 1, 2, 2};
unsigned int expected_dim[4] = {1, 1, 2, 2};
size_t expected_size = 4;
uint8_t expected_arr[4] = {34, 54, 94, 114};
@@ -521,7 +535,8 @@ TEST_F(MlTensorRawDataTestGet, GetTensorRawData5) {
PlatformResult res = tensors_data_->GetTensorRawData(1, location_get, size_get, &raw_data_get);
ASSERT_TRUE(res) << "GetTensorRawData failed";
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ // Expected dimension with rank 4 (Old rank limit of ml-tensors-info)
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
EXPECT_EQ(raw_data_get.shape[i], expected_dim[i]) << "Invalid value at dim " << i;
}
EXPECT_EQ(raw_data_get.size_in_bytes, expected_size);
@@ -533,8 +548,8 @@ TEST_F(MlTensorRawDataTestGet, GetTensorRawData5) {
TEST_F(MlTensorRawDataTestGet, GetTensorRawData6) {
ScopeLogger("GetTensorRawData6");
- unsigned int location_get[4] = {4, 1, 0, 1};
- unsigned int size_get[4] = {5, 4, 3, 2};
+ unsigned int location_get[util::kWebApiMLTensorRankLimit] = {4, 1, 0, 1};
+ unsigned int size_get[util::kWebApiMLTensorRankLimit] = {5, 4, 3, 2};
unsigned int expected_dim[4] = {1, 3, 3, 1};
size_t expected_size = 9;
uint8_t expected_arr[9] = {70, 75, 80, 90, 95, 100, 110, 115, 120};
@@ -543,7 +558,8 @@ TEST_F(MlTensorRawDataTestGet, GetTensorRawData6) {
PlatformResult res = tensors_data_->GetTensorRawData(1, location_get, size_get, &raw_data_get);
ASSERT_TRUE(res) << "GetTensorRawData failed";
- for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ // Expected dimension with rank 4 (Old rank limit of ml-tensors-info)
+ for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
EXPECT_EQ(raw_data_get.shape[i], expected_dim[i]) << "Invalid value at dim " << i;
}
EXPECT_EQ(raw_data_get.size_in_bytes, expected_size);
@@ -555,8 +571,8 @@ TEST_F(MlTensorRawDataTestGet, GetTensorRawData6) {
TEST_F(MlTensorRawDataTestGet, GetTensorRawData7) {
ScopeLogger("GetTensorRawData7");
- unsigned int location_get[4] = {4, 1, 0, 1};
- unsigned int size_get[4] = {5, 4, 3, 2};
+ unsigned int location_get[util::kWebApiMLTensorRankLimit] = {4, 1, 0, 1};
+ unsigned int size_get[util::kWebApiMLTensorRankLimit] = {5, 4, 3, 2};
TensorRawData raw_data_get;
PlatformResult res = tensors_data_->GetTensorRawData(0, location_get, size_get, &raw_data_get);