227227#include <stdio.h>
228228
229229#define GGML_FILE_MAGIC 0x67676d6c // "ggml"
230- #define GGML_FILE_VERSION 1
230+ #define GGML_FILE_VERSION 2
231231
232232#define GGML_QNT_VERSION 2 // bump this on quantization format changes
233233#define GGML_QNT_VERSION_FACTOR 1000 // do not change this
@@ -562,6 +562,8 @@ extern "C" {
562562 GGML_OP_SQR ,
563563 GGML_OP_SQRT ,
564564 GGML_OP_LOG ,
565+ GGML_OP_SIN ,
566+ GGML_OP_COS ,
565567 GGML_OP_SUM ,
566568 GGML_OP_SUM_ROWS ,
567569 GGML_OP_MEAN ,
@@ -603,9 +605,11 @@ extern "C" {
603605 GGML_OP_CLAMP ,
604606 GGML_OP_CONV_TRANSPOSE_1D ,
605607 GGML_OP_IM2COL ,
608+ GGML_OP_IM2COL_BACK ,
606609 GGML_OP_CONV_TRANSPOSE_2D ,
607610 GGML_OP_POOL_1D ,
608611 GGML_OP_POOL_2D ,
612+ GGML_OP_POOL_2D_BACK ,
609613 GGML_OP_UPSCALE , // nearest interpolate
610614 GGML_OP_PAD ,
611615 GGML_OP_ARANGE ,
@@ -1106,6 +1110,22 @@ extern "C" {
11061110 struct ggml_context * ctx ,
11071111 struct ggml_tensor * a );
11081112
1113+ GGML_API struct ggml_tensor * ggml_sin (
1114+ struct ggml_context * ctx ,
1115+ struct ggml_tensor * a );
1116+
1117+ GGML_API struct ggml_tensor * ggml_sin_inplace (
1118+ struct ggml_context * ctx ,
1119+ struct ggml_tensor * a );
1120+
1121+ GGML_API struct ggml_tensor * ggml_cos (
1122+ struct ggml_context * ctx ,
1123+ struct ggml_tensor * a );
1124+
1125+ GGML_API struct ggml_tensor * ggml_cos_inplace (
1126+ struct ggml_context * ctx ,
1127+ struct ggml_tensor * a );
1128+
11091129 // return scalar
11101130 GGML_API struct ggml_tensor * ggml_sum (
11111131 struct ggml_context * ctx ,
@@ -1760,34 +1780,49 @@ extern "C" {
17601780 float min ,
17611781 float max );
17621782
1783+ // im2col
1784+ // converts data into a format that effectively results in a convolution when combined with matrix multiplication
17631785 GGML_API struct ggml_tensor * ggml_im2col (
17641786 struct ggml_context * ctx ,
1765- struct ggml_tensor * a ,
1766- struct ggml_tensor * b ,
1767- int s0 ,
1768- int s1 ,
1769- int p0 ,
1770- int p1 ,
1771- int d0 ,
1772- int d1 ,
1773- bool is_2D ,
1774- enum ggml_type dst_type );
1787+ struct ggml_tensor * a , // convolution kernel
1788+ struct ggml_tensor * b , // data
1789+ int s0 , // stride dimension 0
1790+ int s1 , // stride dimension 1
1791+ int p0 , // padding dimension 0
1792+ int p1 , // padding dimension 1
1793+ int d0 , // dilation dimension 0
1794+ int d1 , // dilation dimension 1
1795+ bool is_2D ,
1796+ enum ggml_type dst_type );
1797+
1798+ GGML_API struct ggml_tensor * ggml_im2col_back (
1799+ struct ggml_context * ctx ,
1800+ struct ggml_tensor * a , // convolution kernel
1801+ struct ggml_tensor * b , // gradient of im2col output
1802+ int64_t * ne , // shape of im2col input
1803+ int s0 , // stride dimension 0
1804+ int s1 , // stride dimension 1
1805+ int p0 , // padding dimension 0
1806+ int p1 , // padding dimension 1
1807+ int d0 , // dilation dimension 0
1808+ int d1 , // dilation dimension 1
1809+ bool is_2D );
17751810
17761811 GGML_API struct ggml_tensor * ggml_conv_depthwise_2d (
17771812 struct ggml_context * ctx ,
1778- struct ggml_tensor * a ,
1779- struct ggml_tensor * b ,
1780- int s0 ,
1781- int s1 ,
1782- int p0 ,
1783- int p1 ,
1784- int d0 ,
1785- int d1 );
1813+ struct ggml_tensor * a , // convolution kernel
1814+ struct ggml_tensor * b , // data
1815+ int s0 , // stride dimension 0
1816+ int s1 , // stride dimension 1
1817+ int p0 , // padding dimension 0
1818+ int p1 , // padding dimension 1
1819+ int d0 , // dilation dimension 0
1820+ int d1 ); // dilation dimension 1
17861821
17871822 GGML_API struct ggml_tensor * ggml_conv_1d (
17881823 struct ggml_context * ctx ,
1789- struct ggml_tensor * a ,
1790- struct ggml_tensor * b ,
1824+ struct ggml_tensor * a , // convolution kernel
1825+ struct ggml_tensor * b , // data
17911826 int s0 , // stride
17921827 int p0 , // padding
17931828 int d0 ); // dilation
@@ -1796,29 +1831,29 @@ extern "C" {
17961831 // alias for ggml_conv_1d(a, b, s, a->ne[0]/2, d)
17971832 GGML_API struct ggml_tensor * ggml_conv_1d_ph (
17981833 struct ggml_context * ctx ,
1799- struct ggml_tensor * a ,
1800- struct ggml_tensor * b ,
1801- int s ,
1802- int d );
1834+ struct ggml_tensor * a , // convolution kernel
1835+ struct ggml_tensor * b , // data
1836+ int s , // stride
1837+ int d ); // dilation
18031838
18041839 GGML_API struct ggml_tensor * ggml_conv_transpose_1d (
18051840 struct ggml_context * ctx ,
1806- struct ggml_tensor * a ,
1807- struct ggml_tensor * b ,
1808- int s0 ,
1809- int p0 ,
1810- int d0 );
1841+ struct ggml_tensor * a , // convolution kernel
1842+ struct ggml_tensor * b , // data
1843+ int s0 , // stride
1844+ int p0 , // padding
1845+ int d0 ); // dilation
18111846
18121847 GGML_API struct ggml_tensor * ggml_conv_2d (
18131848 struct ggml_context * ctx ,
1814- struct ggml_tensor * a ,
1815- struct ggml_tensor * b ,
1816- int s0 ,
1817- int s1 ,
1818- int p0 ,
1819- int p1 ,
1820- int d0 ,
1821- int d1 );
1849+ struct ggml_tensor * a , // convolution kernel
1850+ struct ggml_tensor * b , // data
1851+ int s0 , // stride dimension 0
1852+ int s1 , // stride dimension 1
1853+ int p0 , // padding dimension 0
1854+ int p1 , // padding dimension 1
1855+ int d0 , // dilation dimension 0
1856+ int d1 ); // dilation dimension 1
18221857
18231858
18241859 // kernel size is a->ne[0] x a->ne[1]
@@ -1880,6 +1915,18 @@ extern "C" {
18801915 float p0 ,
18811916 float p1 );
18821917
1918+ GGML_API struct ggml_tensor * ggml_pool_2d_back (
1919+ struct ggml_context * ctx ,
1920+ struct ggml_tensor * a ,
1921+ struct ggml_tensor * af , // "a"/input used in forward pass
1922+ enum ggml_op_pool op ,
1923+ int k0 ,
1924+ int k1 ,
1925+ int s0 ,
1926+ int s1 ,
1927+ float p0 ,
1928+ float p1 );
1929+
18831930 // nearest interpolate
18841931 // multiplies ne0 and ne1 by scale factor
18851932 // used in stable-diffusion
0 commit comments