diff --git a/python_module/CMakeLists.txt b/python_module/CMakeLists.txt index 3d9dbecb8ab09cf28f1538e748a6ab2cef4a3d7a..1a46edf5e23914d17bba1f27b41a7e2f52fc4f06 100644 --- a/python_module/CMakeLists.txt +++ b/python_module/CMakeLists.txt @@ -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}) diff --git a/python_module/src/cpp/megbrain_wrap.cpp b/python_module/src/cpp/megbrain_wrap.cpp index 61795deccbaa67d8f7b6ea4834cbb302bccfb050..9f9becf0f8b973eff3e750bdcae7a2c770243aeb 100644 --- a/python_module/src/cpp/megbrain_wrap.cpp +++ b/python_module/src/cpp/megbrain_wrap.cpp @@ -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 { public: - void process_one_task(CallbackParam &task) { + void process_one_task(const CallbackParam &task) { for (auto &tmp_value: task.value) { tmp_value.sync(); } diff --git a/python_module/src/cpp/megbrain_wrap.h b/python_module/src/cpp/megbrain_wrap.h index e1484e4e14e37af6c3b256c4f01b18ddd264711c..106457ee8ebad55675d780c9631aa56c46c63112 100644 --- a/python_module/src/cpp/megbrain_wrap.h +++ b/python_module/src/cpp/megbrain_wrap.h @@ -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 diff --git a/python_module/src/cpp/plugin.cpp b/python_module/src/cpp/plugin.cpp index 389bf791e371abf40c2657189f948d3d5b6086bb..c997d75f7deb7bb195a3618018b2d56f36328f44 100644 --- a/python_module/src/cpp/plugin.cpp +++ b/python_module/src/cpp/plugin.cpp @@ -76,8 +76,15 @@ class _FastSignal::Impl { std::unordered_map 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(tid)); +#else mgb_log("fast signal worker started in thread 0x%zx", static_cast(pthread_self())); +#endif mgb::sys::set_thread_name("fastsgl"); int signum; for (; ; ) { diff --git a/python_module/src/swig/comp_node.i b/python_module/src/swig/comp_node.i index eb10bc2a023c13e2989961d8f6534d87297e9603..708cd34ff82d2f818a6dc184a6974e478fe874e7 100644 --- a/python_module/src/swig/comp_node.i +++ b/python_module/src/swig/comp_node.i @@ -28,7 +28,7 @@ class CompNode { static CompNode load(const char* id); %extend { - static std::vector _parse_locator(const std::string &id) const { + static std::vector _parse_locator(const std::string &id) { auto logi = CompNode::Locator::parse(id); return { static_cast(logi.type), logi.device, logi.stream, diff --git a/python_module/src/swig/mgb.i b/python_module/src/swig/mgb.i index c9c2a950117afc2d88b6ba429e8ab637587ce691..b8bdf5e02ca4d594a2d2a1373c94799c263ddea6 100644 --- a/python_module/src/swig/mgb.i +++ b/python_module/src/swig/mgb.i @@ -31,7 +31,16 @@ void _init_bfloat16_types(PyObject *m); // implemented in bfloat16.cpp %template(_VectorString) std::vector; %template(_PairStringSizeT) std::pair; %template(_PairSizeTSizeT) std::pair; -%template(_VectorPairUint64String) std::vector>; +/* + * + * 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>; %pythoncode %{ import numpy as np