thrust/mr/pool_options.h
File members: thrust/mr/pool_options.h
/*
 *  Copyright 2018 NVIDIA Corporation
 *
 *  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.
 */
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
#  pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
#  pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
#  pragma system_header
#endif // no system header
#include <thrust/detail/config/memory_resource.h>
#include <thrust/detail/integer_math.h>
#include <cstddef>
THRUST_NAMESPACE_BEGIN
namespace mr
{
struct pool_options
{
  std::size_t min_blocks_per_chunk;
  std::size_t min_bytes_per_chunk;
  std::size_t max_blocks_per_chunk;
  std::size_t max_bytes_per_chunk;
  std::size_t smallest_block_size;
  std::size_t largest_block_size;
  std::size_t alignment;
  bool cache_oversized;
  std::size_t cached_size_cutoff_factor;
  std::size_t cached_alignment_cutoff_factor;
  bool validate() const
  {
    if (!detail::is_power_of_2(smallest_block_size))
    {
      return false;
    }
    if (!detail::is_power_of_2(largest_block_size))
    {
      return false;
    }
    if (!detail::is_power_of_2(alignment))
    {
      return false;
    }
    if (max_bytes_per_chunk == 0 || max_blocks_per_chunk == 0)
    {
      return false;
    }
    if (smallest_block_size == 0 || largest_block_size == 0)
    {
      return false;
    }
    if (min_blocks_per_chunk > max_blocks_per_chunk)
    {
      return false;
    }
    if (min_bytes_per_chunk > max_bytes_per_chunk)
    {
      return false;
    }
    if (smallest_block_size > largest_block_size)
    {
      return false;
    }
    if (min_blocks_per_chunk * smallest_block_size > max_bytes_per_chunk)
    {
      return false;
    }
    if (min_blocks_per_chunk * largest_block_size > max_bytes_per_chunk)
    {
      return false;
    }
    if (max_blocks_per_chunk * largest_block_size < min_bytes_per_chunk)
    {
      return false;
    }
    if (max_blocks_per_chunk * smallest_block_size < min_bytes_per_chunk)
    {
      return false;
    }
    if (alignment > smallest_block_size)
    {
      return false;
    }
    return true;
  }
};
} // namespace mr
THRUST_NAMESPACE_END