Skip to content

Commit dc23c6a

Browse files
committed
Merge branch 'master' into esocrok
2 parents a7a37e3 + 53d0f3f commit dc23c6a

File tree

17 files changed

+1082
-255
lines changed

17 files changed

+1082
-255
lines changed

common/arg.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@
5656
#endif
5757
#define LLAMA_MAX_URL_LENGTH 2084 // Maximum URL Length in Chrome: 2083
5858

59+
// isatty
60+
#if defined(_WIN32)
61+
#include <io.h>
62+
#else
63+
#include <unistd.h>
64+
#endif
65+
5966
using json = nlohmann::ordered_json;
6067

6168
std::initializer_list<enum llama_example> mmproj_examples = {
@@ -102,6 +109,14 @@ static void write_file(const std::string & fname, const std::string & content) {
102109
}
103110
}
104111

112+
static bool is_output_a_tty() {
113+
#if defined(_WIN32)
114+
return _isatty(_fileno(stdout));
115+
#else
116+
return isatty(1);
117+
#endif
118+
}
119+
105120
common_arg & common_arg::set_examples(std::initializer_list<enum llama_example> examples) {
106121
this->examples = std::move(examples);
107122
return *this;
@@ -664,7 +679,11 @@ static std::string show_masked_url(const common_url & parts) {
664679
return parts.scheme + "://" + (parts.user.empty() ? "" : "****:****@") + parts.host + parts.path;
665680
}
666681

667-
static void print_progress(size_t current, size_t total) { // TODO isatty
682+
static void print_progress(size_t current, size_t total) {
683+
if (!is_output_a_tty()) {
684+
return;
685+
}
686+
668687
if (!total) {
669688
return;
670689
}

ggml/include/ggml.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@
237237
#define GGML_EXIT_SUCCESS 0
238238
#define GGML_EXIT_ABORTED 1
239239

240+
// TODO: convert to enum https://github.com/ggml-org/llama.cpp/pull/16187#discussion_r2388538726
241+
#define GGML_ROPE_TYPE_NORMAL 0
240242
#define GGML_ROPE_TYPE_NEOX 2
241243
#define GGML_ROPE_TYPE_MROPE 8
242244
#define GGML_ROPE_TYPE_VISION 24

ggml/src/ggml-webgpu/wgsl-shaders/add.tmpl.wgsl

Lines changed: 0 additions & 44 deletions
This file was deleted.

ggml/src/ggml-webgpu/wgsl-shaders/add_in_place.tmpl.wgsl

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
#define(VARIANTS)
2+
3+
[
4+
{
5+
"SHADER_NAME": "add_f32",
6+
"REPLS": {
7+
"TYPE" : "f32",
8+
"OP": "+"
9+
},
10+
"DECLS": ["NOT_INPLACE"]
11+
},
12+
{
13+
"SHADER_NAME": "add_f16",
14+
"REPLS": {
15+
"TYPE" : "f16",
16+
"OP": "+"
17+
},
18+
"DECLS": ["NOT_INPLACE"]
19+
},
20+
{
21+
"SHADER_NAME": "add_f32_inplace",
22+
"REPLS": {
23+
"TYPE" : "f32",
24+
"OP": "+"
25+
},
26+
"DECLS": ["INPLACE"]
27+
},
28+
{
29+
"SHADER_NAME": "add_f16_inplace",
30+
"REPLS": {
31+
"TYPE" : "f16",
32+
"OP": "+"
33+
},
34+
"DECLS": ["INPLACE"]
35+
},
36+
{
37+
"SHADER_NAME": "mul_f32",
38+
"REPLS": {
39+
"TYPE" : "f32",
40+
"OP": "*"
41+
},
42+
"DECLS": ["NOT_INPLACE"]
43+
},
44+
{
45+
"SHADER_NAME": "mul_f16",
46+
"REPLS": {
47+
"TYPE" : "f16",
48+
"OP": "*"
49+
},
50+
"DECLS": ["NOT_INPLACE"]
51+
},
52+
{
53+
"SHADER_NAME": "mul_f32_inplace",
54+
"REPLS": {
55+
"TYPE" : "f32",
56+
"OP": "*"
57+
},
58+
"DECLS": ["INPLACE"]
59+
},
60+
{
61+
"SHADER_NAME": "mul_f16_inplace",
62+
"REPLS": {
63+
"TYPE" : "f16",
64+
"OP": "*"
65+
},
66+
"DECLS": ["INPLACE"]
67+
},
68+
{
69+
"SHADER_NAME": "sub_f32",
70+
"REPLS": {
71+
"TYPE" : "f32",
72+
"OP": "-"
73+
},
74+
"DECLS": ["NOT_INPLACE"]
75+
},
76+
{
77+
"SHADER_NAME": "sub_f16",
78+
"REPLS": {
79+
"TYPE" : "f16",
80+
"OP": "-"
81+
},
82+
"DECLS": ["NOT_INPLACE"]
83+
},
84+
{
85+
"SHADER_NAME": "sub_f32_inplace",
86+
"REPLS": {
87+
"TYPE" : "f32",
88+
"OP": "-"
89+
},
90+
"DECLS": ["INPLACE"]
91+
},
92+
{
93+
"SHADER_NAME": "sub_f16_inplace",
94+
"REPLS": {
95+
"TYPE" : "f16",
96+
"OP": "-"
97+
},
98+
"DECLS": ["INPLACE"]
99+
},
100+
{
101+
"SHADER_NAME": "div_f32",
102+
"REPLS": {
103+
"TYPE" : "f32",
104+
"OP": "/"
105+
},
106+
"DECLS": ["NOT_INPLACE"]
107+
},
108+
{
109+
"SHADER_NAME": "div_f16",
110+
"REPLS": {
111+
"TYPE" : "f16",
112+
"OP": "/"
113+
},
114+
"DECLS": ["NOT_INPLACE"]
115+
},
116+
{
117+
"SHADER_NAME": "div_f32_inplace",
118+
"REPLS": {
119+
"TYPE" : "f32",
120+
"OP": "/"
121+
},
122+
"DECLS": ["INPLACE"]
123+
},
124+
{
125+
"SHADER_NAME": "div_f16_inplace",
126+
"REPLS": {
127+
"TYPE" : "f16",
128+
"OP": "/"
129+
},
130+
"DECLS": ["INPLACE"]
131+
}
132+
]
133+
134+
#end(VARIANTS)
135+
136+
#define(DECLS)
137+
138+
#decl(NOT_INPLACE)
139+
140+
fn update(dst_i: u32, src0_i: u32, src1_i: u32) {
141+
dst[dst_i] = src0[src0_i] {{OP}} src1[src1_i];
142+
}
143+
144+
@group(0) @binding(2)
145+
var<storage, read_write> dst: array<{{TYPE}}>;
146+
147+
@group(0) @binding(3)
148+
var<uniform> params: Params;
149+
150+
#enddecl(NOT_INPLACE)
151+
152+
#decl(INPLACE)
153+
154+
fn update(dst_i: u32, src0_i: u32, src1_i: u32) {
155+
src0[dst_i] = src0[src0_i] {{OP}} src1[src1_i];
156+
}
157+
158+
@group(0) @binding(2)
159+
var<uniform> params: Params;
160+
161+
#enddecl(INPLACE)
162+
163+
#end(DECLS)
164+
165+
166+
#define(SHADER)
167+
168+
enable f16;
169+
170+
#include "binary_head.tmpl"
171+
172+
@group(0) @binding(0)
173+
var<storage, read_write> src0: array<{{TYPE}}>;
174+
175+
@group(0) @binding(1)
176+
var<storage, read_write> src1: array<{{TYPE}}>;
177+
178+
DECLS
179+
180+
override wg_size: u32;
181+
@compute @workgroup_size(wg_size)
182+
fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
183+
if (gid.x < params.ne) {
184+
update(params.offset_dst + gid.x, params.offset_src0 + gid.x, params.offset_src1 + src1_index(gid.x));
185+
}
186+
}
187+
188+
#end(SHADER)

0 commit comments

Comments
 (0)