Files
project_6/cccl_upstream/thrust/thrust/device_malloc.h
EngineX CI 56fd68e7dd [INFRA] Import NVIDIA/CCCL upstream as optimization reference library
CCCL (CUDA C++ Core Libraries) provides:
- CUB: device/block/warp-level GPU primitives (reduce, scan, sort, topk)
- Thrust: high-level parallel algorithms (transform_reduce, sort, scan)
- libcudacxx: CUDA C++ standard library (atomics, barriers, memory)
- cudax: experimental features (memory resources, allocators)
- Tuning policies: per-SM hardware-specific algorithm parameters

Competition optimization vectors mapped to CCCL:
- Output TPS (83% weight): warp_reduce, block_reduce, device_topk
- Input TPS (14% weight): device_scan, block_load, prefetch
- Cache TPS (3% weight): prefix caching strategy patterns
- Memory (0.9 util): pooled/cached/buddy allocators

Source: https://github.com/NVIDIA/cccl (shallow clone, HEAD only)
License: Apache-2.0
2026-07-30 09:35:51 +00:00

72 lines
2.0 KiB
C++

// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
/*! \file
* \brief Allocates storage in device memory.
*/
#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/malloc_and_free.h>
#include <thrust/device_ptr.h>
#include <thrust/iterator/iterator_traits.h>
#include <cuda/std/cstddef>
THRUST_NAMESPACE_BEGIN
/*! \addtogroup memory_management Memory Management
* \{
*/
//! Allocates sequential device storage for new objects of a given type, or raw bytes if the type is \p void.
//!
//! \param n The number of objects of type T, or bytes, to allocate sequentially in device memory.
//! \return A \p device_ptr to the newly allocated memory.
//!
//! The following code snippet demonstrates how to use \p device_malloc to
//! allocate a range of device memory.
//!
//! \code
//! #include <thrust/device_malloc.h>
//! #include <thrust/device_free.h>
//! ...
//! // allocate some integers with device_malloc
//! const int N = 100;
//! thrust::device_ptr<int> int_array = thrust::device_malloc<int>(N);
//! thrust::device_ptr<void> raw_byte_array = thrust::device_malloc(N);
//!
//! // manipulate integers and bytes
//! ...
//!
//! // deallocate with device_free
//! thrust::device_free(raw_byte_array);
//! thrust::device_free(int_array);
//! \endcode
//!
//! \see device_ptr
//! \see device_free
template <typename T = void>
device_ptr<T> device_malloc(const std::size_t n)
{
// using system::detail::generic::select_system;
// XXX lower to select_system(system) here
iterator_system_t<device_ptr<void>> s;
return thrust::device_ptr<T>(thrust::malloc<T>(s, n).get());
}
/*! \} // memory_management
*/
THRUST_NAMESPACE_END