brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · d1c7b90 Raw
66 lines · cpp
1//===----------------------------------------------------------------------===//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/// \file10/// This file contains the implementation of helpers and non-template member11/// functions for the device resource classes.12///13//===----------------------------------------------------------------------===//14 15#include "mathtest/DeviceResources.hpp"16 17#include "mathtest/ErrorHandling.hpp"18 19#include <OffloadAPI.h>20 21using namespace mathtest;22 23//===----------------------------------------------------------------------===//24// Helpers25//===----------------------------------------------------------------------===//26 27void detail::freeDeviceMemory(void *Address) noexcept {28  if (Address)29    OL_CHECK(olMemFree(Address));30}31 32//===----------------------------------------------------------------------===//33// DeviceImage34//===----------------------------------------------------------------------===//35 36DeviceImage::~DeviceImage() noexcept {37  if (Handle)38    OL_CHECK(olDestroyProgram(Handle));39}40 41DeviceImage &DeviceImage::operator=(DeviceImage &&Other) noexcept {42  if (this == &Other)43    return *this;44 45  if (Handle)46    OL_CHECK(olDestroyProgram(Handle));47 48  DeviceHandle = Other.DeviceHandle;49  Handle = Other.Handle;50 51  Other.DeviceHandle = nullptr;52  Other.Handle = nullptr;53 54  return *this;55}56 57DeviceImage::DeviceImage(DeviceImage &&Other) noexcept58    : DeviceHandle(Other.DeviceHandle), Handle(Other.Handle) {59  Other.DeviceHandle = nullptr;60  Other.Handle = nullptr;61}62 63DeviceImage::DeviceImage(ol_device_handle_t DeviceHandle,64                         ol_program_handle_t Handle) noexcept65    : DeviceHandle(DeviceHandle), Handle(Handle) {}66