This commit is contained in:
REDMOND\jingf 2022-03-01 18:51:17 -08:00
Родитель d61c5a8095
Коммит d997ce498f
7 изменённых файлов: 49 добавлений и 32 удалений

Просмотреть файл

@ -40,8 +40,8 @@ void TryEnsurePIXFunctions()
}
// Intentionally leaked
HMODULE pixRuntime = LoadLibrary(dllPath.c_str());
HMODULE pixGPURuntime = LoadLibrary(L"C:\\Program Files\\Microsoft PIX\\2202.25-GpuTimingDataFix\\WinPixGpuCapturer.dll");
HMODULE pixRuntime = LoadLibrary(dllPath.c_str());
LoadPIXGpuCapturer();
if (pixRuntime != nullptr)
{
g_beginCaptureSingleton = (BeginCapture)GetProcAddress(pixRuntime, "PIXBeginCapture2");
@ -53,6 +53,39 @@ void TryEnsurePIXFunctions()
}
}
void GetSubdirs(std::vector<std::wstring>& output, const std::wstring& path)
{
WIN32_FIND_DATA findfiledata;
HANDLE hFind = INVALID_HANDLE_VALUE;
hFind = FindFirstFile((path + L"\\*").c_str(), &findfiledata);
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if ((findfiledata.dwFileAttributes | FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY
&& (findfiledata.cFileName[0] != '.'))
{
output.push_back(findfiledata.cFileName);
}
} while (FindNextFile(hFind, &findfiledata) != 0);
}
}
void LoadPIXGpuCapturer()
{
std::wstring dir = L"C:\\Program Files\\Microsoft PIX\\";
std::vector<std::wstring> subDirs;
GetSubdirs(subDirs, dir);
if (subDirs.size() == 0)
{
printf("Please install PIX for Windows before running this program. (https://devblogs.microsoft.com/pix/download/)\n");
exit(1);
}
dir += subDirs[0] + L"\\WinPixGpuCapturer.dll";
HMODULE pixGPURuntime = LoadLibrary(dir.c_str());
}
void PIXBeginEvent(ID3D12CommandQueue* commandQueue, UINT64 color, _In_ PCSTR string)
{
if (g_beginEventSingleton == nullptr)

Просмотреть файл

@ -23,6 +23,10 @@ static std::mutex g_mutex;
void TryEnsurePIXFunctions();
void GetSubdirs(std::vector<std::wstring>& output, const std::wstring& path);
void LoadPIXGpuCapturer();
void PIXBeginEvent(ID3D12CommandQueue* commandQueue, UINT64 color, _In_ PCSTR string);
void PIXEndEvent(ID3D12CommandQueue* commandQueue);

Просмотреть файл

@ -26,7 +26,7 @@ VideoFrame LoadImageFile(hstring filePath)
try
{
// open the file
StorageFile file = StorageFile::GetFileFromPathAsync(filePath).get();
StorageFile file = StorageFile::GetFileFromPathAsync(dir).get();
// get a stream on it
auto stream = file.OpenAsync(FileAccessMode::Read).get();
// Create the decoder from the stream

Просмотреть файл

@ -14,14 +14,14 @@ using namespace winrt::Windows::Storage;
using namespace std;
// Global variables
static hstring modelPath = L"C:\\WinMLPIXSample\\SqueezeNet.onnx";
static hstring modelPath = L".\\Assets\\SqueezeNet.onnx";
static string deviceName = "default";
static hstring imagePath = L"C:\\WinMLPIXSample\\kitten_224.png";
static hstring imagePath = L"\\Assets\\kitten_224.png";
static LearningModel model = nullptr;
static LearningModelSession session = nullptr;
static LearningModelBinding binding = nullptr;
static VideoFrame imageFrame = nullptr;
static string labelsFilePath = "C:\\WinMLPIXSample\\Labels.txt";
static string labelsFilePath = ".\\Assets\\Labels.txt";
static vector<string> labels;
// Forward declarations

Просмотреть файл

@ -75,7 +75,7 @@ void GetD3D12CommandAssets()
m_d3d12Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&m_fence));
}
void LoadAndEvaluate(ID3D12CommandQueue* commandQueue, ID3D12CommandList* commandList, ID3D12Fence* m_fence)
void LoadAndEvaluate(ID3D12CommandQueue* commandQueue)
{
// Setting markers for each step, these markers will split the commands into sections for easier debugging
PIXSetMarker(commandQueue, 0, "Start loading model...");
@ -109,7 +109,7 @@ void CaptureWithUserSetMarker()
PIXBeginEvent(m_commandQueue, 0, "WinMLPIXSample");
// Do the ML computation
LoadAndEvaluate(m_commandQueue, m_commandList, m_fence);
LoadAndEvaluate(m_commandQueue);
// End PIX event
PIXEndEvent(m_commandQueue);

Просмотреть файл

@ -3,5 +3,5 @@
<package id="Microsoft.AI.DirectML" version="1.8.0" targetFramework="native" />
<package id="Microsoft.AI.MachineLearning" version="1.10.0" targetFramework="native" />
<package id="Microsoft.Windows.CppWinRT" version="2.0.220131.2" targetFramework="native" />
<package id="WinPixEventRuntime" version="1.0.220301001" targetFramework="native" />
<package id="WinPixEventRuntime" version="1.0.220124001" targetFramework="native" />
</packages>

Просмотреть файл

@ -2,29 +2,9 @@
C++/WinRT WinMLPIXSample Project Overview
========================================================================
This project demonstrates how to get started consuming Windows Runtime
classes directly from standard C++, using platform projection headers
generated from Windows SDK metadata files.
Steps to generate and consume SDK platform projection:
1. Build project initially to generate platform projection headers into
your Generated Files folder.
2. Include a projection namespace header in your pch.h, such as
<winrt/Windows.Foundation.h>.
3. Consume winrt namespace and any Windows Runtime namespaces, such as
winrt::Windows::Foundation, from source code.
4. Initialize apartment via init_apartment() and consume winrt classes.
Steps to generate and consume a projection from third party metadata:
1. Add a WinMD reference by right-clicking the References project node
and selecting "Add Reference...". In the Add References dialog,
browse to the component WinMD you want to consume and add it.
2. Build the project once to generate projection headers for the
referenced WinMD file under the "Generated Files" subfolder.
3. As above, include projection headers in pch or source code
to consume projected Windows Runtime classes.
This project demonstrates how to get started using PIX for windows to do
GPU captures as well as setting markers programmatically
========================================================================
Learn more about C++/WinRT here:
http://aka.ms/cppwinrt/
========================================================================