Files
openharmony-mlx/gpt_oss/metal/source/include/internal/math.h
Dominik Kundel 243a1b0276 Initial commit
Co-authored-by: Zhuohan Li <zhuohan@openai.com>
Co-authored-by: Maratyszcza <marat@openai.com>
Co-authored-by: Volodymyr Kyrylov <vol@wilab.org.ua>
2025-08-05 08:19:49 -07:00

26 lines
556 B
C

#pragma once
#include <stddef.h>
#include <stdint.h>
inline static size_t math_ceil_div(size_t numer, size_t denom) {
return (numer + denom - 1) / denom;
}
inline static size_t math_max(size_t a, size_t b) {
return a >= b ? a : b;
}
inline static size_t math_min(size_t a, size_t b) {
return a < b ? a : b;
}
static size_t math_round_up_po2(size_t bytes, size_t multiple) {
const size_t multiple_mask = multiple - 1;
if ((bytes & multiple_mask) != 0) {
bytes |= multiple_mask;
bytes += 1;
}
return bytes;
}