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
75 lines
2.7 KiB
C++
75 lines
2.7 KiB
C++
//===-- unittests/Runtime/CUDA/AllocatorCUF.cpp -----------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "cuda_runtime.h"
|
|
#include "gtest/gtest.h"
|
|
#include "flang-rt/runtime/allocator-registry.h"
|
|
#include "flang-rt/runtime/descriptor.h"
|
|
#include "flang-rt/runtime/terminator.h"
|
|
#include "flang/Runtime/CUDA/allocator.h"
|
|
#include "flang/Runtime/CUDA/descriptor.h"
|
|
#include "flang/Runtime/allocatable.h"
|
|
#include "flang/Support/Fortran.h"
|
|
|
|
using namespace Fortran::runtime;
|
|
using namespace Fortran::runtime::cuda;
|
|
|
|
static OwningPtr<Descriptor> createAllocatable(
|
|
Fortran::common::TypeCategory tc, int kind, int rank = 1) {
|
|
return Descriptor::Create(TypeCode{tc, kind}, kind, nullptr, rank, nullptr,
|
|
CFI_attribute_allocatable);
|
|
}
|
|
|
|
TEST(AllocatableCUFTest, SimpleDeviceAllocate) {
|
|
using Fortran::common::TypeCategory;
|
|
RTNAME(CUFRegisterAllocator)();
|
|
// REAL(4), DEVICE, ALLOCATABLE :: a(:)
|
|
auto a{createAllocatable(TypeCategory::Real, 4)};
|
|
a->SetAllocIdx(kDeviceAllocatorPos);
|
|
EXPECT_EQ((int)kDeviceAllocatorPos, a->GetAllocIdx());
|
|
EXPECT_FALSE(a->HasAddendum());
|
|
RTNAME(AllocatableSetBounds)(*a, 0, 1, 10);
|
|
RTNAME(AllocatableAllocate)
|
|
(*a, /*asyncObject=*/nullptr, /*hasStat=*/false, /*errMsg=*/nullptr, __FILE__,
|
|
__LINE__);
|
|
EXPECT_TRUE(a->IsAllocated());
|
|
RTNAME(AllocatableDeallocate)
|
|
(*a, /*hasStat=*/false, /*errMsg=*/nullptr, __FILE__, __LINE__);
|
|
EXPECT_FALSE(a->IsAllocated());
|
|
}
|
|
|
|
TEST(AllocatableCUFTest, SimplePinnedAllocate) {
|
|
using Fortran::common::TypeCategory;
|
|
RTNAME(CUFRegisterAllocator)();
|
|
// INTEGER(4), PINNED, ALLOCATABLE :: a(:)
|
|
auto a{createAllocatable(TypeCategory::Integer, 4)};
|
|
EXPECT_FALSE(a->HasAddendum());
|
|
a->SetAllocIdx(kPinnedAllocatorPos);
|
|
EXPECT_EQ((int)kPinnedAllocatorPos, a->GetAllocIdx());
|
|
EXPECT_FALSE(a->HasAddendum());
|
|
RTNAME(AllocatableSetBounds)(*a, 0, 1, 10);
|
|
RTNAME(AllocatableAllocate)
|
|
(*a, /*asyncObject=*/nullptr, /*hasStat=*/false, /*errMsg=*/nullptr, __FILE__,
|
|
__LINE__);
|
|
EXPECT_TRUE(a->IsAllocated());
|
|
RTNAME(AllocatableDeallocate)
|
|
(*a, /*hasStat=*/false, /*errMsg=*/nullptr, __FILE__, __LINE__);
|
|
EXPECT_FALSE(a->IsAllocated());
|
|
}
|
|
|
|
TEST(AllocatableCUFTest, DescriptorAllocationTest) {
|
|
using Fortran::common::TypeCategory;
|
|
RTNAME(CUFRegisterAllocator)();
|
|
// REAL(4), DEVICE, ALLOCATABLE :: a(:)
|
|
auto a{createAllocatable(TypeCategory::Real, 4)};
|
|
Descriptor *desc = nullptr;
|
|
desc = RTNAME(CUFAllocDescriptor)(a->SizeInBytes());
|
|
EXPECT_TRUE(desc != nullptr);
|
|
RTNAME(CUFFreeDescriptor)(desc);
|
|
}
|