提交 58f74e2c 编写于 作者: L liaogang

Add main entry for unit test files and replace memalign by posix_memalign

上级 38166e29
...@@ -48,14 +48,10 @@ public: ...@@ -48,14 +48,10 @@ public:
* @return Pointer to the allocated memory * @return Pointer to the allocated memory
*/ */
virtual void* alloc(size_t size) { virtual void* alloc(size_t size) {
#if defined(__APPLE__) || defined(__OSX__)
return malloc(size);
#else
void* ptr; void* ptr;
posix_memalign(&ptr, 32ul, size); posix_memalign(&ptr, 32ul, size);
CHECK(ptr) << "Fail to allocate CPU memory: size=" << size; CHECK(ptr) << "Fail to allocate CPU memory: size=" << size;
return ptr; return ptr;
#endif
} }
/** /**
......
...@@ -24,7 +24,7 @@ limitations under the License. */ ...@@ -24,7 +24,7 @@ limitations under the License. */
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <malloc.h> #include <stdlib.h>
#include <time.h> #include <time.h>
static constexpr size_t VECTOR_LEN = 3072; static constexpr size_t VECTOR_LEN = 3072;
...@@ -37,7 +37,9 @@ static std::mt19937 RandomEngine(time(0)); ...@@ -37,7 +37,9 @@ static std::mt19937 RandomEngine(time(0));
inline static std::unique_ptr<float[]> NewVector(size_t len = VECTOR_LEN, inline static std::unique_ptr<float[]> NewVector(size_t len = VECTOR_LEN,
size_t align = ALIGN) { size_t align = ALIGN) {
return std::unique_ptr<float[]>((float*)memalign(align, len * sizeof(float))); float* ptr;
posix_memalign((void**)&ptr, align, len * sizeof(float));
return std::unique_ptr<float[]>(ptr);
} }
inline static std::unique_ptr<float[]> NewRandomVector(size_t len = VECTOR_LEN, inline static std::unique_ptr<float[]> NewRandomVector(size_t len = VECTOR_LEN,
......
...@@ -249,4 +249,9 @@ TEST_F(PerturbationTest, scale_test) { ...@@ -249,4 +249,9 @@ TEST_F(PerturbationTest, scale_test) {
} }
} }
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
#endif #endif
...@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and ...@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#include <malloc.h> #include <stdlib.h>
#include <paddle/utils/Util.h> #include <paddle/utils/Util.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
...@@ -124,9 +124,11 @@ void CommonTest::test_sgdUpadate(real* gradientBuffer, real* valueBuffer, ...@@ -124,9 +124,11 @@ void CommonTest::test_sgdUpadate(real* gradientBuffer, real* valueBuffer,
TEST_F(CommonTest, sgdUpdate) { TEST_F(CommonTest, sgdUpdate) {
const size_t alignHeader[] = {0, 2, 3, 5, 7, 8}; const size_t alignHeader[] = {0, 2, 3, 5, 7, 8};
for (auto& size : sizeVec_) { for (auto& size : sizeVec_) {
real* gradientBuffer = (real*)memalign(32, sizeof(real) * size); real *gradientBuffer, *valueBuffer, *momentumBuffer;
real* valueBuffer = (real*)memalign(32, sizeof(real) * size); posix_memalign((void**)&gradientBuffer, 32, sizeof(real) * size);
real* momentumBuffer = (real*)memalign(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++) { for (size_t i = 0; i < size; i++) {
gradientBuffer[i] = 1.0; gradientBuffer[i] = 1.0;
valueBuffer[i] = 2.0; valueBuffer[i] = 2.0;
......
...@@ -22,3 +22,8 @@ TEST(StringUtil, to) { ...@@ -22,3 +22,8 @@ TEST(StringUtil, to) {
ASSERT_DEATH(paddle::str::to<double>("12.45x23"), ".*"); ASSERT_DEATH(paddle::str::to<double>("12.45x23"), ".*");
ASSERT_DEATH(paddle::str::to<int>(""), ".*"); ASSERT_DEATH(paddle::str::to<int>(""), ".*");
} }
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册