[flang][cuda][NFC] Move set/get default stream to its own file (#181927)

This commit is contained in:
Valentin Clement (バレンタイン クレメン) 2026-02-17 14:43:38 -08:00 committed by GitHub
parent 61616f2d59
commit 786b3b4741
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 65 additions and 13 deletions

View File

@ -16,6 +16,7 @@ add_flangrt_library(flang_rt.cuda STATIC SHARED
memory.cpp
pointer.cpp
registration.cpp
stream.cpp
TARGET_PROPERTIES
# libflang_rt.runtime depends on a certain version of CUDA. To be able to have

View File

@ -21,8 +21,6 @@
namespace Fortran::runtime::cuda {
static thread_local cudaStream_t defaultStream{nullptr};
struct DeviceAllocation {
void *ptr;
std::size_t size;
@ -155,13 +153,6 @@ int RTDECL(CUFSetAssociatedStream)(void *p, cudaStream_t stream) {
}
return StatOk;
}
int RTDECL(CUFSetDefaultStream)(cudaStream_t stream) {
defaultStream = stream;
return StatOk;
}
cudaStream_t RTDECL(CUFGetDefaultStream)() { return defaultStream; }
}
void *CUFAllocPinned(

View File

@ -0,0 +1,34 @@
//===-- lib/cuda/stream.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 "flang/Runtime/CUDA/stream.h"
#include "flang-rt/runtime/allocator-registry.h"
#include "flang-rt/runtime/derived.h"
#include "flang-rt/runtime/descriptor.h"
#include "flang-rt/runtime/environment.h"
#include "flang-rt/runtime/lock.h"
#include "flang-rt/runtime/stat.h"
#include "flang-rt/runtime/terminator.h"
#include "flang/Runtime/CUDA/common.h"
#include "flang/Support/Fortran.h"
namespace Fortran::runtime::cuda {
static thread_local cudaStream_t defaultStream{nullptr};
extern "C" {
int RTDECL(CUFSetDefaultStream)(cudaStream_t stream) {
defaultStream = stream;
return StatOk;
}
cudaStream_t RTDECL(CUFGetDefaultStream)() { return defaultStream; }
}
} // namespace Fortran::runtime::cuda

View File

@ -16,6 +16,7 @@
#include "flang/Runtime/CUDA/allocator.h"
#include "flang/Runtime/CUDA/common.h"
#include "flang/Runtime/CUDA/descriptor.h"
#include "flang/Runtime/CUDA/stream.h"
#include "flang/Support/Fortran.h"
using namespace Fortran::runtime;

View File

@ -9,6 +9,7 @@
#include "cuda_runtime.h"
#include "gtest/gtest.h"
#include "flang/Runtime/CUDA/allocator.h"
#include "flang/Runtime/CUDA/stream.h"
using namespace Fortran::runtime;
using namespace Fortran::runtime::cuda;

View File

@ -18,12 +18,9 @@
namespace Fortran::runtime::cuda {
extern "C" {
void RTDECL(CUFRegisterAllocator)();
cudaStream_t RTDECL(CUFGetAssociatedStream)(void *);
int RTDECL(CUFSetAssociatedStream)(void *, cudaStream_t);
int RTDECL(CUFSetDefaultStream)(cudaStream_t);
cudaStream_t RTDECL(CUFGetDefaultStream)();
void RTDECL(CUFRegisterAllocator)();
}
void *CUFAllocPinned(std::size_t, std::int64_t *);

View File

@ -0,0 +1,27 @@
//===-- include/flang/Runtime/CUDA/stream.h ---------------------*- 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
//
//===----------------------------------------------------------------------===//
#ifndef FORTRAN_RUNTIME_CUDA_STREAM_H_
#define FORTRAN_RUNTIME_CUDA_STREAM_H_
#include "common.h"
#include "flang/Runtime/descriptor-consts.h"
#include "flang/Runtime/entry-names.h"
#include "cuda_runtime.h"
namespace Fortran::runtime::cuda {
extern "C" {
int RTDECL(CUFSetDefaultStream)(cudaStream_t);
cudaStream_t RTDECL(CUFGetDefaultStream)();
}
} // namespace Fortran::runtime::cuda
#endif // FORTRAN_RUNTIME_CUDA_STREAM_H_