diff --git a/paddle/math/Allocator.h b/paddle/math/Allocator.h index 7d277b1c10d2b498d9b3d7f78a93f079d75044e4..ca8eadbc1aa42265c1e505d41e1a134b0e7f19b9 100644 --- a/paddle/math/Allocator.h +++ b/paddle/math/Allocator.h @@ -48,14 +48,10 @@ public: * @return Pointer to the allocated memory */ virtual void* alloc(size_t size) { - #if defined(__APPLE__) || defined(__OSX__) - return malloc(size); - #else void* ptr; posix_memalign(&ptr, 32ul, size); CHECK(ptr) << "Fail to allocate CPU memory: size=" << size; return ptr; - #endif } /** diff --git a/paddle/math/tests/test_SIMDFunctions.cpp b/paddle/math/tests/test_SIMDFunctions.cpp index 631d0516cf409fda7c20f1d9329328684854aedf..bae5d8c684d8920b738fcd1cda1bd831f2333605 100644 --- a/paddle/math/tests/test_SIMDFunctions.cpp +++ b/paddle/math/tests/test_SIMDFunctions.cpp @@ -24,7 +24,7 @@ limitations under the License. */ #include #include -#include +#include #include static constexpr size_t VECTOR_LEN = 3072; @@ -37,7 +37,9 @@ static std::mt19937 RandomEngine(time(0)); inline static std::unique_ptr NewVector(size_t len = VECTOR_LEN, size_t align = ALIGN) { - return std::unique_ptr((float*)memalign(align, len * sizeof(float))); + float* ptr; + posix_memalign((void**)&ptr, align, len * sizeof(float)); + return std::unique_ptr(ptr); } inline static std::unique_ptr NewRandomVector(size_t len = VECTOR_LEN, diff --git a/paddle/math/tests/test_perturbation.cpp b/paddle/math/tests/test_perturbation.cpp index 4fa9bc72013da6a3d551854516e0f0d2fe5ee1ef..51e346fef91bf8dae7a5084ba8b2d86d9021650b 100644 --- a/paddle/math/tests/test_perturbation.cpp +++ b/paddle/math/tests/test_perturbation.cpp @@ -249,4 +249,9 @@ TEST_F(PerturbationTest, scale_test) { } } +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + #endif diff --git a/paddle/parameter/tests/test_common.cpp b/paddle/parameter/tests/test_common.cpp index 3db96ccf941e3b0687b6e010b21b7f68faca364b..4f92aec1d967169e2c27579b8a95941c029a3e49 100644 --- a/paddle/parameter/tests/test_common.cpp +++ b/paddle/parameter/tests/test_common.cpp @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -#include +#include #include #include @@ -124,9 +124,11 @@ void CommonTest::test_sgdUpadate(real* gradientBuffer, real* valueBuffer, TEST_F(CommonTest, sgdUpdate) { const size_t alignHeader[] = {0, 2, 3, 5, 7, 8}; for (auto& size : sizeVec_) { - real* gradientBuffer = (real*)memalign(32, sizeof(real) * size); - real* valueBuffer = (real*)memalign(32, sizeof(real) * size); - real* momentumBuffer = (real*)memalign(32, sizeof(real) * size); + real *gradientBuffer, *valueBuffer, *momentumBuffer; + posix_memalign((void**)&gradientBuffer, 32, sizeof(real) * size); + posix_memalign((void**)&valueBuffer, 32, sizeof(real) * size); + posix_memalign((void**)&momentumBuffer, 32, sizeof(real) * size); + for (size_t i = 0; i < size; i++) { gradientBuffer[i] = 1.0; valueBuffer[i] = 2.0; diff --git a/paddle/utils/tests/test_StringUtils.cpp b/paddle/utils/tests/test_StringUtils.cpp index b8636709e9b42c7baa5d0106492ab6c0782ed6d4..95290005ae98384d3b040815f64309bb74fe8b81 100644 --- a/paddle/utils/tests/test_StringUtils.cpp +++ b/paddle/utils/tests/test_StringUtils.cpp @@ -22,3 +22,8 @@ TEST(StringUtil, to) { ASSERT_DEATH(paddle::str::to("12.45x23"), ".*"); ASSERT_DEATH(paddle::str::to(""), ".*"); } + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}