MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / parse_kernel

Method parse_kernel

paddle/phi/api/generator/api_base.py:498–561  ·  view source on GitHub ↗
(self, kernel_config)

Source from the content-addressed store, hash-verified

496 return infer_meta
497
498 def parse_kernel(self, kernel_config):
499 # kernel :
500 # func : [], Kernel functions (example: scale, scale_sr)
501 # param : [], Input params of kernel
502 # backend : str, the names of param to choose the kernel backend, default is None
503 # layout : str, the names of param to choose the kernel layout, default is None
504 # data_type : str, the names of param to choose the kernel data_type, default is None
505 # dispatch : {}, the key is kernel_func, the value is type of inputs and outputs for kernel (example: {kernel_name : (['dense','sparse_coo']#input,['sparse_coo']#output)})
506 kernel = {
507 'func': [],
508 'param': None,
509 'backend': None,
510 'layout': None,
511 'data_type': None,
512 'dispatch': {},
513 }
514 if 'backend' in kernel_config and len(kernel_config['backend']) > 0:
515 kernel['backend'] = kernel_config['backend']
516 if 'layout' in kernel_config and len(kernel_config['layout']) > 0:
517 kernel['layout'] = kernel_config['layout']
518 if 'data_type' in kernel_config and len(kernel_config['data_type']) > 0:
519 kernel['data_type'] = kernel_config['data_type']
520 if 'param' in kernel_config:
521 kernel['param'] = kernel_config['param']
522 kernel_funcs = re.compile(r'([a-zA-Z0-9_]+)\s*({[^}]+})?').findall(
523 kernel_config['func']
524 )
525
526 def parse_kernel_in_out_type(in_out_str):
527 if len(in_out_str) == 0:
528 return None
529 tmp_in_out_list = in_out_str[1:-1].split('->')
530 inputs = [item.strip() for item in tmp_in_out_list[0].split(',')]
531 outputs = [item.strip() for item in tmp_in_out_list[1].split(',')]
532
533 # check the tensor type
534 for item in inputs:
535 assert item in [
536 'dense',
537 'selected_rows',
538 'sparse_coo',
539 'sparse_csr',
540 ], (
541 f"{self.api} : Invalid input tensor type ('{item}'), here we only support 'dense', 'selected_rows', 'sparse_coo' and 'sparse_csr'."
542 )
543 for item in outputs:
544 assert item in [
545 'dense',
546 'selected_rows',
547 'sparse_coo',
548 'sparse_csr',
549 ], (
550 f"{self.api} : Invalid output tensor type ('{item}'), here we only support 'dense', 'selected_rows', 'sparse_coo' and 'sparse_csr'."
551 )
552
553 return (inputs, outputs)
554
555 for func_item in kernel_funcs:

Callers 1

__init__Method · 0.95

Calls 3

parse_kernel_in_out_typeFunction · 0.85
compileMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected