|
| 1 | +//===--------- async_alloc.cpp - CUDA Adapter -----------------------------===// |
| 2 | +// |
| 3 | +// Copyright (C) 2024 Intel Corporation |
| 4 | +// |
| 5 | +// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM |
| 6 | +// Exceptions. See LICENSE.TXT |
| 7 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 8 | +// |
| 9 | +//===----------------------------------------------------------------------===// |
| 10 | + |
| 11 | +#include <ur_api.h> |
| 12 | + |
| 13 | +#include "context.hpp" |
| 14 | +#include "enqueue.hpp" |
| 15 | +#include "event.hpp" |
| 16 | +#include "queue.hpp" |
| 17 | +#include "usm.hpp" |
| 18 | + |
| 19 | +UR_APIEXPORT ur_result_t urEnqueueUSMDeviceAllocExp( |
| 20 | + ur_queue_handle_t hQueue, ur_usm_pool_handle_t pPool, const size_t size, |
| 21 | + const ur_exp_async_usm_alloc_properties_t *, uint32_t numEventsInWaitList, |
| 22 | + const ur_event_handle_t *phEventWaitList, void **ppMem, |
| 23 | + ur_event_handle_t *phEvent) { |
| 24 | + try { |
| 25 | + std::unique_ptr<ur_event_handle_t_> RetImplEvent{nullptr}; |
| 26 | + |
| 27 | + ScopedContext Active(hQueue->getDevice()); |
| 28 | + uint32_t StreamToken; |
| 29 | + ur_stream_guard_ Guard; |
| 30 | + CUstream CuStream = hQueue->getNextComputeStream( |
| 31 | + numEventsInWaitList, phEventWaitList, Guard, &StreamToken); |
| 32 | + |
| 33 | + UR_CHECK_ERROR(enqueueEventsWait(hQueue, CuStream, numEventsInWaitList, |
| 34 | + phEventWaitList)); |
| 35 | + |
| 36 | + if (phEvent) { |
| 37 | + RetImplEvent = |
| 38 | + std::unique_ptr<ur_event_handle_t_>(ur_event_handle_t_::makeNative( |
| 39 | + UR_COMMAND_KERNEL_LAUNCH, hQueue, CuStream, StreamToken)); |
| 40 | + UR_CHECK_ERROR(RetImplEvent->start()); |
| 41 | + } |
| 42 | + |
| 43 | + if (pPool) { |
| 44 | + assert(pPool->usesCudaPool()); |
| 45 | + |
| 46 | + } else { |
| 47 | + UR_CHECK_ERROR(cuMemAllocAsync(reinterpret_cast<CUdeviceptr *>(ppMem), |
| 48 | + size, CuStream)); |
| 49 | + } |
| 50 | + |
| 51 | + if (phEvent) { |
| 52 | + UR_CHECK_ERROR(RetImplEvent->record()); |
| 53 | + *phEvent = RetImplEvent.release(); |
| 54 | + } |
| 55 | + |
| 56 | + } catch (ur_result_t Err) { |
| 57 | + return Err; |
| 58 | + } |
| 59 | + return UR_RESULT_SUCCESS; |
| 60 | +} |
| 61 | + |
| 62 | +UR_APIEXPORT ur_result_t urEnqueueUSMSharedAllocExp( |
| 63 | + ur_queue_handle_t, ur_usm_pool_handle_t, const size_t, |
| 64 | + const ur_exp_async_usm_alloc_properties_t *, uint32_t, |
| 65 | + const ur_event_handle_t *, void **, ur_event_handle_t *) { |
| 66 | + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 67 | +} |
| 68 | + |
| 69 | +UR_APIEXPORT ur_result_t urEnqueueUSMHostAllocExp( |
| 70 | + ur_queue_handle_t, ur_usm_pool_handle_t, const size_t, |
| 71 | + const ur_exp_async_usm_alloc_properties_t *, uint32_t, |
| 72 | + const ur_event_handle_t *, void **, ur_event_handle_t *) { |
| 73 | + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 74 | +} |
| 75 | + |
| 76 | +UR_APIEXPORT ur_result_t urEnqueueUSMFreeExp(ur_queue_handle_t, |
| 77 | + ur_usm_pool_handle_t, void *, |
| 78 | + uint32_t, |
| 79 | + const ur_event_handle_t *, |
| 80 | + ur_event_handle_t *) { |
| 81 | + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 82 | +} |
| 83 | +/* |
| 84 | +
|
| 85 | +UR_APIEXPORT ur_result_t urEnqueueUSMSharedAllocExp( |
| 86 | + ur_queue_handle_t hQueue, ur_usm_pool_handle_t pPool, const size_t size, |
| 87 | + const ur_exp_async_usm_alloc_properties_t *pProperties, |
| 88 | + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, |
| 89 | + void **ppMem, ur_event_handle_t *phEvent) { |
| 90 | + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 91 | +} |
| 92 | +
|
| 93 | +UR_APIEXPORT ur_result_t urEnqueueUSMHostAllocExp( |
| 94 | + ur_queue_handle_t hQueue, ur_usm_pool_handle_t pPool, const size_t size, |
| 95 | + const ur_exp_async_usm_alloc_properties_t *pProperties, |
| 96 | + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, |
| 97 | + void **ppMem, ur_event_handle_t *phEvent) { |
| 98 | + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 99 | +} |
| 100 | +
|
| 101 | +UR_APIEXPORT ur_result_t urEnqueueUSMFreeExp( |
| 102 | + ur_queue_handle_t hQueue, ur_usm_pool_handle_t pPool, void *pMem, |
| 103 | + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, |
| 104 | + ur_event_handle_t *phEvent) { |
| 105 | + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 106 | +} |
| 107 | +*/ |
0 commit comments