| 379 | */ |
| 380 | template <typename T> |
| 381 | void fill_tensor(T &tensor) |
| 382 | { |
| 383 | ARM_COMPUTE_ERROR_ON(!is_open()); |
| 384 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_NOT_IN(&tensor, arm_compute::DataType::QASYMM8, arm_compute::DataType::S32, |
| 385 | arm_compute::DataType::F32, arm_compute::DataType::F16); |
| 386 | try |
| 387 | { |
| 388 | // Map buffer if creating a CLTensor |
| 389 | map(tensor, true); |
| 390 | |
| 391 | // Check if the file is large enough to fill the tensor |
| 392 | const size_t current_position = _fs.tellg(); |
| 393 | _fs.seekg(0, std::ios_base::end); |
| 394 | const size_t end_position = _fs.tellg(); |
| 395 | _fs.seekg(current_position, std::ios_base::beg); |
| 396 | |
| 397 | ARM_COMPUTE_ERROR_ON_MSG((end_position - current_position) < |
| 398 | tensor.info()->tensor_shape().total_size() * tensor.info()->element_size(), |
| 399 | "Not enough data in file"); |
| 400 | ARM_COMPUTE_UNUSED(end_position); |
| 401 | |
| 402 | // Check if the typestring matches the given one |
| 403 | std::string expect_typestr = get_typestring(tensor.info()->data_type()); |
| 404 | |
| 405 | bool enable_f32_to_f16_conversion = false; |
| 406 | if (_typestring != expect_typestr) |
| 407 | { |
| 408 | const std::string f32_typestring = "<f4"; |
| 409 | const std::string f16_typestring = "<f2"; |
| 410 | // if typestring does not match, check whether _typestring is F32 and can be downcasted to expect_typestr |
| 411 | if (_typestring == f32_typestring && expect_typestr == f16_typestring) |
| 412 | { |
| 413 | enable_f32_to_f16_conversion = true; |
| 414 | } |
| 415 | else |
| 416 | { |
| 417 | ARM_COMPUTE_ERROR("Typestrings mismatch"); |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | bool are_layouts_different = (_file_layout != tensor.info()->data_layout()); |
| 422 | // Correct dimensions (Needs to match TensorShape dimension corrections) |
| 423 | if (_shape.size() != tensor.info()->tensor_shape().num_dimensions()) |
| 424 | { |
| 425 | for (int i = static_cast<int>(_shape.size()) - 1; i > 0; --i) |
| 426 | { |
| 427 | if (_shape[i] == 1) |
| 428 | { |
| 429 | _shape.pop_back(); |
| 430 | } |
| 431 | else |
| 432 | { |
| 433 | break; |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | TensorShape permuted_shape = tensor.info()->tensor_shape(); |
no test coverage detected