brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · d3f5cfe Raw
88 lines · cpp
1//===-- lib/cuda/pointer.cpp ------------------------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "flang/Runtime/CUDA/pointer.h"10#include "flang-rt/runtime/assign-impl.h"11#include "flang-rt/runtime/descriptor.h"12#include "flang-rt/runtime/stat.h"13#include "flang-rt/runtime/terminator.h"14#include "flang/Runtime/CUDA/descriptor.h"15#include "flang/Runtime/CUDA/memmove-function.h"16#include "flang/Runtime/pointer.h"17 18#include "cuda_runtime.h"19 20namespace Fortran::runtime::cuda {21 22extern "C" {23RT_EXT_API_GROUP_BEGIN24 25int RTDEF(CUFPointerAllocate)(Descriptor &desc, int64_t *stream, bool *pinned,26    bool hasStat, const Descriptor *errMsg, const char *sourceFile,27    int sourceLine) {28  // Perform the standard allocation.29  int stat{30      RTNAME(PointerAllocate)(desc, hasStat, errMsg, sourceFile, sourceLine)};31  if (pinned) {32    // Set pinned according to stat. More infrastructre is needed to set it33    // closer to the actual allocation call.34    *pinned = (stat == StatOk);35  }36  return stat;37}38 39int RTDEF(CUFPointerAllocateSync)(Descriptor &desc, int64_t *stream,40    bool *pinned, bool hasStat, const Descriptor *errMsg,41    const char *sourceFile, int sourceLine) {42  int stat{RTNAME(CUFPointerAllocate)(43      desc, stream, pinned, hasStat, errMsg, sourceFile, sourceLine)};44#ifndef RT_DEVICE_COMPILATION45  // Descriptor synchronization is only done when the allocation is done46  // from the host.47  if (stat == StatOk) {48    void *deviceAddr{49        RTNAME(CUFGetDeviceAddress)((void *)&desc, sourceFile, sourceLine)};50    RTNAME(CUFDescriptorSync)51    ((Descriptor *)deviceAddr, &desc, sourceFile, sourceLine);52  }53#endif54  return stat;55}56 57int RTDEF(CUFPointerAllocateSource)(Descriptor &pointer,58    const Descriptor &source, int64_t *stream, bool *pinned, bool hasStat,59    const Descriptor *errMsg, const char *sourceFile, int sourceLine) {60  int stat{RTNAME(CUFPointerAllocate)(61      pointer, stream, pinned, hasStat, errMsg, sourceFile, sourceLine)};62  if (stat == StatOk) {63    Terminator terminator{sourceFile, sourceLine};64    Fortran::runtime::DoFromSourceAssign(65        pointer, source, terminator, &MemmoveHostToDevice);66  }67  return stat;68}69 70int RTDEF(CUFPointerAllocateSourceSync)(Descriptor &pointer,71    const Descriptor &source, int64_t *stream, bool *pinned, bool hasStat,72    const Descriptor *errMsg, const char *sourceFile, int sourceLine) {73  int stat{RTNAME(CUFPointerAllocateSync)(74      pointer, stream, pinned, hasStat, errMsg, sourceFile, sourceLine)};75  if (stat == StatOk) {76    Terminator terminator{sourceFile, sourceLine};77    Fortran::runtime::DoFromSourceAssign(78        pointer, source, terminator, &MemmoveHostToDevice);79  }80  return stat;81}82 83RT_EXT_API_GROUP_END84 85} // extern "C"86 87} // namespace Fortran::runtime::cuda88