Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CCS
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Brice Videau
CCS
Commits
f87778b3
Commit
f87778b3
authored
Oct 27, 2020
by
Brice Videau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better user-defined tuner implementation.
parent
03031d71
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
185 additions
and
173 deletions
+185
-173
bindings/python/cconfigspace/tuner.py
bindings/python/cconfigspace/tuner.py
+26
-26
bindings/python/test/test_tuner.py
bindings/python/test/test_tuner.py
+6
-6
bindings/ruby/lib/cconfigspace/tuner.rb
bindings/ruby/lib/cconfigspace/tuner.rb
+17
-35
bindings/ruby/test/test_tuner.rb
bindings/ruby/test/test_tuner.rb
+6
-6
include/cconfigspace/tuner.h
include/cconfigspace/tuner.h
+19
-36
samples/test_python.py
samples/test_python.py
+6
-6
samples/test_python_from_ruby.rb
samples/test_python_from_ruby.rb
+1
-1
samples/test_ruby.rb
samples/test_ruby.rb
+6
-6
src/tuner.c
src/tuner.c
+5
-5
src/tuner_internal.h
src/tuner_internal.h
+9
-0
src/tuner_random.c
src/tuner_random.c
+4
-4
src/tuner_user_defined.c
src/tuner_user_defined.c
+40
-20
tests/test_user_defined_tuner.c
tests/test_user_defined_tuner.c
+40
-22
No files found.
bindings/python/cconfigspace/tuner.py
View file @
f87778b3
...
@@ -152,11 +152,11 @@ class ccs_tuner_common_data(ct.Structure):
...
@@ -152,11 +152,11 @@ class ccs_tuner_common_data(ct.Structure):
(
'configuration_space'
,
ccs_configuration_space
),
(
'configuration_space'
,
ccs_configuration_space
),
(
'objective_space'
,
ccs_objective_space
)
]
(
'objective_space'
,
ccs_objective_space
)
]
ccs_user_defined_tuner_del_type
=
ct
.
CFUNCTYPE
(
ccs_result
,
c
t
.
c_void_p
)
ccs_user_defined_tuner_del_type
=
ct
.
CFUNCTYPE
(
ccs_result
,
c
cs_tuner
)
ccs_user_defined_tuner_ask_type
=
ct
.
CFUNCTYPE
(
ccs_result
,
c
t
.
c_void_p
,
ct
.
c_size_t
,
ct
.
POINTER
(
ccs_configuration
),
ct
.
POINTER
(
ct
.
c_size_t
))
ccs_user_defined_tuner_ask_type
=
ct
.
CFUNCTYPE
(
ccs_result
,
c
cs_tuner
,
ct
.
c_size_t
,
ct
.
POINTER
(
ccs_configuration
),
ct
.
POINTER
(
ct
.
c_size_t
))
ccs_user_defined_tuner_tell_type
=
ct
.
CFUNCTYPE
(
ccs_result
,
c
t
.
c_void_p
,
ct
.
c_size_t
,
ct
.
POINTER
(
ccs_evaluation
))
ccs_user_defined_tuner_tell_type
=
ct
.
CFUNCTYPE
(
ccs_result
,
c
cs_tuner
,
ct
.
c_size_t
,
ct
.
POINTER
(
ccs_evaluation
))
ccs_user_defined_tuner_get_optimums_type
=
ct
.
CFUNCTYPE
(
ccs_result
,
c
t
.
c_void_p
,
ct
.
c_size_t
,
ct
.
POINTER
(
ccs_evaluation
),
ct
.
POINTER
(
ct
.
c_size_t
))
ccs_user_defined_tuner_get_optimums_type
=
ct
.
CFUNCTYPE
(
ccs_result
,
c
cs_tuner
,
ct
.
c_size_t
,
ct
.
POINTER
(
ccs_evaluation
),
ct
.
POINTER
(
ct
.
c_size_t
))
ccs_user_defined_tuner_get_history_type
=
ct
.
CFUNCTYPE
(
ccs_result
,
c
t
.
c_void_p
,
ct
.
c_size_t
,
ct
.
POINTER
(
ccs_evaluation
),
ct
.
POINTER
(
ct
.
c_size_t
))
ccs_user_defined_tuner_get_history_type
=
ct
.
CFUNCTYPE
(
ccs_result
,
c
cs_tuner
,
ct
.
c_size_t
,
ct
.
POINTER
(
ccs_evaluation
),
ct
.
POINTER
(
ct
.
c_size_t
))
class
ccs_user_defined_tuner_vector
(
ct
.
Structure
):
class
ccs_user_defined_tuner_vector
(
ct
.
Structure
):
_fields_
=
[
_fields_
=
[
...
@@ -166,31 +166,24 @@ class ccs_user_defined_tuner_vector(ct.Structure):
...
@@ -166,31 +166,24 @@ class ccs_user_defined_tuner_vector(ct.Structure):
(
'get_optimums'
,
ccs_user_defined_tuner_get_optimums_type
),
(
'get_optimums'
,
ccs_user_defined_tuner_get_optimums_type
),
(
'get_history'
,
ccs_user_defined_tuner_get_history_type
)
]
(
'get_history'
,
ccs_user_defined_tuner_get_history_type
)
]
class
ccs_user_defined_tuner_data
(
ct
.
Structure
):
_fields_
=
[
(
'common_data'
,
ccs_tuner_common_data
),
(
'vector'
,
ccs_user_defined_tuner_vector
),
(
'tuner_data'
,
ct
.
c_void_p
)
]
ccs_create_user_defined_tuner
=
_ccs_get_function
(
"ccs_create_user_defined_tuner"
,
[
ct
.
c_char_p
,
ccs_configuration_space
,
ccs_objective_space
,
ct
.
c_void_p
,
ct
.
POINTER
(
ccs_user_defined_tuner_vector
),
ct
.
c_void_p
,
ct
.
POINTER
(
ccs_tuner
)])
ccs_create_user_defined_tuner
=
_ccs_get_function
(
"ccs_create_user_defined_tuner"
,
[
ct
.
c_char_p
,
ccs_configuration_space
,
ccs_objective_space
,
ct
.
c_void_p
,
ct
.
POINTER
(
ccs_user_defined_tuner_vector
),
ct
.
c_void_p
,
ct
.
POINTER
(
ccs_tuner
)])
ccs_user_defined_tuner_get_tuner_data
=
_ccs_get_function
(
"ccs_user_defined_tuner_get_tuner_data"
,
[
ccs_tuner
,
ct
.
POINTER
(
ct
.
c_void_p
)])
def
_wrap_user_defined_callbacks
(
delete
,
ask
,
tell
,
get_optimums
,
get_history
):
def
_wrap_user_defined_callbacks
(
delete
,
ask
,
tell
,
get_optimums
,
get_history
):
ptr
=
ct
.
c_int
(
33
)
ptr
=
ct
.
c_int
(
33
)
def
delete_wrapper
(
data
):
def
delete_wrapper
(
tun
):
try
:
try
:
data
=
ct
.
cast
(
data
,
ct
.
POINTER
(
ccs_user_defined_tuner_data
))
delete
(
Object
.
from_handle
(
tun
))
delete
(
data
.
contents
)
del
_callbacks
[
ct
.
addressof
(
ptr
)]
del
_callbacks
[
ct
.
addressof
(
ptr
)]
return
ccs_error
.
SUCCESS
return
ccs_error
.
SUCCESS
except
Error
as
e
:
except
Error
as
e
:
return
-
e
.
message
.
value
return
-
e
.
message
.
value
def
ask_wrapper
(
data
,
count
,
p_configurations
,
p_count
):
def
ask_wrapper
(
tun
,
count
,
p_configurations
,
p_count
):
try
:
try
:
data
=
ct
.
cast
(
data
,
ct
.
POINTER
(
ccs_user_defined_tuner_data
))
p_confs
=
ct
.
cast
(
p_configurations
,
ct
.
c_void_p
)
p_confs
=
ct
.
cast
(
p_configurations
,
ct
.
c_void_p
)
p_c
=
ct
.
cast
(
p_count
,
ct
.
c_void_p
)
p_c
=
ct
.
cast
(
p_count
,
ct
.
c_void_p
)
(
configurations
,
count_ret
)
=
ask
(
data
.
contents
,
count
if
p_confs
.
value
else
None
)
(
configurations
,
count_ret
)
=
ask
(
Tuner
.
from_handle
(
tun
)
,
count
if
p_confs
.
value
else
None
)
if
p_confs
.
value
is
not
None
and
count
<
count_ret
:
if
p_confs
.
value
is
not
None
and
count
<
count_ret
:
raise
Error
(
ccs_error
(
ccs_error
.
INVALID_VALUE
))
raise
Error
(
ccs_error
(
ccs_error
.
INVALID_VALUE
))
if
p_confs
.
value
is
not
None
:
if
p_confs
.
value
is
not
None
:
...
@@ -206,26 +199,24 @@ def _wrap_user_defined_callbacks(delete, ask, tell, get_optimums, get_history):
...
@@ -206,26 +199,24 @@ def _wrap_user_defined_callbacks(delete, ask, tell, get_optimums, get_history):
except
Error
as
e
:
except
Error
as
e
:
return
-
e
.
message
.
value
return
-
e
.
message
.
value
def
tell_wrapper
(
data
,
count
,
p_evaluations
):
def
tell_wrapper
(
tun
,
count
,
p_evaluations
):
try
:
try
:
if
count
==
0
:
if
count
==
0
:
return
ccs_error
.
SUCCESS
return
ccs_error
.
SUCCESS
data
=
ct
.
cast
(
data
,
ct
.
POINTER
(
ccs_user_defined_tuner_data
))
p_evals
=
ct
.
cast
(
p_evaluations
,
ct
.
c_void_p
)
p_evals
=
ct
.
cast
(
p_evaluations
,
ct
.
c_void_p
)
if
p_evals
.
value
is
None
:
if
p_evals
.
value
is
None
:
raise
Error
(
ccs_error
(
ccs_error
.
INVALID_VALUE
))
raise
Error
(
ccs_error
(
ccs_error
.
INVALID_VALUE
))
evals
=
[
Evaluation
.
from_handle
(
ccs_evaluation
(
p_evaluations
[
i
]))
for
i
in
range
(
count
)]
evals
=
[
Evaluation
.
from_handle
(
ccs_evaluation
(
p_evaluations
[
i
]))
for
i
in
range
(
count
)]
tell
(
data
.
contents
,
evals
)
tell
(
Tuner
.
from_handle
(
tun
)
,
evals
)
return
ccs_error
.
SUCCESS
return
ccs_error
.
SUCCESS
except
Error
as
e
:
except
Error
as
e
:
return
-
e
.
message
.
value
return
-
e
.
message
.
value
def
get_optimums_wrapper
(
data
,
count
,
p_evaluations
,
p_count
):
def
get_optimums_wrapper
(
tun
,
count
,
p_evaluations
,
p_count
):
try
:
try
:
data
=
ct
.
cast
(
data
,
ct
.
POINTER
(
ccs_user_defined_tuner_data
))
p_evals
=
ct
.
cast
(
p_evaluations
,
ct
.
c_void_p
)
p_evals
=
ct
.
cast
(
p_evaluations
,
ct
.
c_void_p
)
p_c
=
ct
.
cast
(
p_count
,
ct
.
c_void_p
)
p_c
=
ct
.
cast
(
p_count
,
ct
.
c_void_p
)
optimums
=
get_optimums
(
data
.
contents
)
optimums
=
get_optimums
(
Tuner
.
from_handle
(
tun
)
)
count_ret
=
len
(
optimums
)
count_ret
=
len
(
optimums
)
if
p_evals
.
value
is
not
None
and
count
<
count_ret
:
if
p_evals
.
value
is
not
None
and
count
<
count_ret
:
raise
Error
(
ccs_error
(
ccs_error
.
INVALID_VALUE
))
raise
Error
(
ccs_error
(
ccs_error
.
INVALID_VALUE
))
...
@@ -240,12 +231,11 @@ def _wrap_user_defined_callbacks(delete, ask, tell, get_optimums, get_history):
...
@@ -240,12 +231,11 @@ def _wrap_user_defined_callbacks(delete, ask, tell, get_optimums, get_history):
except
Error
as
e
:
except
Error
as
e
:
return
-
e
.
message
.
value
return
-
e
.
message
.
value
def
get_history_wrapper
(
data
,
count
,
p_evaluations
,
p_count
):
def
get_history_wrapper
(
tun
,
count
,
p_evaluations
,
p_count
):
try
:
try
:
data
=
ct
.
cast
(
data
,
ct
.
POINTER
(
ccs_user_defined_tuner_data
))
p_evals
=
ct
.
cast
(
p_evaluations
,
ct
.
c_void_p
)
p_evals
=
ct
.
cast
(
p_evaluations
,
ct
.
c_void_p
)
p_c
=
ct
.
cast
(
p_count
,
ct
.
c_void_p
)
p_c
=
ct
.
cast
(
p_count
,
ct
.
c_void_p
)
history
=
get_history
(
data
.
contents
)
history
=
get_history
(
Tuner
.
from_handle
(
tun
)
)
count_ret
=
len
(
history
)
count_ret
=
len
(
history
)
if
p_evals
.
value
is
not
None
and
count
<
count_ret
:
if
p_evals
.
value
is
not
None
and
count
<
count_ret
:
raise
Error
(
ccs_error
(
ccs_error
.
INVALID_VALUE
))
raise
Error
(
ccs_error
(
ccs_error
.
INVALID_VALUE
))
...
@@ -305,4 +295,14 @@ class UserDefinedTuner(Tuner):
...
@@ -305,4 +295,14 @@ class UserDefinedTuner(Tuner):
else
:
else
:
super
().
__init__
(
handle
=
handle
,
retain
=
retain
,
auto_release
=
auto_release
)
super
().
__init__
(
handle
=
handle
,
retain
=
retain
,
auto_release
=
auto_release
)
@
property
def
tuner_data
(
self
):
if
hasattr
(
self
,
"_tuner_data"
):
return
self
.
_tuner_data
v
=
ct
.
c_void_p
()
res
=
ccs_user_defined_tuner_get_tuner_data
(
self
.
handle
,
ct
.
byref
(
v
))
Error
.
check
(
res
)
self
.
_tuner_data
=
v
return
v
bindings/python/test/test_tuner.py
View file @
f87778b3
...
@@ -46,17 +46,17 @@ class TestTuner(unittest.TestCase):
...
@@ -46,17 +46,17 @@ class TestTuner(unittest.TestCase):
history
=
[]
history
=
[]
optimums
=
[]
optimums
=
[]
def
delete
(
data
):
def
delete
(
tuner
):
return
None
return
None
def
ask
(
data
,
count
):
def
ask
(
tuner
,
count
):
if
count
is
None
:
if
count
is
None
:
return
(
None
,
1
)
return
(
None
,
1
)
else
:
else
:
cs
=
ccs
.
ConfigurationSpace
.
from_handle
(
ccs
.
ccs_configuration_space
(
data
.
common_data
.
configuration_space
))
cs
=
tuner
.
configuration_space
return
(
cs
.
samples
(
count
),
count
)
return
(
cs
.
samples
(
count
),
count
)
def
tell
(
data
,
evaluations
):
def
tell
(
tuner
,
evaluations
):
nonlocal
history
nonlocal
history
nonlocal
optimums
nonlocal
optimums
history
+=
evaluations
history
+=
evaluations
...
@@ -78,10 +78,10 @@ class TestTuner(unittest.TestCase):
...
@@ -78,10 +78,10 @@ class TestTuner(unittest.TestCase):
optimums
=
new_optimums
optimums
=
new_optimums
return
None
return
None
def
get_history
(
data
):
def
get_history
(
tuner
):
return
history
return
history
def
get_optimums
(
data
):
def
get_optimums
(
tuner
):
return
optimums
return
optimums
(
cs
,
os
)
=
self
.
create_tuning_problem
()
(
cs
,
os
)
=
self
.
create_tuning_problem
()
...
...
bindings/ruby/lib/cconfigspace/tuner.rb
View file @
f87778b3
...
@@ -113,23 +113,11 @@ module CCS
...
@@ -113,23 +113,11 @@ module CCS
end
end
end
end
class
TunerCommonData
<
FFI
::
Struct
callback
:ccs_user_defined_tuner_del
,
[
:ccs_tuner_t
],
:ccs_result_t
layout
:type
,
:ccs_tuner_type_t
,
callback
:ccs_user_defined_tuner_ask
,
[
:ccs_tuner_t
,
:size_t
,
:pointer
,
:pointer
],
:ccs_result_t
:name
,
:string
,
callback
:ccs_user_defined_tuner_tell
,
[
:ccs_tuner_t
,
:size_t
,
:pointer
],
:ccs_result_t
:user_data
,
:pointer
,
callback
:ccs_user_defined_tuner_get_optimums
,
[
:ccs_tuner_t
,
:size_t
,
:pointer
,
:pointer
],
:ccs_result_t
:configuration_space
,
:ccs_configuration_space_t
,
callback
:ccs_user_defined_tuner_get_history
,
[
:ccs_tuner_t
,
:size_t
,
:pointer
,
:pointer
],
:ccs_result_t
:objective_space
,
:ccs_objective_space_t
end
typedef
TunerCommonData
.
by_value
,
:ccs_tuner_common_data_t
class
UserDefinedTunerData
<
FFI
::
Struct
end
callback
:ccs_user_defined_tuner_del
,
[
UserDefinedTunerData
.
by_ref
],
:ccs_result_t
callback
:ccs_user_defined_tuner_ask
,
[
UserDefinedTunerData
.
by_ref
,
:size_t
,
:pointer
,
:pointer
],
:ccs_result_t
callback
:ccs_user_defined_tuner_tell
,
[
UserDefinedTunerData
.
by_ref
,
:size_t
,
:pointer
],
:ccs_result_t
callback
:ccs_user_defined_tuner_get_optimums
,
[
UserDefinedTunerData
.
by_ref
,
:size_t
,
:pointer
,
:pointer
],
:ccs_result_t
callback
:ccs_user_defined_tuner_get_history
,
[
UserDefinedTunerData
.
by_ref
,
:size_t
,
:pointer
,
:pointer
],
:ccs_result_t
class
UserDefinedTunerVector
<
FFI
::
Struct
class
UserDefinedTunerVector
<
FFI
::
Struct
layout
:del
,
:ccs_user_defined_tuner_del
,
layout
:del
,
:ccs_user_defined_tuner_del
,
:ask
,
:ccs_user_defined_tuner_ask
,
:ask
,
:ccs_user_defined_tuner_ask
,
...
@@ -139,27 +127,19 @@ module CCS
...
@@ -139,27 +127,19 @@ module CCS
end
end
typedef
UserDefinedTunerVector
.
by_value
,
:ccs_user_defined_tuner_vector_t
typedef
UserDefinedTunerVector
.
by_value
,
:ccs_user_defined_tuner_vector_t
class
UserDefinedTunerData
layout
:common_data
,
:ccs_tuner_common_data_t
,
:vector
,
:ccs_user_defined_tuner_vector_t
,
:tuner_data
,
:pointer
end
typedef
UserDefinedTunerData
.
by_value
,
:ccs_user_defined_tuner_data_t
def
self
.
wrap_user_defined_callbacks
(
del
,
ask
,
tell
,
get_optimums
,
get_history
)
def
self
.
wrap_user_defined_callbacks
(
del
,
ask
,
tell
,
get_optimums
,
get_history
)
delwrapper
=
lambda
{
|
data
|
delwrapper
=
lambda
{
|
tun
|
begin
begin
del
.
call
(
data
)
del
.
call
(
CCS
::
Object
.
from_handle
(
tun
)
)
@@callbacks
.
delete
(
delwrapper
)
@@callbacks
.
delete
(
delwrapper
)
CCSError
.
to_native
(
:CCS_SUCCESS
)
CCSError
.
to_native
(
:CCS_SUCCESS
)
rescue
CCSError
=>
e
rescue
CCSError
=>
e
e
.
to_native
e
.
to_native
end
end
}
}
askwrapper
=
lambda
{
|
data
,
count
,
p_configurations
,
p_count
|
askwrapper
=
lambda
{
|
tun
,
count
,
p_configurations
,
p_count
|
begin
begin
configurations
,
count_ret
=
ask
.
call
(
data
,
p_configurations
.
null?
?
nil
:
count
)
configurations
,
count_ret
=
ask
.
call
(
Tuner
.
from_handle
(
tun
)
,
p_configurations
.
null?
?
nil
:
count
)
raise
CCSError
,
:CCS_INVALID_VALUE
if
!
p_configurations
.
null?
&&
count
<
count_ret
raise
CCSError
,
:CCS_INVALID_VALUE
if
!
p_configurations
.
null?
&&
count
<
count_ret
if
!
p_configurations
.
null?
if
!
p_configurations
.
null?
configurations
.
each_with_index
{
|
c
,
i
|
configurations
.
each_with_index
{
|
c
,
i
|
...
@@ -175,20 +155,20 @@ module CCS
...
@@ -175,20 +155,20 @@ module CCS
e
.
to_native
e
.
to_native
end
end
}
}
tellwrapper
=
lambda
{
|
data
,
count
,
p_evaluations
|
tellwrapper
=
lambda
{
|
tun
,
count
,
p_evaluations
|
begin
begin
if
count
>
0
if
count
>
0
evals
=
count
.
times
.
collect
{
|
i
|
Evaluation
::
from_handle
(
p_evaluations
.
get_pointer
(
i
*
8
))
}
evals
=
count
.
times
.
collect
{
|
i
|
Evaluation
::
from_handle
(
p_evaluations
.
get_pointer
(
i
*
8
))
}
tell
.
call
(
data
,
evals
)
tell
.
call
(
Tuner
.
from_handle
(
tun
)
,
evals
)
end
end
CCSError
.
to_native
(
:CCS_SUCCESS
)
CCSError
.
to_native
(
:CCS_SUCCESS
)
rescue
CCSError
=>
e
rescue
CCSError
=>
e
e
.
to_native
e
.
to_native
end
end
}
}
get_optimumswrapper
=
lambda
{
|
data
,
count
,
p_evaluations
,
p_count
|
get_optimumswrapper
=
lambda
{
|
tun
,
count
,
p_evaluations
,
p_count
|
begin
begin
optimums
=
get_optimums
.
call
(
data
)
optimums
=
get_optimums
.
call
(
Tuner
.
from_handle
(
tun
)
)
raise
CCSError
,
:CCS_INVALID_VALUE
if
!
p_evaluations
.
null?
&&
count
<
optimums
.
size
raise
CCSError
,
:CCS_INVALID_VALUE
if
!
p_evaluations
.
null?
&&
count
<
optimums
.
size
unless
p_evaluations
.
null?
unless
p_evaluations
.
null?
optimums
.
each_with_index
{
|
o
,
i
|
optimums
.
each_with_index
{
|
o
,
i
|
...
@@ -202,9 +182,9 @@ module CCS
...
@@ -202,9 +182,9 @@ module CCS
e
.
to_native
e
.
to_native
end
end
}
}
get_historywrapper
=
lambda
{
|
data
,
count
,
p_evaluations
,
p_count
|
get_historywrapper
=
lambda
{
|
tun
,
count
,
p_evaluations
,
p_count
|
begin
begin
history
=
get_history
.
call
(
data
)
history
=
get_history
.
call
(
Tuner
.
from_handle
(
tun
)
)
raise
CCSError
,
:CCS_INVALID_VALUE
if
!
p_evaluations
.
null?
&&
count
<
history
.
size
raise
CCSError
,
:CCS_INVALID_VALUE
if
!
p_evaluations
.
null?
&&
count
<
history
.
size
unless
p_evaluations
.
null?
unless
p_evaluations
.
null?
history
.
each_with_index
{
|
e
,
i
|
history
.
each_with_index
{
|
e
,
i
|
...
@@ -222,7 +202,9 @@ module CCS
...
@@ -222,7 +202,9 @@ module CCS
end
end
attach_function
:ccs_create_user_defined_tuner
,
[
:string
,
:ccs_configuration_space_t
,
:ccs_objective_space_t
,
:pointer
,
UserDefinedTunerVector
.
by_ref
,
:pointer
,
:pointer
],
:ccs_result_t
attach_function
:ccs_create_user_defined_tuner
,
[
:string
,
:ccs_configuration_space_t
,
:ccs_objective_space_t
,
:pointer
,
UserDefinedTunerVector
.
by_ref
,
:pointer
,
:pointer
],
:ccs_result_t
attach_function
:ccs_user_defined_tuner_get_tuner_data
,
[
:ccs_tuner_t
,
:pointer
],
:ccs_result_t
class
UserDefinedTuner
<
Tuner
class
UserDefinedTuner
<
Tuner
add_property
:tuner_data
,
:pointer
,
:ccs_user_defined_tuner_get_tuner_data
,
memoize:
true
class
<<
self
class
<<
self
attr_reader
:callbacks
attr_reader
:callbacks
end
end
...
...
bindings/ruby/test/test_tuner.rb
View file @
f87778b3
...
@@ -51,16 +51,16 @@ class CConfigSpaceTestTuner < Minitest::Test
...
@@ -51,16 +51,16 @@ class CConfigSpaceTestTuner < Minitest::Test
def
test_user_defined
def
test_user_defined
history
=
[]
history
=
[]
optimums
=
[]
optimums
=
[]
del
=
lambda
{
|
data
|
nil
}
del
=
lambda
{
|
tuner
|
nil
}
ask
=
lambda
{
|
data
,
count
|
ask
=
lambda
{
|
tuner
,
count
|
if
count
if
count
cs
=
CCS
::
ConfigurationSpace
::
from_handle
(
data
[
:common_data
][
:configuration_space
])
cs
=
tuner
.
configuration_space
[
cs
.
samples
(
count
),
count
]
[
cs
.
samples
(
count
),
count
]
else
else
[
nil
,
1
]
[
nil
,
1
]
end
end
}
}
tell
=
lambda
{
|
data
,
evaluations
|
tell
=
lambda
{
|
tuner
,
evaluations
|
history
+=
evaluations
history
+=
evaluations
evaluations
.
each
{
|
e
|
evaluations
.
each
{
|
e
|
discard
=
false
discard
=
false
...
@@ -82,10 +82,10 @@ class CConfigSpaceTestTuner < Minitest::Test
...
@@ -82,10 +82,10 @@ class CConfigSpaceTestTuner < Minitest::Test
optimums
.
push
(
e
)
unless
discard
optimums
.
push
(
e
)
unless
discard
}
}
}
}
get_history
=
lambda
{
|
data
|
get_history
=
lambda
{
|
tuner
|
history
history
}
}
get_optimums
=
lambda
{
|
data
|
get_optimums
=
lambda
{
|
tuner
|
optimums
optimums
}
}
cs
,
os
=
create_tuning_problem
cs
,
os
=
create_tuning_problem
...
...
include/cconfigspace/tuner.h
View file @
f87778b3
...
@@ -63,55 +63,35 @@ ccs_create_random_tuner(const char *name,
...
@@ -63,55 +63,35 @@ ccs_create_random_tuner(const char *name,
void
*
user_data
,
void
*
user_data
,
ccs_tuner_t
*
tuner_ret
);
ccs_tuner_t
*
tuner_ret
);
struct
ccs_tuner_common_data_s
{
ccs_tuner_type_t
type
;
const
char
*
name
;
void
*
user_data
;
ccs_configuration_space_t
configuration_space
;
ccs_objective_space_t
objective_space
;
};
typedef
struct
ccs_tuner_common_data_s
ccs_tuner_common_data_t
;
struct
ccs_user_defined_tuner_data_s
;
typedef
struct
ccs_user_defined_tuner_data_s
ccs_user_defined_tuner_data_t
;
struct
ccs_user_defined_tuner_vector_s
{
struct
ccs_user_defined_tuner_vector_s
{
ccs_result_t
(
*
del
)(
ccs_result_t
(
*
del
)(
ccs_
user_defined_tuner_data_t
*
data
);
ccs_
tuner_t
tuner
);
ccs_result_t
(
*
ask
)(
ccs_result_t
(
*
ask
)(
ccs_
user_defined_tuner_data_t
*
data
,
ccs_
tuner_t
tuner
,
size_t
num_configurations
,
size_t
num_configurations
,
ccs_configuration_t
*
configurations
,
ccs_configuration_t
*
configurations
,
size_t
*
num_configurations_ret
);
size_t
*
num_configurations_ret
);
ccs_result_t
(
*
tell
)(
ccs_result_t
(
*
tell
)(
ccs_
user_defined_tuner_data_t
*
data
,
ccs_
tuner_t
tuner
,
size_t
num_evaluations
,
size_t
num_evaluations
,
ccs_evaluation_t
*
evaluations
);
ccs_evaluation_t
*
evaluations
);
ccs_result_t
(
*
get_optimums
)(
ccs_result_t
(
*
get_optimums
)(
ccs_
user_defined_tuner_data_t
*
data
,
ccs_
tuner_t
tuner
,
size_t
num_evaluations
,
size_t
num_evaluations
,
ccs_evaluation_t
*
evaluations
,
ccs_evaluation_t
*
evaluations
,
size_t
*
num_evaluations_ret
);
size_t
*
num_evaluations_ret
);
ccs_result_t
(
*
get_history
)(
ccs_result_t
(
*
get_history
)(
ccs_
user_defined_tuner_data_t
*
data
,
ccs_
tuner_t
tuner
,
size_t
num_evaluations
,
size_t
num_evaluations
,
ccs_evaluation_t
*
evaluations
,
ccs_evaluation_t
*
evaluations
,
size_t
*
num_evaluations_ret
);
size_t
*
num_evaluations_ret
);
};
};
typedef
struct
ccs_user_defined_tuner_vector_s
ccs_user_defined_tuner_vector_t
;
typedef
struct
ccs_user_defined_tuner_vector_s
ccs_user_defined_tuner_vector_t
;
struct
ccs_user_defined_tuner_data_s
{
ccs_tuner_common_data_t
common_data
;
ccs_user_defined_tuner_vector_t
vector
;
void
*
tuner_data
;
};
extern
ccs_result_t
extern
ccs_result_t
ccs_create_user_defined_tuner
(
const
char
*
name
,
ccs_create_user_defined_tuner
(
const
char
*
name
,
ccs_configuration_space_t
configuration_space
,
ccs_configuration_space_t
configuration_space
,
...
@@ -121,6 +101,9 @@ ccs_create_user_defined_tuner(const char *name,
...
@@ -121,6 +101,9 @@ ccs_create_user_defined_tuner(const char *name,
void
*
tuner_data
,
void
*
tuner_data
,
ccs_tuner_t
*
tuner_ret
);
ccs_tuner_t
*
tuner_ret
);
extern
ccs_result_t
ccs_user_defined_tuner_get_tuner_data
(
ccs_tuner_t
tuner
,
void
**
tuner_data_ret
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
samples/test_python.py
View file @
f87778b3
...
@@ -11,17 +11,17 @@ class TestTuner(ccs.UserDefinedTuner):
...
@@ -11,17 +11,17 @@ class TestTuner(ccs.UserDefinedTuner):
self
.
__history
=
[]
self
.
__history
=
[]
self
.
__optimums
=
[]
self
.
__optimums
=
[]
def
delete
(
data
):
def
delete
(
tuner
):
return
None
return
None
def
ask
(
data
,
count
):
def
ask
(
tuner
,
count
):
if
count
is
None
:
if
count
is
None
:
return
(
None
,
1
)
return
(
None
,
1
)
else
:
else
:
cs
=
ccs
.
ConfigurationSpace
.
from_handle
(
ccs
.
ccs_configuration_space
(
data
.
common_data
.
configuration_space
))
cs
=
tuner
.
configuration_space
return
(
cs
.
samples
(
count
),
count
)
return
(
cs
.
samples
(
count
),
count
)
def
tell
(
data
,
evaluations
):
def
tell
(
tuner
,
evaluations
):
self
.
__history
+=
evaluations
self
.
__history
+=
evaluations
for
e
in
evaluations
:
for
e
in
evaluations
:
discard
=
False
discard
=
False
...
@@ -41,10 +41,10 @@ class TestTuner(ccs.UserDefinedTuner):
...
@@ -41,10 +41,10 @@ class TestTuner(ccs.UserDefinedTuner):
self
.
__optimums
=
new_optimums
self
.
__optimums
=
new_optimums
return
None
return
None
def
get_history
(
data
):
def
get_history
(
tuner
):
return
self
.
__history
return
self
.
__history
def
get_optimums
(
data
):
def
get_optimums
(
tuner
):
return
self
.
__optimums
return
self
.
__optimums
super
().
__init__
(
name
=
"tuner"
,
configuration_space
=
cs
,
objective_space
=
os
,
delete
=
delete
,
ask
=
ask
,
tell
=
tell
,
get_optimums
=
get_optimums
,
get_history
=
get_history
)
super
().
__init__
(
name
=
"tuner"
,
configuration_space
=
cs
,
objective_space
=
os
,
delete
=
delete
,
ask
=
ask
,
tell
=
tell
,
get_optimums
=
get_optimums
,
get_history
=
get_history
)
...
...
samples/test_python_from_ruby.rb
View file @
f87778b3
ENV
[
"PYTHONPATH"
]
=
"./
:"
+
ENV
[
"PYTHONPATH"
]
ENV
[
"PYTHONPATH"
]
=
"./
"
+
(
ENV
[
"PYTHONPATH"
]
?
":"
+
ENV
[
"PYTHONPATH"
]
:
""
)
require
'rubygems'
require
'rubygems'
require_relative
'../bindings/ruby/lib/cconfigspace'
require_relative
'../bindings/ruby/lib/cconfigspace'
...
...
samples/test_ruby.rb
View file @
f87778b3
...
@@ -5,16 +5,16 @@ class TestTuner < CCS::UserDefinedTuner
...
@@ -5,16 +5,16 @@ class TestTuner < CCS::UserDefinedTuner
def
initialize
(
cs
,
os
)
def
initialize
(
cs
,
os
)
@history
=
[]
@history
=
[]
@optimums
=
[]
@optimums
=
[]
del
=
lambda
{
|
data
|
nil
}
del
=
lambda
{
|
tuner
|
nil
}
ask
=
lambda
{
|
data
,
count
|
ask
=
lambda
{
|
tuner
,
count
|
if
count
if
count
cs
=
CCS
::
ConfigurationSpace
::
from_handle
(
data
[
:common_data
][
:configuration_space
])
cs
=
tuner
.
configuration_space
[
cs
.
samples
(
count
),
count
]
[
cs
.
samples
(
count
),
count
]
else
else
[
nil
,
1
]
[
nil
,
1
]
end
end
}
}
tell
=
lambda
{
|
data
,
evaluations
|
tell
=
lambda
{
|
tuner
,
evaluations
|
@history
+=
evaluations
@history
+=
evaluations
evaluations
.
each
{
|
e
|
evaluations
.
each
{
|
e
|
discard
=
false
discard
=
false
...
@@ -36,10 +36,10 @@ class TestTuner < CCS::UserDefinedTuner
...
@@ -36,10 +36,10 @@ class TestTuner < CCS::UserDefinedTuner
@optimums
.
push
(
e
)
unless
discard
@optimums
.
push
(
e
)
unless
discard
}
}
}
}
get_history
=
lambda
{
|
data
|
get_history
=
lambda
{
|
tuner
|
@history
@history
}
}
get_optimums
=
lambda
{
|
data
|
get_optimums
=
lambda
{
|
tuner
|
@optimums
@optimums
}
}
super
(
name:
"tuner"
,
configuration_space:
cs
,
objective_space:
os
,
del:
del
,
ask:
ask
,
tell:
tell
,
get_optimums:
get_optimums
,
get_history:
get_history
)
super
(
name:
"tuner"
,
configuration_space:
cs
,
objective_space:
os
,
del:
del
,
ask:
ask
,
tell:
tell
,
get_optimums:
get_optimums
,
get_history:
get_history
)
...
...
src/tuner.c
View file @
f87778b3
...
@@ -11,7 +11,7 @@ ccs_tuner_get_type(ccs_tuner_t tuner,
...
@@ -11,7 +11,7 @@ ccs_tuner_get_type(ccs_tuner_t tuner,
ccs_tuner_type_t
*
type_ret
)
{
ccs_tuner_type_t
*
type_ret
)
{
CCS_CHECK_OBJ
(
tuner
,
CCS_TUNER
);
CCS_CHECK_OBJ
(
tuner
,
CCS_TUNER
);
CCS_CHECK_PTR
(
type_ret
);
CCS_CHECK_PTR
(
type_ret
);
ccs_tuner_common_data_t
*
d
=
(
ccs_tuner_common_data_t
*
)
tuner
->
data
;
_ccs_tuner_common_data_t
*
d
=
(
_
ccs_tuner_common_data_t
*
)
tuner
->
data
;
*
type_ret
=
d
->
type
;
*
type_ret
=
d
->
type
;
return
CCS_SUCCESS
;
return
CCS_SUCCESS
;
}
}
...
@@ -21,7 +21,7 @@ ccs_tuner_get_name(ccs_tuner_t tuner,
...
@@ -21,7 +21,7 @@ ccs_tuner_get_name(ccs_tuner_t tuner,
const
char
**
name_ret
)
{
const
char
**
name_ret
)
{
CCS_CHECK_OBJ
(
tuner
,
CCS_TUNER
);
CCS_CHECK_OBJ
(
tuner
,
CCS_TUNER
);
CCS_CHECK_PTR
(
name_ret
);
CCS_CHECK_PTR
(
name_ret
);
ccs_tuner_common_data_t
*
d
=
(
ccs_tuner_common_data_t
*
)
tuner
->
data
;
_ccs_tuner_common_data_t
*
d
=
(
_
ccs_tuner_common_data_t
*
)
tuner
->
data
;
*
name_ret
=
d
->
name
;
*
name_ret
=
d
->
name
;
return
CCS_SUCCESS
;
return
CCS_SUCCESS
;
}
}
...
@@ -31,7 +31,7 @@ ccs_tuner_get_user_data(ccs_tuner_t tuner,
...
@@ -31,7 +31,7 @@ ccs_tuner_get_user_data(ccs_tuner_t tuner,
void
**
user_data_ret
)
{
void
**
user_data_ret
)
{
CCS_CHECK_OBJ
(
tuner
,
CCS_TUNER
);
CCS_CHECK_OBJ
(
tuner
,
CCS_TUNER
);
CCS_CHECK_PTR
(
user_data_ret
);
CCS_CHECK_PTR
(
user_data_ret
);
ccs_tuner_common_data_t
*
d
=
(
ccs_tuner_common_data_t
*
)
tuner
->
data
;
_ccs_tuner_common_data_t
*
d
=
(
_
ccs_tuner_common_data_t
*
)
tuner
->
data
;
*
user_data_ret
=
d
->
user_data
;
*
user_data_ret
=
d
->
user_data
;
return
CCS_SUCCESS
;
return
CCS_SUCCESS
;
}
}
...
@@ -41,7 +41,7 @@ ccs_tuner_get_configuration_space(ccs_tuner_t tuner,
...
@@ -41,7 +41,7 @@ ccs_tuner_get_configuration_space(ccs_tuner_t tuner,
ccs_configuration_space_t
*
configuration_space_ret
)
{
ccs_configuration_space_t
*
configuration_space_ret
)
{
CCS_CHECK_OBJ
(
tuner
,
CCS_TUNER
);
CCS_CHECK_OBJ
(
tuner
,
CCS_TUNER
);
CCS_CHECK_PTR
(
configuration_space_ret
);
CCS_CHECK_PTR
(
configuration_space_ret
);
ccs_tuner_common_data_t
*
d
=
(
ccs_tuner_common_data_t
*
)
tuner
->
data
;
_ccs_tuner_common_data_t
*
d
=
(
_
ccs_tuner_common_data_t
*
)
tuner
->
data
;
*
configuration_space_ret
=
d
->
configuration_space
;
*
configuration_space_ret
=
d
->
configuration_space
;
return
CCS_SUCCESS
;
return
CCS_SUCCESS
;
}
}
...
@@ -51,7 +51,7 @@ ccs_tuner_get_objective_space(ccs_tuner_t tuner,
...
@@ -51,7 +51,7 @@ ccs_tuner_get_objective_space(ccs_tuner_t tuner,
ccs_objective_space_t
*
objective_space_ret
)
{
ccs_objective_space_t
*
objective_space_ret
)
{
CCS_CHECK_OBJ
(
tuner
,
CCS_TUNER
);
CCS_CHECK_OBJ
(
tuner
,
CCS_TUNER
);
CCS_CHECK_PTR
(
objective_space_ret
);
CCS_CHECK_PTR
(
objective_space_ret
);
ccs_tuner_common_data_t
*
d
=
(
ccs_tuner_common_data_t
*
)
tuner
->
data
;
_ccs_tuner_common_data_t
*
d
=
(
_
ccs_tuner_common_data_t
*
)
tuner
->
data
;
*
objective_space_ret
=
d
->
objective_space
;
*
objective_space_ret
=
d
->
objective_space
;
return
CCS_SUCCESS
;
return
CCS_SUCCESS
;
}
}
...
...
src/tuner_internal.h
View file @
f87778b3
...
@@ -37,4 +37,13 @@ struct _ccs_tuner_s {
...
@@ -37,4 +37,13 @@ struct _ccs_tuner_s {
_ccs_tuner_data_t
*
data
;
_ccs_tuner_data_t
*
data
;
};
};
struct
_ccs_tuner_common_data_s
{
ccs_tuner_type_t
type
;
const
char
*
name
;
void
*
user_data
;
ccs_configuration_space_t
configuration_space
;
ccs_objective_space_t
objective_space
;
};