Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
062f8cc4
Commit
062f8cc4
authored
Aug 28, 2019
by
Cody Hao Yu
Committed by
Haichen Shen
Aug 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[AutoTVM] Fix database APIs (#3821)
* [AutoTVM] Fix database APIs * Refactor the byte conversion
parent
19b8b3a4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
11 deletions
+22
-11
python/tvm/autotvm/database.py
+10
-11
tests/python/unittest/test_autotvm_database.py
+12
-0
No files found.
python/tvm/autotvm/database.py
View file @
062f8cc4
...
...
@@ -117,12 +117,12 @@ class RedisDatabase(Database):
self
.
db
.
set
(
key
,
value
)
def
get
(
self
,
key
):
return
self
.
db
.
get
(
key
)
current
=
self
.
db
.
get
(
key
)
return
current
.
decode
()
if
isinstance
(
current
,
bytes
)
else
current
def
load
(
self
,
inp
,
get_all
=
False
):
current
=
self
.
get
(
measure_str_key
(
inp
))
if
current
is
not
None
:
current
=
str
(
current
)
records
=
[
decode
(
x
)
for
x
in
current
.
split
(
RedisDatabase
.
MAGIC_SPLIT
)]
results
=
[
rec
[
1
]
for
rec
in
records
]
if
get_all
:
...
...
@@ -142,29 +142,31 @@ class RedisDatabase(Database):
def
filter
(
self
,
func
):
"""
Dump all of the records
for a particular target
Dump all of the records
that match the given rule
Parameters
----------
func: callable
The signature of the function is
bool (MeasureInput, Array of MeasureResult)
The signature of the function is
(MeasureInput, [MeasureResult]) -> bool
Returns
-------
list of records
(inp, result) matching the target
list of records
in tuple (MeasureInput, MeasureResult) matching the rule
Examples
--------
get records for a target
>>> db.filter(lambda inp, resulst: "cuda" in inp.target.keys)
get records with errors
>>> db.filter(lambda inp, results: any(r.error_no != 0 for r in results))
"""
matched_records
=
list
()
# may consider filtering in iterator in the future
for
key
in
self
.
db
:
for
key
in
self
.
db
.
keys
()
:
current
=
self
.
get
(
key
)
try
:
records
=
[
decode
(
x
)
for
x
in
current
.
sp
il
t
(
RedisDatabase
.
MAGIC_SPLIT
)]
except
TypeError
:
# got a badly formatted/old format record
records
=
[
decode
(
x
)
for
x
in
current
.
sp
li
t
(
RedisDatabase
.
MAGIC_SPLIT
)]
except
TypeError
:
# got a badly formatted/old format record
continue
inps
,
results
=
zip
(
*
records
)
...
...
@@ -190,8 +192,5 @@ class DummyDatabase(RedisDatabase):
def
set
(
self
,
key
,
value
):
self
.
db
[
key
]
=
value
def
get
(
self
,
key
):
return
self
.
db
.
get
(
key
)
def
flush
(
self
):
self
.
db
=
{}
tests/python/unittest/test_autotvm_database.py
View file @
062f8cc4
...
...
@@ -99,8 +99,20 @@ def test_db_latest_all():
assert
encode
(
inp1
,
load4
[
1
])
==
encode
(
inp1
,
res2
)
assert
encode
(
inp1
,
load4
[
2
])
==
encode
(
inp1
,
res3
)
def
test_db_filter
():
logging
.
info
(
"test db filter ..."
)
records
=
get_sample_records
(
5
)
_db
=
database
.
DummyDatabase
()
_db
.
flush
()
for
inp
,
result
in
records
:
_db
.
save
(
inp
,
result
)
records
=
_db
.
filter
(
lambda
inp
,
ress
:
any
(
r
.
costs
[
0
]
<=
2
for
r
in
ress
))
assert
len
(
records
)
==
2
if
__name__
==
'__main__'
:
logging
.
basicConfig
(
level
=
logging
.
INFO
)
test_save_load
()
test_db_hash
()
test_db_latest_all
()
test_db_filter
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment