Next: Priming message buffers, Previous: Touching memory, Up: Touching memory [Contents][Index]
While the statements described in Delaying execution delay for a specified length of time, it is also possible to delay for the duration of a specified amount of “work”. “Work” is expressed in terms of memory accesses. That is, a coNCePTuaL program can touch (i.e., read plus write) data with a given stride from a memory region of a given size. By varying these parameters, a program can emulate an application’s computation by hoarding the CPU or any level of the memory hierarchy.
<touch_stmt> | ::= | <source_task> |
TOUCHES |
||
[
<expr> <data_type> OF ] |
||
AN
<item_size> MEMORY REGION |
||
[
<expr>
TIMES ] |
||
[
WITH STRIDE <expr>
<data_type> | WITH RANDOM
STRIDE ] |
<item_size> and <data_type> are described in Item size and <expr> is described in Arithmetic expressions.
As shown by the formal definition of
<touch_stmt> the required components are a
<source_task> and
the size of the memory region to touch. By default, every WORD
(see
Item size) of memory in the
region is touched exactly once. The type of data that is touched
can be varied with an ‘ <expr>
<data_type> OF’ clause. For instance,
‘100 BYTES OF’ of a memory region will touch
individual bytes. An optional repeat count enables the memory
region (or subset thereof) to be touched multiple times. Hence, if
‘TASK 0 TOUCHES A 6 MEGABYTE MEMORY REGION 5 TIMES’,
then the touch will be performed as if ‘TASK 0’ were
told to ‘TOUCH 5*6M BYTES OF A 6 MEGABYTE MEMORY REGION 1
TIME’ or simply to ‘TOUCH 5*6M BYTES OF A 6 MEGABYTE
MEMORY REGION’.
By default, every <data_type> of data
is touched. However, a <touch_stmt>
provides for touching only a subset of the
<data_type>s in the memory region. By writing
‘WITH STRIDE <expr>
<data_type>’, only the first
<data_type> out of every <expr> will be touched.
Instead of specifying an exact stride, the memory region can be
accessed in random order using the
WITH RANDOM STRIDE
clause.
Unless the number of touches and data type are specified
explicitly, the number of WORD
s that are touched is equal to
the size of the memory region divided by the stride length then
multiplied by the repeat count. Therefore, if ‘TASK 0 TOUCHES
AN 8 MEGABYTE MEMORY REGION 2 TIMES WITH STRIDE 8 WORDS’,
then a total of (2^23 / (4*8)) * 2 = 524288 touches will
be performed. For the purpose of the preceding calculation,
‘WITH RANDOM STRIDE’ should be treated as if it were
‘WITH STRIDE 1 WORD’ (again, unless the number of
touches and data type are specified explicitly).
To save memory, all
TOUCH
statements in a coNCePTuaL program access
subsets of the same region of memory, whose size is determined by
the maximum needed. However, each dynamic execution of a
<touch_stmt> starts touching from where the
previous execution left off. For example, consider the following
statement:
TASK 0 TOUCHES 100 WORDS OF A 200 WORD MEMORY REGION
The first time that that statement is executed within a loop (see Iterating), the first 200 words are touched. The second time, the second 200 words are touched. The third time, the index into the region wraps around and the first 200 words are touched again.
Each static <touch_stmt> maintains its own index into the memory region. Therefore, the first of the following two statements will terminate successfully (assuming it’s not executed in the body of a loop) while the second will result in a run-time error because the final byte of the final word does not fit within the given memory region.
TASK 0 TOUCHES 100 WORDS OF A 799 BYTE MEMORY REGION THEN TASK 0 TOUCHES 100 WORDS OF A 799 BYTE MEMORY REGION FOR 2 REPETITIONS TASK 0 TOUCHES 100 WORDS OF A 799 BYTE MEMORY REGION
( THEN
is described in Combining
statements, and
FOR
… REPETITIONS
is described in
Counted loops.) The
first statement shown above touches the same 100 words
(400 bytes) in each of the two
<touch_stmt>s. The second statement touches the
first 100 words the first time the
<touch_stmt> is executed and fails when trying to
touch the (only partially extant) second 100 words.
Next: Priming message buffers, Previous: Touching memory, Up: Touching memory [Contents][Index]