Skip to content

Commit 1c742f4

Browse files
automated generation of quantifier types and some fixes/improvements
1 parent 07c92b8 commit 1c742f4

File tree

8 files changed

+95
-73
lines changed

8 files changed

+95
-73
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ version = "0.2.0"
66
[deps]
77
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
88
CpuId = "adafc99b-e345-5852-983c-f28acb93d879"
9+
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
910
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
1011
Scratch = "6c6a2e73-6563-6170-7368-637461726353"
1112
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

src/PlatformAware.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ using TOML
1010
using JSON
1111
using Artifacts
1212
using Scratch
13+
using Downloads
1314

1415
# quantifiers
1516
include("quantifiers/atleast.jl")

src/awareness.jl

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ function try_download(url,fname)
6363
if (isfile(fname))
6464
cp(fname,fname * ".backup", force=true)
6565
end
66-
download(url, fname)
66+
Downloads.download(url, fname)
6767
catch e
68-
print(stderr,"error downloading ", url, ".")
68+
@info "error downloading $url."
6969
if (isfile(fname) || isfile(fname * ".backup"))
70-
println(stderr," Using existing file ", fname)
70+
@info " Using existing file $fname"
7171
if (!isfile(fname))
7272
cp(fname * ".backup", fname)
7373
end
7474
else
75-
println(stderr," Check internet connection and try again.")
75+
@info " Check internet connection and try again."
7676
rethrow(e)
7777
end
7878
end
@@ -864,18 +864,16 @@ function setup()
864864
close(fn)
865865
end
866866
end
867-
println()
868-
println("Platform.toml file was created in the current folder.")
869-
println("You can move it to your preferred target.")
870-
println("Platform.toml will be searched in the following locations:")
871-
println(" 1) A file path pointed by a PLATFORM_DESCRIPTION environment variable;")
872-
println(" 2) The current directory;")
873-
println(" 3) The /etc directory.")
867+
@info "Platform.toml file was created in the current folder."
868+
@info "You can move it to your preferred target."
869+
@info "Platform.toml will be searched in the following locations:"
870+
@info " 1) A file path pointed by a PLATFORM_DESCRIPTION environment variable;"
871+
@info " 2) The current directory;"
872+
@info " 3) The /etc directory."
874873
else
875874
TOML.print(stdout, platform_features)
876-
println(stderr)
877-
println(stderr, "Platform description file already exists in the current folder (Platform.toml).")
878-
println(stderr, "You must delete or move it before creating a new one.")
875+
@info "Platform description file already exists in the current folder (Platform.toml)."
876+
@info "You must delete or move it before creating a new one."
879877
end
880878

881879
end

src/features.jl

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function readPlatormDescription()
7070
# read the platform description file (default to the current directory)
7171
filename = get(ENV,"PLATFORM_DESCRIPTION","Platform.toml")
7272

73-
println("reading platform description at " * filename);
73+
@info "reading platform description at $filename"
7474

7575
platform_description_toml =
7676
try
@@ -85,9 +85,9 @@ function readPlatormDescription()
8585
close(io)
8686
contents
8787
catch
88-
println(stderr,"The platform description file (Platform.toml) was not found.")
89-
println(stderr,"Using default platform features (calling default kernels).")
90-
println(stderr,"A Platform.toml file may be created by calling PlatformAware.setup()")
88+
@info "The platform description file (Platform.toml) was not found."
89+
@info "Using default platform features (calling default kernels)."
90+
@info "A Platform.toml file may be created by calling PlatformAware.setup()"
9191

9292
io = joinpath(artifact"default_platform_description", "DefaultPlatform.toml")
9393
read(io,String)
@@ -99,25 +99,31 @@ end
9999

100100
function get_quantifier_from_number(n)
101101

102-
magnitude = Dict(0 => "", 1 => "K", 2 => "M", 3 => "G", 4 => "T", 5 => "P", 6 => "E")
102+
if n>0
103103

104-
l = log(2,n)
105-
a = round(l)
106-
b = isinteger(l) ? a : a + 1;
104+
magnitude = Dict(0 => "", 1 => "K", 2 => "M", 3 => "G", 4 => "T", 5 => "P", 6 => "E")
107105

108-
# the following loop separates a and b in multiplier*magnitude (see the POPL's paper).
106+
l = log(2,n)
107+
a = round(l)
108+
b = isinteger(l) ? a : a + 1;
109109

110-
# let A = 2^a
111-
m=0
112-
while a>9
113-
# loop invariant: A = 2^a * 2^(10*m)
114-
a = a - 10
115-
b = b - 10
116-
m = m + 1
117-
end
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
118120

119-
a_str = "AtLeast" * string(Integer(2^a)) * magnitude[m]
120-
b_str = "AtMost" * string(Integer(2^b)) * magnitude[m]
121+
a_str = "AtLeast" * string(Integer(2^a)) * magnitude[m]
122+
b_str = "AtMost" * string(Integer(2^b)) * magnitude[m]
123+
else
124+
a_str = "AtLeast0"
125+
b_str = "AtMost0"
126+
end
121127

122128
a_type = getfield(@__MODULE__, Meta.parse(a_str))
123129
b_type = getfield(@__MODULE__, Meta.parse(b_str))

src/identification.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ macro platform(t,f)
195195
elseif (t == :parameter && getaddparameter())
196196
platform_parameter_macro!(f)
197197
elseif (t == :parameter && !getaddparameter())
198-
println("cannot add parameters after including the first kernel method")
198+
@info "cannot add parameters after including the first kernel method"
199199
else
200-
println("usage: platform [default | aware] <function declaration>")
201-
println(" platform parameter :(<parameter name>)")
200+
@info "usage: platform [default | aware] <function declaration>"
201+
@info " platform parameter :(<parameter name>)"
202202
end
203203
end
204204

src/platforms/common.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55

66
# OpenCL
7-
abstract type OpenCL <: AcceleratorBackend end
8-
abstract type OpenCL_1_0 <: OpenCL end
7+
abstract type OpenCL_API <: AcceleratorBackend end
8+
abstract type OpenCL_1_0 <: OpenCL_API end
99
abstract type OpenCL_1_1 <: OpenCL_1_0 end
1010
abstract type OpenCL_1_2 <: OpenCL_1_1 end
1111
abstract type OpenCL_2_0 <: OpenCL_1_2 end
1212
abstract type OpenCL_2_1 <: OpenCL_2_0 end
1313
abstract type OpenCL_2_2 <: OpenCL_2_1 end
1414
abstract type OpenCL_3 <: OpenCL_2_2 end
1515

16-
export OpenCL, OpenCL_1_0, OpenCL_1_1, OpenCL_1_2, OpenCL_2_0, OpenCL_2_1, OpenCL_2_2, OpenCL_3
16+
export OpenCL_API, OpenCL_1_0, OpenCL_1_1, OpenCL_1_2, OpenCL_2_0, OpenCL_2_1, OpenCL_2_2, OpenCL_3
1717

1818
# SIMD extensions
1919

src/quantifiers/atleast.jl

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,30 @@
22
# Licensed under the MIT License. See LICENCE in the project root.
33
# ------------------------------------------------------------------
44

5-
#
6-
#abstract type AtLeast0 end # 0
7-
#
8-
#multiplier_super = 0
9-
#magnitude_ = ""
10-
#for magnitude in ['n', 'u', 'm', ' ', 'K', 'M', 'G', 'T', 'P', 'E']
11-
# for multiplier in [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
12-
# magnitude_super = multiplier == 1 ? magnitude_ : magnitude
13-
# code = "abstract type AtLeast" * string(multiplier) * magnitude * " <: AtLeast" * string(multiplier_super) * magnitude_super * " end"
14-
# eval(Meta.parse(code))
15-
# multiplier_super = multiplier
16-
# end
17-
# magnitude_ = magnitude
18-
#end
19-
#
20-
#abstract type AtLeastInf <: AtLeast512E end
5+
# automated declaration of at-least quantifier types
216

7+
abstract type AtLeast0 end
228

9+
let mul_super = 0
10+
mag_ = ""
11+
for mag in ["n", "u", "m", "", "K", "M", "G", "T", "P", "E"]
12+
for mul in [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
13+
mag_super = mul == 1 ? mag_ : mag
14+
nm1 = Symbol("AtLeast" * string(mul) * mag)
15+
nm2 = Symbol("AtLeast" * string(mul_super) * mag_super)
16+
@eval abstract type $nm1 <: $nm2 end
17+
@eval export $nm1
18+
mul_super = mul
19+
end
20+
mag_ = mag
21+
end
22+
end
23+
24+
abstract type AtLeastInf <: AtLeast512E end
25+
26+
27+
28+
#=
2329
# abstract quantities of resources (magnitude order)
2430
2531
abstract type AtLeast0 end # 0
@@ -136,4 +142,6 @@ abstract type AtLeast512E <: AtLeast256E end # 2^69
136142
137143
# ...
138144
139-
abstract type AtLeastInf <: AtLeast512E end #
145+
abstract type AtLeastInf <: AtLeast512E end # ∞
146+
147+
=#

src/quantifiers/atmost.jl

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,33 @@
22
# Licensed under the MIT License. See LICENCE in the project root.
33
# ------------------------------------------------------------------
44

5-
#abstract type AtMostInf end # 0
65

7-
#multiplier_super = "Inf"
8-
#magnitude_ = ""
9-
#for magnitude in reverse(['n', 'u', 'm', ' ', 'K', 'M', 'G', 'T', 'P', 'E'])
10-
# for multiplier in reverse([1, 2, 4, 8, 16, 32, 64, 128, 256, 512])
11-
# magnitude_super = multiplier == 512 ? magnitude_ : magnitude
12-
# code = "abstract type AtMost" * string(multiplier) * magnitude * " <: AtMost" * string(multiplier_super) * magnitude_super * " end"
13-
# eval(Meta.parse(code)); println(code)
14-
# multiplier_super = multiplier
15-
# end
16-
# magnitude_ = magnitude
17-
#end
18-
#
19-
#abstract type AtMost0 <: AtMost1n end
6+
# automated declaration of at-most quantifier types
7+
8+
abstract type AtMostInf end
9+
10+
let mul_super = "Inf" ,
11+
mag_ = "" ;
12+
for mag in reverse(["n", "u", "m", "", "K", "M", "G", "T", "P", "E"])
13+
for mul in reverse([1, 2, 4, 8, 16, 32, 64, 128, 256, 512])
14+
mag_super = mul==512 ? mag_ : mag
15+
nm1 = Symbol("AtMost" * string(mul) * mag)
16+
nm2 = Symbol("AtMost" * string(mul_super) * mag_super)
17+
@eval abstract type $nm1 <: $nm2 end
18+
mul_super = mul
19+
end
20+
mag_ = mag
21+
end
22+
end
23+
24+
abstract type AtMost0 <: AtMost1n end
2025

2126

22-
# abstract quantities of resources (magnitude order)
2327

24-
abstract type AtMostInf end #
2528

26-
# ...
29+
#=
30+
31+
abstract type AtMostInf end # ∞
2732
2833
abstract type AtMost512E <: AtMostInf end # 2^69
2934
abstract type AtMost256E <: AtMost512E end # 2^68
@@ -137,3 +142,6 @@ abstract type AtMost1n <: AtMost2n end # 2^-30
137142
138143
abstract type AtMost0 <: AtMost1n end # 0
139144
145+
=#
146+
147+

0 commit comments

Comments
 (0)