Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
py-bake
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
sds
py-bake
Commits
84e2ce9b
Commit
84e2ce9b
authored
Jun 04, 2018
by
Matthieu Dorier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved from boost.python to pybind11
parent
e42fea37
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
178 additions
and
188 deletions
+178
-188
pybake/server.py
pybake/server.py
+1
-0
pybake/src/client.cpp
pybake/src/client.cpp
+122
-116
pybake/src/server.cpp
pybake/src/server.cpp
+34
-39
pybake/src/target.cpp
pybake/src/target.cpp
+20
-25
setup.py
setup.py
+0
-7
test/server.py
test/server.py
+1
-1
No files found.
pybake/server.py
View file @
84e2ce9b
# (C) 2018 The University of Chicago
# See COPYRIGHT in top-level directory.
import
_pybaketarget
import
_pybakeserver
import
pymargo
from
pybake.target
import
BakeTargetID
...
...
pybake/src/client.cpp
View file @
84e2ce9b
This diff is collapsed.
Click to expand it.
pybake/src/server.cpp
View file @
84e2ce9b
...
...
@@ -3,14 +3,7 @@
*
* See COPYRIGHT in top-level directory.
*/
#define BOOST_NO_AUTO_PTR
#include <boost/python.hpp>
#include <boost/python/return_opaque_pointer.hpp>
#include <boost/python/handle.hpp>
#include <boost/python/enum.hpp>
#include <boost/python/def.hpp>
#include <boost/python/module.hpp>
#include <boost/python/return_value_policy.hpp>
#include <pybind11/pybind11.h>
#include <string>
#include <vector>
#include <cstring>
...
...
@@ -19,59 +12,66 @@
#include <bake.h>
#include <bake-server.h>
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID
(
margo_instance
)
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID
(
bake_server_context_t
)
namespace
py11
=
pybind11
;
namespace
bpl
=
boost
::
python
;
typedef
py11
::
capsule
pymargo_instance_id
;
typedef
py11
::
capsule
pymargo_addr
;
typedef
py11
::
capsule
pybake_provider_t
;
static
bake_provider_t
pybake_provider_register
(
margo_instance_id
mid
,
uint8_t
provider_id
)
{
#define MID2CAPSULE(__mid) py11::capsule((void*)(__mid), "margo_instance_id", nullptr)
#define ADDR2CAPSULE(__addr) py11::capsule((void*)(__addr), "hg_addr_t", nullptr)
#define BAKEPR2CAPSULE(__bpr) py11::capsule((void*)(__bpr), "bake_provider_t", nullptr)
static
pybake_provider_t
pybake_provider_register
(
pymargo_instance_id
mid
,
uint8_t
provider_id
)
{
bake_provider_t
provider
;
int
ret
=
bake_provider_register
(
mid
,
provider_id
,
BAKE_ABT_POOL_DEFAULT
,
&
provider
);
if
(
ret
!=
0
)
return
NULL
;
else
return
provider
;
if
(
ret
!=
0
)
return
py11
::
none
()
;
else
return
BAKEPR2CAPSULE
(
provider
)
;
}
static
bpl
::
object
pybake_provider_add_storage_target
(
bake_provider_t
provider
,
static
py11
::
object
pybake_provider_add_storage_target
(
py
bake_provider_t
provider
,
const
std
::
string
&
target_name
)
{
bake_target_id_t
target_id
;
std
::
memset
(
&
target_id
,
0
,
sizeof
(
target_id
));
int
ret
=
bake_provider_add_storage_target
(
provider
,
target_name
.
c_str
(),
&
target_id
);
if
(
ret
!=
0
)
return
bpl
::
object
();
return
bpl
::
object
(
target_id
);
if
(
ret
!=
0
)
{
return
py11
::
none
();
}
return
py11
::
cast
(
target_id
);
}
static
bool
pybake_provider_remove_storage_target
(
bake_provider_t
provider
,
py
bake_provider_t
provider
,
bake_target_id_t
target_id
)
{
return
0
==
bake_provider_remove_storage_target
(
provider
,
target_id
);
}
static
bool
pybake_provider_remove_all_storage_targets
(
bake_provider_t
provider
)
py
bake_provider_t
provider
)
{
return
0
==
bake_provider_remove_all_storage_targets
(
provider
);
}
static
uint64_t
pybake_provider_count_storage_targets
(
bake_provider_t
provider
)
py
bake_provider_t
provider
)
{
uint64_t
n
=
0
;
bake_provider_count_storage_targets
(
provider
,
&
n
);
return
n
;
}
static
bpl
::
list
pybake_provider_list_storage_targets
(
bake_provider_t
provider
)
static
py11
::
list
pybake_provider_list_storage_targets
(
py
bake_provider_t
provider
)
{
std
::
vector
<
bake_target_id_t
>
result
;
uint64_t
n
=
pybake_provider_count_storage_targets
(
provider
);
if
(
n
==
0
)
return
bpl
::
list
();
if
(
n
==
0
)
return
py11
::
list
();
result
.
resize
(
n
);
bake_provider_list_storage_targets
(
provider
,
result
.
data
());
bpl
::
list
list_result
;
py11
::
list
list_result
;
for
(
const
auto
&
t
:
result
)
list_result
.
append
(
t
);
return
list_result
;
}
...
...
@@ -81,19 +81,14 @@ static bool pybake_make_pool(const std::string& pool_name,
return
0
==
bake_makepool
(
pool_name
.
c_str
(),
pool_size
,
mode
);
}
BOOST_PYTHON_MODULE
(
_pybakeserver
)
PYBIND11_MODULE
(
_pybakeserver
,
m
)
{
#define ret_policy_opaque bpl::return_value_policy<bpl::return_opaque_pointer>()
bpl
::
import
(
"_pybaketarget"
);
bpl
::
opaque
<
bake_server_context_t
>
();
bpl
::
def
(
"register"
,
&
pybake_provider_register
,
ret_policy_opaque
);
bpl
::
def
(
"add_storage_target"
,
&
pybake_provider_add_storage_target
);
bpl
::
def
(
"remove_storage_target"
,
&
pybake_provider_remove_storage_target
);
bpl
::
def
(
"remove_all_storage_targets"
,
&
pybake_provider_remove_all_storage_targets
);
bpl
::
def
(
"count_storage_targets"
,
&
pybake_provider_count_storage_targets
);
bpl
::
def
(
"list_storage_targets"
,
&
pybake_provider_list_storage_targets
);
bpl
::
def
(
"make_pool"
,
&
pybake_make_pool
);
#undef ret_policy_opaque
py11
::
module
::
import
(
"_pybaketarget"
);
m
.
def
(
"register"
,
&
pybake_provider_register
);
m
.
def
(
"add_storage_target"
,
&
pybake_provider_add_storage_target
);
m
.
def
(
"remove_storage_target"
,
&
pybake_provider_remove_storage_target
);
m
.
def
(
"remove_all_storage_targets"
,
&
pybake_provider_remove_all_storage_targets
);
m
.
def
(
"count_storage_targets"
,
&
pybake_provider_count_storage_targets
);
m
.
def
(
"list_storage_targets"
,
&
pybake_provider_list_storage_targets
);
m
.
def
(
"make_pool"
,
&
pybake_make_pool
);
}
pybake/src/target.cpp
View file @
84e2ce9b
...
...
@@ -3,14 +3,7 @@
*
* See COPYRIGHT in top-level directory.
*/
#define BOOST_NO_AUTO_PTR
#include <boost/python.hpp>
#include <boost/python/return_opaque_pointer.hpp>
#include <boost/python/handle.hpp>
#include <boost/python/enum.hpp>
#include <boost/python/def.hpp>
#include <boost/python/module.hpp>
#include <boost/python/return_value_policy.hpp>
#include <pybind11/pybind11.h>
#include <string>
#include <vector>
#include <cstring>
...
...
@@ -19,43 +12,45 @@
#include <bake.h>
#include <bake-server.h>
namespace
bpl
=
boost
::
python
;
namespace
py11
=
pybind11
;
static
std
::
string
pybake_target_id_to_string
(
bake_target_id_t
tid
)
{
static
py11
::
bytes
pybake_target_id_to_string
(
bake_target_id_t
tid
)
{
char
id
[
37
];
uuid_unparse
(
tid
.
id
,
id
);
return
std
::
string
(
id
);
return
py11
::
bytes
(
std
::
string
(
id
)
);
}
static
bpl
::
object
pybake_target_id_from_string
(
const
std
::
string
&
tidstr
)
{
static
py11
::
object
pybake_target_id_from_string
(
const
py11
::
bytes
&
b
tidstr
)
{
bake_target_id_t
tid
;
memset
(
tid
.
id
,
0
,
sizeof
(
uuid_t
));
if
(
tidstr
.
size
()
!=
36
)
return
bpl
::
object
();
std
::
string
tidstr
=
(
std
::
string
)
btidstr
;
if
(
tidstr
.
size
()
!=
36
)
return
py11
::
none
();
int
ret
=
uuid_parse
((
char
*
)
tidstr
.
c_str
(),
tid
.
id
);
if
(
ret
==
0
)
return
bpl
::
objec
t
(
tid
);
else
return
bpl
::
object
();
if
(
ret
==
0
)
return
py11
::
cas
t
(
tid
);
else
return
py11
::
none
();
}
static
std
::
string
pybake_region_id_to_string
(
const
bake_region_id_t
&
region_id
)
{
static
py11
::
bytes
pybake_region_id_to_string
(
const
bake_region_id_t
&
region_id
)
{
std
::
string
result
((
const
char
*
)(
&
region_id
),
sizeof
(
region_id
));
return
result
;
return
py11
::
bytes
(
result
)
;
}
static
bpl
::
object
pybake_region_id_from_string
(
const
std
::
string
&
region_str
)
{
static
py11
::
object
pybake_region_id_from_string
(
const
py11
::
bytes
&
b
region_str
)
{
bake_region_id_t
result
;
std
::
string
region_str
=
(
std
::
string
)
bregion_str
;
memset
(
&
result
,
0
,
sizeof
(
result
));
if
(
region_str
.
size
()
!=
sizeof
(
bake_region_id_t
))
return
bpl
::
object
();
return
py11
::
none
();
memcpy
(
&
result
,
region_str
.
data
(),
sizeof
(
bake_region_id_t
));
return
bpl
::
objec
t
(
result
);
return
py11
::
cas
t
(
result
);
}
BOOST_PYTHON_MODULE
(
_pybaketarget
)
PYBIND11_MODULE
(
_pybaketarget
,
m
)
{
bpl
::
class_
<
bake_target_id_t
>
(
"bake_target_id"
,
bpl
::
no_init
)
py11
::
class_
<
bake_target_id_t
>
(
m
,
"bake_target_id"
)
.
def
(
"__str__"
,
pybake_target_id_to_string
);
bpl
::
def
(
"target_id_from_string"
,
pybake_target_id_from_string
);
bpl
::
class_
<
bake_region_id_t
>
(
"bake_region_id"
,
bpl
::
no_init
)
m
.
def
(
"target_id_from_string"
,
pybake_target_id_from_string
);
py11
::
class_
<
bake_region_id_t
>
(
m
,
"bake_region_id"
)
.
def
(
"__str__"
,
pybake_region_id_to_string
);
bpl
::
def
(
"region_id_from_string"
,
pybake_region_id_from_string
);
m
.
def
(
"region_id_from_string"
,
pybake_region_id_from_string
);
}
setup.py
View file @
84e2ce9b
...
...
@@ -10,8 +10,6 @@ import sys
os
.
environ
[
'OPT'
]
=
" "
.
join
(
flag
for
flag
in
opt
.
split
()
if
flag
!=
'-Wstrict-prototypes'
)
python_version
=
str
(
sys
.
version_info
[
0
])
+
str
(
sys
.
version_info
[
1
])
# Find out if Numpy is present
try
:
import
numpy
...
...
@@ -23,23 +21,18 @@ except ImportError:
# For client...
pk
=
pkgconfig
.
parse
(
'bake-client'
)
client_libraries
=
pk
[
'libraries'
]
client_libraries
.
append
(
'boost_python'
+
python_version
)
if
(
has_numpy
==
1
):
client_libraries
.
append
(
'boost_numpy'
+
python_version
)
client_library_dirs
=
pk
[
'library_dirs'
]
client_include_dirs
=
pk
[
'include_dirs'
]
client_include_dirs
.
append
(
"."
)
# For server...
pk
=
pkgconfig
.
parse
(
'bake-server'
)
server_libraries
=
pk
[
'libraries'
]
server_libraries
.
append
(
'boost_python'
+
python_version
)
server_library_dirs
=
pk
[
'library_dirs'
]
server_include_dirs
=
pk
[
'include_dirs'
]
server_include_dirs
.
append
(
"."
)
# For target...
pk
=
pkgconfig
.
parse
(
'uuid'
)
target_libraries
=
pk
[
'libraries'
]
target_libraries
.
append
(
'boost_python'
+
python_version
)
target_library_dirs
=
pk
[
'library_dirs'
]
target_include_dirs
=
pk
[
'include_dirs'
]
target_include_dirs
.
append
(
'.'
)
...
...
test/server.py
View file @
84e2ce9b
...
...
@@ -8,7 +8,7 @@ from pybake.server import BakeProvider
mid
=
MargoInstance
(
'tcp'
)
mid
.
enable_remote_shutdown
()
mplex_id
=
42
print
"Server running at address "
+
str
(
mid
.
addr
())
+
"with mplex_id="
+
str
(
mplex_id
)
print
"Server running at address "
+
str
(
mid
.
addr
())
+
"
with mplex_id="
+
str
(
mplex_id
)
provider
=
BakeProvider
(
mid
,
mplex_id
)
target
=
provider
.
add_storage_target
(
"/dev/shm/baketarget"
)
...
...
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