Skip to content

Commit 08d9eaa

Browse files
committed
Update
1 parent 9d85bcb commit 08d9eaa

File tree

9 files changed

+841
-260
lines changed

9 files changed

+841
-260
lines changed

DirectMLGraph.exe

14 KB
Binary file not shown.

MLGraph.xaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,38 @@
106106
<MenuBarItem Title="Adapter" x:Name="AdapterMenu">
107107
</MenuBarItem>
108108

109+
<MenuBarItem Title="Set" >
110+
<MenuFlyoutItem Text="Add new" Click="OnAddSet" >
111+
<MenuFlyoutItem.Icon>
112+
<FontIcon Glyph="&#xE710;"/>
113+
</MenuFlyoutItem.Icon>
114+
<MenuFlyoutItem.KeyboardAccelerators>
115+
<KeyboardAccelerator Key="N" Modifiers="Shift"/>
116+
</MenuFlyoutItem.KeyboardAccelerators>
117+
</MenuFlyoutItem>
118+
<MenuFlyoutSeparator/>
119+
<MenuFlyoutSubItem x:Name="EditSetSubmenu" Text="Switch to set" />
120+
<MenuFlyoutSubItem x:Name="DeleteSetSubmenu" Text="Remove set" />
121+
122+
</MenuBarItem>
123+
124+
125+
<MenuBarItem Title="Variable" >
126+
<MenuFlyoutItem Text="Add" Click="OnAddVariable" >
127+
<MenuFlyoutItem.Icon>
128+
<FontIcon Glyph="&#xE710;"/>
129+
</MenuFlyoutItem.Icon>
130+
<MenuFlyoutItem.KeyboardAccelerators>
131+
<KeyboardAccelerator Key="V" Modifiers="Shift"/>
132+
</MenuFlyoutItem.KeyboardAccelerators>
133+
</MenuFlyoutItem>
134+
<MenuFlyoutSeparator/>
135+
<MenuFlyoutSubItem x:Name="EditVariableSubmenu" Text="Edit variable" />
136+
<MenuFlyoutSubItem x:Name="DeleteVariableSubmenu" Text="Remove variable" />
137+
138+
</MenuBarItem>
139+
140+
109141
<MenuBarItem Title="Operator" >
110142
<MenuFlyoutItem Text="Add" Click="OnAddOp" >
111143
<MenuFlyoutItem.Icon>

MLGraph.xaml.cpp

Lines changed: 449 additions & 84 deletions
Large diffs are not rendered by default.

MLGraph.xaml.h

Lines changed: 142 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,69 @@ struct XLNODEBULLET
2222
std::vector<unsigned long long> g;
2323
};
2424

25+
struct VARIABLE
26+
{
27+
std::wstring n;
28+
std::wstring v;
29+
30+
void Ser(XML3::XMLElement& e)
31+
{
32+
e.vv("n").SetWideValue(n.c_str());
33+
e.vv("v").SetWideValue(v.c_str());
34+
}
35+
36+
void Unser(XML3::XMLElement& e)
37+
{
38+
n = e.vv("n").GetWideValue();
39+
v = e.vv("v").GetWideValue();
40+
}
41+
};
42+
2543
struct PARAM
2644
{
2745
std::wstring n;
28-
float v = 0;
29-
std::wstring string_param;
46+
std::wstring v;
47+
std::wstring save_v;
3048
float minv = std::numeric_limits<float>::min();
3149
float maxv = std::numeric_limits<float>::max();
3250
std::vector<std::wstring> list_names;
51+
52+
const wchar_t* w()
53+
{
54+
return v.c_str();
55+
}
56+
operator const wchar_t* ()
57+
{
58+
return w();
59+
}
60+
operator float()
61+
{
62+
return std::stof(v.c_str());
63+
}
64+
operator double()
65+
{
66+
return std::stod(v.c_str());
67+
}
68+
operator int()
69+
{
70+
return std::stoi(v.c_str());
71+
}
72+
operator unsigned int()
73+
{
74+
return std::stoul(v.c_str());
75+
}
76+
operator bool()
77+
{
78+
return std::stoi(v.c_str()) == 1;
79+
}
80+
operator long long()
81+
{
82+
return std::stoll(v.c_str());
83+
}
84+
operator unsigned long long()
85+
{
86+
return std::stoull(v.c_str());
87+
}
3388
};
3489

3590
struct XLNODE
@@ -355,22 +410,22 @@ struct XLNODE_ANY : public XLNODE
355410
}
356411
for (auto& p : Params)
357412
{
358-
if (p.list_names.size() && (size_t)p.v < p.list_names.size())
413+
if (p.list_names.size() && (int)p < p.list_names.size())
359414
{
360-
swprintf_s(t, 1000, L"\r\n%s: %s", p.n.c_str(), p.list_names[(size_t)p.v].c_str());
415+
swprintf_s(t, 1000, L"\r\n%s: %s", p.n.c_str(), p.list_names[p].c_str());
361416
}
362417
else
363418
if (p.minv <= -1 && p.maxv <= -1)
364419
{
365-
swprintf_s(t, 1000, L"\r\n%s: %s", p.n.c_str(), p.string_param.c_str());
420+
swprintf_s(t, 1000, L"\r\n%s: %s", p.n.c_str(), p.w());
366421
}
367422
else
368423
if (p.minv == 0 && p.maxv == 1)
369424
{
370-
swprintf_s(t, 1000, L"\r\n%s: %s", p.n.c_str(), p.v == 1 ? L"True" : L"False");
425+
swprintf_s(t, 1000, L"\r\n%s: %s", p.n.c_str(), p ? L"True" : L"False");
371426
}
372427
else
373-
swprintf_s(t, 1000, L"\r\n%s: %.2f", p.n.c_str(), p.v);
428+
swprintf_s(t, 1000, L"\r\n%s: %.2f", p.n.c_str(), (float)p);
374429
n += t;
375430
}
376431
return n;
@@ -399,7 +454,7 @@ struct XLNODE_ANY : public XLNODE
399454
{
400455
auto& pe = ee["Params"].AddElement("Param");
401456
pe.vv("Name").SetWideValue(p.n.c_str());
402-
pe.vv("Value").SetValueFloat(p.v);
457+
pe.vv("Value").SetWideValue(p.w());
403458
pe.vv("Min").SetValueFloat(p.minv);
404459
pe.vv("Max").SetValueFloat(p.maxv);
405460
for (auto& s : p.list_names)
@@ -415,7 +470,7 @@ struct XLNODE_ANY : public XLNODE
415470
{
416471
PARAM p;
417472
p.n = pe.vv("Name").GetWideValue();
418-
p.v = pe.vv("Value").GetValueFloat();
473+
p.v = pe.vv("Value").GetWideValue();
419474
p.minv = pe.vv("Min").GetValueFloat(std::numeric_limits<float>::min());
420475
p.maxv = pe.vv("Max").GetValueFloat(std::numeric_limits<float>::max());
421476
for (auto& le : pe["list"])
@@ -433,7 +488,11 @@ struct XLNODE_CONSTANT : public XLNODE_ANY
433488

434489
XLNODE_CONSTANT() : XLNODE_ANY(0, TYPE_CONSTANT)
435490
{
436-
Params.push_back({ L"Value",0 });
491+
PARAM p;
492+
p.n = L"Value";
493+
p.minv = -1;
494+
p.maxv = -1;
495+
Params.push_back(p);
437496
}
438497
std::vector<unsigned int> tensor_dims;
439498

@@ -593,7 +652,7 @@ struct XLOP : public XLNODE
593652
ee.vv("Zoom").SetValueFloat(Zoom);
594653
for (auto& n : nodes)
595654
{
596-
auto& ne = ee.AddElement("Node");
655+
auto& ne = ee["Nodes"].AddElement("Node");
597656
n->Ser(ne);
598657
}
599658
}
@@ -652,9 +711,9 @@ struct XLOP : public XLNODE
652711
virtual void Unser(XML3::XMLElement& e)
653712
{
654713
nodes.clear();
655-
for (size_t i = 0; i < e.GetChildrenNum(); i++)
714+
for (size_t i = 0; i < e["Nodes"].GetChildrenNum(); i++)
656715
{
657-
auto& ne = e.GetChildren()[i];
716+
auto& ne = e["Nodes"].GetChildren()[i];
658717
auto n = Unser2(*ne);
659718
nodes.push_back(n);
660719
}
@@ -665,47 +724,103 @@ struct XLOP : public XLNODE
665724

666725
struct XL : public XLNODE
667726
{
727+
std::wstring n;
668728
std::vector<XLOP> ops;
729+
std::vector<VARIABLE> variables;
669730
virtual std::wstring name() { return L"DML"; }
670731
virtual std::wstring subname() { return L""; }
671732

672733
virtual void Ser(XML3::XMLElement& ee)
673734
{
735+
ee.vv("n").SetWideValue(n.c_str());
674736
for (auto& op : ops)
675737
{
676-
auto& oe = ee.AddElement("Operator");
738+
auto& oe = ee["Operators"].AddElement("Operator");
677739
op.Ser(oe);
678740
}
741+
742+
for (auto& v : variables)
743+
{
744+
auto& nv = ee["Variables"].AddElement("Variable");
745+
v.Ser(nv);
746+
}
747+
679748
}
680749
virtual void Unser(XML3::XMLElement& e)
681750
{
751+
n = e.vv("n").GetWideValue();
682752
ops.clear();
683-
for (size_t i = 0; i < e.GetChildrenNum(); i++)
753+
for (size_t i = 0; i < e["Operators"].GetChildrenNum(); i++)
684754
{
685-
auto& oe = e.GetChildren()[i];
755+
auto& oe = e["Operators"].GetChildren()[i];
686756
XLOP op;
687757
op.Unser(*oe);
688758
ops.push_back(op);
689759
}
690760

691761
for (auto& op : ops)
692762
{
693-
for (auto& n : op.nodes)
763+
for (auto& no : op.nodes)
694764
{
695-
for (auto& c : n->children)
765+
for (auto& c : no->children)
696766
{
697767
for(auto& gg : c.g)
698-
nnn = std::max((unsigned long long)abs(n->ShareMemory),std::max(nnn + 1,gg + 1));
768+
nnn = std::max((unsigned long long)abs(no->ShareMemory),std::max(nnn + 1,gg + 1));
699769
}
700770
}
701771
}
772+
773+
variables.clear();
774+
for (auto& ve : e["Variables"])
775+
{
776+
VARIABLE v;
777+
v.Unser(ve);
778+
variables.push_back(v);
779+
}
780+
702781
}
703782
};
704783

705-
inline bool Hit(float x, float y, D2D1_RECT_F rc)
784+
struct PROJECT
706785
{
707-
return x >= rc.left && x <= rc.right && y >= rc.top && y <= rc.bottom;
708-
}
786+
std::vector<XL> xls;
787+
size_t iActive = 0;
788+
XL& xl()
789+
{
790+
if (xls.empty())
791+
{
792+
xls.push_back(XL());
793+
return xls[0];
794+
}
795+
if (iActive < xls.size())
796+
return xls[iActive];
797+
return xls[0];
798+
}
799+
800+
void Ser(XML3::XMLElement& e)
801+
{
802+
for (auto& xl : xls)
803+
{
804+
auto& xe = e["Pages"].AddElement("Page");
805+
xl.Ser(xe);
806+
}
807+
}
808+
809+
void Unser(XML3::XMLElement& e)
810+
{
811+
xls.clear();
812+
for (size_t i = 0; i < e["Pages"].GetChildrenNum(); i++)
813+
{
814+
auto& xe = e["Pages"].GetChildren()[i];
815+
XL xl;
816+
xl.Unser(*xe);
817+
xls.push_back(xl);
818+
}
819+
}
820+
};
821+
822+
823+
709824

710825
namespace winrt::DirectMLGraph::implementation
711826
{
@@ -725,15 +840,14 @@ namespace winrt::DirectMLGraph::implementation
725840
void FullRefresh();
726841

727842
ML ml;
728-
XL xl;
843+
PROJECT prj;
844+
// XL xl;
729845
std::stack<XML3::XMLElement> undo_list;
730846
std::stack<XML3::XMLElement> redo_list;
731847
size_t ActiveOperator2 = (size_t)-1;
732848
std::shared_ptr<D2D> d2d;
733849
MLGraph()
734850
{
735-
// Xaml objects should not call InitializeComponent during construction.
736-
// See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent
737851
}
738852

739853

@@ -796,6 +910,9 @@ namespace winrt::DirectMLGraph::implementation
796910
void OnCompile(IInspectable const&, IInspectable const&);
797911
void OnRun(IInspectable const&, IInspectable const&);
798912
void OnAddOp(IInspectable const&, IInspectable const&);
913+
void OnAddSet(IInspectable const&, IInspectable const&);
914+
void Tip(const wchar_t*);
915+
void OnAddVariable(IInspectable const&, IInspectable const&);
799916
void OnAddInput(IInspectable const&, IInspectable const&);
800917
void OnAddConstant(IInspectable const&, IInspectable const&);
801918
void OnAddOutput(IInspectable const&, IInspectable const&);

Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?xml version="1.0" encoding="utf-8" standalone="yes" ?><Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap rescap"><Identity Name="d5667bc5-597d-4ce3-89f1-cc97e6a0f047" Publisher="CN=EDD191C1-439D-4D37-B608-DD521142451D" Version="1.16.0.0"/><mp:PhoneIdentity PhoneProductId="d5667bc5-597d-4ce3-89f1-cc97e6a0f047" PhonePublisherId="00000000-0000-0000-0000-000000000000"/><Properties><DisplayName>DirectMLGraph</DisplayName><PublisherDisplayName>chour</PublisherDisplayName><Logo>Assets\StoreLogo.png</Logo></Properties><Dependencies><TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0"/><TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0"/></Dependencies><Resources><Resource Language="x-generate"/></Resources><Applications><Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$"><uap:VisualElements DisplayName="DirectMLGraph" Description="DirectMLGraph" BackgroundColor="transparent" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png"><uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/><uap:SplashScreen Image="Assets\SplashScreen.png"/></uap:VisualElements></Application></Applications><Capabilities><rescap:Capability Name="runFullTrust"/></Capabilities></Package>
1+
<?xml version="1.0" encoding="utf-8" standalone="yes" ?><Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap rescap"><Identity Name="d5667bc5-597d-4ce3-89f1-cc97e6a0f047" Publisher="CN=EDD191C1-439D-4D37-B608-DD521142451D" Version="1.17.0.0"/><mp:PhoneIdentity PhoneProductId="d5667bc5-597d-4ce3-89f1-cc97e6a0f047" PhonePublisherId="00000000-0000-0000-0000-000000000000"/><Properties><DisplayName>DirectMLGraph</DisplayName><PublisherDisplayName>chour</PublisherDisplayName><Logo>Assets\StoreLogo.png</Logo></Properties><Dependencies><TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0"/><TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0"/></Dependencies><Resources><Resource Language="x-generate"/></Resources><Applications><Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$"><uap:VisualElements DisplayName="DirectMLGraph" Description="DirectMLGraph" BackgroundColor="transparent" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png"><uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/><uap:SplashScreen Image="Assets\SplashScreen.png"/></uap:VisualElements></Application></Applications><Capabilities><rescap:Capability Name="runFullTrust"/></Capabilities></Package>

Readme.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ A tool to visually-design DirectML operators that run in the GPU.
55

66
## Features
77

8-
Undo, Redo, Save, Load
8+
Undo, Redo, Save, Load, Multiple Sets
99

1010
Multiple Visible/Active DirectML operators
1111

1212
Direct2D Drawing
1313

1414
Memory Sharing
1515

16-
Input/Output CSV or binary
16+
Input/Output CSV or binary, Input Random, Output to MessageBox
1717

18+
Adapter Selection
19+
20+
Show Adapter Memory Consumed
1821

1922
## Supported Operators
2023

o1.csv

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
3
2-
4
3-
5
4-
6
5-
7
6-
8
7-
9
8-
10
9-
11
10-
12
11-
13
12-
14
13-
15
14-
16
15-
17
16-
18
17-
19
18-
20
19-
21
20-
22
1+
2.5
2+
3.5
3+
4.5
4+
5.5
5+
6.5
6+
7.5
7+
8.5
8+
9.5
9+
10.5
10+
11.5
11+
12.5
12+
13.5
13+
14.5
14+
15.5
15+
16.5
16+
17.5
17+
18.5
18+
19.5
19+
20.5
20+
21.5

0 commit comments

Comments
 (0)