From 3fafcd9438f646e2ce0e0aae9760c8ea7c877d4b Mon Sep 17 00:00:00 2001 From: happynear Date: Wed, 30 Sep 2015 14:04:59 +0800 Subject: [PATCH 1/2] visual studio compatible macros --- python/mxnet/libinfo.py | 5 +++-- src/common/object_pool.h | 5 +++++ src/io/image_augmenter.h | 3 +++ src/io/iter_mnist.cc | 4 ++++ src/storage/cpu_device_storage.h | 12 ++++++++++-- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/python/mxnet/libinfo.py b/python/mxnet/libinfo.py index 821d33e5bce2..030f2eb7436e 100644 --- a/python/mxnet/libinfo.py +++ b/python/mxnet/libinfo.py @@ -16,10 +16,11 @@ def find_lib_path(): api_path = os.path.join(curr_path, '../../lib/') dll_path = [curr_path, api_path] if os.name == 'nt': + vs_configuration = 'Release' if platform.architecture()[0] == '64bit': - dll_path.append(os.path.join(api_path, '../../windows/x64/Release/')) + dll_path.append(os.path.join(curr_path, '../../windows/x64', vs_configuration)) else: - dll_path.append(os.path.join(api_path, '../../windows/Release/')) + dll_path.append(os.path.join(curr_path, '../../windows', vs_configuration)) if os.name == 'nt': dll_path = [os.path.join(p, 'mxnet.dll') for p in dll_path] else: diff --git a/src/common/object_pool.h b/src/common/object_pool.h index 0306ed6ef355..5787f53ff497 100644 --- a/src/common/object_pool.h +++ b/src/common/object_pool.h @@ -157,8 +157,13 @@ void ObjectPool::AllocateChunk() { static_assert(alignof(LinkedList) % alignof(T) == 0, "ObjectPooll Invariant"); static_assert(kPageSize % alignof(LinkedList) == 0, "ObjectPooll Invariant"); void* new_chunk_ptr; +#ifdef _MSC_VER + new_chunk_ptr = _aligned_malloc(kPageSize, kPageSize); + CHECK_NE(new_chunk_ptr, NULL) << "Allocation failed"; +#else int ret = posix_memalign(&new_chunk_ptr, kPageSize, kPageSize); CHECK_EQ(ret, 0) << "Allocation failed"; +#endif allocated_.emplace_back(new_chunk_ptr); auto new_chunk = static_cast(new_chunk_ptr); auto size = kPageSize / sizeof(LinkedList); diff --git a/src/io/image_augmenter.h b/src/io/image_augmenter.h index cd50c5e10b08..b76b8da4650e 100644 --- a/src/io/image_augmenter.h +++ b/src/io/image_augmenter.h @@ -114,6 +114,9 @@ class ImageAugmenter { } } #if MXNET_USE_OPENCV +#ifdef _MSC_VER +#define M_PI CV_PI +#endif /*! * \brief augment src image, store result into dst * this function is not thread safe, and will only be called by one thread diff --git a/src/io/iter_mnist.cc b/src/io/iter_mnist.cc index 89fb7efb026f..7ba717b1c7f9 100644 --- a/src/io/iter_mnist.cc +++ b/src/io/iter_mnist.cc @@ -171,7 +171,11 @@ class MNISTIter: public IIterator { unsigned char buf[4]; CHECK(fi->Read(buf, sizeof(buf)) == sizeof(buf)) << "invalid mnist format"; +#ifdef _MSC_VER + return (buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3]); +#else return reinterpret_cast(buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3]); +#endif } private: diff --git a/src/storage/cpu_device_storage.h b/src/storage/cpu_device_storage.h index 82aa0e7573f6..6838af037535 100644 --- a/src/storage/cpu_device_storage.h +++ b/src/storage/cpu_device_storage.h @@ -39,7 +39,9 @@ class CPUDeviceStorage { inline void* CPUDeviceStorage::Alloc(size_t size) { #if _MSC_VER - return CHECK_NOTNULL(_aligned_malloc(size, alignment_)); + void* ptr; + ptr = _aligned_malloc(size, alignment_); + return CHECK_NOTNULL(ptr); #else void* ptr; int ret = posix_memalign(&ptr, alignment_, size); @@ -48,7 +50,13 @@ inline void* CPUDeviceStorage::Alloc(size_t size) { #endif } -inline void CPUDeviceStorage::Free(void* ptr) { free(ptr); } +inline void CPUDeviceStorage::Free(void* ptr) { +#if _MSC_VER + _aligned_free(ptr); +#else + free(ptr); +#endif +} } // namespace storage } // namespace mxnet From f4e9f8e2f12582fb12aac5966dcf4fcba1ea220f Mon Sep 17 00:00:00 2001 From: happynear Date: Wed, 30 Sep 2015 16:17:35 +0800 Subject: [PATCH 2/2] add contributor --- CONTRIBUTORS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 58c9ba0d9a26..55d498d24cd2 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -41,3 +41,5 @@ List of Contributors - To contributors: please add your name to the list when you submit a patch to the project:) * [Qiang Kou](https://github.com/thirdwing) - KK is a R ninja, he will make mxnet available for R users. +* [Feng Wang](https://github.com/happynear) + - Feng makes mxnet compatible with Windows Visual Studio.