| 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-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
/// |
| 9 |
/// \file |
| 10 |
/// This file contains the implementation of helpers and non-template member |
| 11 |
/// 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 |
|
| 21 |
using namespace mathtest; |
| 22 |
|
| 23 |
//===----------------------------------------------------------------------===// |
| 24 |
// Helpers |
| 25 |
//===----------------------------------------------------------------------===// |
| 26 |
|
| 27 |
void detail::freeDeviceMemory(void *Address) noexcept { |
| 28 |
if (Address) |
| 29 |
OL_CHECK(olMemFree(Address)); |
| 30 |
} |
| 31 |
|
| 32 |
//===----------------------------------------------------------------------===// |
| 33 |
// DeviceImage |
| 34 |
//===----------------------------------------------------------------------===// |
| 35 |
|
| 36 |
DeviceImage::~DeviceImage() noexcept { |
| 37 |
if (Handle) |
| 38 |
OL_CHECK(olDestroyProgram(Handle)); |
| 39 |
} |
| 40 |
|
| 41 |
DeviceImage &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 |
|
| 57 |
DeviceImage::DeviceImage(DeviceImage &&Other) noexcept |
| 58 |
: DeviceHandle(Other.DeviceHandle), Handle(Other.Handle) { |
| 59 |
Other.DeviceHandle = nullptr; |
| 60 |
Other.Handle = nullptr; |
| 61 |
} |
| 62 |
|
| 63 |
DeviceImage::DeviceImage(ol_device_handle_t DeviceHandle, |
| 64 |
ol_program_handle_t Handle) noexcept |
| 65 |
: DeviceHandle(DeviceHandle), Handle(Handle) {} |