-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpch.h
316 lines (277 loc) · 6.08 KB
/
pch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#define DISABLE_XAML_GENERATED_MAIN
#define DML_TARGET_VERSION_USE_LATEST
#pragma once
#include <windows.h>
#include <unknwn.h>
#include <wininet.h>
#include <restrictederrorinfo.h>
#include <hstring.h>
#include <queue>
#include <any>
#include <optional>
#include <stack>
#include <mutex>
#include <vector>
#include <set>
#include <functional>
#include <memory>
#include <limits>
#include <vector>
#include <shlobj.h>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <ctime>
#include <fstream>
#include <algorithm>
#include <random>
#include <dwmapi.h>
#include <wincodec.h>
#include <d2d1.h>
#include <d2d1_1.h>
#include <d2d1_2.h>
#include <d2d1_3.h>
#include <dwrite.h>
#include <d3d11.h>
#include <d3d12.h>
#include <dxgi.h>
#include <optional>
#include <dxgi1_4.h>
#include <dxgi1_6.h>
#include <atlbase.h>
#include "d3dx12.h"
#include ".\\packages\\Microsoft.AI.DirectML.1.15.4\\include\\DirectML.h"
#include "DirectMLX.h"
#include "ystring.h"
#include <random>
#undef min
#undef max
// Undefine GetCurrentTime macro to prevent
// conflict with Storyboard::GetCurrentTime
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Storage.Streams.h>
#include <winrt/Windows.ApplicationModel.Activation.h>
#include <winrt/Microsoft.UI.Composition.h>
#include <winrt/Microsoft.UI.Xaml.h>
#include <winrt/Microsoft.UI.Xaml.Input.h>
#include <winrt/Microsoft.UI.Input.h>
#include <winrt/Microsoft.UI.Xaml.Controls.h>
#include <winrt/Microsoft.UI.Xaml.Controls.Primitives.h>
#include <winrt/Microsoft.UI.Xaml.Data.h>
#include <winrt/Microsoft.UI.Xaml.Interop.h>
#include <winrt/Windows.UI.Xaml.Interop.h>
#include <microsoft.ui.xaml.window.h>
#include <winrt/Microsoft.UI.Xaml.Markup.h>
#include <microsoft.ui.xaml.media.dxinterop.h>
#include <winrt/Microsoft.UI.Xaml.Media.h>
#include <winrt/Microsoft.Windows.AppNotifications.h>
#include <winrt/Microsoft.Windows.AppNotifications.Builder.h>
#include <winrt/Microsoft.UI.Xaml.Navigation.h>
#include <winrt/Microsoft.UI.Xaml.Shapes.h>
#include <winrt/Microsoft.UI.Xaml.Media.h>
#include <winrt/Microsoft.UI.Xaml.Media.Imaging.h>
#include <winrt/Microsoft.UI.Dispatching.h>
#include <wil/cppwinrt_helpers.h>
#include <appmodel.h>
struct D2F : public D2D1_RECT_F
{
float Width()
{
return right - left;
}
float Height()
{
return bottom - top;
}
float MiddleX()
{
return left + (right - left) / 2.0f;
}
float MiddleY()
{
return top + (bottom - top) / 2.0f;
}
void Shrink(float x)
{
left += x;
top += x;
right -= x;
bottom -= x;
}
D2F(const D2F& d)
{
*this = d;
}
void reset()
{
left = 0; right = 0; top = 0; bottom = 0;
}
D2F(float l = 0, float t = 0, float r = 0, float b = 0)
{
left = l; right = r; top = t; bottom = b;
}
D2F(const D2D1_RECT_F& r)
{
operator=(r);
}
D2F& operator=(const D2D1_RECT_F& r)
{
left = r.left;
top = r.top;
right = r.right;
bottom = r.bottom;
return *this;
}
operator D2D1_RECT_F()
{
return *this;
}
};
#include "xml3all.h"
#include "d2d.hpp"
#include "dmllib.hpp"
class FMAP
{
private:
HANDLE hX = INVALID_HANDLE_VALUE;
HANDLE hY = INVALID_HANDLE_VALUE;
unsigned long long sz = 0;
char* d = 0;
std::wstring mappedfile;
public:
std::wstring fil(bool WithFolder) const
{
if (WithFolder)
return mappedfile;
std::vector<wchar_t> t(1000);
wcscpy_s(t.data(), 1000, mappedfile.c_str());
PathStripPath(t.data());
return t.data();
}
void Stop(unsigned long long p)
{
LARGE_INTEGER li = { 0 };
GetFileSizeEx(hX, &li);
if (p > (unsigned long long)li.QuadPart)
p = li.QuadPart;
sz = p;
}
HANDLE& hF() { return hX; }
unsigned long long size() { return sz; }
char* p() { return d; }
bool CreateForRecord(const wchar_t* f)
{
mappedfile = f;
hX = CreateFile(f, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_ALWAYS, 0, 0);
if (hX == INVALID_HANDLE_VALUE || hX == 0)
{
hX = 0;
return false;
}
return true;
}
bool Map(const wchar_t* f)
{
hX = CreateFile(f, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
if (hX == INVALID_HANDLE_VALUE || hX == 0)
{
hX = 0;
return false;
}
LARGE_INTEGER li = { 0 };
GetFileSizeEx(hX, &li);
sz = li.QuadPart;
hY = CreateFileMapping(hX, 0, PAGE_READONLY, 0, 0, 0);
if (hY == 0)
return false;
d = (char*)MapViewOfFile(hY, FILE_MAP_READ, 0, 0, 0);
mappedfile = f;
return true;
}
void Unmap()
{
if (d)
UnmapViewOfFile(d);
d = 0;
if (hY != 0)
CloseHandle(hY);
hY = 0;
if (hX != 0)
CloseHandle(hX);
hX = 0;
hY = 0;
}
FMAP(const wchar_t* f = 0)
{
if (f)
Map(f);
}
~FMAP()
{
Unmap();
}
};
template <typename T>
bool PutFile(const wchar_t* f, std::vector<T>& d, bool Fw = true)
{
HANDLE hX = CreateFile(f, GENERIC_WRITE, 0, 0, Fw ? CREATE_ALWAYS : CREATE_NEW, 0, 0);
if (hX == INVALID_HANDLE_VALUE)
return false;
DWORD A = 0;
WriteFile(hX, d.data(), (DWORD)(d.size() * sizeof(T)), &A, 0);
CloseHandle(hX);
if (A != d.size())
return false;
return true;
}
inline std::shared_ptr<XML3::XML> SettingsX;
inline std::wstring datafolder;
inline const wchar_t* ttitle = L"Visual DML";
template <typename T = unsigned int>
std::vector<T> TensorFromString(const wchar_t* str)
{
std::vector<T> newSizes;
try
{
std::vector<std::wstring> split(const std::wstring & s, wchar_t delim);
auto sp = split(str, L'x');
for (auto& s : sp)
newSizes.push_back((T)std::stoi(s));
}
catch (...)
{
}
return newSizes;
}
inline std::vector<std::string> StringTensorFromString(const char* str)
{
std::vector<std::string> newSizes;
try
{
std::vector<std::string> split(const std::string & s, char delim);
auto sp = split(str, 'x');
for (auto& s : sp)
newSizes.push_back(s);
}
catch (...)
{
}
return newSizes;
}
template <typename T = unsigned int>
std::wstring TensorToString(std::vector<T> in,const wchar_t* sep = L",")
{
std::wstring x;
for (auto& i : in)
{
x += std::to_wstring(i);
x += sep;
}
if (x.length())
x.pop_back();
return x;
}
bool Hit(float x, float y, D2D1_RECT_F rc);
std::wstring TensorStringToString(std::wstring v);
#include "./cparse/shunting-yard.h"