| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | #pragma once |
| | |
| | #include <functional> |
| | #include <memory> |
| | #include <type_traits> |
| |
|
| | #include "device_functions-generated.h" |
| | #include "macros.h" |
| |
|
| | namespace ait { |
| |
|
| | |
| | |
| | using GPUPtr = std::unique_ptr<void, std::function<void(void*)>>; |
| |
|
| | using StreamPtr = std:: |
| | unique_ptr<std::remove_pointer<StreamType>::type, decltype(&StreamDestroy)>; |
| |
|
| | using EventPtr = std:: |
| | unique_ptr<std::remove_pointer<EventType>::type, decltype(&DestroyEvent)>; |
| |
|
| | using GraphPtr = std::unique_ptr< |
| | std::remove_pointer<GraphType>::type, |
| | std::function<void(GraphType)>>; |
| |
|
| | inline GPUPtr RAII_DeviceMalloc( |
| | size_t num_bytes, |
| | AITemplateAllocator& allocator) { |
| | auto* output = allocator.Allocate(num_bytes); |
| | auto deleter = [&allocator](void* ptr) mutable { allocator.Free(ptr); }; |
| | return GPUPtr(output, deleter); |
| | } |
| |
|
| | inline StreamPtr RAII_StreamCreate(bool non_blocking = false) { |
| | StreamType stream; |
| | DEVICE_CHECK(StreamCreate(&stream, non_blocking)); |
| | return StreamPtr(stream, StreamDestroy); |
| | } |
| |
|
| | inline EventPtr RAII_CreateEvent() { |
| | EventType event; |
| | DEVICE_CHECK(CreateEvent(&event)); |
| | return EventPtr(event, DestroyEvent); |
| | } |
| |
|
| | inline GraphPtr RAII_EndCaptureAndCreateGraph( |
| | const std::function<DeviceError(GraphType*)>& end_capture_fn) { |
| | GraphType graph; |
| | |
| | |
| | |
| | |
| | |
| | DEVICE_CHECK(end_capture_fn(&graph)) |
| | return GraphPtr(graph, GraphDestroy); |
| | } |
| |
|
| | class RAII_ProfilerRange { |
| | public: |
| | RAII_ProfilerRange(char* name) { |
| | ProfilerRangePush(name); |
| | } |
| | ~RAII_ProfilerRange() { |
| | ProfilerRangePop(); |
| | } |
| |
|
| | RAII_ProfilerRange(const RAII_ProfilerRange&) = delete; |
| | RAII_ProfilerRange(RAII_ProfilerRange&&) = delete; |
| | }; |
| |
|
| | } |
| |
|