/*
 * Copyright (c) 2022-2024, 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.
 */

// Modifications Copyright (c) 2025 Advanced Micro Devices, Inc.
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#pragma once

#include <nv/target>
#include <cuda/std/version>

//TODO(HIP/AMD): this is not supported/used presently
// #if !defined(__CUDACC_VER_MAJOR__) || !defined(__CUDACC_VER_MINOR__)
// #error "NVCC version not found"
// #elif __CUDACC_VER_MAJOR__ < 11 || (__CUDACC_VER_MAJOR__ == 11 && __CUDACC_VER_MINOR__ < 5)
// #error "NVCC version 11.5 or later is required"
// #endif

// TODO(HIP/AMD): check for compatibility in the future.
// #if !defined(__CUDACC_EXTENDED_LAMBDA__) 
// #error "Support for extended device lambdas is required  (nvcc flag --expt-extended-lambda)"
// #endif

// TODO(HIP/AMD): do we need current CCCL?
#ifndef __HIP_PLATFORM_AMD__
#if !defined(CCCL_VERSION) || (CCCL_VERSION < 2005000)
#error "CCCL version 2.5.0 or later is required"
#endif
#endif

// TODO(HIP/AMD): still necessary?
#ifdef __HIP_PLATFORM_AMD__
#include <hipcub/hipcub.hpp>
#endif

// WAR for libcudacxx/296
#define CUCO_CUDA_MINIMUM_ARCH _NV_FIRST_ARG(__CUDA_ARCH_LIST__)

// NOTE(HIP/AMD): No IFP on AMD GPUs. -> No support for barrier (02-26-2025).
#if defined(CUDART_VERSION) && (CUDART_VERSION >= 11000) && (CUCO_CUDA_MINIMUM_ARCH >= 700)
#define CUCO_HAS_CUDA_BARRIER
#endif

#if defined(CUDART_VERSION) && (CUDART_VERSION >= 12010)
#define CUCO_HAS_CG_INVOKE_ONE
#endif

#if (CUCO_CUDA_MINIMUM_ARCH >= 700)
#define CUCO_HAS_INDEPENDENT_THREADS
#endif

#if defined(__SIZEOF_INT128__)
#define CUCO_HAS_INT128
#endif

#if defined(CUDART_VERSION) && (CUDART_VERSION >= 12000)
#define CUCO_HAS_CG_REDUCE_UPDATE_ASYNC
#endif
