Skip to content

Commit 65d0731

Browse files
adding features.jl
1 parent 01e8d59 commit 65d0731

File tree

4 files changed

+208
-29
lines changed

4 files changed

+208
-29
lines changed

DefaultPlatform.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ storage_networkbandwidth = "unset"
6262

6363
[interconnection]
6464

65-
interconnection_starttime = "unset"
65+
interconnection_startuptime = "unset"
6666
interconnection_latency = "unset"
6767
interconnection_bandwidth = "unset"
6868
interconnection_topology = "unset"

src/awareness.jl

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,22 @@ using XMLDict
77
using TOML
88
using JSON
99

10-
function readDB2(filename)
11-
12-
d = Dict()
13-
14-
for ls in readlines(filename)
15-
l = split(ls,',')
16-
d[l[1]] = tuple(l...)
17-
end
18-
19-
return d
20-
end
21-
2210
function readDB(filename)
2311

2412
d = Dict()
13+
i=0
2514
for ls in readlines(filename)
26-
l = split(ls,',')
27-
ks = split(l[1],';')
28-
d2 = d
29-
for k in ks
30-
d = get!(d,k,Dict())
31-
end
32-
d[l[2]] = tuple(l[2:length(l)]...)
33-
d = d2
15+
if i>0
16+
l = split(ls,',')
17+
ks = split(l[1],';')
18+
d2 = d
19+
for k in ks
20+
d = get!(d,k,Dict())
21+
end
22+
d[l[2]] = tuple(l[2:length(l)]...)
23+
d = d2
24+
end
25+
i = i + 1
3426
end
3527

3628
return d
@@ -351,16 +343,16 @@ function collectProcessorFeatures_CpuId()
351343

352344
proc_info = identifyProcessorModel(cpu_brand)
353345
if (!isnothing(proc_info))
354-
processor_features["processor_manufacturer"] = isnothing(processor_features["processor_manufacturer"]) ? proc_info[10] : processor_features["processor_manufacturer"]
346+
processor_features["processor_manufacturer"] = isnothing(processor_features["processor_manufacturer"]) ? proc_info[9] : processor_features["processor_manufacturer"]
355347
processor_features["processor_core_clock"] = isnothing(processor_features["processor_core_clock"]) ? getCoreClockString(proc_info[3]) : processor_features["processor_core_clock"]
356348
processor_features["processor_core_count"] = isnothing(processor_features["processor_core_count"]) ? parse(Int64,proc_info[2]) : processor_features["processor_core_count"]
357349
processor_features["processor_core_threads_count"] = isnothing(processor_features["processor_core_threads_count"]) ? parse(Int64,proc_info[4]) : processor_features["processor_core_count"]
358350
processor_features["processor_simd"] = isnothing(processor_features["processor_simd"]) ? identifySIMD_2(proc_info[6]) : processor_features["processor_simd"]
359351
processor_features["processor_isa"] = identifyISA_2(proc_info[5])
360352
processor_features["processor_microarchitecture"] = proc_info[7]
361-
tdp = tryparse(Int64, proc_info[11])
362-
processor_features["processor_tdp"] = isnothing(tdp) ? proc_info[11] : parse(Int64,proc_info[11])
363-
processor_features["processor"] = proc_info[9]
353+
tdp = tryparse(Int64, proc_info[10])
354+
processor_features["processor_tdp"] = isnothing(tdp) ? proc_info[11] : parse(Int64,proc_info[10])
355+
processor_features["processor"] = proc_info[8]
364356
end
365357

366358
return processor_features
@@ -637,7 +629,7 @@ function identityInterconnection()
637629

638630
interconnection_features = Dict()
639631

640-
interconnection_features["interconnection_starttime"] = "unset"
632+
interconnection_features["interconnection_startuptime"] = "unset"
641633
interconnection_features["interconnection_latency"] = "unset"
642634
interconnection_features["interconnection_bandwidth"] = "unset"
643635
interconnection_features["interconnection_topology"] = "unset"
@@ -727,7 +719,7 @@ function setup()
727719
println(" 1) A file path pointed by a PLATFORM_DESCRIPTION environment variable;")
728720
println(" 2) The current directory;")
729721
println(" 3) The /etc/conf directory.")
730-
println("In the interctive environment, call PlatformAware.reload!() to reflect changes.")
722+
println("In the interactive environment, you may call PlatformAware.reload!() to reflect changes.")
731723
else
732724
TOML.print(stdout, platform_features)
733725
println(stderr)

src/features.jl

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
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

src/identification.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ global default_platform_types_all = Dict(
4949
:accelerator_memorysize => Tuple{AtLeast0,AtMostInf},
5050
:accelerator_tdp => Tuple{AtLeast0,AtMostInf},
5151
:accelerator => Accelerator,
52-
:interconnection_starttime => Tuple{AtLeast0,AtMostInf},
52+
:interconnection_startuptime => Tuple{AtLeast0,AtMostInf},
5353
:interconnection_latency => Tuple{AtLeast0,AtMostInf},
5454
:interconnection_bandwidth => Tuple{AtLeast0,AtMostInf},
5555
:interconnection_topology => InterconnectionTopology,
@@ -74,7 +74,7 @@ global actual_platform_arguments_all = Dict()
7474
loadFeatures(actual_platform_arguments_all)
7575
actual_platform_arguments = Dict(actual_platform_arguments_all)
7676

77-
function reload!()
77+
function reload!()
7878
empty!(actual_platform_arguments_all)
7979
loadFeatures(actual_platform_arguments_all)
8080
empty!(actual_platform_arguments)

0 commit comments

Comments
 (0)