-
Notifications
You must be signed in to change notification settings - Fork 555
Expand file tree
/
Copy pathiir.cpp
More file actions
73 lines (62 loc) · 2.13 KB
/
Copy pathiir.cpp
File metadata and controls
73 lines (62 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*******************************************************
* Copyright (c) 2022, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <Array.hpp>
#include <arith.hpp>
#include <convolve.hpp>
#include <err_oneapi.hpp>
#include <iir.hpp>
#include <kernel/iir.hpp>
#include <math.hpp>
#include <af/dim4.hpp>
using af::dim4;
namespace arrayfire {
namespace oneapi {
template<typename T>
Array<T> iir(const Array<T> &b, const Array<T> &a, const Array<T> &x) {
AF_BATCH_KIND type = x.ndims() == 1 ? AF_BATCH_NONE : AF_BATCH_SAME;
if (x.ndims() != b.ndims()) {
type = (x.ndims() < b.ndims()) ? AF_BATCH_RHS : AF_BATCH_LHS;
}
// Extract the first N elements
Array<T> c = convolve<T, T>(x, b, type, 1, true);
dim4 cdims = c.dims();
cdims[0] = x.dims()[0];
c.resetDims(cdims);
int num_a = a.dims()[0];
if (num_a == 1) { return c; }
size_t local_bytes_req = (num_a * 2 + 1) * sizeof(T);
if (local_bytes_req >
getDevice().get_info<sycl::info::device::local_mem_size>()) {
char errMessage[256];
snprintf(errMessage, sizeof(errMessage),
"\ncurrent OneAPI device does not have sufficient local "
"memory,\n"
"for iir kernel, %zu(required) > %zu(available)\n",
local_bytes_req,
getDevice().get_info<sycl::info::device::local_mem_size>());
AF_ERROR(errMessage, AF_ERR_RUNTIME);
}
dim4 ydims = c.dims();
Array<T> y = createEmptyArray<T>(ydims);
if (a.ndims() > 1) {
kernel::iir<T, true>(y, c, a);
} else {
kernel::iir<T, false>(y, c, a);
}
return y;
}
#define INSTANTIATE(T) \
template Array<T> iir(const Array<T> &b, const Array<T> &a, \
const Array<T> &x);
INSTANTIATE(float)
INSTANTIATE(double)
INSTANTIATE(cfloat)
INSTANTIATE(cdouble)
} // namespace oneapi
} // namespace arrayfire