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

Function TEST_CASE

tests/validation/NEON/UNIT/TensorAllocator.cpp:52–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50TEST_SUITE(TensorAllocator)
51
52TEST_CASE(ImportMemory, framework::DatasetMode::ALL)
53{
54 // Init tensor info
55 TensorInfo info(TensorShape(24U, 16U, 3U), 1, DataType::F32);
56
57 // Allocate memory buffer
58 const size_t total_size = info.total_size();
59 auto data = std::make_unique<uint8_t[]>(total_size);
60
61 // Negative case : Import nullptr
62 Tensor t1;
63 t1.allocator()->init(info);
64 ARM_COMPUTE_ASSERT(!bool(t1.allocator()->import_memory(nullptr)));
65 ARM_COMPUTE_ASSERT(t1.info()->is_resizable());
66
67 // Negative case : Import misaligned pointer
68 Tensor t2;
69 size_t required_alignment = 339;
70 ARM_COMPUTE_ASSERT(data.get() != nullptr);
71 // If the data ptr is aligned with 339, keep adding 1 until it is misaligned.
72 while (arm_compute::utility::check_aligned(data.get(), required_alignment))
73 {
74 required_alignment += 1;
75 }
76 t2.allocator()->init(info, required_alignment);
77 ARM_COMPUTE_ASSERT(!bool(t2.allocator()->import_memory(data.get())));
78 ARM_COMPUTE_ASSERT(t2.info()->is_resizable());
79
80 // Negative case : Import memory to a tensor that is memory managed
81 Tensor t3;
82 MemoryGroup mg;
83 t3.allocator()->set_associated_memory_group(&mg);
84 ARM_COMPUTE_ASSERT(!bool(t3.allocator()->import_memory(data.get())));
85 ARM_COMPUTE_ASSERT(t3.info()->is_resizable());
86
87 // Positive case : Set raw pointer
88 Tensor t4;
89 t4.allocator()->init(info);
90 ARM_COMPUTE_ASSERT(bool(t4.allocator()->import_memory(data.get())));
91 ARM_COMPUTE_ASSERT(!t4.info()->is_resizable());
92 ARM_COMPUTE_ASSERT(t4.buffer() == reinterpret_cast<uint8_t *>(data.get()));
93 t4.allocator()->free();
94 ARM_COMPUTE_ASSERT(t4.info()->is_resizable());
95 ARM_COMPUTE_ASSERT(t4.buffer() == nullptr);
96}
97
98TEST_CASE(ImportMemoryMalloc, framework::DatasetMode::ALL)
99{

Callers

nothing calls this directly

Calls 15

check_alignedFunction · 0.85
seedMethod · 0.80
is_mappedMethod · 0.80
alignmentMethod · 0.80
TensorShapeClass · 0.50
TensorInfoClass · 0.50
validateFunction · 0.50
ActivationLayerInfoClass · 0.50
total_sizeMethod · 0.45
initMethod · 0.45
allocatorMethod · 0.45
import_memoryMethod · 0.45

Tested by

no test coverage detected