From b8d5b958d489c21214cc23755d442e4e78f03878 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Thu, 16 May 2019 14:13:03 +0100 Subject: COMPMID-2166: Add tests for importing memory mapped files. Change-Id: I011773bbe0bf6774a9718d414b4b297b4d8996c0 Signed-off-by: Georgios Pinitas Reviewed-on: https://review.mlplatform.org/c/1179 Reviewed-by: Michalis Spyrou Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins --- tests/validation/NEON/UNIT/TensorAllocator.cpp | 60 ++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'tests/validation/NEON') diff --git a/tests/validation/NEON/UNIT/TensorAllocator.cpp b/tests/validation/NEON/UNIT/TensorAllocator.cpp index 7ba83c11b3..217933da48 100644 --- a/tests/validation/NEON/UNIT/TensorAllocator.cpp +++ b/tests/validation/NEON/UNIT/TensorAllocator.cpp @@ -23,6 +23,7 @@ */ #include "arm_compute/runtime/TensorAllocator.h" +#include "arm_compute/core/utils/misc/MMappedFile.h" #include "arm_compute/core/utils/misc/Utility.h" #include "arm_compute/runtime/MemoryGroup.h" #include "arm_compute/runtime/MemoryRegion.h" @@ -141,6 +142,65 @@ TEST_CASE(ImportMemoryMalloc, framework::DatasetMode::ALL) ARM_COMPUTE_EXPECT(tensor.info()->is_resizable(), framework::LogLevel::ERRORS); } +#if !defined(BARE_METAL) +TEST_CASE(ImportMemoryMappedFile, framework::DatasetMode::ALL) +{ + const ActivationLayerInfo act_info(ActivationLayerInfo::ActivationFunction::RELU); + const TensorShape shape = TensorShape(24U, 16U, 3U); + const DataType data_type = DataType::F32; + + // Create tensor + const TensorInfo info(shape, 1, data_type); + Tensor tensor; + tensor.allocator()->init(info); + + // Create and configure activation function + NEActivationLayer act_func; + act_func.configure(&tensor, nullptr, act_info); + + // Get number of elements + const size_t total_size_in_elems = tensor.info()->tensor_shape().total_size(); + const size_t total_size_in_bytes = tensor.info()->total_size(); + + // Create file + std::ofstream output_file("test_mmap_import.bin", std::ios::binary | std::ios::out); + output_file.seekp(total_size_in_bytes - 1); + output_file.write("", 1); + output_file.close(); + + // Map file + utils::mmap_io::MMappedFile mmapped_file("test_mmap_import.bin", 0 /** Whole file */, 0); + ARM_COMPUTE_EXPECT(mmapped_file.is_mapped(), framework::LogLevel::ERRORS); + unsigned char *data = mmapped_file.data(); + + // Import memory mapped memory + ARM_COMPUTE_EXPECT(bool(tensor.allocator()->import_memory(data)), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!tensor.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Fill tensor + std::uniform_real_distribution distribution(-5.f, 5.f); + std::mt19937 gen(library->seed()); + auto *typed_ptr = reinterpret_cast(data); + for(unsigned int i = 0; i < total_size_in_elems; ++i) + { + typed_ptr[i] = distribution(gen); + } + + // Execute function and sync + act_func.run(); + + // Validate result by checking that the input has no negative values + for(unsigned int i = 0; i < total_size_in_elems; ++i) + { + ARM_COMPUTE_EXPECT(typed_ptr[i] >= 0, framework::LogLevel::ERRORS); + } + + // Release resources + tensor.allocator()->free(); + ARM_COMPUTE_EXPECT(tensor.info()->is_resizable(), framework::LogLevel::ERRORS); +} +#endif // !defined(BARE_METAL) + TEST_CASE(AlignedAlloc, framework::DatasetMode::ALL) { // Init tensor info -- cgit v1.2.1