-
Notifications
You must be signed in to change notification settings - Fork 548
Expand file tree
/
Copy pathEvent.hpp
More file actions
68 lines (52 loc) · 1.8 KB
/
Event.hpp
File metadata and controls
68 lines (52 loc) · 1.8 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
/*******************************************************
* 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
********************************************************/
#pragma once
#include <common/EventBase.hpp>
#include <cuda.h>
#include <cuda_runtime_api.h>
#include <af/event.h>
namespace arrayfire {
namespace cuda {
class CUDARuntimeEventPolicy {
public:
using EventType = CUevent;
using QueueType = CUstream;
using ErrorType = CUresult;
static ErrorType createAndMarkEvent(CUevent *e) noexcept {
// Creating events with the CU_EVENT_BLOCKING_SYNC flag
// severly impacts the speed if/when creating many arrays
auto err = cuEventCreate(e, CU_EVENT_DISABLE_TIMING);
return err;
}
static ErrorType markEvent(CUevent *e, QueueType &stream) noexcept {
auto err = cuEventRecord(*e, stream);
return err;
}
static ErrorType waitForEvent(CUevent *e, QueueType &stream) noexcept {
auto err = cuStreamWaitEvent(stream, *e, 0);
return err;
}
static ErrorType syncForEvent(CUevent *e) noexcept {
return cuEventSynchronize(*e);
}
static ErrorType destroyEvent(CUevent *e) noexcept {
auto err = cuEventDestroy(*e);
return err;
}
};
using Event = common::EventBase<CUDARuntimeEventPolicy>;
/// \brief Creates a new event and marks it in the stream
Event makeEvent(cudaStream_t queue);
af_event createEvent();
void markEventOnActiveQueue(af_event eventHandle);
void enqueueWaitOnActiveQueue(af_event eventHandle);
void block(af_event eventHandle);
af_event createAndMarkEvent();
} // namespace cuda
} // namespace arrayfire