提交 aa147b74 编写于 作者: M Megvii Engine Team

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

GitOrigin-RevId: 5dde1b4e81a841c588f6e8d82bbdd35fc6cf7fb1
上级 1e576e32
......@@ -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})
......
......@@ -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();
}
......
......@@ -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
......
......@@ -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 (; ; ) {
......
......@@ -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,
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册