Some checks failed
Bindings Tests (Go) / ubuntu-22 (push) Failing after 31s
CI (sycl) / ubuntu-22-cmake-sycl (linux/arm/v7, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl (linux/ppc64le, icx, icpx, ON) (push) Failing after 2s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/amd64, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/arm/v7, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/arm64, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/ppc64le, icx, icpx, ON) (push) Failing after 3s
CI (vad) / vad (push) Failing after 3s
CI (wasm) / emscripten (Release) (push) Failing after 4s
Bindings Tests (Ruby) / ubuntu-22 (push) Failing after 37s
CI (android) / android (push) Failing after 16s
CI (android) / android_java (push) Failing after 3s
CI (clang) / ubuntu-22-clang (linux/amd64, Debug) (push) Failing after 3s
CI (clang) / ubuntu-22-clang (linux/amd64, Release) (push) Failing after 2s
CI (clang) / ubuntu-22-clang (linux/ppc64le, Debug) (push) Failing after 3s
CI (clang) / ubuntu-22-clang (linux/ppc64le, Release) (push) Failing after 3s
CI (cpu) / ggml-ci-x64-cpu-low-perf (push) Failing after 3s
CI (cpu) / ggml-ci-x64-cpu-high-perf (push) Failing after 2s
CI (gcc) / ubuntu-22-gcc (linux/amd64, Debug) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc (linux/amd64, Release) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc (linux/ppc64le, Debug) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc (linux/ppc64le, Release) (push) Failing after 4s
CI (gcc) / ubuntu-22-gcc-arm-v7 (linux/arm/v7, Debug) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc-arm-v7 (linux/arm/v7, Release) (push) Failing after 3s
CI (quantize) / quantize (push) Failing after 3s
CI (sanitize) / ubuntu-22-gcc-sanitized (ADDRESS) (push) Failing after 3s
CI (sanitize) / ubuntu-22-gcc-sanitized (THREAD) (push) Failing after 3s
CI (sanitize) / ubuntu-22-gcc-sanitized (UNDEFINED) (push) Failing after 2s
CI (sycl) / ubuntu-22-cmake-sycl (linux/amd64, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl (linux/arm64, icx, icpx, ON) (push) Failing after 3s
Examples WASM / deploy-wasm-github-pages (push) Failing after 3s
Examples Tests / addon_node-ubuntu-22 (20.x) (push) Failing after 3s
Examples Tests / addon_node-ubuntu-22 (22.x) (push) Failing after 2s
CI (coreml) / coreml-base-en (push) Has been cancelled
CI (self-hosted) / gpu-vulkan (push) Has been cancelled
CI (self-hosted) / npu-amd-windows (push) Has been cancelled
CI (self-hosted) / gpu-vulkan-nvidia-cm2 (push) Has been cancelled
CI (clang) / ubuntu-22-clang-arm64 (Debug) (push) Has been cancelled
CI (clang) / ubuntu-22-clang-arm64 (Release) (push) Has been cancelled
CI (self-hosted) / gpu-cuda (push) Has been cancelled
CI (self-hosted) / gpu-vulkan-nvidia-cm (push) Has been cancelled
CI (cpu) / ggml-ci-arm64-cpu-low-perf (push) Has been cancelled
CI (cpu) / ggml-ci-arm64-cpu-high-perf (push) Has been cancelled
CI (cpu) / ggml-ci-arm64-cpu-high-perf-sve (push) Has been cancelled
CI (freebsd) / freeBSD-latest (push) Has been cancelled
CI (self-hosted) / gpu-metal (push) Has been cancelled
CI (gcc) / ubuntu-22-gcc-arm64 (Debug) (push) Has been cancelled
CI (gcc) / ubuntu-22-gcc-arm64 (Release) (push) Has been cancelled
CI (macOS) / macOS-latest (generic/platform=iOS) (push) Has been cancelled
CI (macOS) / macOS-latest (generic/platform=macOS) (push) Has been cancelled
CI (macOS) / macOS-latest (generic/platform=tvOS) (push) Has been cancelled
CI (self-hosted) / npu-amd-linux (push) Has been cancelled
CI (windows) / windows-msys2 (Release, clang, clang-x86_64, CLANG64) (push) Has been cancelled
CI (windows) / windows-msys2 (Release, gcc, ucrt-x86_64, UCRT64) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-cuda.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-cuda]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-intel.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-intel]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-musa.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-musa]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-vulkan.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-vulkan]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-vulkan.Dockerfile platform:linux/arm64 runs_on:ubuntu-24.04-arm tag:main-vulkan-arm64]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main.Dockerfile platform:linux/arm64 runs_on:ubuntu-24.04-arm tag:main-arm64]) (push) Has been cancelled
Mark inactive issues stale / mark-issues (push) Failing after 1s
139 lines
4.5 KiB
C
139 lines
4.5 KiB
C
#ifndef HTP_TENSOR_H
|
|
#define HTP_TENSOR_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include "htp-ops.h"
|
|
#include "hex-bitmap.h"
|
|
#include "hex-common.h"
|
|
#include "hex-fastdiv.h"
|
|
|
|
enum {
|
|
HTP_TENSOR_MDEV_LINE_SIZE = 128,
|
|
};
|
|
|
|
struct htp_tensor_mdev_range {
|
|
uint32_t start;
|
|
uint32_t count;
|
|
};
|
|
|
|
static inline void * htp_tensor_data(const struct htp_tensor * t) {
|
|
return (void *) (uintptr_t) t->data;
|
|
}
|
|
|
|
static inline uint32_t * htp_tensor_flags(const struct htp_tensor * t) {
|
|
return (uint32_t *) &t->flags;
|
|
}
|
|
|
|
static inline bool htp_tensor_is_contiguous(const struct htp_tensor * t, uint32_t type_size) {
|
|
uint32_t next_nb = type_size;
|
|
if (t->ne[0] != 1 && t->nb[0] != next_nb) {
|
|
return false;
|
|
}
|
|
next_nb *= t->ne[0];
|
|
for (int i = 1; i < HTP_OP_MAX_DIMS; i++) {
|
|
if (t->ne[i] != 1 && t->nb[i] != next_nb) {
|
|
return false;
|
|
}
|
|
next_nb *= t->ne[i];
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static inline bool htp_tensor_is_permuted(const struct htp_tensor * t) {
|
|
return t->nb[0] > t->nb[1] || t->nb[1] > t->nb[2] || t->nb[2] > t->nb[3];
|
|
}
|
|
|
|
static inline bool htp_tensor_mdev_data_aligned(const struct htp_tensor * t) {
|
|
return ((uintptr_t) t->data & (HTP_TENSOR_MDEV_LINE_SIZE - 1)) == 0;
|
|
}
|
|
|
|
static inline bool htp_tensor_can_row_partition(const struct htp_tensor * t, uint32_t elem_size) {
|
|
if (!htp_tensor_mdev_data_aligned(t)) {
|
|
return false;
|
|
}
|
|
if (t->ne[0] != 1 && t->nb[0] != elem_size) {
|
|
return false;
|
|
}
|
|
if (htp_tensor_is_permuted(t)) {
|
|
return false;
|
|
}
|
|
if (t->ne[1] > 1 && (t->nb[1] & (HTP_TENSOR_MDEV_LINE_SIZE - 1)) != 0) return false;
|
|
if (t->ne[2] > 1 && (t->nb[2] & (HTP_TENSOR_MDEV_LINE_SIZE - 1)) != 0) return false;
|
|
if (t->ne[3] > 1 && (t->nb[3] & (HTP_TENSOR_MDEV_LINE_SIZE - 1)) != 0) return false;
|
|
return true;
|
|
}
|
|
|
|
static inline bool htp_tensor_mdev_rows_per_chunk(const struct htp_tensor * t, uint32_t elem_size, uint32_t row_size, uint32_t * rows_per_chunk) {
|
|
*rows_per_chunk = 0;
|
|
|
|
if (!htp_tensor_mdev_data_aligned(t)) {
|
|
return false;
|
|
}
|
|
if (t->ne[0] != 1 && t->nb[0] != elem_size) {
|
|
return false;
|
|
}
|
|
if (htp_tensor_is_permuted(t)) {
|
|
return false;
|
|
}
|
|
if (t->ne[1] > 1 && (t->nb[1] & (HTP_TENSOR_MDEV_LINE_SIZE - 1)) == 0 &&
|
|
(t->ne[2] <= 1 || (t->nb[2] & (HTP_TENSOR_MDEV_LINE_SIZE - 1)) == 0) &&
|
|
(t->ne[3] <= 1 || (t->nb[3] & (HTP_TENSOR_MDEV_LINE_SIZE - 1)) == 0)) {
|
|
*rows_per_chunk = 1;
|
|
return true;
|
|
}
|
|
if (t->nb[1] == row_size &&
|
|
(t->ne[2] <= 1 || t->nb[2] == t->nb[1] * t->ne[1]) &&
|
|
(t->ne[3] <= 1 || t->nb[3] == t->nb[2] * t->ne[2])) {
|
|
*rows_per_chunk = (row_size > 0) ? (HTP_TENSOR_MDEV_LINE_SIZE / hex_gcd_u32(row_size, HTP_TENSOR_MDEV_LINE_SIZE)) : 1;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static inline struct htp_tensor_mdev_range htp_tensor_mdev_partition(uint32_t total_units, uint32_t units_per_chunk, uint32_t mdev_idx, uint32_t mdev_count, const struct fastdiv_values * mdev_count_div) {
|
|
struct htp_tensor_mdev_range range = { 0, total_units };
|
|
|
|
if (mdev_count <= 1) {
|
|
return range;
|
|
}
|
|
|
|
if (units_per_chunk == 0) {
|
|
range.start = (mdev_idx == 0) ? 0 : total_units;
|
|
range.count = (mdev_idx == 0) ? total_units : 0;
|
|
return range;
|
|
}
|
|
|
|
const uint32_t total_chunks = total_units / units_per_chunk;
|
|
if (total_chunks < mdev_count) {
|
|
range.start = (mdev_idx == 0) ? 0 : total_units;
|
|
range.count = (mdev_idx == 0) ? total_units : 0;
|
|
return range;
|
|
}
|
|
|
|
const uint32_t chunks_per_mdev = fastdiv(total_chunks + mdev_count - 1, mdev_count_div);
|
|
range.start = MIN(mdev_idx * chunks_per_mdev * units_per_chunk, total_units);
|
|
if (mdev_idx == mdev_count - 1) {
|
|
range.count = total_units - range.start;
|
|
} else {
|
|
range.count = MIN(chunks_per_mdev * units_per_chunk, total_units - range.start);
|
|
}
|
|
return range;
|
|
}
|
|
|
|
static inline uint32_t htp_tensor_get_row_size(int type, uint32_t ne00) {
|
|
switch (type) {
|
|
case HTP_TYPE_F32: return ne00 * 4;
|
|
case HTP_TYPE_F16: return ne00 * 2;
|
|
case HTP_TYPE_Q8_0: return (ne00 / 32) * 34;
|
|
default: return 0;
|
|
}
|
|
}
|
|
|
|
struct htp_context;
|
|
void htp_flush_dirty_ranges(struct htp_context * ctx);
|
|
void htp_tensor_flush_all(struct htp_context * ctx, const struct htp_tensor * const * tensors, uint32_t n);
|
|
void htp_tensor_dirty_all(struct htp_context * ctx, const struct htp_tensor * const * tensors, uint32_t n);
|
|
|
|
#endif // HTP_TENSOR_H
|