Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
AMDMIGraphX/test/gpu/sqlite_problem_cache.cpp at develop · ROCm/AMDMIGraphX · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
ROCm
/
AMDMIGraphX
Public
Notifications
You must be signed in to change notification settings
Fork
148
Star
329
Code
Issues
247
Pull requests
122
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Files
Expand file tree
develop
Breadcrumbs
AMDMIGraphX
/
test
/
gpu
/
sqlite_problem_cache.cpp
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
211 lines (175 loc) · 7.63 KB
develop
Breadcrumbs
AMDMIGraphX
/
test
/
gpu
/
sqlite_problem_cache.cpp
Copy path
Top
File metadata and controls
Code
Blame
211 lines (175 loc) · 7.63 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#
include
<
migraphx/gpu/problem_cache.hpp
>
#
include
<
migraphx/gpu/problem_cache_backend.hpp
>
#
include
<
migraphx/gpu/sqlite_problem_cache.hpp
>
#
include
<
migraphx/tmp_dir.hpp
>
#
include
<
migraphx/value.hpp
>
#
include
"
test.hpp
"
namespace
{
migraphx::gpu::cache_device_key
make_key
(
const
std::string& gfx, std::
size_t
cu)
{
migraphx::gpu::cache_device_key k;
k.
device_name
=
"
test_device_
"
+ gfx;
k.
gfx_name
= gfx;
k.
cu_count
= cu;
k.
wavefront_size
=
32
;
return
k;
}
migraphx::value
make_problem
(
const
std::string& name, std::
size_t
variant)
{
return
{{
"
name
"
, name}, {
"
problem
"
, migraphx::value{{
"
variant
"
, variant}}}};
}
}
//
namespace
//
--------------------------------------------------------------------------
//
Round-trip: write entries, save, load into a fresh instance, verify.
//
--------------------------------------------------------------------------
TEST_CASE
(sqlite_problem_cache_round_trip)
{
migraphx::tmp_dir td{
"
sqlite_problem_cache_round_trip
"
};
auto
path = (td.
path
/
"
cache.db
"
).
string
();
auto
dk1 =
make_key
(
"
gfx1201
"
,
64
);
auto
dk2 =
make_key
(
"
gfx1100
"
,
96
);
auto
key_a =
make_problem
(
"
gemm
"
,
0
);
auto
key_b =
make_problem
(
"
conv
"
,
1
);
auto
sol_a = migraphx::value{{
"
block
"
, std::
size_t
{
256
}}, {
"
kernel
"
,
"
kA
"
}};
auto
sol_b = migraphx::value{{
"
block
"
, std::
size_t
{
128
}}, {
"
kernel
"
,
"
kB
"
}};
migraphx::gpu::sqlite_problem_cache writer;
writer.
insert
(dk1, key_a, sol_a);
writer.
insert
(dk2, key_b, sol_b);
writer.
mark
(dk1, key_b);
//
sentinel: tried, no solution
writer.
save
(path);
migraphx::gpu::sqlite_problem_cache reader;
reader.
load
(path);
EXPECT
(reader.
has
(dk1, key_a));
EXPECT
(reader.
has
(dk2, key_b));
EXPECT
(reader.
has
(dk1, key_b));
//
sentinel still "present"
auto
got_a = reader.
get
(dk1, key_a);
EXPECT
(
bool
(got_a));
EXPECT
(*got_a == sol_a);
auto
got_b = reader.
get
(dk2, key_b);
EXPECT
(
bool
(got_b));
EXPECT
(*got_b == sol_b);
//
Sentinel: get() returns a present optional whose value is null.
auto
sentinel = reader.
get
(dk1, key_b);
EXPECT
(
bool
(sentinel));
EXPECT
(sentinel->
is_null
());
//
Miss across buckets: dk2's bucket has no key_a.
EXPECT
(
not
reader.
has
(dk2, key_a));
EXPECT
(
not
bool
(reader.
get
(dk2, key_a)));
}
//
--------------------------------------------------------------------------
//
load() from a non-existent path is a no-op (typical first-run case).
//
--------------------------------------------------------------------------
TEST_CASE
(sqlite_problem_cache_missing_file_is_noop)
{
migraphx::tmp_dir td{
"
sqlite_problem_cache_missing
"
};
auto
path = (td.
path
/
"
does_not_exist.db
"
).
string
();
migraphx::gpu::sqlite_problem_cache c;
c.
load
(path);
//
must not throw
EXPECT
(c.
cache
.
empty
());
//
Subsequent save() must create the file and round-trip cleanly.
auto
dk =
make_key
(
"
gfx1201
"
,
64
);
c.
insert
(dk,
make_problem
(
"
gemm
"
,
0
), migraphx::value{{
"
kernel
"
,
"
kX
"
}});
c.
save
(path);
migraphx::gpu::sqlite_problem_cache c2;
c2.
load
(path);
EXPECT
(c2.
has
(dk,
make_problem
(
"
gemm
"
,
0
)));
}
//
--------------------------------------------------------------------------
//
Save-overwrite: a second save() of a smaller cache must replace the
//
previous file's rows (DELETE FROM solutions semantics), not accumulate.
//
--------------------------------------------------------------------------
TEST_CASE
(sqlite_problem_cache_save_overwrite)
{
migraphx::tmp_dir td{
"
sqlite_problem_cache_overwrite
"
};
auto
path = (td.
path
/
"
cache.db
"
).
string
();
auto
dk =
make_key
(
"
gfx1201
"
,
64
);
auto
key_a =
make_problem
(
"
gemm
"
,
0
);
auto
key_b =
make_problem
(
"
conv
"
,
1
);
migraphx::gpu::sqlite_problem_cache c;
c.
insert
(dk, key_a, migraphx::value{{
"
kernel
"
,
"
kA
"
}});
c.
insert
(dk, key_b, migraphx::value{{
"
kernel
"
,
"
kB
"
}});
c.
save
(path);
//
Reload, drop one entry, save again.
migraphx::gpu::sqlite_problem_cache c2;
c2.
load
(path);
EXPECT
(c2.
has
(dk, key_a));
EXPECT
(c2.
has
(dk, key_b));
//
Keys are stored normalized (as insert/load do), so erase by the normalized key.
c2.
cache
[dk].
erase
(key_b.
normalize
());
c2.
save
(path);
//
Third instance must see the smaller set.
migraphx::gpu::sqlite_problem_cache c3;
c3.
load
(path);
EXPECT
(c3.
has
(dk, key_a));
EXPECT
(
not
c3.
has
(dk, key_b));
}
//
--------------------------------------------------------------------------
//
Type-erasure round-trip: wrap sqlite_problem_cache in problem_cache_backend
//
and exercise every concept member. Verifies the te.py-generated wrapper
//
forwards correctly to a *different* concrete backend than json.
//
--------------------------------------------------------------------------
TEST_CASE
(problem_cache_backend_sqlite_type_erasure)
{
migraphx::tmp_dir td{
"
problem_cache_backend_sqlite_te
"
};
auto
path = (td.
path
/
"
cache.db
"
).
string
();
migraphx::gpu::problem_cache_backend backend = migraphx::gpu::sqlite_problem_cache{};
auto
dk =
make_key
(
"
gfx1201
"
,
64
);
auto
key =
make_problem
(
"
gemm
"
,
7
);
auto
sol = migraphx::value{{
"
block
"
, std::
size_t
{
512
}}, {
"
kernel
"
,
"
kY
"
}};
auto
miss =
make_problem
(
"
never_inserted
"
,
99
);
EXPECT
(
not
backend.
has
(dk, key));
EXPECT
(
not
bool
(backend.
get
(dk, key)));
backend.
insert
(dk, key, sol);
EXPECT
(backend.
has
(dk, key));
auto
got = backend.
get
(dk, key);
EXPECT
(
bool
(got));
EXPECT
(*got == sol);
backend.
mark
(dk, miss);
auto
m = backend.
get
(dk, miss);
EXPECT
(
bool
(m));
EXPECT
(m->
is_null
());
backend.
save
(path);
migraphx::gpu::problem_cache_backend reloaded = migraphx::gpu::sqlite_problem_cache{};
reloaded.
load
(path);
EXPECT
(reloaded.
has
(dk, key));
auto
got2 = reloaded.
get
(dk, key);
EXPECT
(
bool
(got2));
EXPECT
(*got2 == sol);
}
//
--------------------------------------------------------------------------
//
any_cast lets callers recover the concrete sqlite backend.
//
--------------------------------------------------------------------------
TEST_CASE
(problem_cache_backend_sqlite_any_cast)
{
migraphx::gpu::problem_cache_backend backend = migraphx::gpu::sqlite_problem_cache{};
auto
* concrete = backend.
any_cast
<migraphx::gpu::sqlite_problem_cache>();
EXPECT
(concrete !=
nullptr
);
//
Casting to a sibling concrete type returns nullptr (no cross-type
//
recovery via the type-erased interface).
auto
* wrong = backend.
any_cast
<
int
>();
EXPECT
(wrong ==
nullptr
);
}
int
main
(
int
argc,
const
char
* argv[]) {
test::run
(argc, argv); }
You can’t perform that action at this time.