CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
148 lines
4.2 KiB
C++
148 lines
4.2 KiB
C++
// -*- C++ -*-
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of libcu++, the C++ Standard Library for your entire system,
|
|
// under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef _CUDA_PTX_HELPER_FUNCTIONS_H_
|
|
#define _CUDA_PTX_HELPER_FUNCTIONS_H_
|
|
|
|
#include <cuda/std/detail/__config>
|
|
|
|
#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 <cuda/std/__type_traits/enable_if.h>
|
|
#include <cuda/std/__type_traits/integral_constant.h>
|
|
#include <cuda/std/cstddef>
|
|
#include <cuda/std/cstdint>
|
|
|
|
#if _CCCL_HAS_CUDA_COMPILER()
|
|
|
|
_LIBCUDACXX_BEGIN_NAMESPACE_CUDA_PTX
|
|
|
|
/*************************************************************
|
|
*
|
|
* Conversion from generic pointer -> state space "pointer"
|
|
*
|
|
**************************************************************/
|
|
inline _CCCL_DEVICE _CUDA_VSTD::uint32_t __as_ptr_smem(const void* __ptr)
|
|
{
|
|
// Consider adding debug asserts here.
|
|
return static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(__ptr));
|
|
}
|
|
|
|
inline _CCCL_DEVICE _CUDA_VSTD::uint32_t __as_ptr_dsmem(const void* __ptr)
|
|
{
|
|
// No difference in implementation to __as_ptr_smem.
|
|
// Consider adding debug asserts here.
|
|
return __as_ptr_smem(__ptr);
|
|
}
|
|
|
|
inline _CCCL_DEVICE _CUDA_VSTD::uint32_t __as_ptr_remote_dsmem(const void* __ptr)
|
|
{
|
|
// No difference in implementation to __as_ptr_smem.
|
|
// Consider adding debug asserts here.
|
|
return __as_ptr_smem(__ptr);
|
|
}
|
|
|
|
inline _CCCL_DEVICE _CUDA_VSTD::uint64_t __as_ptr_gmem(const void* __ptr)
|
|
{
|
|
// Consider adding debug asserts here.
|
|
return static_cast<_CUDA_VSTD::uint64_t>(__cvta_generic_to_global(__ptr));
|
|
}
|
|
|
|
/*************************************************************
|
|
*
|
|
* Conversion from state space "pointer" -> generic pointer
|
|
*
|
|
**************************************************************/
|
|
template <typename _Tp>
|
|
inline _CCCL_DEVICE _Tp* __from_ptr_smem(_CUDA_VSTD::size_t __ptr)
|
|
{
|
|
// Consider adding debug asserts here.
|
|
return reinterpret_cast<_Tp*>(__cvta_shared_to_generic(__ptr));
|
|
}
|
|
|
|
template <typename _Tp>
|
|
inline _CCCL_DEVICE _Tp* __from_ptr_dsmem(_CUDA_VSTD::size_t __ptr)
|
|
{
|
|
// Consider adding debug asserts here.
|
|
return __from_ptr_smem<_Tp>(__ptr);
|
|
}
|
|
|
|
template <typename _Tp>
|
|
inline _CCCL_DEVICE _Tp* __from_ptr_remote_dsmem(_CUDA_VSTD::size_t __ptr)
|
|
{
|
|
// Consider adding debug asserts here.
|
|
return __from_ptr_smem<_Tp>(__ptr);
|
|
}
|
|
|
|
template <typename _Tp>
|
|
inline _CCCL_DEVICE _Tp* __from_ptr_gmem(_CUDA_VSTD::size_t __ptr)
|
|
{
|
|
// Consider adding debug asserts here.
|
|
return reinterpret_cast<_Tp*>(__cvta_global_to_generic(__ptr));
|
|
}
|
|
|
|
/*************************************************************
|
|
*
|
|
* Conversion from template type -> concrete binary type
|
|
*
|
|
**************************************************************/
|
|
template <typename _Tp>
|
|
inline _CCCL_DEVICE _CUDA_VSTD::uint32_t __as_b32(_Tp __val)
|
|
{
|
|
static_assert(sizeof(_Tp) == 4, "");
|
|
// Consider using std::bitcast
|
|
return *reinterpret_cast<_CUDA_VSTD::uint32_t*>(&__val);
|
|
}
|
|
|
|
template <typename _Tp>
|
|
inline _CCCL_DEVICE _CUDA_VSTD::uint64_t __as_b64(_Tp __val)
|
|
{
|
|
static_assert(sizeof(_Tp) == 8, "");
|
|
// Consider using std::bitcast
|
|
return *reinterpret_cast<_CUDA_VSTD::uint64_t*>(&__val);
|
|
}
|
|
|
|
/*************************************************************
|
|
*
|
|
* Conversion to and from b8 type
|
|
*
|
|
**************************************************************/
|
|
|
|
template <typename _B8>
|
|
inline _CCCL_DEVICE uint32_t __b8_as_u32(_B8 __val)
|
|
{
|
|
static_assert(sizeof(_B8) == 1);
|
|
_CUDA_VSTD::uint32_t __u32 = 0;
|
|
::memcpy(&__u32, &__val, 1);
|
|
return __u32;
|
|
}
|
|
|
|
template <typename _B8>
|
|
inline _CCCL_DEVICE _B8 __u32_as_b8(uint32_t __u32)
|
|
{
|
|
static_assert(sizeof(_B8) == 1);
|
|
_B8 b8;
|
|
::memcpy(&b8, &__u32, 1);
|
|
return b8;
|
|
}
|
|
|
|
_LIBCUDACXX_END_NAMESPACE_CUDA_PTX
|
|
|
|
#endif // _CCCL_HAS_CUDA_COMPILER()
|
|
|
|
#endif // _CUDA_PTX_HELPER_FUNCTIONS_H_
|