Update Mac OS X port

* follow comments to fix bugs
avx_docs
liaogang 8 years ago
parent 54c37ab735
commit 8ddc5faac1

@ -44,8 +44,8 @@ set(ATLAS_LIB_SEARCH_PATHS
/usr/lib /usr/lib
/usr/lib/blas/atlas /usr/lib/blas/atlas
/usr/lib/atlas /usr/lib/atlas
/usr/lib/atlas-base) # special for ubuntu 14.04. /usr/lib/atlas-base # special for ubuntu 14.04.
)
find_path(ATLAS_INC_DIR NAMES cblas.h find_path(ATLAS_INC_DIR NAMES cblas.h
PATHS ${ATLAS_INCLUDE_SEARCH_PATHS}) PATHS ${ATLAS_INCLUDE_SEARCH_PATHS})
find_library(ATLAS_CBLAS_LIB NAMES cblas libcblas.so.3 find_library(ATLAS_CBLAS_LIB NAMES cblas libcblas.so.3

@ -24,7 +24,9 @@ function(target_circle_link_libraries TARGET_NAME)
list(APPEND libsInArgn ${arg}) list(APPEND libsInArgn ${arg})
endif() endif()
endforeach() endforeach()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
list(APPEND LIBS "-undefined dynamic_lookup")
endif()
list(REVERSE libsInArgn) list(REVERSE libsInArgn)
target_link_libraries(${TARGET_NAME} target_link_libraries(${TARGET_NAME}
${LIBS} ${LIBS}

File diff suppressed because it is too large Load Diff

@ -95,7 +95,7 @@ float Matrix::get(size_t x, size_t y) const throw(RangeError) {
} }
void Matrix::set(size_t x, size_t y, float val) throw(RangeError, void Matrix::set(size_t x, size_t y, float val) throw(RangeError,
UnsupportError) { UnsupportError) {
if (x > this->getWidth() || y > this->getHeight()) { if (x > this->getWidth() || y > this->getHeight()) {
RangeError e; RangeError e;
throw e; throw e;
@ -239,7 +239,7 @@ void Matrix::toNumpyMatInplace(float** view_data, int* dim1,
} }
void Matrix::copyToNumpyMat(float** view_m_data, int* dim1, void Matrix::copyToNumpyMat(float** view_m_data, int* dim1,
int* dim2) throw(UnsupportError) { int* dim2) throw(UnsupportError) {
static_assert(sizeof(float) == sizeof(float), static_assert(sizeof(paddle::real) == sizeof(float),
"Currently PaddleAPI only support for single " "Currently PaddleAPI only support for single "
"precision version of paddle."); "precision version of paddle.");
if (this->isSparse()) { if (this->isSparse()) {
@ -251,12 +251,12 @@ void Matrix::copyToNumpyMat(float** view_m_data, int* dim1,
if (auto cpuMat = dynamic_cast<paddle::CpuMatrix*>(m->mat.get())) { if (auto cpuMat = dynamic_cast<paddle::CpuMatrix*>(m->mat.get())) {
auto src = cpuMat->getData(); auto src = cpuMat->getData();
auto dest = *view_m_data; auto dest = *view_m_data;
std::memcpy(dest, src, sizeof(float) * (*dim1) * (*dim2)); std::memcpy(dest, src, sizeof(paddle::real) * (*dim1) * (*dim2));
} else if (auto gpuMat = dynamic_cast<paddle::GpuMatrix*>(m->mat.get())) { } else if (auto gpuMat = dynamic_cast<paddle::GpuMatrix*>(m->mat.get())) {
auto src = gpuMat->getData(); auto src = gpuMat->getData();
auto dest = *view_m_data; auto dest = *view_m_data;
hl_memcpy_device2host(dest, src, hl_memcpy_device2host(dest, src,
sizeof(float) * (*dim1) * (*dim2)); sizeof(paddle::real) * (*dim1) * (*dim2));
} else { } else {
LOG(WARNING) << "Unexpected Situation"; LOG(WARNING) << "Unexpected Situation";
throw UnsupportError(); throw UnsupportError();

@ -385,10 +385,17 @@ void NeuralNetwork::setOutputGrad(const std::vector<Argument>& args) {
} }
} }
extern NeuralNetwork* newCustomNerualNetwork(
const std::string& name, NeuralNetwork* network) __attribute__((weak));
NeuralNetwork* NeuralNetwork::newNeuralNetwork( NeuralNetwork* NeuralNetwork::newNeuralNetwork(
const std::string& name, const std::string& name,
NeuralNetwork* rootNetwork) { NeuralNetwork* rootNetwork) {
return new NeuralNetwork(name, rootNetwork); if (newCustomNerualNetwork) {
return newCustomNerualNetwork(name, rootNetwork);
} else {
return new NeuralNetwork(name, rootNetwork);
}
} }
} // namespace paddle } // namespace paddle

@ -94,7 +94,11 @@ TEST(checkGradient, multi) {
TEST(checkGradient, hsigmoid) { checkGradientTest(configFile2, false, false); } TEST(checkGradient, hsigmoid) { checkGradientTest(configFile2, false, false); }
TEST(checkGradient, chunk) { TEST(checkGradient, chunk) {
#if defined(__APPLE__) || defined (__OSX__)
EXPECT_EQ(0, system("python trainer/tests/gen_proto_data.py")); EXPECT_EQ(0, system("python trainer/tests/gen_proto_data.py"));
#else
EXPECT_EQ(0, system("python2 trainer/tests/gen_proto_data.py"));
#endif
checkGradientTest(configFile3, false, false); checkGradientTest(configFile3, false, false);
#ifndef PADDLE_ONLY_CPU #ifndef PADDLE_ONLY_CPU
checkGradientTest(configFile3, true, true); checkGradientTest(configFile3, true, true);

@ -144,12 +144,12 @@ PyObjectPtr createPythonClass(
const std::map<std::string, std::string>& kwargs) { const std::map<std::string, std::string>& kwargs) {
PyGuard guard; PyGuard guard;
PyObjectPtr pyModule(PyImport_ImportModule(moduleName.c_str())); PyObjectPtr pyModule(PyImport_ImportModule(moduleName.c_str()));
// LOG(INFO) << "createPythonClass moduleName.c_str:" << moduleName.c_str(); LOG(INFO) << "createPythonClass moduleName.c_str:" << moduleName.c_str();
CHECK_PY(pyModule) << "Import module " << moduleName << " failed."; CHECK_PY(pyModule) << "Import module " << moduleName << " failed.";
PyObjectPtr pyDict(PyModule_GetDict(pyModule.get())); PyObjectPtr pyDict(PyModule_GetDict(pyModule.get()));
CHECK_PY(pyDict) << "Get Dict failed."; CHECK_PY(pyDict) << "Get Dict failed.";
PyObjectPtr pyClass(PyDict_GetItemString(pyDict.get(), className.c_str())); PyObjectPtr pyClass(PyDict_GetItemString(pyDict.get(), className.c_str()));
// LOG(INFO) << "createPythonClass className.c_str():" << className.c_str(); LOG(INFO) << "createPythonClass className.c_str():" << className.c_str();
CHECK_PY(pyClass) << "Import class " << className << " failed."; CHECK_PY(pyClass) << "Import class " << className << " failed.";
PyObjectPtr argsObjectList(PyTuple_New(args.size())); PyObjectPtr argsObjectList(PyTuple_New(args.size()));
for (size_t i = 0; i < args.size(); ++i) { for (size_t i = 0; i < args.size(); ++i) {

@ -35,13 +35,6 @@ limitations under the License. */
#include <Python.h> #include <Python.h>
#include <frameobject.h> #include <frameobject.h>
// #ifndef _POSIX_C_SOURCE
// #warning "no _POSIX_C_SOURCE defined in Python.h"
// #endif
// #ifndef _XOPEN_SOURCE
// #warning "no _XOPEN_SOURCE defined in Python.h"
// #endif
#endif #endif
#include "paddle/utils/Util.h" #include "paddle/utils/Util.h"

@ -13,28 +13,12 @@ See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#include "Stat.h" #include "Stat.h"
#include "Util.h"
#include <sys/syscall.h> // for syscall()
#include <sys/types.h>
#include <iomanip> #include <iomanip>
#include <algorithm> #include <algorithm>
namespace paddle { namespace paddle {
// return the thread id used by glog
pid_t getTID() {
#if defined(__APPLE__) || defined(__OSX__)
pid_t tid = syscall(SYS_thread_selfid);
#else
#ifndef __NR_gettid
#define __NR_gettid 224
#endif
pid_t tid = syscall(__NR_gettid);
#endif
CHECK_NE(tid, -1);
return tid;
}
StatSet globalStat("GlobalStatInfo"); StatSet globalStat("GlobalStatInfo");
void Stat::addSample(uint64_t value) { void Stat::addSample(uint64_t value) {

@ -13,24 +13,10 @@ See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#pragma once #pragma once
#include "Util.h"
#include "Logging.h" #include "Logging.h"
#include <thread> #include <thread>
#include <sys/syscall.h>
#include <unistd.h>
inline pid_t gettid() {
#if defined(__APPLE__) || defined(__OSX__)
pid_t tid = syscall(SYS_thread_selfid);
#else
#ifndef __NR_gettid
#define __NR_gettid 224
#endif
pid_t tid = syscall(__NR_gettid);
#endif
CHECK_NE(tid, -1);
return tid;
}
#include "Queue.h" #include "Queue.h"
#include "ThreadLocal.h" #include "ThreadLocal.h"
@ -186,7 +172,7 @@ public:
jobFinishBarrier_(numWorkers + 1), jobFinishBarrier_(numWorkers + 1),
jobFunc_(nullptr), jobFunc_(nullptr),
checkOwner_(checkOwner) { checkOwner_(checkOwner) {
ownerThreadId_ = ::gettid(); ownerThreadId_ = getTID();
workers_.resize(numWorkers); workers_.resize(numWorkers);
start(); start();
} }
@ -210,7 +196,7 @@ public:
*/ */
void exec(JobFunc jobFunc, JobFunc ownerFunc = nullptr) { void exec(JobFunc jobFunc, JobFunc ownerFunc = nullptr) {
if (checkOwner_) { if (checkOwner_) {
CHECK_EQ(ownerThreadId_, ::gettid()) CHECK_EQ(ownerThreadId_, getTID())
<< "this sync thread pool should be used in one thread"; << "this sync thread pool should be used in one thread";
} }

@ -12,10 +12,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#include "Util.h"
#include "ThreadLocal.h" #include "ThreadLocal.h"
#include "Thread.h"
#include "CommandLineParser.h" #include "CommandLineParser.h"
P_DEFINE_bool(thread_local_rand_use_global_seed, false, P_DEFINE_bool(thread_local_rand_use_global_seed, false,
@ -31,11 +29,11 @@ unsigned int* ThreadLocalRand::getSeed() {
if (!p) { // init seed if (!p) { // init seed
if (FLAGS_thread_local_rand_use_global_seed) { if (FLAGS_thread_local_rand_use_global_seed) {
p = new unsigned int(defaultSeed_); p = new unsigned int(defaultSeed_);
} else if (getpid() == gettid()) { // main thread } else if (getpid() == getTID()) { // main thread
// deterministic, but differs from global srand() // deterministic, but differs from global srand()
p = new unsigned int(defaultSeed_ - 1); p = new unsigned int(defaultSeed_ - 1);
} else { } else {
p = new unsigned int(defaultSeed_ + gettid()); p = new unsigned int(defaultSeed_ + getTID());
LOG(INFO) << "thread use undeterministic rand seed:" << *p; LOG(INFO) << "thread use undeterministic rand seed:" << *p;
} }
seed_.set(p); seed_.set(p);
@ -51,7 +49,7 @@ std::default_random_engine& ThreadLocalRandomEngine::get() {
int defaultSeed = ThreadLocalRand::getDefaultSeed(); int defaultSeed = ThreadLocalRand::getDefaultSeed();
engine->seed(FLAGS_thread_local_rand_use_global_seed engine->seed(FLAGS_thread_local_rand_use_global_seed
? defaultSeed ? defaultSeed
: defaultSeed + gettid()); : defaultSeed + getTID());
engine_.set(engine); engine_.set(engine);
} }
return *engine; return *engine;

@ -93,6 +93,19 @@ static void installProfilerSwitch() {}
namespace paddle { namespace paddle {
pid_t getTID() {
#if defined(__APPLE__) || defined(__OSX__)
pid_t tid = syscall(SYS_thread_selfid);
#else
#ifndef __NR_gettid
#define __NR_gettid 224
#endif
pid_t tid = syscall(__NR_gettid);
#endif
CHECK_NE(tid, -1);
return tid;
}
static bool g_initialized = false; static bool g_initialized = false;
typedef std::pair<int, std::function<void()>> PriorityFuncPair; typedef std::pair<int, std::function<void()>> PriorityFuncPair;
typedef std::vector<PriorityFuncPair> InitFuncList; typedef std::vector<PriorityFuncPair> InitFuncList;

@ -24,6 +24,8 @@ limitations under the License. */
#include <unordered_map> #include <unordered_map>
#include <mutex> #include <mutex>
#include <functional> #include <functional>
#include <sys/syscall.h> // for syscall()
#include <sys/types.h>
#include "CommandLineParser.h" #include "CommandLineParser.h"
#include "Logging.h" #include "Logging.h"
@ -63,6 +65,9 @@ limitations under the License. */
namespace paddle { namespace paddle {
// return the thread id used by glog
pid_t getTID();
/** /**
* return the 1-based index of the highest bit set * return the 1-based index of the highest bit set
* *

Loading…
Cancel
Save