diff --git a/cmake/cudnn.cmake b/cmake/cudnn.cmake index 9eebea816cbfc91052c95ecf99ecc4b0bea4e4c2..1a6d1bce79bbcf3e3068c72017cef50fb63fd865 100644 --- a/cmake/cudnn.cmake +++ b/cmake/cudnn.cmake @@ -31,7 +31,6 @@ find_library(CUDNN_LIBRARY NAMES libcudnn.so libcudnn.dylib # libcudnn_static.a NO_DEFAULT_PATH DOC "Path to cuDNN library.") - if(CUDNN_INCLUDE_DIR AND CUDNN_LIBRARY) set(CUDNN_FOUND ON) else() diff --git a/cmake/external/boost.cmake b/cmake/external/boost.cmake index 73713d93d5a52738651dda498fac5ea66e3589d2..9bc4133f6a515706d4da13314221ff1ed1ae00fe 100644 --- a/cmake/external/boost.cmake +++ b/cmake/external/boost.cmake @@ -35,13 +35,18 @@ set(BOOST_INCLUDE_DIR "${BOOST_DOWNLOAD_DIR}/${BOOST_TAR}" CACHE PATH "boost inc set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM 1) include_directories(${BOOST_INCLUDE_DIR}) +set(COMMAND "wget --no-check-certificate ${BOOST_URL} -c -q -O ${BOOST_TAR}.tar.gz + && tar zxf ${BOOST_TAR}.tar.gz") +if (NOT WIN32) +set(COMMAND "") +message(WARNING "Windows do not support automaticlly download and install boost. Please manually install it in the thrid_party/install/boost.") +endif(NOT WIN32) ExternalProject_Add( ${BOOST_PROJECT} ${EXTERNAL_PROJECT_LOG_ARGS} DOWNLOAD_DIR ${BOOST_DOWNLOAD_DIR} - DOWNLOAD_COMMAND wget --no-check-certificate ${BOOST_URL} -c -q -O ${BOOST_TAR}.tar.gz - && tar zxf ${BOOST_TAR}.tar.gz + DOWNLOAD_COMMAND DOWNLOAD_NO_PROGRESS 1 PREFIX ${BOOST_SOURCES_DIR} CONFIGURE_COMMAND "" diff --git a/paddle/fluid/memory/detail/system_allocator.cc b/paddle/fluid/memory/detail/system_allocator.cc index 9b1ab1e228dd758b52975abc4c4aa0bdeadbe2de..e36c338fcea819e41cc3ad4fddf1f3dd070b25ef 100644 --- a/paddle/fluid/memory/detail/system_allocator.cc +++ b/paddle/fluid/memory/detail/system_allocator.cc @@ -11,11 +11,17 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ +#define GLOG_NO_ABBREVIATED_SEVERITIES #include "paddle/fluid/memory/detail/system_allocator.h" -#include // for malloc and free +#ifdef _WIN32 +#include +#include +#else #include // for mlock and munlock +#endif +#include // for malloc and free #include // for std::max #include "gflags/gflags.h" @@ -35,6 +41,24 @@ namespace paddle { namespace memory { namespace detail { +void* AlignedMalloc(size_t size) { + void* p = nullptr; + size_t alignment = 32ul; + #ifdef PADDLE_WITH_MKLDNN + // refer to https://github.com/01org/mkl-dnn/blob/master/include/mkldnn.hpp + // memory alignment + alignment = 4096ul; + #endif +#ifdef _WIN32 + p = _aligned_malloc(size, alignment); +#else + PADDLE_ENFORCE_EQ(posix_memalign(&p, alignment, size), 0, "Alloc %ld error!", + size); +#endif + PADDLE_ENFORCE(p, "Fail to allocate CPU memory: size = %d .", size); + return p; +} + void* CPUAllocator::Alloc(size_t* index, size_t size) { // According to http://www.cplusplus.com/reference/cstdlib/malloc/, // malloc might not return nullptr if size is zero, but the returned @@ -43,23 +67,16 @@ void* CPUAllocator::Alloc(size_t* index, size_t size) { *index = 0; // unlock memory - void* p = nullptr; - -#ifdef PADDLE_WITH_MKLDNN - // refer to https://github.com/01org/mkl-dnn/blob/master/include/mkldnn.hpp - // memory alignment - PADDLE_ENFORCE_EQ(posix_memalign(&p, 4096ul, size), 0, "Alloc %ld error!", - size); -#else - PADDLE_ENFORCE_EQ(posix_memalign(&p, 32ul, size), 0, "Alloc %ld error!", - size); -#endif - PADDLE_ENFORCE(p, "Fail to allocate CPU memory: size = %d .", size); + void* p = AlignedMalloc(size); if (p != nullptr) { if (FLAGS_use_pinned_memory) { *index = 1; +#ifdef _WIN32 + VirtualLock(p, size); +#else mlock(p, size); // lock memory +#endif } } @@ -68,7 +85,11 @@ void* CPUAllocator::Alloc(size_t* index, size_t size) { void CPUAllocator::Free(void* p, size_t size, size_t index) { if (p != nullptr && index == 1) { +#ifdef _WIN32 + VirtualUnlock(p, size); +#else munlock(p, size); +#endif } free(p); } diff --git a/paddle/fluid/platform/cpu_info.cc b/paddle/fluid/platform/cpu_info.cc index 7d53a684d6068c79659719159696ef5aebfeaa2b..dc09f2657c8d422255daa320b81e63fcd7882bf8 100644 --- a/paddle/fluid/platform/cpu_info.cc +++ b/paddle/fluid/platform/cpu_info.cc @@ -22,6 +22,9 @@ limitations under the License. */ #ifdef __APPLE__ #include #include +#elif defined(_WIN32) +#include +#include #else #include #endif @@ -60,6 +63,11 @@ inline size_t CpuTotalPhysicalMemory() { size_t len = sizeof(size); if (sysctl(mib, 2, &size, &len, NULL, 0) == 0) return (size_t)size; return 0L; +#elif defined(_WIN32) +MEMORYSTATUSEX sMeminfo; +sMeminfo.dwLength = sizeof(sMeminfo); +GlobalMemoryStatusEx(&sMeminfo); +return sMeminfo.ullTotalPhys; #else int64_t pages = sysconf(_SC_PHYS_PAGES); int64_t page_size = sysconf(_SC_PAGE_SIZE);