MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / fill_tensor

Method fill_tensor

utils/Utils.h:381–539  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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();

Callers 1

access_tensorMethod · 0.45

Calls 15

mapFunction · 0.85
unmapFunction · 0.85
readMethod · 0.80
ptr_to_elementMethod · 0.80
get_typestringFunction · 0.70
permuteFunction · 0.50
total_sizeMethod · 0.45
infoMethod · 0.45
element_sizeMethod · 0.45
data_typeMethod · 0.45
data_layoutMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected