/* * Copyright 2008-2013 NVIDIA Corporation * Modifications Copyright© 2019-2025 Advanced Micro Devices, Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include "test_param_fixtures.hpp" #include "test_utils.hpp" struct alloc_id { std::size_t id; std::size_t size; std::size_t alignment; std::size_t offset; __host__ __device__ bool operator==(const alloc_id& other) const { return id == other.id && size == other.size && alignment == other.alignment; } alloc_id operator+(std::size_t size) const { alloc_id ret; ret.id = id; ret.size = size; ret.alignment = alignment; ret.offset = size; return ret; } }; template <> struct thrust::detail::pointer_traits { template struct rebind { using other = alloc_id; }; // implemented for the purposes of alignment test in disjoint pool's do_deallocate static void* get(const alloc_id& id) { return reinterpret_cast(id.alignment); } }; class dummy_resource final : public thrust::mr::memory_resource { public: dummy_resource() : id_to_allocate(0) , id_to_deallocate(0) {} ~dummy_resource() { EXPECT_EQ(id_to_allocate, 0u); EXPECT_EQ(id_to_deallocate, 0u); } virtual alloc_id do_allocate(std::size_t bytes, std::size_t alignment) override { EXPECT_EQ(static_cast(id_to_allocate), true); alloc_id ret; ret.id = id_to_allocate; ret.size = bytes; ret.alignment = alignment; id_to_allocate = 0; return ret; } virtual void do_deallocate(alloc_id p, std::size_t bytes, std::size_t alignment) override { ASSERT_EQ(p.size, bytes); ASSERT_EQ(p.alignment, alignment); if (id_to_deallocate != 0) { EXPECT_EQ(p.id, id_to_deallocate); id_to_deallocate = 0; } } std::size_t id_to_allocate; std::size_t id_to_deallocate; }; template