Repository navigation
Expand file tree
/
Copy pathtest_codegen.py
More file actions
75 lines (58 loc) · 2.55 KB
/
Copy pathtest_codegen.py
File metadata and controls
75 lines (58 loc) · 2.55 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
74
75
from __future__ import print_function
from unittest import TestCase
import visioncpp as vp
from visioncpp import codegen
class test_codegen(TestCase):
def test_bad_device(self):
node_in = vp.Image("examples/lena.jpg")
node_out = vp.show(node_in)
with self.assertRaises(vp.VisionCppException):
codegen.generate(node_out, "bad_device", use_clang_format=False)
def test_load_and_show_cpu(self):
node_in = vp.Image("examples/lena.jpg")
node_out = vp.show(node_in)
self.assertEqual(codegen.generate(node_out, "cpu",
use_clang_format=False)[1],
"""\
#include <visioncpp.hpp>
extern "C" {
int native_expression_tree(unsigned char *const Image_1_arg, unsigned char *const out) {
auto device = visioncpp::make_device<visioncpp::backend::sycl, visioncpp::device::cpu>();
// inputs:
std::shared_ptr<unsigned char> Image_1_data(new unsigned char[786432], [](unsigned char *d) { delete[] d; });
{ // compute scope
auto Image_1 = visioncpp::terminal<visioncpp::pixel::U8C3, 512, 512, visioncpp::memory_type::Buffer2D>(Image_1_arg);
auto Image_1_out = visioncpp::terminal<visioncpp::pixel::U8C3, 512, 512, visioncpp::memory_type::Buffer2D>(Image_1_data.get());
auto show_1 = visioncpp::assign(Image_1_out, Image_1);
visioncpp::execute<visioncpp::policy::Fuse, 16, 16, 8, 8>(show_1, device);
} // compute scope
// outputs:
memcpy(out, Image_1_data.get(), 786432);
return 0;
}
} // extern "C"
""")
def test_load_and_show_gpu(self):
node_in = vp.Image("examples/lena.jpg")
node_out = vp.show(node_in)
self.assertEqual(codegen.generate(node_out, "gpu",
use_clang_format=False)[1],
"""\
#include <visioncpp.hpp>
extern "C" {
int native_expression_tree(unsigned char *const Image_1_arg, unsigned char *const out) {
auto device = visioncpp::make_device<visioncpp::backend::sycl, visioncpp::device::gpu>();
// inputs:
std::shared_ptr<unsigned char> Image_1_data(new unsigned char[786432], [](unsigned char *d) { delete[] d; });
{ // compute scope
auto Image_1 = visioncpp::terminal<visioncpp::pixel::U8C3, 512, 512, visioncpp::memory_type::Buffer2D>(Image_1_arg);
auto Image_1_out = visioncpp::terminal<visioncpp::pixel::U8C3, 512, 512, visioncpp::memory_type::Buffer2D>(Image_1_data.get());
auto show_1 = visioncpp::assign(Image_1_out, Image_1);
visioncpp::execute<visioncpp::policy::Fuse, 16, 16, 8, 8>(show_1, device);
} // compute scope
// outputs:
memcpy(out, Image_1_data.get(), 786432);
return 0;
}
} // extern "C"
""")