File: test_mr_new.cpp

package info (click to toggle)
rocthrust 6.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,588 kB
  • sloc: cpp: 66,309; ansic: 34,184; python: 1,519; sh: 331; xml: 212; makefile: 115
file content (38 lines) | stat: -rw-r--r-- 1,279 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <thrust/mr/new.h>
#include <thrust/fill.h>

#include "test_header.hpp"

template<typename MemoryResource>
void TestAlignment(MemoryResource memres, std::size_t size, std::size_t alignment)
{
    void * ptr = memres.do_allocate(size, alignment);
    ASSERT_EQ(reinterpret_cast<std::size_t>(ptr) % alignment, 0u);

    char * char_ptr = reinterpret_cast<char *>(ptr);
    thrust::fill(char_ptr, char_ptr + size, 0);

    memres.do_deallocate(ptr, size, alignment);
}

static const std::size_t MinTestedSize = 32;
static const std::size_t MaxTestedSize = 8 * 1024;
static const std::size_t TestedSizeStep = 1;

static const std::size_t MinTestedAlignment = 16;
static const std::size_t MaxTestedAlignment = 4 * 1024;
static const std::size_t TestedAlignmentShift = 1;

TEST(MrAlignmentTests, TestNewDeleteResourceAlignedAllocation)
{
    SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
    
    for (std::size_t size = MinTestedSize; size <= MaxTestedSize; size += TestedSizeStep)
    {
        for (std::size_t alignment = MinTestedAlignment; alignment <= MaxTestedAlignment;
            alignment <<= TestedAlignmentShift)
        {
            TestAlignment(thrust::mr::new_delete_resource(), size, alignment);
        }
    }
}