MCPcopy Create free account
hub / github.com/KomputeProject/kompute / test_sequence

Function test_sequence

python/test/test_kompute.py:115–169  ·  view source on GitHub ↗

Test basic OpAlgoBase operation

()

Source from the content-addressed store, hash-verified

113
114
115def test_sequence():
116 """
117 Test basic OpAlgoBase operation
118 """
119
120 shader = """
121 #version 450
122 layout(set = 0, binding = 0) buffer tensorLhs {float valuesLhs[];};
123 layout(set = 0, binding = 1) buffer tensorRhs {float valuesRhs[];};
124 layout(set = 0, binding = 2) buffer tensorOutput { float valuesOutput[];};
125 layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
126
127 void main()
128 {
129 uint index = gl_GlobalInvocationID.x;
130 valuesOutput[index] = valuesLhs[index] * valuesRhs[index];
131 }
132 """
133
134 spirv = compile_source(shader)
135
136 mgr = kp.Manager(0)
137
138 tensor_in_a = mgr.tensor([2, 2, 2])
139 tensor_in_b = mgr.tensor([1, 2, 3])
140 tensor_out = mgr.tensor([0, 0, 0])
141
142 params = [tensor_in_a, tensor_in_b, tensor_out]
143
144 algo = mgr.algorithm(params, spirv)
145
146 sq = mgr.sequence()
147
148 sq.record(kp.OpTensorSyncDevice(params))
149 sq.record(kp.OpAlgoDispatch(algo))
150 sq.record(kp.OpTensorSyncLocal(params))
151
152 sq.eval()
153
154 assert sq.is_init() == True
155
156 sq.destroy()
157
158 assert sq.is_init() == False
159
160 assert tensor_out.data().tolist() == [2.0, 4.0, 6.0]
161 assert np.all(tensor_out.data() == [2.0, 4.0, 6.0])
162
163 tensor_in_a.destroy()
164 tensor_in_b.destroy()
165 tensor_out.destroy()
166
167 assert tensor_in_a.is_init() == False
168 assert tensor_in_b.is_init() == False
169 assert tensor_out.is_init() == False
170
171
172def test_pushconsts():

Callers

nothing calls this directly

Calls 12

tensorMethod · 0.95
algorithmMethod · 0.95
sequenceMethod · 0.95
ManagerMethod · 0.80
OpTensorSyncDeviceMethod · 0.80
OpAlgoDispatchMethod · 0.80
OpTensorSyncLocalMethod · 0.80
compile_sourceFunction · 0.70
recordMethod · 0.45
evalMethod · 0.45
destroyMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected