blob: eca6ab967efabda6febe3bd0a27153e95bb9e43f [file] [log] [blame]
Georgios Pinitas41984a02019-12-11 12:05:17 +00001//
Pablo Marquez Tellof113f372021-07-20 14:03:42 +01002// Copyright © 2020-2021 Arm Ltd. All rights reserved.
Georgios Pinitas41984a02019-12-11 12:05:17 +00003// SPDX-License-Identifier: MIT
4//
5
6package arm_compute_library_nn_driver
7
8import (
9 "android/soong/android"
10 "android/soong/cc"
Michele Di Giorgiof0a4e602020-10-15 11:54:17 +010011 "strings"
Pablo Marquez Tellof113f372021-07-20 14:03:42 +010012 "fmt"
Georgios Pinitas41984a02019-12-11 12:05:17 +000013)
14
15func globalFlags(ctx android.BaseContext) []string {
16 var cppflags []string
17
Pablo Marquez Tello6fc7d522021-07-13 11:09:47 +010018 if ctx.AConfig().PlatformVersionName() == "Q" || ctx.AConfig().PlatformVersionName() == "10" ||
Teresa Charlin65d04482021-02-12 12:29:26 +000019 ctx.AConfig().PlatformVersionName() == "R" || ctx.AConfig().PlatformVersionName() == "11" ||
20 ctx.AConfig().PlatformVersionName() == "S" || ctx.AConfig().PlatformVersionName() == "12" {
Georgios Pinitasfec13b82020-02-26 16:11:32 +000021 cppflags = append(cppflags, "-fno-addrsig")
22 }
23
Pablo Marquez Tellof113f372021-07-20 14:03:42 +010024 if ctx.AConfig().PlatformVersionName() == "P" || ctx.AConfig().PlatformVersionName() == "9" {
25 fmt.Println("!! This is Android P!!")
26 } else if ctx.AConfig().PlatformVersionName() == "R" || ctx.AConfig().PlatformVersionName() == "11" {
27 fmt.Println("!! This is Android R!!")
28 if ctx.AConfig().DevicePrimaryArchType().String() == "armv8-2a" {
29 cppflags = append(cppflags, "-march=armv8.2-a+fp16")
30 }
31 }
Pablo Marquez Tello6fc7d522021-07-13 11:09:47 +010032
Michele Di Giorgiof0a4e602020-10-15 11:54:17 +010033 data_types := strings.Split(ctx.AConfig().GetenvWithDefault("COMPUTE_LIB_DATA_TYPE", "ALL"), ",")
34
35 for _, x := range data_types {
Michalis Spyroue9aaacd2021-01-14 13:24:05 +000036 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "INTEGER" {
37 cppflags = append(cppflags, "-DENABLE_INTEGER_KERNELS")
38 }
Michalis Spyrouc4d45552020-10-19 12:41:30 +010039 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM8" {
40 cppflags = append(cppflags, "-DENABLE_QASYMM8_KERNELS")
41 }
42 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM8_SIGNED" {
43 cppflags = append(cppflags, "-DENABLE_QASYMM8_SIGNED_KERNELS")
44 }
45 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM16" {
46 cppflags = append(cppflags, "-DENABLE_QASYMM16_KERNELS")
47 }
Michalis Spyroue5a41282020-11-03 17:00:04 +000048 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QSYMM16" {
49 cppflags = append(cppflags, "-DENABLE_QSYMM16_KERNELS")
50 }
Michele Di Giorgiof0a4e602020-10-15 11:54:17 +010051 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "FP16" {
52 cppflags = append(cppflags, "-DENABLE_FP16_KERNELS")
53 }
54 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "FP32" {
55 cppflags = append(cppflags, "-DENABLE_FP32_KERNELS")
56 }
57 }
58
Sheri Zhang79144a62021-02-08 17:43:04 +000059 data_layouts := strings.Split(ctx.AConfig().GetenvWithDefault("COMPUTE_LIB_DATA_LAYOUT", "ALL"), ",")
60
61 for _, x := range data_layouts {
62 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "NHWC" {
63 cppflags = append(cppflags, "-DENABLE_NHWC_KERNELS")
64 }
65 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "NCHW" {
66 cppflags = append(cppflags, "-DENABLE_NCHW_KERNELS")
67 }
68 }
69
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000070 cppflags = append(cppflags, "-ARM_COMPUTE_CPU_ENABLED")
71 cppflags = append(cppflags, "-ARM_COMPUTE_OPENCL_ENABLED")
72
Georgios Pinitas41984a02019-12-11 12:05:17 +000073 return cppflags
74}
75
76func clframeworkNNDriverDefaults(ctx android.LoadHookContext) {
77 type props struct {
78 Cppflags []string
79 }
80
81 p := &props{}
82 p.Cppflags = globalFlags(ctx)
83
84 ctx.AppendProperties(p)
85}
86
87func init() {
88
89 android.RegisterModuleType("arm_compute_library_defaults", clframeworkNNDriverDefaultsFactory)
90}
91
92func clframeworkNNDriverDefaultsFactory() android.Module {
93
94 module := cc.DefaultsFactory()
95 android.AddLoadHook(module, clframeworkNNDriverDefaults)
96 return module
97}