29 if (!image || !patches ||
C <= 0 || H <= 0 || W <= 0 || P <= 0) {
33 int num_patches_h = H / P;
34 int num_patches_w = W / P;
35 int patch_dim =
C * P * P;
37 for (
int ph = 0; ph < num_patches_h; ++ph) {
38 for (
int pw = 0; pw < num_patches_w; ++pw) {
39 int patch_idx = ph * num_patches_w + pw;
40 uint16_t *dst_patch = patches + (size_t)patch_idx * (
size_t)patch_dim;
42 for (
int c = 0; c <
C; ++c) {
43 for (
int py = 0; py < P; ++py) {
47 const uint16_t *src_row = image + (size_t)c * (
size_t)H * (size_t)W + (
size_t)y * (size_t)W + (
size_t)x;
48 uint16_t *dst_row = dst_patch + (size_t)c * (
size_t)P * (size_t)P + (
size_t)py * (size_t)P;
50 memcpy(dst_row, src_row, (
size_t)P *
sizeof(uint16_t));
64 if (!d_patches || !d_image ||
C <= 0 || H <= 0 || W <= 0 || P <= 0) {
68 int num_patches_h = H / P;
69 int num_patches_w = W / P;
70 int patch_dim =
C * P * P;
72 memset(d_image, 0, (
size_t)
C * (
size_t)H * (
size_t)W *
sizeof(uint16_t));
74 for (
int ph = 0; ph < num_patches_h; ++ph) {
75 for (
int pw = 0; pw < num_patches_w; ++pw) {
76 int patch_idx = ph * num_patches_w + pw;
77 const uint16_t *src_patch = d_patches + (size_t)patch_idx * (
size_t)patch_dim;
79 for (
int c = 0; c <
C; ++c) {
80 for (
int py = 0; py < P; ++py) {
84 uint16_t *dst_row = d_image + (size_t)c * (
size_t)H * (size_t)W + (
size_t)y * (size_t)W + (
size_t)x;
85 const uint16_t *src_row = src_patch + (size_t)c * (
size_t)P * (size_t)P + (
size_t)py * (size_t)P;
87 for (
int px = 0; px < P; ++px) {
static uint16_t float_to_bf16(float f)
static float bf16_to_float(uint16_t v)
void im2patch_bf16(const uint16_t *image, uint16_t *patches, int C, int H, int W, int P)
void patch2im_bf16(const uint16_t *d_patches, uint16_t *d_image, int C, int H, int W, int P)