Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #193 from happynear/msvc
Browse files Browse the repository at this point in the history
Add Visual Studio compatible macros. Thanks for the contribution! This is merged
  • Loading branch information
tqchen committed Sep 30, 2015
2 parents c8bacb1 + f4e9f8e commit d61e601
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 3 additions & 2 deletions python/mxnet/libinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions src/common/object_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,13 @@ void ObjectPool<T>::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<LinkedList*>(new_chunk_ptr);
auto size = kPageSize / sizeof(LinkedList);
Expand Down
3 changes: 3 additions & 0 deletions src/io/image_augmenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/io/iter_mnist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ class MNISTIter: public IIterator<TBlobBatch> {
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<int>(buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3]);
#endif
}

private:
Expand Down
12 changes: 10 additions & 2 deletions src/storage/cpu_device_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit d61e601

Please sign in to comment.