Calls operator from kernel: 1. Determines kernel's operation through kernel.op_index, which indexes into operator list from Program's execution plan. 2. After identifying operation, determines number of arguments and keyword arguments through operator sche
(self, kernel: KernelCall)
| 307 | ) |
| 308 | |
| 309 | def call_kernel(self, kernel: KernelCall) -> None: |
| 310 | """ |
| 311 | Calls operator from kernel: |
| 312 | 1. Determines kernel's operation through kernel.op_index, |
| 313 | which indexes into operator list from Program's execution plan. |
| 314 | 2. After identifying operation, determines number of arguments and |
| 315 | keyword arguments through operator schema. |
| 316 | 3. Extracts arguments from value list and calls operator. |
| 317 | 4. Sets the given output indices in value list with the values |
| 318 | returned from operation. |
| 319 | |
| 320 | Args: |
| 321 | `kernel` : stores information about operator and which indices in |
| 322 | the value list contain the necessary arguments |
| 323 | |
| 324 | Returns: No returned values - value list is updated with outputs |
| 325 | from operator in place |
| 326 | """ |
| 327 | |
| 328 | operator = self._operators_list[kernel.op_index] |
| 329 | num_args = len( |
| 330 | [arg for arg in operator._schema.arguments if not arg.kwarg_only] |
| 331 | ) |
| 332 | kwarg_list = [kwarg for kwarg in operator._schema.arguments if kwarg.kwarg_only] |
| 333 | num_kwargs = len(kwarg_list) |
| 334 | |
| 335 | # Extracting arguments and keyword arguments from value_list given indices kernel.args |
| 336 | args = [] |
| 337 | for i in kernel.args[:num_args]: |
| 338 | self.load_value(i) |
| 339 | args.append(self._value_list[i]) |
| 340 | |
| 341 | kwargs = {} |
| 342 | for j in range(num_kwargs): |
| 343 | i = kernel.args[num_args + j] |
| 344 | keyword = kwarg_list[j].name |
| 345 | |
| 346 | self.load_value(i) |
| 347 | kwargs[keyword] = self._value_list[i] |
| 348 | |
| 349 | res = operator(*args, **kwargs) |
| 350 | output_idxs = kernel.args[num_args + num_kwargs :] |
| 351 | |
| 352 | assert ( |
| 353 | len(output_idxs) == 1 |
| 354 | ), "emitter is expected to pack multiple outputs into a TensorList" |
| 355 | if isinstance(res, tuple): |
| 356 | self.set_value(output_idxs[0], list(res)) |
| 357 | else: |
| 358 | self.set_value(output_idxs[0], res) |
| 359 | |
| 360 | def run(self, *raw_args: torch.Tensor) -> PyTree: |
| 361 | """ |
no test coverage detected