1 /*
2 * Copyright (c) 2017, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 #include "cm_device.h"
23 #include "cm_event_base.h"
24 #include "cm_queue_base_hw.h"
25 #include "cm_timer.h"
26
27 //!
28 //! \brief Destroys CM Device
29 //! \details Destroys the CM Device. Also destroys surfaces,
30 //! kernels, samplers and the queue that was created
31 //! using this device instance that haven't already been
32 //! explicitly destroyed by calling respective destroy functions.
33 //! \param [in] device
34 //! Reference to the pointer to the CmDevice to be destroyed
35 //! \retval CM_SUCCESS if device successfully destroyed
36 //! \retval CM_FAILURE if failed to destroy device
37 //!
38 extern "C"
DestroyCmDevice(CmDevice * & device)39 CM_RT_API int32_t DestroyCmDevice(CmDevice* &device)
40 {
41 INSERT_PROFILER_RECORD();
42
43 CmDevice_RT* p = static_cast<CmDevice_RT*>(device);
44 int32_t result = CmDevice_RT::Destroy(p);
45
46 if(result == CM_SUCCESS)
47 {
48 device = nullptr;
49 }
50
51 return result;
52 }
53
54 //!
55 //! \brief Enqueue a task
56 //! \details Enqueues a task represented by CmTask.
57 //! The kernels in the CmTask object may be run concurrently.
58 //! Each task can have up to CAP_KERNEL_COUNT_PER_TASK kernels.
59 //! Tasks are executed according to the order they
60 //! were enqueued. The next task will not start execution until
61 //! the current task finishes.
62 //! This is a nonblocking call. i.e. it returns immediately
63 //! without waiting for GPU to start or finish execution of the
64 //! task. A CmEvent is generated each time a task is enqueued.
65 //! The CmEvent can be used to check the status or other data
66 //! regarding the task execution. The generated event needs to
67 //! be managed and released by the user.
68 //! To avoid generating an event, the user can set the event
69 //! as CM_NO_EVENT and pass it to this function.
70 //! \param [in] queue
71 //! Pointer to the CmQueue
72 //! \param [in] task
73 //! Pointer to the CmTask
74 //! \param [out] event
75 //! Reference to the pointer for the CmEvent to be created
76 //! \param [in] threadSpace
77 //! Pointer to the thread space
78 //! \retval CM_SUCCESS if task successfully enqueued
79 //! \retval CM_OUT_OF_HOST_MEMORY if out of host memory
80 //! \retval CM_FAILURE otherwise
81 //!
CMRT_Enqueue(CmQueue * queue,CmTask * task,CmEvent ** event,const CmThreadSpace * threadSpace=nullptr)82 EXTERN_C CM_RT_API int32_t CMRT_Enqueue(CmQueue* queue, CmTask* task, CmEvent** event, const CmThreadSpace* threadSpace = nullptr)
83 {
84 INSERT_PROFILER_RECORD();
85
86 return queue->Enqueue(task, *event, threadSpace);
87 }
88
89