@@ -47,37 +47,37 @@ constexpr int M = 20;
47
47
constexpr int T = 20 ;
48
48
// The parameter for generating the sequence.
49
49
constexpr int seed = 0 ;
50
- // Minimal double to initialize logarithms for Viterbi values equal to 0.
51
- constexpr double MIN_DOUBLE = -1.0 * std::numeric_limits<double >::max();
50
+ // Minimal float to initialize logarithms for Viterbi values equal to 0.
51
+ constexpr float MIN_FLOAT = -1.0 * std::numeric_limits<float >::max();
52
52
53
- bool ViterbiCondition (double x, double y, double z, double compare);
53
+ bool ViterbiCondition (float x, float y, float z, float compare);
54
54
55
55
int main () {
56
56
try {
57
57
// Initializing and generating initial probabilities for the hidden states.
58
- double (*pi ) = new double [N];
58
+ float (*pi ) = new float [N];
59
59
for (int i = 0 ; i < N; ++i) {
60
60
pi [i] = sycl::log10 (1 .0f / N);
61
61
}
62
- buffer<double , 1 > pi_buf (pi , N);
62
+ buffer<float , 1 > pi_buf (pi , N);
63
63
64
64
// Device initialization.
65
65
queue q (default_selector_v);
66
66
cout << " Device: " << q.get_device ().get_info <info::device::name>() << " "
67
67
<< q.get_device ().get_platform ().get_info <info::platform::name>() << " \n " ;
68
68
69
69
// Buffers initialization.
70
- buffer<double , 2 > viterbi (range<2 >(N, T));
70
+ buffer<float , 2 > viterbi (range<2 >(N, T));
71
71
buffer<int , 2 > back_pointer (range<2 >(N, T));
72
- buffer<double , 2 > a (range<2 >(N, N));
73
- buffer<double , 2 > b (range<2 >(N, M));
72
+ buffer<float , 2 > a (range<2 >(N, N));
73
+ buffer<float , 2 > b (range<2 >(N, M));
74
74
75
75
// Generating transition matrix A for the Markov process.
76
76
q.submit ([&](handler& h) {
77
77
auto a_acc = a.get_access <access ::mode::write >(h);
78
78
h.parallel_for (range<2 >(N, N), [=](id<2 > index ) {
79
79
// The sum of the probabilities in each row of the matrix A has to be equal to 1.
80
- double prob = 1 .0f / N;
80
+ float prob = 1 .0f / N;
81
81
// The algorithm computes logarithms of the probability values to improve small numbers processing.
82
82
a_acc[index ] = sycl::log10 (prob);
83
83
});
@@ -88,9 +88,9 @@ int main() {
88
88
auto b_acc = b.get_access <access ::mode::write >(h);
89
89
h.parallel_for (range<2 >(N, M), [=](id<2 > index ) {
90
90
// The sum of the probabilities in each row of the matrix B has to be equal to 1.
91
- double prob = ((index [0 ] + index [1 ]) % M) * 2 .0f / M / (M - 1 );
91
+ float prob = ((index [0 ] + index [1 ]) % M) * 2 .0f / M / (M - 1 );
92
92
// The algorithm computes logarithms of the probability values to improve small numbers processing.
93
- b_acc[index ] = (prob == 0 .0f ) ? MIN_DOUBLE : sycl::log10 (prob);
93
+ b_acc[index ] = (prob == 0 .0f ) ? MIN_FLOAT : sycl::log10 (prob);
94
94
});
95
95
});
96
96
@@ -113,7 +113,7 @@ int main() {
113
113
int j = index [1 ];
114
114
// At starting point only the first Viterbi values are defined and these Values are substituted
115
115
// with logarithms due to the following equation: log(x*y) = log(x) + log(y).
116
- v_acc[index ] = (j != 0 ) ? MIN_DOUBLE : pi_acc[i] + b_acc[i][seq_acc[0 ]];
116
+ v_acc[index ] = (j != 0 ) ? MIN_FLOAT : pi_acc[i] + b_acc[i][seq_acc[0 ]];
117
117
// Default values of all the back pointers are (-1) to show that they are not determined yet.
118
118
b_ptr_acc[index ] = -1 ;
119
119
});
@@ -147,7 +147,7 @@ int main() {
147
147
auto v_acc = viterbi.get_access <access ::mode::read >();
148
148
auto b_ptr_acc = back_pointer.get_access <access ::mode::read >();
149
149
auto vit_path_acc = vit_path.get_access <access ::mode::read_write>();
150
- double v_max = MIN_DOUBLE ;
150
+ float v_max = MIN_FLOAT ;
151
151
// Constructing the Viterbi path. The last state of this path is the one with
152
152
// the biggest Viterbi value (the most likely state).
153
153
for (int i = 0 ; i < N; ++i) {
@@ -180,8 +180,8 @@ int main() {
180
180
}
181
181
182
182
// The method checks if all three components of the sum are not equivalent to logarithm of zero
183
- // (that is incorrect value and is substituted with minimal possible value of double ) and that
183
+ // (that is incorrect value and is substituted with minimal possible value of float ) and that
184
184
// the Viterbi value on the new step exceeds the current one.
185
- bool ViterbiCondition (double x, double y, double z, double compare) {
186
- return (x > MIN_DOUBLE ) && (y > MIN_DOUBLE ) && (z > MIN_DOUBLE ) && (x + y + z > compare);
185
+ bool ViterbiCondition (float x, float y, float z, float compare) {
186
+ return (x > MIN_FLOAT ) && (y > MIN_FLOAT ) && (z > MIN_FLOAT ) && (x + y + z > compare);
187
187
}
0 commit comments