Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/gpgmm/common/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ namespace gpgmm {
return output.str();
}

template <typename T, typename... Args>
std::string ToString(T object, Args... args) {
return ToString(object) + ToString(args...);
}

} // namespace gpgmm

#endif // GPGMM_COMMON_UTILS_H_
32 changes: 27 additions & 5 deletions src/gpgmm/d3d12/ResidencyManagerD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ namespace gpgmm { namespace d3d12 {
static constexpr uint32_t kDefaultEvictLimit = 50ll * 1024ll * 1024ll; // 50MB
static constexpr float kDefaultVideoMemoryBudget = 0.95f; // 95%

namespace {
const char* GetMemorySegmentGroupName(const DXGI_MEMORY_SEGMENT_GROUP& memorySegmentGroup) {
switch (memorySegmentGroup) {
case DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL:
return "NonLocal";
case DXGI_MEMORY_SEGMENT_GROUP_LOCAL:
return "Local";
default:
UNREACHABLE();
return "";
}
}
} // namespace

GPGMM_UNUSED_FUNC(GetMemorySegmentGroupName);

// static
HRESULT ResidencyManager::CreateResidencyManager(ComPtr<ID3D12Device> device,
ComPtr<IDXGIAdapter> adapter,
Expand Down Expand Up @@ -273,11 +289,17 @@ namespace gpgmm { namespace d3d12 {
mVideoMemoryBudget);
}

TRACE_COUNTER1(TraceEventCategory::Default, "GPU memory budget (MB)",
videoMemoryInfo->Budget / 1e6);

TRACE_COUNTER1(TraceEventCategory::Default, "GPU memory usage (MB)",
videoMemoryInfo->CurrentUsage / 1e6);
TRACE_COUNTER1(
TraceEventCategory::Default,
ToString("GPU memory (", GetMemorySegmentGroupName(memorySegmentGroup), ") budget (MB)")
.c_str(),
videoMemoryInfo->Budget / 1e6);

TRACE_COUNTER1(
TraceEventCategory::Default,
ToString("GPU memory (", GetMemorySegmentGroupName(memorySegmentGroup), ") usage (MB)")
.c_str(),
videoMemoryInfo->CurrentUsage / 1e6);

return S_OK;
}
Expand Down
1 change: 1 addition & 0 deletions src/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ test("gpgmm_unittests") {
"unittests/SegmentedMemoryAllocatorTests.cpp",
"unittests/SlabBlockAllocatorTests.cpp",
"unittests/SlabMemoryAllocatorTests.cpp",
"unittests/UtilsTest.cpp",
]

# When building inside Chromium, use their gtest main function because it is
Expand Down
23 changes: 23 additions & 0 deletions src/tests/unittests/UtilsTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2021 The GPGMM Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <gtest/gtest.h>

#include "gpgmm/common/Utils.h"

using namespace gpgmm;

TEST(UtilsTest, ConcatString) {
EXPECT_TRUE(ToString("This ", "is ", "a ", "sentance") == std::string("This is a sentance"));
}