File tree 2 files changed +43
-0
lines changed
2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ hcc -hc ` hcc-config --cxxflags --ldflags ` test_math.cpp -o test_math -lm -Xclang -fauto-compile-for-accelerator
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < hc.hpp>
3
+ #include < hc_math.hpp>
4
+
5
+ float compute2 (float f) {
6
+ return cosf (f);
7
+ }
8
+
9
+ float compute (float f) [[hc,cpu]] {
10
+ return cosf (f);
11
+ }
12
+
13
+ int main (int argc, char * argv[]) {
14
+
15
+ float f = 1 .0f ;
16
+ if (argc == 2 ) {
17
+ f = (float )atof (argv[1 ]);
18
+ }
19
+
20
+ float cpu = compute (f);
21
+ float cpu2 = cosf (f);
22
+
23
+ hc::array_view<float ,1 > gpu (1 );
24
+ gpu[0 ] = f;
25
+
26
+ hc::array_view<float ,1 > gpu2 (1 );
27
+ gpu2[0 ] = f;
28
+
29
+ hc::parallel_for_each (gpu.get_extent (), [=] (hc::index <1 > i) [[hc]] {
30
+ gpu[i] = compute (gpu[i]);
31
+ gpu2[i] = compute2 (gpu2[i]);
32
+ });
33
+
34
+ std::cout << " cpu: " << cpu << std::endl;
35
+ std::cout << " cpu2: " << cpu2 << std::endl;
36
+ std::cout << " gpu: " << gpu[0 ] << std::endl;
37
+ std::cout << " gpu2: " << gpu2[0 ] << std::endl;
38
+
39
+ return 0 ;
40
+ }
You can’t perform that action at this time.
0 commit comments