Skip to content

Commit

Permalink
[Fix] Fix aligned allocations on Android (open-mmlab#1612)
Browse files Browse the repository at this point in the history
* fix android alignment

* fix typo

* fix size
  • Loading branch information
lzhangzz authored and irexyc committed Jan 11, 2023
1 parent 28750ac commit f4b2187
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion csrc/mmdeploy/device/cpu/cpu_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ class CpuHostMemory : public NonCopyable {
public:
CpuHostMemory() : size_(), data_(), owned_data_{false} {}
Result<void> Init(size_t size, size_t alignment) {
size_t space = (size + alignment - 1) / alignment * alignment;
alignment = std::max(alignment, sizeof(void*));
auto space = (size + alignment - 1) / alignment * alignment;
#ifdef _MSC_VER
data_ = _aligned_malloc(space, alignment);
#elif defined(ANDROID)
posix_memalign(&data_, alignment, space);
#else
data_ = std::aligned_alloc(alignment, space);
#endif
Expand Down

0 comments on commit f4b2187

Please sign in to comment.