Browse Source

fix(osx/python_module): fix build python module on osx

GitOrigin-RevId: 5dde1b4e81
tags/v0.6.0
Megvii Engine Team 5 years ago
parent
commit
aa147b7426
6 changed files with 31 additions and 7 deletions
  1. +10
    -2
      python_module/CMakeLists.txt
  2. +2
    -2
      python_module/src/cpp/megbrain_wrap.cpp
  3. +1
    -1
      python_module/src/cpp/megbrain_wrap.h
  4. +7
    -0
      python_module/src/cpp/plugin.cpp
  5. +1
    -1
      python_module/src/swig/comp_node.i
  6. +10
    -1
      python_module/src/swig/mgb.i

+ 10
- 2
python_module/CMakeLists.txt View File

@@ -11,7 +11,11 @@ find_package(NumPy REQUIRED)

find_package(SWIG REQUIRED)
set(SWIG_SRC src/swig/mgb.i)
set(CMAKE_SWIG_FLAGS -Wall -threads -py3 -modern -DSWIGWORDSIZE64)
if (APPLE)
set(CMAKE_SWIG_FLAGS -Wall -threads -py3 -modern)
else()
set(CMAKE_SWIG_FLAGS -Wall -threads -py3 -modern -DSWIGWORDSIZE64)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")

file(GLOB_RECURSE OPR_DECL_SRCS "${PROJECT_SOURCE_DIR}/src/**/*.oprdecl")
@@ -66,7 +70,11 @@ set(VERSION_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/src/version.ld)
add_custom_target(version_ld SOURCES ${VERSION_SCRIPT})

set_target_properties(mgb PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/megengine/_internal)
target_link_libraries(mgb megbrain megdnn -Wl,--version-script=${VERSION_SCRIPT})
if (APPLE)
target_link_libraries(mgb megbrain megdnn)
else()
target_link_libraries(mgb megbrain megdnn -Wl,--version-script=${VERSION_SCRIPT})
endif()
target_include_directories(mgb PRIVATE ${PYTHON_INCLUDE_DIRS} src/cpp ${CMAKE_CURRENT_BINARY_DIR} ${NUMPY_INCLUDE_DIR})
target_link_libraries(mgb ${PYTHON_LIBRARIES})



+ 2
- 2
python_module/src/cpp/megbrain_wrap.cpp View File

@@ -404,7 +404,7 @@ void CompGraphCallbackValueProxy::do_copy() {
m_copy_event->record();
}

void CompGraphCallbackValueProxy::sync() {
void CompGraphCallbackValueProxy::sync() const {
mgb_assert(!m_use_raw_hv);
RealTimer t0;
double next_warn_time = 2, warn_time_delta = 1;
@@ -516,7 +516,7 @@ class AsyncExec::Core {

class Worker final: public AsyncQueueSC<CallbackParam, Worker> {
public:
void process_one_task(CallbackParam &task) {
void process_one_task(const CallbackParam &task) {
for (auto &tmp_value: task.value) {
tmp_value.sync();
}


+ 1
- 1
python_module/src/cpp/megbrain_wrap.h View File

@@ -214,7 +214,7 @@ class CompGraphCallbackValueProxy {
}

void setup(const mgb::DeviceTensorND &val, bool eager_copy);
void sync();
void sync() const;

/*!
* \brief called after python callback returned


+ 7
- 0
python_module/src/cpp/plugin.cpp View File

@@ -76,8 +76,15 @@ class _FastSignal::Impl {
std::unordered_map<int, HandlerCallback> m_handler_callbacks;

void worker() {
#ifdef __APPLE__
uint64_t tid;
pthread_threadid_np(NULL, &tid);
mgb_log("fast signal worker started in thread 0x%zx",
static_cast<size_t>(tid));
#else
mgb_log("fast signal worker started in thread 0x%zx",
static_cast<size_t>(pthread_self()));
#endif
mgb::sys::set_thread_name("fastsgl");
int signum;
for (; ; ) {


+ 1
- 1
python_module/src/swig/comp_node.i View File

@@ -28,7 +28,7 @@ class CompNode {
static CompNode load(const char* id);

%extend {
static std::vector<int> _parse_locator(const std::string &id) const {
static std::vector<int> _parse_locator(const std::string &id) {
auto logi = CompNode::Locator::parse(id);
return {
static_cast<int>(logi.type), logi.device, logi.stream,


+ 10
- 1
python_module/src/swig/mgb.i View File

@@ -31,7 +31,16 @@ void _init_bfloat16_types(PyObject *m); // implemented in bfloat16.cpp
%template(_VectorString) std::vector<std::string>;
%template(_PairStringSizeT) std::pair<std::string, size_t>;
%template(_PairSizeTSizeT) std::pair<size_t, size_t>;
%template(_VectorPairUint64String) std::vector<std::pair<uint64_t, std::string>>;
/*
*
* real define uint64_t here, BUT, do not define SWIGWORDSIZE64
* at osx env, at this time uint64_t means unsigned long long,
* BUT, unsigned long long do not have type_name() method at c++,
* when define SWIGWORDSIZE64 at linux env, uint64_t means
* unsigned long int, more detail refs stdint.i
*
*/
%template(_VectorPairUint64String) std::vector<std::pair<unsigned long int, std::string>>;

%pythoncode %{
import numpy as np


Loading…
Cancel
Save