-
Notifications
You must be signed in to change notification settings - Fork 555
Expand file tree
/
Copy pathEvent.cpp
More file actions
73 lines (63 loc) · 2.03 KB
/
Copy pathEvent.cpp
File metadata and controls
73 lines (63 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*******************************************************
* Copyright (c) 2019, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <Event.hpp>
#include <common/err_common.hpp>
#include <cuda_runtime_api.h>
#include <events.hpp>
#include <platform.hpp>
#include <af/event.h>
#include <memory>
namespace arrayfire {
namespace cuda {
/// \brief Creates a new event and marks it in the queue
Event makeEvent(cudaStream_t queue) {
Event e;
if (e.create() == CUDA_SUCCESS) { e.mark(queue); }
return e;
}
af_event createEvent() {
// Default CUDA stream needs to be initialized to use the CUDA driver
// Ctx
getActiveStream();
auto e = std::make_unique<Event>();
if (e->create() != CUDA_SUCCESS) {
AF_ERROR("Could not create event", AF_ERR_RUNTIME);
}
return getHandle(*(e.release()));
}
void markEventOnActiveQueue(af_event eventHandle) {
Event& event = getEvent(eventHandle);
// Use the currently-active stream
cudaStream_t stream = getActiveStream();
if (event.mark(stream) != CUDA_SUCCESS) {
AF_ERROR("Could not mark event on active stream", AF_ERR_RUNTIME);
}
}
void enqueueWaitOnActiveQueue(af_event eventHandle) {
Event& event = getEvent(eventHandle);
// Use the currently-active stream
cudaStream_t stream = getActiveStream();
if (event.enqueueWait(stream) != CUDA_SUCCESS) {
AF_ERROR("Could not enqueue wait on active stream for event",
AF_ERR_RUNTIME);
}
}
void block(af_event eventHandle) {
Event& event = getEvent(eventHandle);
if (event.block() != CUDA_SUCCESS) {
AF_ERROR("Could not block on active stream for event", AF_ERR_RUNTIME);
}
}
af_event createAndMarkEvent() {
af_event handle = createEvent();
markEventOnActiveQueue(handle);
return handle;
}
} // namespace cuda
} // namespace arrayfire