Skip to content

Commit 1477d5a

Browse files
committed
[SYCL][Graph] async_malloc use allocation size for zeVirtualMemQueryPageSize
1 parent e3d10c8 commit 1477d5a

File tree

26 files changed

+165
-83
lines changed

26 files changed

+165
-83
lines changed

sycl/cmake/modules/FetchUnifiedRuntime.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ set(UR_BUILD_TESTS "${SYCL_UR_BUILD_TESTS}" CACHE BOOL "" FORCE)
2828
# UR tests require the examples to be built
2929
set(UR_BUILD_EXAMPLES "${SYCL_UR_BUILD_TESTS}" CACHE BOOL "" FORCE)
3030

31+
option(SYCL_UR_FORMAT_CPP_STYLE "Format code style of UR C++ sources" OFF)
32+
set(UR_FORMAT_CPP_STYLE "${SYCL_UR_FORMAT_CPP_STYLE}" CACHE BOOL "" FORCE)
33+
3134
# Here we override the defaults to unified-runtime
3235
set(UR_BUILD_XPTI_LIBS OFF CACHE BOOL "")
3336
set(UR_ENABLE_SYMBOLIZER ON CACHE BOOL "Enable symbolizer for sanitizer layer.")

sycl/source/detail/graph/memory_pool.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "memory_pool.hpp"
10+
#include "detail/virtual_mem.hpp"
1011
#include "graph_impl.hpp"
1112

1213
#include <optional>
@@ -42,7 +43,8 @@ void *graph_mem_pool::malloc(size_t Size, usm::alloc AllocType,
4243
context_impl &CtxImpl = *getSyclObjImpl(MContext);
4344
adapter_impl &Adapter = CtxImpl.getAdapter();
4445

45-
size_t Granularity = get_mem_granularity(MDevice, MContext);
46+
const size_t Granularity = get_mem_granularity_for_allocation_size(
47+
MDevice, MContext, granularity_mode::recommended, Size);
4648
uintptr_t StartPtr = 0;
4749
size_t AlignedSize = alignByteSize(Size, Granularity);
4850
// See if we can find an allocation to reuse

sycl/source/detail/graph/memory_pool.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <detail/physical_mem_impl.hpp> // For physical_mem_impl
1313
#include <sycl/context.hpp> // For context
1414
#include <sycl/device.hpp> // For device
15-
#include <sycl/ext/oneapi/virtual_mem/virtual_mem.hpp> // For get_mem_granularity
15+
#include <sycl/ext/oneapi/virtual_mem/virtual_mem.hpp> // For unmap
1616

1717
namespace sycl {
1818
inline namespace _V1 {

sycl/source/detail/virtual_mem.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//==---------------- virtual_mem.hpp ---------------------------------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include <sycl/ext/oneapi/virtual_mem/virtual_mem.hpp>
12+
13+
namespace sycl {
14+
inline namespace _V1 {
15+
namespace ext::oneapi::experimental {
16+
17+
size_t get_mem_granularity_for_allocation_size(const device &SyclDevice,
18+
const context &SyclContext,
19+
granularity_mode Mode,
20+
size_t AllocationSize);
21+
22+
} // namespace ext::oneapi::experimental
23+
} // namespace _V1
24+
} // namespace sycl

sycl/source/virtual_mem.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <detail/context_impl.hpp>
1010
#include <detail/device_impl.hpp>
1111
#include <detail/physical_mem_impl.hpp>
12-
#include <sycl/ext/oneapi/virtual_mem/virtual_mem.hpp>
12+
#include <detail/virtual_mem.hpp>
1313

1414
// System headers for querying page-size.
1515
#ifdef _WIN32
@@ -22,9 +22,10 @@ namespace sycl {
2222
inline namespace _V1 {
2323
namespace ext::oneapi::experimental {
2424

25-
__SYCL_EXPORT size_t get_mem_granularity(const device &SyclDevice,
26-
const context &SyclContext,
27-
granularity_mode Mode) {
25+
size_t get_mem_granularity_for_allocation_size(const device &SyclDevice,
26+
const context &SyclContext,
27+
granularity_mode Mode,
28+
const size_t AllocationSize) {
2829
if (!SyclDevice.has(aspect::ext_oneapi_virtual_mem))
2930
throw sycl::exception(
3031
sycl::make_error_code(sycl::errc::feature_not_supported),
@@ -45,20 +46,29 @@ __SYCL_EXPORT size_t get_mem_granularity(const device &SyclDevice,
4546
#ifndef NDEBUG
4647
size_t InfoOutputSize = 0;
4748
Adapter->call<sycl::detail::UrApiKind::urVirtualMemGranularityGetInfo>(
48-
urCtx, urDevice, GranularityQuery, 0u, nullptr, &InfoOutputSize);
49+
urCtx, urDevice, AllocationSize, GranularityQuery, 0u, nullptr,
50+
&InfoOutputSize);
4951
assert(InfoOutputSize == sizeof(size_t) &&
5052
"Unexpected output size of granularity info query.");
5153
#endif // NDEBUG
5254
size_t Granularity = 0;
5355
Adapter->call<sycl::detail::UrApiKind::urVirtualMemGranularityGetInfo>(
54-
urCtx, urDevice, GranularityQuery, sizeof(size_t), &Granularity, nullptr);
56+
urCtx, urDevice, AllocationSize, GranularityQuery, sizeof(size_t),
57+
&Granularity, nullptr);
5558
if (Granularity == 0)
5659
throw sycl::exception(
5760
sycl::make_error_code(sycl::errc::invalid),
5861
"Unexpected granularity result: memory granularity shouldn't be 0.");
5962
return Granularity;
6063
}
6164

65+
__SYCL_EXPORT size_t get_mem_granularity(const device &SyclDevice,
66+
const context &SyclContext,
67+
granularity_mode Mode) {
68+
return get_mem_granularity_for_allocation_size(SyclDevice, SyclContext, Mode,
69+
1);
70+
}
71+
6272
__SYCL_EXPORT size_t get_mem_granularity(const context &SyclContext,
6373
granularity_mode Mode) {
6474
const std::vector<device> Devices = SyclContext.get_devices();

sycl/test-e2e/Graph/AsyncAlloc/Inputs/async_alloc_different_sizes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ int main() {
3030
asyncAllocWorksWithSize(131);
3131
asyncAllocWorksWithSize(10071);
3232
asyncAllocWorksWithSize(1007177);
33-
// asyncAllocWorksWithSize(191439360); // BUG
33+
asyncAllocWorksWithSize(191439360);
3434
}

unified-runtime/include/ur_api.h

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unified-runtime/include/ur_ddi.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unified-runtime/include/ur_print.hpp

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unified-runtime/scripts/core/virtual_memory.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ params:
4141
[in][optional] is the device to get the granularity from, if the
4242
device is null then the granularity is suitable for all devices in
4343
context.
44+
- type: size_t
45+
name: allocationSize
46+
desc: "[in] size in bytes of allocation size which granurality we search for."
4447
- type: $x_virtual_mem_granularity_info_t
4548
name: propName
4649
desc: "[in] type of the info to query."

0 commit comments

Comments
 (0)