carray-jit 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +771 -3
- data/README.md +7 -6
- data/carray-jit.gemspec +1 -3
- data/docs/00_Introduction.md +4 -3
- data/docs/01_GettingStarted.md +1 -1
- data/docs/02_KernelShapes.md +93 -14
- data/docs/03_SupportedFeatures.md +582 -26
- data/docs/04_Compiling.md +33 -6
- data/docs/05_DesignNotes.md +3 -3
- data/docs/06_Cheatsheet.md +198 -5
- data/docs/07_StepByStep.ja.md +534 -0
- data/docs/07_StepByStep.md +535 -0
- data/examples/README.md +12 -0
- data/examples/applications/alarm.rb +121 -0
- data/examples/applications/collatz.rb +105 -0
- data/examples/applications/cubic_spline.rb +331 -0
- data/examples/applications/dithering.rb +144 -0
- data/examples/applications/group_stats.rb +115 -0
- data/examples/applications/lookup.rb +126 -0
- data/examples/applications/median_filter.rb +153 -0
- data/examples/applications/parcel_ascent.rb +220 -0
- data/examples/applications/point_in_polygon.rb +111 -0
- data/examples/applications/random_walk.rb +98 -0
- data/examples/applications/van_der_pol.rb +186 -0
- data/examples/applications/wet_bulb.rb +140 -0
- data/examples/features/10_complex.rb +14 -4
- data/examples/features/15_loops.rb +7 -1
- data/lib/carray/jit/access.rb +14 -0
- data/lib/carray/jit/analyzer.rb +2077 -136
- data/lib/carray/jit/block_reader.rb +37 -6
- data/lib/carray/jit/c_function.rb +613 -76
- data/lib/carray/jit/c_generator.rb +1595 -156
- data/lib/carray/jit/call.rb +68 -0
- data/lib/carray/jit/compiler.rb +75 -11
- data/lib/carray/jit/kernel.rb +369 -32
- data/lib/carray/jit/node.rb +359 -9
- data/lib/carray/jit/sorting_networks.rb +182 -0
- data/lib/carray/jit/type_assignment.rb +371 -34
- data/lib/carray/jit/version.rb +1 -1
- data/lib/carray/jit.rb +560 -64
- metadata +22 -8
- data/ext/carray_jit_access/carray_jit_access.c +0 -460
- data/ext/carray_jit_access/extconf.rb +0 -8
|
@@ -25,14 +25,16 @@ class CArray
|
|
|
25
25
|
unless defined?(RubyVM::InstructionSequence)
|
|
26
26
|
raise Unsupported,
|
|
27
27
|
"this Ruby has no RubyVM::InstructionSequence; " \
|
|
28
|
-
"
|
|
28
|
+
"compile the kernel from text with " \
|
|
29
|
+
"`CArray::JIT.compile` instead"
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
sequence = RubyVM::InstructionSequence.of(block)
|
|
32
33
|
unless sequence
|
|
33
34
|
raise Unsupported,
|
|
34
35
|
"the block has no instruction sequence (defined in C?); " \
|
|
35
|
-
"
|
|
36
|
+
"compile the kernel from text with " \
|
|
37
|
+
"`CArray::JIT.compile` instead"
|
|
36
38
|
end
|
|
37
39
|
|
|
38
40
|
location = code_location(sequence)
|
|
@@ -57,7 +59,8 @@ class CArray
|
|
|
57
59
|
unless location
|
|
58
60
|
raise Unsupported,
|
|
59
61
|
"this Ruby does not report a code location for blocks; " \
|
|
60
|
-
"
|
|
62
|
+
"compile the kernel from text with " \
|
|
63
|
+
"`CArray::JIT.compile` instead"
|
|
61
64
|
end
|
|
62
65
|
location
|
|
63
66
|
end
|
|
@@ -75,14 +78,42 @@ class CArray
|
|
|
75
78
|
|
|
76
79
|
path = sequence.absolute_path
|
|
77
80
|
if path && File.file?(path)
|
|
78
|
-
return
|
|
81
|
+
return read_script(path)
|
|
79
82
|
end
|
|
80
83
|
|
|
81
84
|
raise Unsupported,
|
|
82
85
|
"the block's source is not available " \
|
|
83
86
|
"(defined in eval or in a console?); " \
|
|
84
|
-
"
|
|
85
|
-
"
|
|
87
|
+
"set RubyVM.keep_script_lines = true before defining it, " \
|
|
88
|
+
"or compile it from text with `CArray::JIT.compile`"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Ruby reads a source file as UTF-8 unless a magic comment says
|
|
92
|
+
# otherwise, and `Encoding.default_external` has nothing to do with
|
|
93
|
+
# it. Reading by that is what `File.read` does, and on a machine
|
|
94
|
+
# with no locale set it hands back the file's own bytes under a
|
|
95
|
+
# US-ASCII tag -- which every later `rstrip` on a line holding a
|
|
96
|
+
# non-ASCII comment raises on. So the bytes are read as bytes and
|
|
97
|
+
# given the encoding the parser gave them.
|
|
98
|
+
def read_script (path)
|
|
99
|
+
source = File.binread(path)
|
|
100
|
+
source.force_encoding(script_encoding(source))
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# The magic comment, on the first line or on the second where a
|
|
104
|
+
# shebang takes the first -- the two places Ruby looks for it. The
|
|
105
|
+
# word is `coding`, with no boundary before it: `# encoding: euc-jp`
|
|
106
|
+
# and `# -*- coding: utf-8 -*-` are both spellings Ruby takes.
|
|
107
|
+
def script_encoding (source)
|
|
108
|
+
head = source.byteslice(0, 1024).lines.first(2)
|
|
109
|
+
head.shift if head.first&.start_with?("#!")
|
|
110
|
+
name = head.first&.slice(/coding\s*[:=]\s*([\w.\-]+)/, 1)
|
|
111
|
+
return Encoding::UTF_8 unless name
|
|
112
|
+
begin
|
|
113
|
+
Encoding.find(name)
|
|
114
|
+
rescue ArgumentError
|
|
115
|
+
Encoding::UTF_8
|
|
116
|
+
end
|
|
86
117
|
end
|
|
87
118
|
|
|
88
119
|
def locate (source, location)
|