aboutsummaryrefslogtreecommitdiff
path: root/tests/validation/CL/UNIT/TensorAllocator.cpp
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2019-05-16 14:13:03 +0100
committerGeorgios Pinitas <georgios.pinitas@arm.com>2019-05-22 12:38:27 +0000
commitb8d5b958d489c21214cc23755d442e4e78f03878 (patch)
tree24e14a2258f5b8ff884d768f09c00e32923ee3b2 /tests/validation/CL/UNIT/TensorAllocator.cpp
parentac33d7eb7bf0db65c3663d9707e509ca91337349 (diff)
downloadComputeLibrary-b8d5b958d489c21214cc23755d442e4e78f03878.tar.gz
COMPMID-2166: Add tests for importing memory mapped files.
Change-Id: I011773bbe0bf6774a9718d414b4b297b4d8996c0 Signed-off-by: Georgios Pinitas <georgios.pinitas@arm.com> Reviewed-on: https://review.mlplatform.org/c/1179 Reviewed-by: Michalis Spyrou <michalis.spyrou@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'tests/validation/CL/UNIT/TensorAllocator.cpp')
-rw-r--r--tests/validation/CL/UNIT/TensorAllocator.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/validation/CL/UNIT/TensorAllocator.cpp b/tests/validation/CL/UNIT/TensorAllocator.cpp
index 7e47e3d983..e5b37d8387 100644
--- a/tests/validation/CL/UNIT/TensorAllocator.cpp
+++ b/tests/validation/CL/UNIT/TensorAllocator.cpp
@@ -23,6 +23,7 @@
*/
#include "arm_compute/runtime/CL/CLTensorAllocator.h"
+#include "arm_compute/core/utils/misc/MMappedFile.h"
#include "arm_compute/runtime/CL/CLMemoryGroup.h"
#include "arm_compute/runtime/CL/CLScheduler.h"
#include "arm_compute/runtime/CL/functions/CLActivationLayer.h"
@@ -166,6 +167,74 @@ TEST_CASE(ImportMemoryMalloc, framework::DatasetMode::ALL)
}
}
+#if !defined(BARE_METAL)
+TEST_CASE(ImportMemoryMappedFile, framework::DatasetMode::ALL)
+{
+ // Check if import extension is supported
+ if(!device_supports_extension(CLKernelLibrary::get().get_device(), "cl_arm_import_memory_host"))
+ {
+ return;
+ }
+ else
+ {
+ 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);
+ CLTensor tensor;
+ tensor.allocator()->init(info);
+
+ // Create and configure activation function
+ CLActivationLayer 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();
+
+ cl::Buffer wrapped_buffer(import_malloc_memory_helper(data, total_size_in_bytes));
+ ARM_COMPUTE_EXPECT(bool(tensor.allocator()->import_memory(wrapped_buffer)), framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT(!tensor.info()->is_resizable(), framework::LogLevel::ERRORS);
+
+ // Fill tensor
+ std::uniform_real_distribution<float> distribution(-5.f, 5.f);
+ std::mt19937 gen(library->seed());
+ auto *typed_ptr = reinterpret_cast<float *>(data);
+ for(unsigned int i = 0; i < total_size_in_elems; ++i)
+ {
+ typed_ptr[i] = distribution(gen);
+ }
+
+ // Execute function and sync
+ act_func.run();
+ CLScheduler::get().sync();
+
+ // 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_SUITE_END() // TensorAllocator
TEST_SUITE_END() // UNIT
TEST_SUITE_END() // CL