8#include <gtest/gtest.h>
10#include "arcane/utils/MemoryView.h"
11#include "arcane/utils/UniqueArray.h"
12#include "arcane/utils/Exception.h"
14#include "arcane/utils/NumericTypes.h"
15#include "arccore/common/internal/MemoryUtilsInternal.h"
27template <
typename DataType>
30 char _initValue(
Int32 v,
char*)
32 auto x =
static_cast<char>(v + 5);
37 auto x =
static_cast<Int16>(v + 5);
42 auto x =
static_cast<Int32>(v + 5);
47 auto x =
static_cast<Int64>(v + 5);
52 auto x =
static_cast<Real>(v + 5);
58 return Real3(x, x / 2.0, x + 1.5);
64 Real2 b(x - 7.9, x * 2.0);
70 Real3 a(x, x / 2.0, x + 1.5);
71 Real3 b(x - 7.9, x * 2.0, x / 1.5);
72 Real3 c(x + 3.2, x + 4.7, x + 2.5);
80 Int32 nb_value = 1000;
81 DataType* dummy =
nullptr;
83 for (
Int32 i = 0; i < nb_value; ++i) {
84 DataType x = _initValue(i, dummy);
94 ASSERT_EQ(array1, array2);
100 unsigned int seed0 = 942244294;
101 std::mt19937 mt1(seed0);
102 auto diff_2 = (mt1.max() - mt1.min()) / 2;
103 for (
Int32 i = 0; i < nb_value; ++i) {
104 auto r = mt1() - mt1.min();
109 std::cout <<
"NB_COPY=" << nb_index <<
"\n";
117 for (
Int32 i = 0; i < nb_index; ++i)
118 array2[i] = array1[copy_indexes[i]];
124 ASSERT_EQ(array2, array3);
138 for (
Int32 i = 0; i < nb_value; ++i) {
139 DataType x = _initValue(i + 27, dummy);
144 for (
Int32 i = 0; i < nb_index; ++i)
145 array2[copy_indexes[i]] = array1[i];
150 ASSERT_EQ(array2, array3);
172 std::cerr <<
"ERROR=" << ex <<
"\n";
184 ASSERT_EQ(v, expected_mem_resource);
187 ASSERT_EQ(v2, expected_mem_resource);
206 for (Int32 i = 0; i < n; ++i)
Memory and allocator management functions.
Integer size() const
Number of elements in the vector.
Span< const T > span() const
Immutable view of this array.
void add(ConstReferenceType val)
Adds element val to the end of the array.
ArrayView< T > view() const
Mutable view of this array.
Constant view on a contiguous memory region containing fixed-size elements.
constexpr SpanType bytes() const
View in byte form.
Base class for an exception.
Mutable view on a contiguous memory region containing fixed-size elements.
Class managing a 2-dimensional real vector.
Class managing a 2x2 matrix of reals.
Class managing a 3-dimensional real vector.
Class managing a 3x3 real matrix.
View of an array of elements of type T.
View of an array of elements of type T.
Unicode character string.
1D data vector with value semantics (STL style).
Concept for allocating, resizing and freeing memory block.
void setDefaultDataMemoryResource(eMemoryResource mem_resource)
Sets the memory resource used for the data memory allocator.
void copyHostWithIndexedSource(MutableMemoryView destination, ConstMemoryView source, Span< const Int32 > indexes)
Copies data on the host with indirection.
eMemoryResource getMemoryResourceFromName(const String &name)
Returns the memory resource by its name.
void copyHostWithIndexedDestination(MutableMemoryView destination, ConstMemoryView source, Span< const Int32 > indexes)
Copies indexed data from v into the instance.
void copyHost(MutableMemoryView destination, ConstMemoryView source)
Copies the data from source into destination.
eMemoryResource getDefaultDataMemoryResource()
Memory resource used by the default allocator for data.
void copy(MutableMemoryView destination, eMemoryResource destination_mem, ConstMemoryView source, eMemoryResource source_mem, const RunQueue *queue=nullptr)
Copies source to destination using the queue queue.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
std::int16_t Int16
Signed integer type of 16 bits.
double Real
Type representing a real number.
Impl::SpanTypeFromSize< conststd::byte, SizeType >::SpanType asBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converts the view into an array of non-modifiable bytes.
eMemoryResource
List of available memory resources.
@ HostPinned
Allocates on the host.
@ Host
Allocates on the host.
@ UnifiedMemory
Allocates using unified memory.
@ Device
Allocates on the device.
std::int32_t Int32
Signed integer type of 32 bits.