From e4eb8911c5be0e4986ab8bce536ad5c167b0b476 Mon Sep 17 00:00:00 2001 From: Gajesh Naik <26431906+Gajesh2007@users.noreply.github.com> Date: Sat, 5 Sep 2026 23:52:04 -0700 Subject: [PATCH 1/2] Expose coherent allocator snapshots and checked footprint policy Signed publication snapshot of validated source 560f57ccc1e42cb451651976363764a5033c8c95. The committed tree is identical; original milestone history remains preserved locally. --- mlx/backend/common/allocation_footprint.h | 39 +++++++ mlx/backend/common/buffer_cache.h | 7 +- mlx/backend/cuda/allocator.cpp | 41 +++++-- mlx/backend/cuda/allocator.h | 2 + mlx/backend/metal/allocator.cpp | 22 +++- mlx/backend/metal/allocator.h | 2 + mlx/backend/no_gpu/allocator.cpp | 20 ++++ mlx/memory.h | 65 +++++++++++ tests/allocator_tests.cpp | 127 ++++++++++++++++++++++ 9 files changed, 316 insertions(+), 9 deletions(-) create mode 100644 mlx/backend/common/allocation_footprint.h diff --git a/mlx/backend/common/allocation_footprint.h b/mlx/backend/common/allocation_footprint.h new file mode 100644 index 0000000000..c7ec23de6a --- /dev/null +++ b/mlx/backend/common/allocation_footprint.h @@ -0,0 +1,39 @@ +// Copyright © 2026 Apple Inc. + +#pragma once + +#include +#include +#include +#include + +namespace mlx::core::allocator { + +inline size_t checked_allocation_add(size_t size, size_t extra) { + if (extra > std::numeric_limits::max() - size) { + throw std::overflow_error("allocation footprint overflow"); + } + return size + extra; +} + +inline size_t round_allocation_size(size_t size, size_t alignment) { + if (alignment == 0) { + throw std::invalid_argument("allocation alignment is zero"); + } + auto remainder = size % alignment; + return checked_allocation_add(size, remainder ? alignment - remainder : 0); +} + +// Inclusive cache-reuse bound. A fresh buffer never exceeds this bound. +inline size_t maximum_reuse_size(size_t size, size_t page_size) { + if (size == 0) { + return 0; + } + auto two_pages = checked_allocation_add(page_size, page_size); + if (two_pages == 0) { + throw std::invalid_argument("cache page size is zero"); + } + return checked_allocation_add(size, std::min(size - 1, two_pages - 1)); +} + +} // namespace mlx::core::allocator diff --git a/mlx/backend/common/buffer_cache.h b/mlx/backend/common/buffer_cache.h index 27648b2fbc..177dbc11ac 100644 --- a/mlx/backend/common/buffer_cache.h +++ b/mlx/backend/common/buffer_cache.h @@ -7,6 +7,8 @@ #include #include +#include "mlx/backend/common/allocation_footprint.h" + namespace mlx::core { template @@ -28,10 +30,13 @@ class BufferCache { BufferCache& operator=(const BufferCache&) = delete; T* reuse_from_cache(size_t size) { + if (size == 0) { + return nullptr; + } // Find the closest buffer in pool. auto it = buffer_pool_.lower_bound(size); if (it == buffer_pool_.end() || - it->first >= std::min(2 * size, size + 2 * page_size_)) { + it->first > allocator::maximum_reuse_size(size, page_size_)) { return nullptr; } diff --git a/mlx/backend/cuda/allocator.cpp b/mlx/backend/cuda/allocator.cpp index 36eb494e2d..e483317845 100644 --- a/mlx/backend/cuda/allocator.cpp +++ b/mlx/backend/cuda/allocator.cpp @@ -24,6 +24,19 @@ constexpr int page_size = 16384; // Any allocations smaller than this will try to use the small pool constexpr int small_block_size = 8; +size_t normalized_allocation_size(size_t size) { + if (size == 0) { + return 0; + } + if (size <= small_block_size) { + return 8; + } + if (size < page_size) { + return next_power_of_2(size); + } + return allocator::round_allocation_size(size, page_size); +} + // The small pool size in bytes. This should be a multiple of the host page // size and small_block_size. constexpr int small_pool_size = 4 * page_size; @@ -168,13 +181,7 @@ CudaAllocator::malloc_async(size_t size, int device, cudaStream_t stream) { return Buffer{new CudaBuffer{nullptr, 0, -1}}; } - if (size <= small_block_size) { - size = 8; - } else if (size < page_size) { - size = next_power_of_2(size); - } else { - size = page_size * ((size + page_size - 1) / page_size); - } + size = normalized_allocation_size(size); if (size <= small_block_size || stream == nullptr) { device = -1; @@ -339,6 +346,11 @@ void CudaAllocator::reset_peak_memory() { peak_memory_ = 0; } +MemorySnapshot CudaAllocator::get_memory_snapshot() { + std::lock_guard lock(mutex_); + return {active_memory_, buffer_cache_.cache_size(), peak_memory_}; +} + size_t CudaAllocator::get_memory_limit() { return memory_limit_; } @@ -404,6 +416,21 @@ bool can_reuse_alien_buffer(void* ptr) { } // namespace allocator +AllocationFootprintPolicy get_allocation_footprint_policy() noexcept { + return {cu::page_size, 0, cu::small_block_size, cu::page_size, cu::page_size}; +} + +size_t get_allocation_size_upper_bound(size_t size) { + size_t result; + if (!get_allocation_footprint_policy().upper_bound(size, result)) { + throw std::overflow_error("allocation footprint overflow"); + } + return result; +} + +MemorySnapshot get_memory_snapshot() { + return cu::allocator().get_memory_snapshot(); +} size_t get_active_memory() { return cu::allocator().get_active_memory(); } diff --git a/mlx/backend/cuda/allocator.h b/mlx/backend/cuda/allocator.h index af76ad9059..457b8fb372 100644 --- a/mlx/backend/cuda/allocator.h +++ b/mlx/backend/cuda/allocator.h @@ -3,6 +3,7 @@ #pragma once #include "mlx/allocator.h" +#include "mlx/memory.h" #include "mlx/backend/common/buffer_cache.h" #include "mlx/backend/cuda/cuda_utils.h" @@ -58,6 +59,7 @@ class CudaAllocator : public allocator::Allocator { // host memory), and copy the data over. Pass |stream| to copy asynchronously. void move_to_unified_memory(CudaBuffer& buf, cudaStream_t stream = nullptr); + MemorySnapshot get_memory_snapshot(); size_t get_active_memory() const; size_t get_peak_memory() const; void reset_peak_memory(); diff --git a/mlx/backend/metal/allocator.cpp b/mlx/backend/metal/allocator.cpp index 54f51c5536..cad39b4d99 100644 --- a/mlx/backend/metal/allocator.cpp +++ b/mlx/backend/metal/allocator.cpp @@ -120,6 +120,11 @@ size_t MetalAllocator::set_memory_limit(size_t limit) { return limit; }; +MemorySnapshot MetalAllocator::get_memory_snapshot() { + std::lock_guard lock(mutex_); + return {active_memory_, buffer_cache_.cache_size(), peak_memory_}; +} + size_t MetalAllocator::get_memory_limit() { return block_limit_; } @@ -149,7 +154,7 @@ Buffer MetalAllocator::malloc(size_t size) { // Align up memory if (size > vm_page_size) { - size = vm_page_size * ((size + vm_page_size - 1) / vm_page_size); + size = allocator::round_allocation_size(size, vm_page_size); } // Try the cache @@ -291,6 +296,18 @@ MetalAllocator& allocator() { } // namespace metal +AllocationFootprintPolicy get_allocation_footprint_policy() noexcept { + return {vm_page_size, vm_page_size, 0, 0, vm_page_size}; +} + +size_t get_allocation_size_upper_bound(size_t size) { + size_t result; + if (!get_allocation_footprint_policy().upper_bound(size, result)) { + throw std::overflow_error("allocation footprint overflow"); + } + return result; +} + size_t set_cache_limit(size_t limit) { return metal::allocator().set_cache_limit(limit); } @@ -309,6 +326,9 @@ size_t set_wired_limit(size_t limit) { } return metal::allocator().set_wired_limit(limit); } +MemorySnapshot get_memory_snapshot() { + return metal::allocator().get_memory_snapshot(); +} size_t get_active_memory() { return metal::allocator().get_active_memory(); } diff --git a/mlx/backend/metal/allocator.h b/mlx/backend/metal/allocator.h index 00cd7a1245..79d8f66d43 100644 --- a/mlx/backend/metal/allocator.h +++ b/mlx/backend/metal/allocator.h @@ -7,6 +7,7 @@ #include #include "mlx/allocator.h" +#include "mlx/memory.h" #include "mlx/backend/common/buffer_cache.h" #include "mlx/backend/metal/device.h" @@ -23,6 +24,7 @@ class MetalAllocator : public allocator::Allocator { virtual Buffer make_buffer(void* ptr, size_t size) override; virtual void release(Buffer buffer) override; + MemorySnapshot get_memory_snapshot(); size_t get_active_memory() { return active_memory_; }; diff --git a/mlx/backend/no_gpu/allocator.cpp b/mlx/backend/no_gpu/allocator.cpp index 3d2515c53d..f766707bce 100644 --- a/mlx/backend/no_gpu/allocator.cpp +++ b/mlx/backend/no_gpu/allocator.cpp @@ -41,6 +41,11 @@ class CommonAllocator : public Allocator { virtual void free(Buffer buffer) override; virtual size_t size(Buffer buffer) const override; + MemorySnapshot get_memory_snapshot() const { + std::lock_guard lock(mutex_); + return {active_memory_, buffer_cache_.cache_size(), peak_memory_}; + } + size_t get_active_memory() const { return active_memory_; }; @@ -184,6 +189,21 @@ bool can_reuse_alien_buffer(void*) { } // namespace allocator +AllocationFootprintPolicy get_allocation_footprint_policy() noexcept { + return {1, 0, 0, 0, 4096}; +} + +size_t get_allocation_size_upper_bound(size_t size) { + size_t result; + if (!get_allocation_footprint_policy().upper_bound(size, result)) { + throw std::overflow_error("allocation footprint overflow"); + } + return result; +} + +MemorySnapshot get_memory_snapshot() { + return allocator::common_allocator().get_memory_snapshot(); +} size_t get_active_memory() { return allocator::common_allocator().get_active_memory(); } diff --git a/mlx/memory.h b/mlx/memory.h index 4e82512ba9..04adaa4782 100644 --- a/mlx/memory.h +++ b/mlx/memory.h @@ -2,12 +2,77 @@ #pragma once +#include #include +#include #include "mlx/api.h" namespace mlx::core { +struct MemorySnapshot { + size_t active_memory; + size_t cache_memory; + size_t peak_memory; +}; + +/* Read allocator accounting under one lock. This does not synchronize streams + * or include allocations that have not entered allocator accounting yet. */ +MLX_API MemorySnapshot get_memory_snapshot(); + +/* Bound one allocator buffer, including alignment and larger cache reuse. + * This does not allocate, synchronize, or inspect the live buffer cache. */ +MLX_API size_t get_allocation_size_upper_bound(size_t size); + +// A detached value: evaluating bounds requires no allocator, error callback, +// exception, lock, or allocation. Capture once before entering admission locks. +struct AllocationFootprintPolicy { + size_t alignment; + size_t rounding_threshold; + size_t minimum_allocation; + size_t power_of_two_below; + size_t cache_page_size; + + bool upper_bound(size_t size, size_t& result) const noexcept { + if (size == 0) { result = 0; return true; } + if (alignment == 0 || cache_page_size == 0) { return false; } + size = std::max(size, minimum_allocation); + if (power_of_two_below && size < power_of_two_below) { + size_t rounded = 1; + while (rounded < size) { + if (!add(rounded, rounded, rounded)) { return false; } + } + size = rounded; + } else if (size > rounding_threshold) { + auto remainder = size % alignment; + if (remainder && !add(size, alignment - remainder, size)) { return false; } + } + size_t two_pages; + return add(cache_page_size, cache_page_size, two_pages) && + add(size, std::min(size - 1, two_pages - 1), result); + } + + // For any positive n with a valid bound, B(n) <= n + this overhead. + bool maximum_extra_bytes(size_t& result) const noexcept { + if (alignment == 0 || cache_page_size == 0) { return false; } + auto normalization = std::max({alignment - 1, + minimum_allocation ? minimum_allocation - 1 : 0, + power_of_two_below ? power_of_two_below - 1 : 0}); + size_t two_pages; + return add(cache_page_size, cache_page_size, two_pages) && + add(normalization, two_pages - 1, result); + } + + private: + static bool add(size_t a, size_t b, size_t& result) noexcept { + if (b > std::numeric_limits::max() - a) { return false; } + result = a + b; + return true; + } +}; + +MLX_API AllocationFootprintPolicy get_allocation_footprint_policy() noexcept; + /* Get the actively used memory in bytes. * * Note, this will not always match memory use reported by the system because diff --git a/tests/allocator_tests.cpp b/tests/allocator_tests.cpp index 9658e29f00..f59f47544b 100644 --- a/tests/allocator_tests.cpp +++ b/tests/allocator_tests.cpp @@ -1,8 +1,10 @@ // Copyright © 2023-2026 Apple Inc. +#include #include #include #include +#include #include #include @@ -118,3 +120,128 @@ TEST_CASE("test clear cache synchronizes cpu streams") { set_cache_limit(old_limit); } + +TEST_CASE("test coherent memory snapshot during cache transfers") { + auto old_limit = set_cache_limit(1 << 20); + clear_cache(); + auto live = allocator::malloc(32768); + auto moving = allocator::malloc(65536); + auto moving_bytes = allocator::allocator().size(moving); + auto active = get_memory_snapshot(); + allocator::free(moving); + auto cached = get_memory_snapshot(); + CHECK_EQ(active.active_memory, cached.active_memory + moving_bytes); + CHECK_EQ(active.cache_memory + moving_bytes, cached.cache_memory); + CHECK_EQ(active.peak_memory, cached.peak_memory); + auto total = cached.active_memory + cached.cache_memory; + + std::atomic stop{false}; + std::promise started; + auto started_future = started.get_future(); + auto churn = std::async(std::launch::async, [&] { + started.set_value(); + size_t transfers = 0; + do { + auto buffer = allocator::malloc(65536); + allocator::free(buffer); + ++transfers; + } while (!stop.load(std::memory_order_relaxed)); + return transfers; + }); + started_future.wait(); + + size_t inconsistent = 0; + for (int i = 0; i < 20000; ++i) { + auto snapshot = get_memory_snapshot(); + inconsistent += snapshot.active_memory + snapshot.cache_memory != total; + inconsistent += snapshot.active_memory > snapshot.peak_memory; + } + stop.store(true, std::memory_order_relaxed); + CHECK_GT(churn.get(), 0); + CHECK_EQ(inconsistent, 0); + + allocator::free(live); + clear_cache(); + set_cache_limit(old_limit); +} + +TEST_CASE("test memory snapshot does not wait for stream work") { + std::promise started; + auto started_future = started.get_future(); + std::promise release; + auto release_future = release.get_future().share(); + auto stream = new_stream(Device{Device::cpu}); + scheduler::enqueue(stream, [&] { + started.set_value(); + release_future.wait(); + }); + started_future.wait(); + + auto snapshot = std::async(std::launch::async, [] { + return get_memory_snapshot(); + }); + auto status = snapshot.wait_for(std::chrono::seconds(1)); + release.set_value(); + synchronize(stream); + snapshot.get(); + CHECK_EQ(status, std::future_status::ready); +} + +TEST_CASE("allocation footprint bounds fresh and cached buffer owners") { + auto old_limit = set_cache_limit(1 << 20); + clear_cache(); + for (size_t size : {size_t(4), size_t(6000), size_t(24576), size_t(65536)}) { + auto bound = get_allocation_size_upper_bound(size); + CHECK_GE(bound, size); + auto buffer = allocator::malloc(size); + CHECK_LE(allocator::allocator().size(buffer), bound); + allocator::free(buffer); + } + clear_cache(); + auto large = allocator::malloc(49152); + auto larger_bytes = allocator::allocator().size(large); + allocator::free(large); + auto reused = allocator::malloc(32768); + CHECK_LE(allocator::allocator().size(reused), + get_allocation_size_upper_bound(32768)); + CHECK_GE(larger_bytes, 49152); + allocator::free(reused); + clear_cache(); + set_cache_limit(old_limit); +} + +TEST_CASE("allocation prediction does not change allocator counters") { + auto before = get_memory_snapshot(); + CHECK_GE(get_allocation_size_upper_bound(24576), 24576); + CHECK_EQ(get_allocation_size_upper_bound(0), 0); + CHECK_THROWS(get_allocation_size_upper_bound(std::numeric_limits::max())); + auto after = get_memory_snapshot(); + CHECK_EQ(after.active_memory, before.active_memory); + CHECK_EQ(after.cache_memory, before.cache_memory); + CHECK_EQ(after.peak_memory, before.peak_memory); +} + +TEST_CASE("detached allocation policies preserve backend size classes without exceptions") { + const AllocationFootprintPolicy cpu{1, 0, 0, 0, 4096}; + const AllocationFootprintPolicy metal{16384, 16384, 0, 0, 16384}; + const AllocationFootprintPolicy cuda{16384, 0, 8, 16384, 16384}; + size_t result = 0; + CHECK(cpu.upper_bound(24576, result)); + CHECK_EQ(result, 32767); + CHECK(metal.upper_bound(24576, result)); + CHECK_EQ(result, 65535); + CHECK(cuda.upper_bound(1, result)); + CHECK_EQ(result, 15); + CHECK(cuda.upper_bound(8193, result)); + CHECK_EQ(result, 32767); + for (auto p : {cpu, metal, cuda}) { + size_t extra = 0; + REQUIRE(p.maximum_extra_bytes(extra)); + for (size_t n : {1, 4, 8191, 8192, 8193, 16383, 16384, 16385, 24576, 65537}) { + REQUIRE(p.upper_bound(n, result)); + CHECK_GE(result, n); + CHECK_LE(result - n, extra); + } + CHECK_FALSE(p.upper_bound(std::numeric_limits::max(), result)); + } +} From f8eec2476cdb5263fb6e2a19dd71f2c8b7c0a7d3 Mon Sep 17 00:00:00 2001 From: Gajesh Naik <26431906+Gajesh2007@users.noreply.github.com> Date: Sun, 6 Sep 2026 01:26:52 -0700 Subject: [PATCH 2/2] Correct quantized bias accumulation in reviewed 0.9.0 source Append-only signed publication of reviewed source fab0f39f69140393b454c32d6f4bf7a9b32f9dcc. Preserves the existing publication parent and original milestone history. Implementation tree is identical to reviewed source. --- mlx/backend/metal/kernels/quantized.h | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/mlx/backend/metal/kernels/quantized.h b/mlx/backend/metal/kernels/quantized.h index 6831cfd294..1f28e82cc3 100644 --- a/mlx/backend/metal/kernels/quantized.h +++ b/mlx/backend/metal/kernels/quantized.h @@ -36,7 +36,7 @@ inline U load_vector(const device T* x, thread U* x_thread) { if (bits == 2) { for (int i = 0; i < values_per_thread; i += 4) { - sum += x[i] + x[i + 1] + x[i + 2] + x[i + 3]; + sum += U(x[i]) + U(x[i + 1]) + U(x[i + 2]) + U(x[i + 3]); x_thread[i] = x[i]; x_thread[i + 1] = x[i + 1] / 4.0f; x_thread[i + 2] = x[i + 2] / 16.0f; @@ -46,8 +46,8 @@ inline U load_vector(const device T* x, thread U* x_thread) { else if (bits == 3) { for (int i = 0; i < values_per_thread; i += 8) { - sum += x[i] + x[i + 1] + x[i + 2] + x[i + 3] + x[i + 4] + x[i + 5] + - x[i + 6] + x[i + 7]; + sum += U(x[i]) + U(x[i + 1]) + U(x[i + 2]) + U(x[i + 3]) + U(x[i + 4]) + + U(x[i + 5]) + U(x[i + 6]) + U(x[i + 7]); x_thread[i] = x[i]; x_thread[i + 1] = x[i + 1] / 8.0f; x_thread[i + 2] = x[i + 2] / 64.0f; @@ -61,7 +61,7 @@ inline U load_vector(const device T* x, thread U* x_thread) { else if (bits == 4) { for (int i = 0; i < values_per_thread; i += 4) { - sum += x[i] + x[i + 1] + x[i + 2] + x[i + 3]; + sum += U(x[i]) + U(x[i + 1]) + U(x[i + 2]) + U(x[i + 3]); x_thread[i] = x[i]; x_thread[i + 1] = x[i + 1] / 16.0f; x_thread[i + 2] = x[i + 2] / 256.0f; @@ -71,8 +71,8 @@ inline U load_vector(const device T* x, thread U* x_thread) { else if (bits == 5) { for (int i = 0; i < values_per_thread; i += 8) { - sum += x[i] + x[i + 1] + x[i + 2] + x[i + 3] + x[i + 4] + x[i + 5] + - x[i + 6] + x[i + 7]; + sum += U(x[i]) + U(x[i + 1]) + U(x[i + 2]) + U(x[i + 3]) + U(x[i + 4]) + + U(x[i + 5]) + U(x[i + 6]) + U(x[i + 7]); x_thread[i] = x[i]; x_thread[i + 1] = x[i + 1] / 32.0f; x_thread[i + 2] = x[i + 2] / 4.0f; @@ -86,7 +86,7 @@ inline U load_vector(const device T* x, thread U* x_thread) { else if (bits == 6) { for (int i = 0; i < values_per_thread; i += 4) { - sum += x[i] + x[i + 1] + x[i + 2] + x[i + 3]; + sum += U(x[i]) + U(x[i + 1]) + U(x[i + 2]) + U(x[i + 3]); x_thread[i] = x[i]; x_thread[i + 1] = x[i + 1] / 64.0f; x_thread[i + 2] = x[i + 2] / 16.0f; @@ -115,7 +115,7 @@ inline U load_vector_safe(const device T* x, thread U* x_thread, int N) { if (bits == 2) { for (int i = 0; i < N; i += 4) { - sum += x[i] + x[i + 1] + x[i + 2] + x[i + 3]; + sum += U(x[i]) + U(x[i + 1]) + U(x[i + 2]) + U(x[i + 3]); x_thread[i] = x[i]; x_thread[i + 1] = x[i + 1] / 4.0f; x_thread[i + 2] = x[i + 2] / 16.0f; @@ -125,8 +125,8 @@ inline U load_vector_safe(const device T* x, thread U* x_thread, int N) { else if (bits == 3) { for (int i = 0; i < N; i += 8) { - sum += x[i] + x[i + 1] + x[i + 2] + x[i + 3] + x[i + 4] + x[i + 5] + - x[i + 6] + x[i + 7]; + sum += U(x[i]) + U(x[i + 1]) + U(x[i + 2]) + U(x[i + 3]) + U(x[i + 4]) + + U(x[i + 5]) + U(x[i + 6]) + U(x[i + 7]); x_thread[i] = x[i]; x_thread[i + 1] = x[i + 1] / 8.0f; @@ -141,7 +141,7 @@ inline U load_vector_safe(const device T* x, thread U* x_thread, int N) { else if (bits == 4) { for (int i = 0; i < N; i += 4) { - sum += x[i] + x[i + 1] + x[i + 2] + x[i + 3]; + sum += U(x[i]) + U(x[i + 1]) + U(x[i + 2]) + U(x[i + 3]); x_thread[i] = x[i]; x_thread[i + 1] = x[i + 1] / 16.0f; x_thread[i + 2] = x[i + 2] / 256.0f; @@ -151,8 +151,8 @@ inline U load_vector_safe(const device T* x, thread U* x_thread, int N) { else if (bits == 5) { for (int i = 0; i < N; i += 8) { - sum += x[i] + x[i + 1] + x[i + 2] + x[i + 3] + x[i + 4] + x[i + 5] + - x[i + 6] + x[i + 7]; + sum += U(x[i]) + U(x[i + 1]) + U(x[i + 2]) + U(x[i + 3]) + U(x[i + 4]) + + U(x[i + 5]) + U(x[i + 6]) + U(x[i + 7]); x_thread[i] = x[i]; x_thread[i + 1] = x[i + 1] / 32.0f; x_thread[i + 2] = x[i + 2] / 4.0f; @@ -166,7 +166,7 @@ inline U load_vector_safe(const device T* x, thread U* x_thread, int N) { else if (bits == 6) { for (int i = 0; i < N; i += 4) { - sum += x[i] + x[i + 1] + x[i + 2] + x[i + 3]; + sum += U(x[i]) + U(x[i + 1]) + U(x[i + 2]) + U(x[i + 3]); x_thread[i] = x[i]; x_thread[i + 1] = x[i + 1] / 64.0f; x_thread[i + 2] = x[i + 2] / 16.0f;