-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathallocator.cpp
More file actions
63 lines (56 loc) · 1.98 KB
/
Copy pathallocator.cpp
File metadata and controls
63 lines (56 loc) · 1.98 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
/*
* This file is part of AdaptiveCpp, an implementation of SYCL and C++ standard
* parallelism for CPUs and GPUs.
*
* Copyright The AdaptiveCpp Contributors
*
* AdaptiveCpp is released under the BSD 2-Clause "Simplified" License.
* See file LICENSE in the project root for full license details.
*/
// SPDX-License-Identifier: BSD-2-Clause
#include "hipSYCL/runtime/allocator.hpp"
#include "hipSYCL/runtime/allocation_tracker.hpp"
#include "hipSYCL/runtime/application.hpp"
#include "hipSYCL/runtime/hints.hpp"
#include "hipSYCL/runtime/runtime_event_handlers.hpp"
namespace hipsycl {
namespace rt {
void *allocate_device(backend_allocator *alloc, size_t min_alignment,
size_t size_bytes, const allocation_hints &hints) {
auto *ptr = alloc->raw_allocate(min_alignment, size_bytes, hints);
if(ptr) {
application::event_handler_layer().on_new_allocation(
ptr, size_bytes,
allocation_info{alloc->get_device(),
allocation_info::allocation_type::device});
}
return ptr;
}
void *allocate_host(backend_allocator *alloc, size_t min_alignment,
size_t bytes, const allocation_hints &hints) {
auto* ptr = alloc->raw_allocate_optimized_host(min_alignment, bytes, hints);
if(ptr) {
application::event_handler_layer().on_new_allocation(
ptr, bytes,
allocation_info{alloc->get_device(),
allocation_info::allocation_type::host});
}
return ptr;
}
void *allocate_shared(backend_allocator *alloc, size_t bytes,
const allocation_hints &hints) {
auto* ptr = alloc->raw_allocate_usm(bytes, hints);
if(ptr) {
application::event_handler_layer().on_new_allocation(
ptr, bytes,
allocation_info{alloc->get_device(),
allocation_info::allocation_type::host});
}
return ptr;
}
void deallocate(backend_allocator* alloc, void *mem) {
alloc->raw_free(mem);
application::event_handler_layer().on_deallocation(mem);
}
}
}