Skip to content

Commit bd272f6

Browse files
committed
Add error messages to kernel checks
1 parent b36737c commit bd272f6

File tree

1 file changed

+54
-11
lines changed

1 file changed

+54
-11
lines changed

kernels/prim_ops/register_prim_ops.cpp

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ namespace function {
2222

2323
namespace {
2424

25-
#define __ET_PRIM_OP_ERROR_IMPL(a, b, context) \
26-
else { \
27-
ET_KERNEL_CHECK(context, false, InvalidType, /* void */); \
25+
#define __ET_PRIM_OP_ERROR_IMPL(a, b, context) \
26+
else { \
27+
ET_KERNEL_CHECK_MSG( \
28+
context, \
29+
false, \
30+
InvalidType, \
31+
/* void */, \
32+
"%zu, %zu", \
33+
(size_t)a.tag, \
34+
(size_t)b.tag); \
2835
}
2936

3037
#define __NUMBER_ET_PRIM_OP_IMPL(operator, stack, context) \
@@ -167,7 +174,14 @@ static Kernel prim_ops[] = {
167174
} else if (a.isDouble() && b.isInt()) {
168175
floor_div_double(a.toDouble(), static_cast<double>(b.toInt()), out);
169176
} else {
170-
ET_KERNEL_CHECK(context, false, InvalidType, /* void */);
177+
ET_KERNEL_CHECK_MSG(
178+
context,
179+
false,
180+
InvalidType,
181+
/* void */,
182+
"%zu, %zu",
183+
(size_t)a.tag,
184+
(size_t)b.tag);
171185
}
172186
}),
173187

@@ -191,7 +205,14 @@ static Kernel prim_ops[] = {
191205
} else if (a.isDouble() && b.isInt()) {
192206
out = EValue(a.toDouble() / b.toInt());
193207
} else {
194-
ET_KERNEL_CHECK(context, false, InvalidType, /* void */);
208+
ET_KERNEL_CHECK_MSG(
209+
context,
210+
false,
211+
InvalidType,
212+
/* void */,
213+
"%zu, %zu",
214+
(size_t)a.tag,
215+
(size_t)b.tag);
195216
}
196217
}),
197218

@@ -211,7 +232,8 @@ static Kernel prim_ops[] = {
211232
// TODO: This should be impossible
212233
out = EValue(a.toDouble());
213234
} else {
214-
ET_KERNEL_CHECK(context, false, InvalidType, /* void */);
235+
ET_KERNEL_CHECK_MSG(
236+
context, false, InvalidType, /* void */, "%zu", (size_t)a.tag);
215237
}
216238
}),
217239

@@ -261,7 +283,8 @@ static Kernel prim_ops[] = {
261283
} else if (a.isDouble()) {
262284
out = EValue(-a.toDouble());
263285
} else {
264-
ET_KERNEL_CHECK(context, false, InvalidType, /* void */);
286+
ET_KERNEL_CHECK_MSG(
287+
context, false, InvalidType, /* void */, "%zu", (size_t)a.tag);
265288
}
266289
}),
267290

@@ -298,7 +321,14 @@ static Kernel prim_ops[] = {
298321
if (a.isInt() && b.isInt()) {
299322
out = EValue(a.toInt() % b.toInt());
300323
} else {
301-
ET_KERNEL_CHECK(context, false, InvalidType, /* void */);
324+
ET_KERNEL_CHECK_MSG(
325+
context,
326+
false,
327+
InvalidType,
328+
/* void */,
329+
"%zu, %zu",
330+
(size_t)a.tag,
331+
(size_t)b.tag);
302332
}
303333
}),
304334

@@ -312,7 +342,13 @@ static Kernel prim_ops[] = {
312342
if (a.isDouble()) {
313343
out = EValue(static_cast<int64_t>(ceil(a.toDouble())));
314344
} else {
315-
ET_KERNEL_CHECK(context, false, InvalidType, /* void */);
345+
ET_KERNEL_CHECK_MSG(
346+
context,
347+
false,
348+
InvalidType,
349+
/* void */,
350+
"Unsupported DType %zu",
351+
(size_t)a.tag);
316352
}
317353
}),
318354

@@ -343,7 +379,13 @@ static Kernel prim_ops[] = {
343379

344380
out = EValue(static_cast<int64_t>(res));
345381
} else {
346-
ET_KERNEL_CHECK(context, false, InvalidType, /* void */);
382+
ET_KERNEL_CHECK_MSG(
383+
context,
384+
false,
385+
InvalidType,
386+
/* void */,
387+
"Unsupported DType %zu",
388+
(size_t)a.tag);
347389
}
348390
}),
349391

@@ -357,7 +399,8 @@ static Kernel prim_ops[] = {
357399
if (a.isDouble()) {
358400
out = EValue(static_cast<int64_t>(trunc(a.toDouble())));
359401
} else {
360-
ET_KERNEL_CHECK(context, false, InvalidType, /* void */);
402+
ET_KERNEL_CHECK_MSG(
403+
context, false, InvalidType, /* void */, "%zu", (size_t)a.tag);
361404
}
362405
}),
363406

0 commit comments

Comments
 (0)