-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/develop' into thread_pool
- Loading branch information
Showing
104 changed files
with
6,559 additions
and
753 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// 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. | ||
|
||
#include "paddle/fluid/framework/new_executor/workqueue_utils.h" | ||
#include <cstdint> | ||
#include <cstdlib> | ||
|
||
namespace paddle { | ||
namespace framework { | ||
|
||
void* AlignedMalloc(size_t size, size_t alignment) { | ||
assert(alignment >= sizeof(void*) && (alignment & (alignment - 1)) == 0); | ||
size = (size + alignment - 1) / alignment * alignment; | ||
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L | ||
void* aligned_mem = nullptr; | ||
if (posix_memalign(&aligned_mem, alignment, size) != 0) { | ||
aligned_mem = nullptr; | ||
} | ||
return aligned_mem; | ||
#elif defined(_WIN32) | ||
return _aligned_malloc(size, alignment); | ||
#else | ||
void* mem = malloc(size + alignment); | ||
if (mem == nullptr) { | ||
return nullptr; | ||
} | ||
size_t adjust = alignment - reinterpret_cast<uint64_t>(mem) % alignment; | ||
void* aligned_mem = reinterpret_cast<char*>(mem) + adjust; | ||
*(reinterpret_cast<void**>(aligned_mem) - 1) = mem; | ||
assert(reinterpret_cast<uint64_t>(aligned_mem) % alignment == 0); | ||
return aligned_mem; | ||
#endif | ||
} | ||
|
||
void AlignedFree(void* mem_ptr) { | ||
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L | ||
free(mem_ptr); | ||
#elif defined(_WIN32) | ||
_aligned_free(mem_ptr); | ||
#else | ||
if (mem_ptr) { | ||
free(*(reinterpret_cast<void**>(mem_ptr) - 1)); | ||
} | ||
#endif | ||
} | ||
|
||
} // namespace framework | ||
} // namespace paddle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
1b34770
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅Congratulation! Your pull request passed all required CI. You could ask reviewer(s) to approve and merge. 🎉