adding trigonomitry etst to dogfood

This commit is contained in:
Blaise Tine 2024-04-09 04:14:28 -07:00
parent cef05d3110
commit b54e85113d
2 changed files with 45 additions and 0 deletions

View file

@ -324,6 +324,19 @@ void kernel_fclamp(int task_id, kernel_arg_t* __UNIFORM__ arg) {
}
}
void kernel_trigo(int task_id, kernel_arg_t* __UNIFORM__ arg) {
auto count = arg->task_size;
auto src0_ptr = (float*)arg->src0_addr;
auto src1_ptr = (float*)arg->src1_addr;
auto dst_ptr = (float*)arg->dst_addr;
auto offset = task_id * count;
for (uint32_t i = 0; i < count; ++i) {
auto a = src0_ptr[offset+i];
auto b = src1_ptr[offset+i];
dst_ptr[offset+i] = sin(a) + cos(b);
}
}
void kernel_bar(int task_id, kernel_arg_t* __UNIFORM__ arg) {
auto num_cores = vx_num_cores();
auto num_warps = vx_num_warps();
@ -405,6 +418,7 @@ static const PFN_Kernel sc_tests[] = {
kernel_itof,
kernel_utof,
kernel_fclamp,
kernel_trigo,
kernel_bar,
kernel_gbar
};

View file

@ -719,6 +719,36 @@ public:
}
};
class Test_TRIGO : public ITestCase {
public:
Test_TRIGO(TestSuite* suite) : ITestCase(suite, "trig") {}
int setup(uint32_t n, void* src1, void* src2) override {
auto a = (float*)src1;
auto b = (float*)src2;
for (uint32_t i = 0; i < n; ++i) {
a[i] = fround((n - i) * (1.0f/n));
b[i] = fround((n + i) * (1.0f/n));
}
return 0;
}
int verify(uint32_t n, void* dst, const void* src1, const void* src2) override {
int errors = 0;
auto a = (float*)src1;
auto b = (float*)src2;
auto c = (float*)dst;
for (uint32_t i = 0; i < n; ++i) {
auto ref = sin(a[i]) + cos(b[i]);
if (!almost_equal(c[i], ref)) {
std::cout << "error at result #" << i << ": expected=" << ref << ", actual=" << c[i] << ", a=" << a[i] << ", b=" << b[i] << std::endl;
++errors;
}
}
return errors;
}
};
class Test_BAR : public ITestCase {
public:
Test_BAR(TestSuite* suite) : ITestCase(suite, "bar") {}
@ -817,6 +847,7 @@ TestSuite::TestSuite(vx_device_h device)
this->add_test(new Test_ITOF(this));
this->add_test(new Test_UTOF(this));
this->add_test(new Test_FCLAMP(this));
this->add_test(new Test_TRIGO(this));
this->add_test(new Test_BAR(this));
this->add_test(new Test_GBAR(this));
}