@@ -286,19 +286,18 @@ __host__ __device__ constexpr inline void ggml_unused_vars_impl(Args&&...) noexc
286286// GGML_TENSOR_LOCALS(size_t, nb1, src1, nb);
287287//
288288#define GGML_TENSOR_LOCALS_1 (type, prefix, pointer, array ) \
289- const type prefix##0 = (pointer)->array[0 ]; \
290- GGML_UNUSED (prefix##0 );
289+ const type prefix##0 = (pointer) ? (pointer)->array[0 ] : 0 ; \
291290#define GGML_TENSOR_LOCALS_2 (type, prefix, pointer, array ) \
292291 GGML_TENSOR_LOCALS_1 (type, prefix, pointer, array) \
293- const type prefix##1 = (pointer)->array[1 ]; \
292+ const type prefix##1 = (pointer) ? (pointer) ->array[1 ] : 0 ; \
294293 GGML_UNUSED (prefix##1 );
295294#define GGML_TENSOR_LOCALS_3 (type, prefix, pointer, array ) \
296295 GGML_TENSOR_LOCALS_2 (type, prefix, pointer, array) \
297- const type prefix##2 = (pointer)->array[2 ]; \
296+ const type prefix##2 = (pointer) ? (pointer) ->array[2 ] : 0 ; \
298297 GGML_UNUSED (prefix##2 );
299298#define GGML_TENSOR_LOCALS (type, prefix, pointer, array ) \
300299 GGML_TENSOR_LOCALS_3 (type, prefix, pointer, array) \
301- const type prefix##3 = (pointer)->array[3 ]; \
300+ const type prefix##3 = (pointer) ? (pointer) ->array[3 ] : 0 ; \
302301 GGML_UNUSED (prefix##3 );
303302
304303#define GGML_TENSOR_UNARY_OP_LOCALS \
@@ -513,6 +512,7 @@ extern "C" {
513512 GGML_OP_CONV_TRANSPOSE_1D,
514513 GGML_OP_IM2COL,
515514 GGML_OP_IM2COL_BACK,
515+ GGML_OP_IM2COL_3D,
516516 GGML_OP_CONV_2D,
517517 GGML_OP_CONV_3D,
518518 GGML_OP_CONV_2D_DW,
@@ -581,7 +581,6 @@ extern "C" {
581581 GGML_UNARY_OP_ROUND,
582582 GGML_UNARY_OP_TRUNC,
583583
584-
585584 GGML_UNARY_OP_COUNT,
586585 };
587586
@@ -1495,7 +1494,7 @@ extern "C" {
14951494 struct ggml_context * ctx,
14961495 struct ggml_tensor * a,
14971496 struct ggml_tensor * b);
1498-
1497+ // note: casting from f32 to i32 will discard the fractional part
14991498 GGML_API struct ggml_tensor * ggml_cast (
15001499 struct ggml_context * ctx,
15011500 struct ggml_tensor * a,
@@ -1620,7 +1619,11 @@ extern "C" {
16201619 struct ggml_context * ctx,
16211620 struct ggml_tensor * a);
16221621
1623- // supports 3D: a->ne[2] == b->ne[1]
1622+ // supports 4D a:
1623+ // a [n_embd, ne1, ne2, ne3]
1624+ // b I32 [n_rows, ne2, ne3, 1]
1625+ //
1626+ // return [n_embd, n_rows, ne2, ne3]
16241627 GGML_API struct ggml_tensor * ggml_get_rows (
16251628 struct ggml_context * ctx,
16261629 struct ggml_tensor * a, // data
@@ -1969,7 +1972,40 @@ extern "C" {
19691972 int p1, // padding dimension 1
19701973 int d0, // dilation dimension 0
19711974 int d1); // dilation dimension 1
1975+ GGML_API struct ggml_tensor * ggml_im2col_3d (
1976+ struct ggml_context * ctx,
1977+ struct ggml_tensor * a,
1978+ struct ggml_tensor * b,
1979+ int64_t IC,
1980+ int s0, // stride width
1981+ int s1, // stride height
1982+ int s2, // stride depth
1983+ int p0, // padding width
1984+ int p1, // padding height
1985+ int p2, // padding depth
1986+ int d0, // dilation width
1987+ int d1, // dilation height
1988+ int d2, // dilation depth
1989+ enum ggml_type dst_type);
19721990
1991+ // a: [OC*IC, KD, KH, KW]
1992+ // b: [N*IC, ID, IH, IW]
1993+ // result: [N*OC, OD, OH, OW]
1994+ GGML_API struct ggml_tensor * ggml_conv_3d (
1995+ struct ggml_context * ctx,
1996+ struct ggml_tensor * a,
1997+ struct ggml_tensor * b,
1998+ int64_t IC,
1999+ int s0, // stride width
2000+ int s1, // stride height
2001+ int s2, // stride depth
2002+ int p0, // padding width
2003+ int p1, // padding height
2004+ int p2, // padding depth
2005+ int d0, // dilation width
2006+ int d1, // dilation height
2007+ int d2 // dilation depth
2008+ );
19732009 // kernel size is a->ne[0] x a->ne[1]
19742010 // stride is equal to kernel size
19752011 // padding is zero
@@ -2041,7 +2077,7 @@ extern "C" {
20412077 int d0, // dilation dimension 0
20422078 int d1); // dilation dimension 1
20432079
2044- GGML_API struct ggml_tensor * ggml_conv_3d (
2080+ GGML_API struct ggml_tensor * ggml_conv_3d_direct (
20452081 struct ggml_context * ctx,
20462082 struct ggml_tensor * a, // kernel [KW, KH, KD, IC * OC]
20472083 struct ggml_tensor * b, // input [W, H, D, C * N]
@@ -2147,6 +2183,19 @@ extern "C" {
21472183 int p1,
21482184 int p2,
21492185 int p3);
2186+
2187+ GGML_API struct ggml_tensor * ggml_pad_ext (
2188+ struct ggml_context * ctx,
2189+ struct ggml_tensor * a,
2190+ int lp0,
2191+ int rp0,
2192+ int lp1,
2193+ int rp1,
2194+ int lp2,
2195+ int rp2,
2196+ int lp3,
2197+ int rp3
2198+ );
21502199
21512200 // pad each dimension with reflection: [a, b, c, d] -> [b, a, b, c, d, c]
21522201 GGML_API struct ggml_tensor * ggml_pad_reflect_1d (
0 commit comments