|
| 1 | +# ------------------------------------------------------------------ |
| 2 | +# Licensed under the MIT License. See LICENCE in the project root. |
| 3 | +# ------------------------------------------------------------------ |
| 4 | + |
| 5 | +@enum FeatureType qualifier=1 quantifier |
| 6 | + |
| 7 | +global feature_type = Dict( |
| 8 | + :node_count => quantifier, |
| 9 | + :node_provider => qualifier, |
| 10 | + :node_virtual => qualifier, |
| 11 | + :node_dedicated => qualifier, |
| 12 | + :node_machinefamily => qualifier, |
| 13 | + :node_machinetype => qualifier, |
| 14 | + :node_machinesize => qualifier, |
| 15 | + :node_vcpus_count => quantifier, |
| 16 | + :node_memory_size => quantifier, |
| 17 | + :node_memory_latency => quantifier, |
| 18 | + :node_memory_bandwidth => quantifier, |
| 19 | + :node_memory_type => qualifier, |
| 20 | + :node_memory_frequency => quantifier, |
| 21 | + :processor_count => quantifier, |
| 22 | + :processor_manufacturer => qualifier, |
| 23 | + :processor_microarchitecture => qualifier, |
| 24 | + :processor_simd => qualifier, |
| 25 | + :processor_isa => qualifier, |
| 26 | + :processor_tdp => quantifier, |
| 27 | + :processor_core_clock => quantifier, |
| 28 | + :processor_core_count => quantifier, |
| 29 | + :processor_core_threads_count => quantifier, |
| 30 | +# :processor_core_L1_mapping => , |
| 31 | + :processor_core_L1_size => quantifier, |
| 32 | +# :processor_core_L1_latency => , |
| 33 | +# :processor_core_L1_bandwidth => , |
| 34 | +# :processor_core_L1_linesize => , |
| 35 | +# :processor_core_L2_mapping => , |
| 36 | + :processor_core_L2_size => quantifier, |
| 37 | +# :processor_core_L2_latency => , |
| 38 | +# :processor_core_L2_bandwidth => , |
| 39 | +# :processor_core_L2_linesize => , |
| 40 | +# :processor_L3_mapping => , |
| 41 | + :processor_L3_size => quantifier, |
| 42 | +# :processor_L3_latency => , |
| 43 | +# :processor_L3_bandwidth => , |
| 44 | +# :processor_L3_linesize => , |
| 45 | + :processor => qualifier, |
| 46 | + :accelerator_count => quantifier, |
| 47 | + :accelerator_manufacturer => qualifier, |
| 48 | + :accelerator_type => qualifier, |
| 49 | + :accelerator_architecture => qualifier, |
| 50 | + :accelerator_api => qualifier, |
| 51 | + :accelerator_memorysize => quantifier, |
| 52 | + :accelerator_tdp => quantifier, |
| 53 | + :accelerator => qualifier, |
| 54 | + :interconnection_startuptime => quantifier, |
| 55 | + :interconnection_latency => quantifier, |
| 56 | + :interconnection_bandwidth => quantifier, |
| 57 | + :interconnection_topology => qualifier, |
| 58 | + :interconnection_RDMA => qualifier, |
| 59 | + :interconnection => qualifier, |
| 60 | + :storage_size => quantifier, |
| 61 | + :storage_latency => quantifier, |
| 62 | + :storage_bandwidth => quantifier, |
| 63 | + :storage_networkbandwidth => quantifier, |
| 64 | + :storage_type => qualifier, |
| 65 | + :storage_interface => qualifier |
| 66 | +) |
| 67 | + |
| 68 | +function readPlatormDescription() |
| 69 | + |
| 70 | + # read the platform description file (default to the current directory) |
| 71 | + filename = get(ENV,"PLATFORM_DESCRIPTION","Platform.toml") |
| 72 | + |
| 73 | + println(pwd()) |
| 74 | + |
| 75 | + platform_description_toml = |
| 76 | + try |
| 77 | + io = open(filename) |
| 78 | + read(io,String) |
| 79 | + catch |
| 80 | + default_location = "/etc/Platform.toml" |
| 81 | + try |
| 82 | + # defaul system location |
| 83 | + io = open(default_location) |
| 84 | + contents = read(io,String) |
| 85 | + close(io) |
| 86 | + contents |
| 87 | + catch |
| 88 | + println(stderr,"The platform description file (Platform.toml) was not found.") |
| 89 | + println(stderr,"Using default platform settings (calling only default kernels).") |
| 90 | + println(stderr,"A Platform.toml file may be created by calling PlatformAware.setup(). Do it !") |
| 91 | + default_platorm_file = pkgdir(@__MODULE__) * "/DefaultPlatform.toml" |
| 92 | + io = open(default_platorm_file) |
| 93 | + contents = read(io,String) |
| 94 | + close(io) |
| 95 | + contents |
| 96 | + end |
| 97 | + end |
| 98 | + |
| 99 | + TOML.parse(platform_description_toml) |
| 100 | +end |
| 101 | + |
| 102 | +function get_quantifier_from_number(n) |
| 103 | + |
| 104 | + magnitude = Dict(0 => "", 1 => "K", 2 => "M", 3 => "G", 4 => "T", 5 => "P", 6 => "E") |
| 105 | + |
| 106 | + l = log(2,n) |
| 107 | + a = round(l) |
| 108 | + b = isinteger(l) ? a : a + 1; |
| 109 | + |
| 110 | + # the following loop separates a and b in multiplier*magnitude (see the POPL's paper). |
| 111 | + |
| 112 | + # let A = 2^a |
| 113 | + m=0 |
| 114 | + while a>9 |
| 115 | + # loop invariant: A = 2^a * 2^(10*m) |
| 116 | + a = a - 10 |
| 117 | + b = b - 10 |
| 118 | + m = m + 1 |
| 119 | + end |
| 120 | + |
| 121 | + a_str = "AtLeast" * string(Integer(2^a)) * magnitude[m] |
| 122 | + b_str = "AtMost" * string(Integer(2^b)) * magnitude[m] |
| 123 | + |
| 124 | + return eval(Meta.parse("Tuple{" * a_str * "," * b_str * "}")) |
| 125 | +end |
| 126 | + |
| 127 | +function get_quantifier_from_string(n) |
| 128 | + |
| 129 | + mag_mult = Dict('K' => 2^10, 'M' => 2^20, 'G' => 2^30, 'T' => 2^40, 'P'=> 2^50, 'E' => 2^60) |
| 130 | + |
| 131 | + m = n[length(n)] |
| 132 | + v1 = get(mag_mult,m,1) |
| 133 | + v0 = v1 == 1 ? parse(Float64,n) : parse(Float64,n[1:length(n)-1]) |
| 134 | + |
| 135 | + get_quantifier_from_number(v0*v1) |
| 136 | +end |
| 137 | + |
| 138 | +function get_quantifier(feature) |
| 139 | + if (typeof(feature) <: Number) |
| 140 | + get_quantifier_from_number(feature) |
| 141 | + elseif (typeof(feature) == String) |
| 142 | + get_quantifier_from_string(feature) |
| 143 | + end |
| 144 | +end |
| 145 | + |
| 146 | +function get_qualifier(feature) |
| 147 | + eval(Meta.parse(feature)) |
| 148 | +end |
| 149 | + |
| 150 | +function check_blank_feature(parameter_id, feature, default_platform_types) |
| 151 | + if (feature == "na") |
| 152 | + default_platform_types[parameter_id] |
| 153 | + elseif (feature == "unset") |
| 154 | + default_platform_types[parameter_id] |
| 155 | + elseif (feature == "unknown") |
| 156 | + default_platform_types[parameter_id] |
| 157 | + elseif (feature == "ignore") |
| 158 | + default_platform_types[parameter_id] |
| 159 | + else |
| 160 | + nothing |
| 161 | + end |
| 162 | +end |
| 163 | + |
| 164 | + |
| 165 | +function loadFeaturesSection!(dict, actual_platform_arguments, default_platform_types) |
| 166 | + |
| 167 | + if ("0" in keys(dict)) |
| 168 | + dict = dict["0"] |
| 169 | + end |
| 170 | + |
| 171 | + for (parameter_id, feature) in dict |
| 172 | + p = Meta.parse(parameter_id) |
| 173 | + v0 = check_blank_feature(p, feature, default_platform_types) |
| 174 | + v = if (isnothing(v0)) |
| 175 | + feature_type[p] == qualifier ? get_qualifier(feature) : get_quantifier(feature) |
| 176 | + else |
| 177 | + v0 |
| 178 | + end |
| 179 | + actual_platform_arguments[p]= v |
| 180 | + end |
| 181 | +end |
| 182 | + |
| 183 | +function loadFeatures!(dict, default_platform_types, actual_platform_arguments) |
| 184 | + for key in ["node","processor","accelerator","memory","storage","interconnection"] |
| 185 | + loadFeaturesSection!(dict[key], actual_platform_arguments, default_platform_types) |
| 186 | + end |
| 187 | +end |
0 commit comments