Skip to content

Commit 487d390

Browse files
Add user provided JSON operator list build
Allow ACL to be built via a user provided JSON file containing operators, data types and data layouts. Modify TFLite file to JSON file script to output data layouts. Fix build issue with "fat_binary" and "high_priority" options. Resolves: COMPMID-4697, COMPMID-4837 Signed-off-by: Freddie Liardet <frederick.liardet@arm.com> Change-Id: I08d494151c98f804325707ffd922ffe216813023 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/6427 Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Gunes Bayir <gunes.bayir@arm.com>
1 parent 841c3e9 commit 487d390

26 files changed

Lines changed: 399 additions & 389 deletions

File tree

‎SConscript‎

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -157,31 +157,28 @@ def create_version_file(target, source, env):
157157
fd.write(build_info)
158158

159159

160-
def get_attrs_list(arch, estate, data_types, data_layouts):
160+
def get_attrs_list(env, data_types, data_layouts):
161161
attrs = []
162162

163163
# Manage data-types
164-
if any(i in data_types for i in ['all']):
164+
if 'all' in data_types:
165165
attrs += ['fp16', 'fp32', 'integer', 'qasymm8', 'qasymm8_signed', 'qsymm16']
166166
else:
167-
if any(i in data_types for i in ['fp16']): attrs += ['fp16']
168-
if any(i in data_types for i in ['fp32']): attrs += ['fp32']
169-
if any(i in data_types for i in ['integer']): attrs += ['integer']
170-
if any(i in data_types for i in ['qasymm8']): attrs += ['qasymm8']
171-
if any(i in data_types for i in ['qasymm8_signed']): attrs += ['qasymm8_signed']
172-
if any(i in data_types for i in ['qsymm16']): attrs += ['qsymm16']
173-
167+
if 'fp16' in data_types: attrs += ['fp16']
168+
if 'fp32' in data_types: attrs += ['fp32']
169+
if 'integer' in data_types: attrs += ['integer']
170+
if 'qasymm8' in data_types: attrs += ['qasymm8']
171+
if 'qasymm8_signed' in data_types: attrs += ['qasymm8_signed']
172+
if 'qsymm16' in data_types: attrs += ['qsymm16']
174173
# Manage data-layouts
175-
if any(i in data_layouts for i in ['all']):
174+
if 'all' in data_layouts:
176175
attrs += ['nhwc', 'nchw']
177176
else:
178-
if any(i in data_layouts for i in ['nhwc']): attrs += ['nhwc']
179-
if any(i in data_layouts for i in ['nchw']): attrs += ['nchw']
177+
if 'nhwc' in data_layouts: attrs += ['nhwc']
178+
if 'nchw' in data_layouts: attrs += ['nchw']
180179

181180
# Manage execution state
182-
estate_attr = 'estate32' if (estate == 'auto' and 'v7a' in arch) or '32' in estate else 'estate64'
183-
attrs += [ estate_attr ]
184-
181+
attrs += ['estate32' if (env['estate'] == 'auto' and 'v7a' in env['arch']) or '32' in env['estate'] else 'estate64']
185182
return attrs
186183

187184

@@ -237,6 +234,27 @@ def resolve_operator_dependencies(filelist, operators, backend=''):
237234

238235
return resolved_operators
239236

237+
def read_build_config_json(build_config):
238+
build_config_contents = {}
239+
custom_operators = []
240+
custom_types = []
241+
custom_layouts = []
242+
if os.path.isfile(build_config):
243+
with open(build_config) as f:
244+
try:
245+
build_config_contents = json.load(f)
246+
except:
247+
print("Warning: Build configuration file is of invalid JSON format!")
248+
else:
249+
try:
250+
build_config_contents = json.loads(build_config)
251+
except:
252+
print("Warning: Build configuration string is of invalid JSON format!")
253+
if build_config_contents:
254+
custom_operators = build_config_contents.get("operators", [])
255+
custom_types = build_config_contents.get("data_types", [])
256+
custom_layouts = build_config_contents.get("data_layouts", [])
257+
return custom_operators, custom_types, custom_layouts
240258

241259
arm_compute_env = env.Clone()
242260
version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
@@ -427,30 +445,25 @@ graph_files = Glob('src/graph/*.cpp')
427445
graph_files += Glob('src/graph/*/*.cpp')
428446

429447
# Specify user-defined priority operators
430-
use_priority_ops = env['high_priority']
431-
priority_operators = filelist['high_priority']
432-
if env['build_config'] != "":
433-
build_config = env['build_config']
434-
build_config_contents = {}
435-
if os.path.isfile(build_config):
436-
with open(build_config) as f:
437-
try:
438-
build_config_contents = json.load(f)
439-
except:
440-
print("Warning: Build configuration file is of invalid JSON format!")
441-
else:
442-
try:
443-
build_config_contents = json.loads(build_config)
444-
except:
445-
print("Warning: Build configuration string is of invalid JSON format!")
446-
if build_config_contents:
447-
priority_operators = build_config_contents.get("operators", [])
448+
custom_operators = []
449+
custom_types = []
450+
custom_layouts = []
451+
452+
use_custom_ops = env['high_priority'] or env['build_config'];
453+
454+
if env['high_priority']:
455+
custom_operators = filelist['high_priority']
456+
custom_types = ['all']
457+
custom_layouts = ['all']
458+
459+
if env['build_config']:
460+
custom_operators, custom_types, custom_layouts = read_build_config_json(env['build_config'])
448461

449462
if env['opencl']:
450463
lib_files += filelist['c_api']['gpu']
451464
lib_files += filelist['gpu']['common']
452465

453-
cl_operators = priority_operators if use_priority_ops else filelist['gpu']['operators'].keys()
466+
cl_operators = custom_operators if use_custom_ops else filelist['gpu']['operators'].keys()
454467
cl_ops_to_build = resolve_operator_dependencies(filelist, cl_operators, 'gpu')
455468
lib_files += get_operator_backend_files(filelist, cl_ops_to_build, 'gpu')['common']
456469

@@ -475,11 +488,15 @@ if env['neon']:
475488
if 'sve' not in env['arch'] or env['fat_binary']: simd += ['neon']
476489

477490
# Get attributes
478-
attrs = get_attrs_list(env['arch'], env['estate'], env['data_type_support'], env['data_layout_support'])
491+
if(use_custom_ops):
492+
attrs = get_attrs_list(env, custom_types, custom_layouts)
493+
else:
494+
attrs = get_attrs_list(env, env['data_type_support'], env['data_layout_support'])
479495

480496
# Setup data-type and data-layout files to include
481-
cpu_operators = priority_operators if use_priority_ops else filelist['cpu']['operators'].keys()
482-
cpu_ops_to_build = resolve_operator_dependencies(filelist, filelist['cpu']['operators'], 'cpu')
497+
cpu_operators = custom_operators if use_custom_ops else filelist['cpu']['operators'].keys()
498+
cpu_ops_to_build = resolve_operator_dependencies(filelist, cpu_operators, 'cpu')
499+
483500
cpu_files = get_operator_backend_files(filelist, cpu_ops_to_build, 'cpu', simd, attrs)
484501
lib_files += cpu_files.get('common', [])
485502
lib_files += cpu_files.get('neon', [])
@@ -488,8 +505,8 @@ if env['neon']:
488505
graph_files += Glob('src/graph/backends/NEON/*.cpp')
489506

490507
# Restrict from building graph API if a reduced operator list has been provided
491-
if use_priority_ops:
492-
print("Graph library requires all operators to be built")
508+
if use_custom_ops:
509+
print("WARNING: Graph library requires all operators to be built")
493510
graph_files = []
494511

495512
# Build bootcode in case of bare-metal

‎SConstruct‎

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,50 @@ def version_at_least(version, required):
4141

4242
return True
4343

44+
def read_build_config_json(build_config):
45+
build_config_contents = {}
46+
custom_types = []
47+
custom_layouts = []
48+
if os.path.isfile(build_config):
49+
with open(build_config) as f:
50+
try:
51+
build_config_contents = json.load(f)
52+
except:
53+
print("Warning: Build configuration file is of invalid JSON format!")
54+
else:
55+
try:
56+
build_config_contents = json.loads(build_config)
57+
except:
58+
print("Warning: Build configuration string is of invalid JSON format!")
59+
if build_config_contents:
60+
custom_types = build_config_contents.get("data_types", [])
61+
custom_layouts = build_config_contents.get("data_layouts", [])
62+
return custom_types, custom_layouts
63+
64+
def update_data_type_layout_flags(env, data_types, data_layouts):
65+
# Manage data-types
66+
if any(i in data_types for i in ['all', 'fp16']):
67+
env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS'])
68+
if any(i in data_types for i in ['all', 'fp32']):
69+
env.Append(CXXFLAGS = ['-DENABLE_FP32_KERNELS'])
70+
if any(i in data_types for i in ['all', 'qasymm8']):
71+
env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_KERNELS'])
72+
if any(i in data_types for i in ['all', 'qasymm8_signed']):
73+
env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_SIGNED_KERNELS'])
74+
if any(i in data_types for i in ['all', 'qsymm16']):
75+
env.Append(CXXFLAGS = ['-DENABLE_QSYMM16_KERNELS'])
76+
if any(i in data_types for i in ['all', 'integer']):
77+
env.Append(CXXFLAGS = ['-DENABLE_INTEGER_KERNELS'])
78+
79+
# Manage data-layouts
80+
if any(i in data_layouts for i in ['all', 'nhwc']):
81+
env.Append(CXXFLAGS = ['-DENABLE_NHWC_KERNELS'])
82+
if any(i in data_layouts for i in ['all', 'nchw']):
83+
env.Append(CXXFLAGS = ['-DENABLE_NCHW_KERNELS'])
84+
85+
return env
86+
87+
4488
vars = Variables("scons")
4589
vars.AddVariables(
4690
BoolVariable("debug", "Debug", False),
@@ -327,25 +371,20 @@ if env['high_priority'] and env['build_config']:
327371
if not env['high_priority'] and not env['build_config']:
328372
env.Append(CPPDEFINES = ['ARM_COMPUTE_GRAPH_ENABLED'])
329373

330-
if env['data_type_support']:
331-
if any(i in env['data_type_support'] for i in ['all', 'fp16']):
332-
env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS'])
333-
if any(i in env['data_type_support'] for i in ['all', 'fp32']):
334-
env.Append(CXXFLAGS = ['-DENABLE_FP32_KERNELS'])
335-
if any(i in env['data_type_support'] for i in ['all', 'qasymm8']):
336-
env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_KERNELS'])
337-
if any(i in env['data_type_support'] for i in ['all', 'qasymm8_signed']):
338-
env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_SIGNED_KERNELS'])
339-
if any(i in env['data_type_support'] for i in ['all', 'qsymm16']):
340-
env.Append(CXXFLAGS = ['-DENABLE_QSYMM16_KERNELS'])
341-
if any(i in env['data_type_support'] for i in ['all', 'integer']):
342-
env.Append(CXXFLAGS = ['-DENABLE_INTEGER_KERNELS'])
374+
data_types = []
375+
data_layouts = []
343376

344-
if env['data_layout_support']:
345-
if any(i in env['data_layout_support'] for i in ['all', 'nhwc']):
346-
env.Append(CXXFLAGS = ['-DENABLE_NHWC_KERNELS'])
347-
if any(i in env['data_layout_support'] for i in ['all', 'nchw']):
348-
env.Append(CXXFLAGS = ['-DENABLE_NCHW_KERNELS'])
377+
# Set correct data types / layouts to build
378+
if env['high_priority']:
379+
data_types = ['all']
380+
data_layouts = ['all']
381+
elif env['build_config']:
382+
data_types, data_layouts = read_build_config_json(env['build_config'])
383+
else:
384+
data_types = env['data_type_support']
385+
data_layouts = env['data_layout_support']
386+
387+
env = update_data_type_layout_flags(env, data_types, data_layouts)
349388

350389
if env['standalone']:
351390
env.Append(CXXFLAGS = ['-fPIC'])
@@ -417,13 +456,20 @@ Export('version_at_least')
417456

418457
SConscript('./SConscript', variant_dir=build_path, duplicate=0)
419458

459+
if env['examples'] and (env['build_config'] or env['high_priority']):
460+
print("WARNING: Building examples for selected operators not supported. Use examples=0")
461+
Return()
462+
420463
if env['examples'] and env['exceptions']:
421464
if env['os'] == 'bare_metal' and env['arch'] == 'armv7a':
422465
print("WARNING: Building examples for bare metal and armv7a is not supported. Use examples=0")
423466
Return()
424467
SConscript('./examples/SConscript', variant_dir='%s/examples' % build_path, duplicate=0)
425468

426469
if env['exceptions']:
470+
if env['build_config'] or env['high_priority']:
471+
print("WARNING: Building tests for selected operators not supported")
472+
Return()
427473
if env['os'] == 'bare_metal' and env['arch'] == 'armv7a':
428474
print("WARNING: Building tests for bare metal and armv7a is not supported")
429475
Return()

0 commit comments

Comments
 (0)