Debian Codegraph @

tensilelite/rocisa/docs/using-rocisa-in-tensilelite.md

raw symbols SCIP
1 # Using rocIsa in TensileLite
2
3 ## countType
4
5 countType is a legacy member function, but quite handy so we movedt into rocIsa as a function.
6
7 ```c++
8 module.countType(Instruction) -> countType(module, Instruction)
9 ```
10
11 It is suitable for prototyping, however it runs slower than directly using templates. If possible, add template function in ``count.cpp`` and export it to Python.
12
13 ```
14 module.countType(Instruction) -> countInstruction(module)
15 ```
16
17 ## Exporting vectors to Python
18
19 Vector memory management between Python and C++ is different, so exporting vectors to Python is copy instead of reference.
20
21 ```python
22 module = Module("Test")
23 vec = module.items() # the vec here is a copy
24 ```
25
26 Since the elements are ``shared_ptr``, you can modify the contents of the elements.
27
28 BUT You cannot assign a new element or replace an existing element.
29
30 ```python
31 # The following codes still work, but does not modify the vector in module.
32 vec[0] = item
33 vec.append(item)
34 ```
35
36 Use the setter function to solve this problem.
37
38 ```python
39 module.add(item)
40 module.add(item, pos=0)
41 ```
42
43 Same as reading ``srcs`` from ``CommonInstruction``
44
45 ```
46 Item.srcs[0] = vgpr(1) # Wrong
47 item.setSrcs(0, vgpr(1)) # Correct
48 ```
49
50 Also avoid using ``module.items()`` to check size, use ``module.itemSize()`` instead
51
52 ```python
53 if module.items(): # Bad
54 # your code here
55
56 if module.itemSize(): # Good
57 # your code here
58 ```