Skip to content

Commit 6112e73

Browse files
committed
[DML] Enable GPU memory trace dumps.
Adds `webnn_enable_resource_dump = true` to create a trace dump. Then open the dump in chrome://tracing to analyze GPU memory usage.
1 parent 27071c7 commit 6112e73

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

build_overrides/webnn_features.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ declare_args() {
4040

4141
webnn_enable_wire = false
4242
webnn_enable_gpu_buffer = false
43+
webnn_enable_resource_dump = false
4344
}

src/webnn/native/BUILD.gn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ source_set("sources") {
247247
if (build_with_chromium == false) {
248248
include_dirs += [ "${webnn_root}/third_party/DirectML/Libraries" ]
249249
}
250+
251+
if (webnn_enable_resource_dump) {
252+
defines = [ "WEBNN_ENABLE_RESOURCE_DUMP" ]
253+
}
250254
}
251255

252256
if (webnn_enable_dml || webnn_enable_dmlx) {

src/webnn/native/dmlx/deps/src/device.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ HRESULT Device::Init()
112112
allocatorDesc.Device = m_d3d12Device;
113113
allocatorDesc.IsUMA = arch.UMA;
114114
allocatorDesc.ResourceHeapTier = options.ResourceHeapTier;
115+
116+
#ifdef WEBNN_ENABLE_RESOURCE_DUMP
117+
allocatorDesc.RecordOptions.Flags |= gpgmm::d3d12::ALLOCATOR_RECORD_FLAG_ALL_EVENTS;
118+
allocatorDesc.RecordOptions.MinMessageLevel = D3D12_MESSAGE_SEVERITY_MESSAGE;
119+
allocatorDesc.RecordOptions.UseDetailedTimingEvents = true;
120+
#endif
121+
115122
ReturnIfFailed(gpgmm::d3d12::ResourceAllocator::CreateAllocator(allocatorDesc, &m_resourceAllocator, &m_residencyManager));
116123

117124
D3D12_DESCRIPTOR_HEAP_DESC descriptorHeapDesc = {};

0 commit comments

Comments
 (0)