Files
project_6/cccl_upstream/thrust/testing/device_delete.cu
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

92 lines
2.2 KiB
Plaintext

#include <thrust/device_delete.h>
#include <thrust/device_new.h>
#include <thrust/device_ptr.h>
#include <thrust/device_vector.h>
#include <nv/target>
#include <unittest/unittest.h>
struct Foo
{
Foo() = default;
Foo(const Foo&) = delete;
Foo& operator=(const Foo&) = delete;
_CCCL_DEVICE ~Foo()
{
if (destroyed != nullptr)
{
*destroyed = true;
}
}
bool* destroyed = nullptr;
};
void TestDeviceDeleteDestructorInvocation()
{
thrust::device_ptr<Foo> foo_ptr = thrust::device_new<Foo>();
thrust::device_vector<bool> destructor_flag(1, false);
*thrust::device_ptr<bool*>(&foo_ptr.get()->destroyed) = destructor_flag.data().get();
ASSERT_EQUAL(false, destructor_flag[0]);
thrust::device_delete(foo_ptr);
ASSERT_EQUAL(true, destructor_flag[0]);
}
DECLARE_UNITTEST(TestDeviceDeleteDestructorInvocation);
// based on: https://github.com/NVIDIA/cccl/issues/6132
struct base
{
_CCCL_HOST_DEVICE virtual ~base()
{
if (base_destroyed != nullptr)
{
*base_destroyed = true;
}
}
// Thrust does not support abstract class types inside vectors, so f() has a body instead of being abstract
_CCCL_HOST_DEVICE virtual void f() {}
bool* base_destroyed = nullptr;
};
struct derived : base
{
_CCCL_HOST_DEVICE ~derived() override
{
if (derived_destroyed != nullptr)
{
*derived_destroyed = true;
}
}
_CCCL_HOST_DEVICE void f() override {}
bool* derived_destroyed = nullptr;
};
void TestDeviceDeleteVirtualDestructorInvocation()
{
{
thrust::device_ptr<derived> ptr = thrust::device_new<derived>();
thrust::device_vector<bool> destructor_flags(2, false);
*thrust::device_ptr<bool*>(&ptr.get()->base_destroyed) = destructor_flags.data().get() + 0;
*thrust::device_ptr<bool*>(&ptr.get()->derived_destroyed) = destructor_flags.data().get() + 1;
thrust::device_ptr<derived> base_ptr = ptr;
ASSERT_EQUAL(false, destructor_flags[0]);
ASSERT_EQUAL(false, destructor_flags[1]);
thrust::device_delete(base_ptr); // delete through the base pointer
ASSERT_EQUAL(true, destructor_flags[0]);
ASSERT_EQUAL(true, destructor_flags[1]);
}
}
DECLARE_UNITTEST(TestDeviceDeleteVirtualDestructorInvocation);