Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.arch > #32297 > unrolled thread
| Started by | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| First post | 2015-12-30 09:21 -0800 |
| Last post | 2016-01-03 14:33 -0800 |
| Articles | 18 — 7 participants |
Back to article view | Back to comp.arch
CLU (clamping logic unit) -- An idea to aid in prefetch operations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-12-30 09:21 -0800
Re: CLU (clamping logic unit) -- An idea to aid in prefetch operations Quadibloc <jsavard@ecn.ab.ca> - 2015-12-30 09:38 -0800
Re: CLU (clamping logic unit) -- An idea to aid in prefetch operations EricP <ThatWouldBeTelling@thevillage.com> - 2015-12-30 13:06 -0500
Re: CLU (clamping logic unit) -- An idea to aid in prefetch operations MitchAlsup <MitchAlsup@aol.com> - 2015-12-31 08:08 -0800
Re: CLU (clamping logic unit) -- An idea to aid in prefetch operations Quadibloc <jsavard@ecn.ab.ca> - 2015-12-31 08:18 -0800
Re: CLU (clamping logic unit) -- An idea to aid in prefetch operations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-12-31 08:19 -0800
Re: CLU (clamping logic unit) -- An idea to aid in prefetch operations Anonymous <no_email@invalid.invalid> - 2016-01-01 01:00 +0000
Re: CLU (clamping logic unit) -- An idea to aid in prefetch operations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-12-31 17:23 -0800
Re: CLU (clamping logic unit) -- An idea to aid in prefetch operations Anonymous <no_email@invalid.invalid> - 2016-01-01 01:33 +0000
Re: CLU (clamping logic unit) -- An idea to aid in prefetch operations Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-01 11:30 +0100
Re: CLU (clamping logic unit) -- An idea to aid in prefetch operations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-12-31 08:23 -0800
Re: CLU (clamping logic unit) -- An idea to aid in prefetch operations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-12-31 08:29 -0800
Re: CLU (clamping logic unit) -- An idea to aid in prefetch operations Quadibloc <jsavard@ecn.ab.ca> - 2015-12-31 11:33 -0800
Re: CLU (clamping logic unit) -- An idea to aid in prefetch operations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-01-02 11:21 -0800
Re: CLU (clamping logic unit) -- An idea to aid in prefetch operations MitchAlsup <MitchAlsup@aol.com> - 2016-01-02 12:04 -0800
Re: CLU (clamping logic unit) -- An idea to aid in prefetch operations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-01-02 12:24 -0800
Re: CLU (clamping logic unit) -- An idea to aid in prefetch operations anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-03 15:34 +0000
Re: CLU (clamping logic unit) -- An idea to aid in prefetch operations MitchAlsup <MitchAlsup@aol.com> - 2016-01-03 14:33 -0800
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2015-12-30 09:21 -0800 |
| Subject | CLU (clamping logic unit) -- An idea to aid in prefetch operations |
| Message-ID | <99749576-6d5c-4df7-b5d2-c6836024a787@googlegroups.com> |
In working with my CAlive compiler design, and my Arxoda CPU hardware
design, I had a thought about one aspect of data processing. This idea
relates to hardware prefetching and may already exist, but it occurred
to me independently as by looking at the needs of the compiler, and the
offerings of the CPU, and I wanted to get some feedback on its concept
and implementation.
Please consider responding if you are interested. Thank you in advance.
-----
Consider:
extern int a[1000000];
extern int b[1000000];
for (int i = 0; i < 1000000; i++)
a[i] += b[i];
In this example, the cache would not do well. Successive accesses
would almost consistently stall because the cache is being traversed
sequentially and the CPU has no way of knowing that without the
injection of some compiler-hints, or explicit code which would
prefetch data that's needed for upcoming use.
I have seen various instructions added for this ability, and a few
ways in source code to address this need, but I had a thought of my
own and I wanted to offer it.
-----
A cache line will be a particular size, and it can be known through a
machine-specific register, for example, such that it would be possible
to setup an exposed ability and condition within the CPU which would
directly address this type of need, but without much mechanical
overhead.
I call this "clamping" because it arbitrary clamps its count value at
the indicated maximum, though the concept may already exist and have
a different name.
Clamping is a two-fold ability. First, it is the utilization of a
register for a particular purpose in a CLU (clamp logic unit). It
allows, for example, the lower half of a register to be utilized as
a count, with the upper half being utilized as a clamp value which
serves as an upper range or boundary. When reached, it causes the
lower 16-bits to roll to 0 and signal the clamp activity at that time.
32-bit register (16-bits and 16-bits, but can be employed with a
40-bit register, or 64-bit register):
[0000000000000000]:[0000000000000000]
clamping value current value
Second, the signald clamping operation is encoded within a few clamp
instructions, and one such use could signal a cache-line read in advance,
for example, but one which does not need to be executed in its temporal
location in the instruction stream, but only "very close to it,"
allowing for the background operation to be scheduled within the next
N instruction before some type of enforcement policy is employed which
does interrupt normal memory read access, allowing the cache line to
be available before its required, but with very little overhead.
But in addition, it could serve as a flag-set feature which triggers
every Nth operation in a loop. By doing this, a condition is
established without traditional logic, as by the clamp logic unit and
its various instructions.
For flag-setting operations, I envision these abilities:
cload <reg>,<imm> ; Load reg with clamp and seed
cincf <reg> ; Inc value, set value to 0 + flag f on
; overflow
cdecf <reg> ; Dec value, set value to clamp + flag f
; on underflow
cload would load the upper N-bit clamp value, and lower N-bit seed value,
allowing subsequent clamp operations to go from there.
cincf and cdecf would increment the lower N-bit value and wrap to the
upper N-bit clamp value on overfow or underflow respectively. It would
set the general purpose flag number on my Arxoda CPU design, or it could
be set to carry? or zero? etc. on other CPUs.
This would allow for arbitrary "mod counts" to be computed and triggered
automatically without the normal overhead of increment-and-test, as by
the CLU's abilities.
-----
For caching operations:
32-bit register:
[00][00000000000000]:[xx][00000000000000]
| clamping value | current value
| |
| +- unused
|
+- Number of cache lines to prefetch
cload <reg>,<imm> ; Loads reg with stride, clamp, and seed
ccache <reg>,<adr> ; Inc value, set value to 0 + issue read
; adr on overflow
In this case, cload would perform the identical operation as above,
but the internal format of the reg would include a new assignment
for the upper 2-bits, that being the number of cache line reads to
hit at the cache address indicated in the ccache instruction, with
the first being one cache line size ahead of that address.
ccache would perform the cincf operation, but upon overflow, instead
of setting a flag, it would instruct the CPU to issue the look-ahead
prefetch operations on adr + cache line size, repeated for a count in
the upper 2-bits. These would be injected into a "needs" unit which
would include injection as soon as possible, with an enforcement policy
after a low number of N cycles.
Such an ability would provide an easy way for compilers to establish
ad hoc cache line prefetch operations for all kinds of scenarios, with
the ability to maintain those values internally for ongoing use through
arbitrary branching, through the simple use of the equivalent of a
single stored integer, as would be used through the CLU.
-----
Together, these abilities would allow the very common logic flow op
of looping to allow for a multitude of lesser-/mod-iterative operations
to be triggered with very little overhead in the normal instruction
stream, simply through the addition of this repurposing of a general
purpose register.
Thank you again for your consideration and input.
Best regards,
Rick C. Hodgin
[toc] | [next] | [standalone]
| From | Quadibloc <jsavard@ecn.ab.ca> |
|---|---|
| Date | 2015-12-30 09:38 -0800 |
| Message-ID | <3b098f29-06c6-4b2a-ade4-264b7e5727d2@googlegroups.com> |
| In reply to | #32297 |
On Wednesday, December 30, 2015 at 10:21:45 AM UTC-7, Rick C. Hodgin wrote: > Consider: > > extern int a[1000000]; > extern int b[1000000]; > > for (int i = 0; i < 1000000; i++) > a[i] += b[i]; > > In this example, the cache would not do well. Successive accesses > would almost consistently stall because the cache is being traversed > sequentially and the CPU has no way of knowing that without the > injection of some compiler-hints, or explicit code which would > prefetch data that's needed for upcoming use. I'm doubtful that is the case. The cache would do badly if the loop accessed the elements in some random order instead of sequentially, but sequential access keeps the references local - and sequential access is very much a normal way of working with vectors _or with program code_, and so prefetching what follows what was used is standard practice. John Savard
[toc] | [prev] | [next] | [standalone]
| From | EricP <ThatWouldBeTelling@thevillage.com> |
|---|---|
| Date | 2015-12-30 13:06 -0500 |
| Message-ID | <Y3Vgy.26013$dB4.23592@fx18.iad> |
| In reply to | #32297 |
Rick C. Hodgin wrote: > In working with my CAlive compiler design, and my Arxoda CPU hardware > design, I had a thought about one aspect of data processing. This idea > relates to hardware prefetching and may already exist, but it occurred > to me independently as by looking at the needs of the compiler, and the > offerings of the CPU, and I wanted to get some feedback on its concept > and implementation. > > Please consider responding if you are interested. Thank you in advance. > > ----- > Consider: > > extern int a[1000000]; > extern int b[1000000]; > > for (int i = 0; i < 1000000; i++) > a[i] += b[i]; > > In this example, the cache would not do well. Successive accesses > would almost consistently stall because the cache is being traversed > sequentially and the CPU has no way of knowing that without the > injection of some compiler-hints, or explicit code which would > prefetch data that's needed for upcoming use. You could of course test this assumption with a quick Google search for various permutations of "cache sequential hardware prefetch". Eric
[toc] | [prev] | [next] | [standalone]
| From | MitchAlsup <MitchAlsup@aol.com> |
|---|---|
| Date | 2015-12-31 08:08 -0800 |
| Message-ID | <cd815b09-b95d-484b-9841-e4c762d2a98c@googlegroups.com> |
| In reply to | #32297 |
On Wednesday, December 30, 2015 at 11:21:45 AM UTC-6, Rick C. Hodgin wrote:
> Consider:
>
> extern int a[1000000];
> extern int b[1000000];
>
> for (int i = 0; i < 1000000; i++)
> a[i] += b[i];
>
> In this example, the cache would not do well.
The above code "strip mines" memory.
This is easy to get around by adding loops:
for (int i = 0; i < 1000000; i++)
for( int j = 0; j < CacheSize/4; j++, i++ )
a[i] += b[i];
> I call this "clamping" because it arbitrary clamps its count value at
> the indicated maximum, though the concept may already exist and have
> a different name.
The real name is "saturation". Saturation can also prevent integer overflows
but it has to be attached to the integer operation that would overflow
because once overflow has happened, saturation cannot be applied "easily".
Floating point saturation can be done "after the fact".
Other than that, adding the overhead you speak of in the snipped text won't
fly.
[toc] | [prev] | [next] | [standalone]
| From | Quadibloc <jsavard@ecn.ab.ca> |
|---|---|
| Date | 2015-12-31 08:18 -0800 |
| Message-ID | <dff143ff-6d7d-4d84-8e18-355fafda836c@googlegroups.com> |
| In reply to | #32331 |
On Thursday, December 31, 2015 at 9:08:25 AM UTC-7, MitchAlsup wrote: > This is easy to get around by adding loops: > > for (int i = 0; i < 1000000; i++) > for( int j = 0; j < CacheSize/4; j++, i++ ) > a[i] += b[i]; You are altering a loop variable somewhere else, outside the FOR statement!!?? Of course, in C, that is perfectly legal. Having learned to program originally in FORTRAN (well, not quite, I had some BASIC experience before that) I am instinctively horrified. However, even in C, it looks a bit odd to me that you can use a *comma* to separate multiple statements - although being able to do so is certainly useful, since the semicolon has an additional significance in the FOR statement. John Savard
[toc] | [prev] | [next] | [standalone]
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2015-12-31 08:19 -0800 |
| Message-ID | <4de964d8-f7ac-4991-ba0a-dc633fd9954b@googlegroups.com> |
| In reply to | #32331 |
On Thursday, December 31, 2015 at 11:08:25 AM UTC-5, MitchAlsup wrote: > On Wednesday, December 30, 2015 at 11:21:45 AM UTC-6, Rick C. Hodgin wrote: > > I call this "clamping" because it arbitrary clamps its count value at > > the indicated maximum, though the concept may already exist and have > > a different name. > > The real name is "saturation". Saturation can also prevent integer overflows > but it has to be attached to the integer operation that would overflow > because once overflow has happened, saturation cannot be applied "easily". > Floating point saturation can be done "after the fact". Saturation is a different concept, in that if a value exceeds its target it is saturated to the maximum, or minimum. Clamping relates to an arbitrary maximum range defined within the clamping register, such that when the count in that register reaches its clamp value, it wraps to 0, or when it reaches 0 it wraps to the clamp value. Best regards, Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | Anonymous <no_email@invalid.invalid> |
|---|---|
| Date | 2016-01-01 01:00 +0000 |
| Message-ID | <dem1e4Fke12U1@mid.individual.net> |
| In reply to | #32334 |
Rick C. Hodgin <rick.c.hodgin@gmail.com> wrote: > On Thursday, December 31, 2015 at 11:08:25 AM UTC-5, MitchAlsup wrote: >> On Wednesday, December 30, 2015 at 11:21:45 AM UTC-6, Rick C. Hodgin wrote: >>> I call this "clamping" because it arbitrary clamps its count value at >>> the indicated maximum, though the concept may already exist and have >>> a different name. >> >> The real name is "saturation". Saturation can also prevent integer overflows >> but it has to be attached to the integer operation that would overflow >> because once overflow has happened, saturation cannot be applied "easily". >> Floating point saturation can be done "after the fact". > > Saturation is a different concept, in that if a value exceeds its target > it is saturated to the maximum, or minimum. Clamping relates to an > arbitrary maximum range defined within the clamping register, such that > when the count in that register reaches its clamp value, it wraps to 0, > or when it reaches 0 it wraps to the clamp value. type cyclic is mod 19; a : cyclic := 18; b : cyclic := 0; ... a := a+1; -- with effect a := 0 b := b-1; -- with effect b:= 18 Guess the language! -- Bill Findlay
[toc] | [prev] | [next] | [standalone]
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2015-12-31 17:23 -0800 |
| Message-ID | <635e5b61-a02b-4b14-8f1c-c66c28bdde7f@googlegroups.com> |
| In reply to | #32360 |
Bill Findlay wrote: > type cyclic is mod 19; > a : cyclic := 18; > b : cyclic := 0; > ... a := a+1; > -- with effect a := 0 b := b-1; > -- with effect b := 18 (sorry for loss of formatting, my phone lost it on copy/paste) > Guess the language! Ada? :-) My CLU offering is about a more efficient way to implement that ability within the ISA, not in the base language (though it is nice to have such language abilities). Best regards, Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | Anonymous <no_email@invalid.invalid> |
|---|---|
| Date | 2016-01-01 01:33 +0000 |
| Message-ID | <dem3bvFkrneU1@mid.individual.net> |
| In reply to | #32362 |
Rick C. Hodgin <rick.c.hodgin@gmail.com> wrote: > Bill Findlay wrote: >> type cyclic is mod 19; >> a : cyclic := 18; >> b : cyclic := 0; >> ... a := a+1; >> -- with effect a := 0 b := b-1; >> -- with effect b := 18 > > (sorry for loss of formatting, my phone lost it on copy/paste) > >> Guess the language! > > Ada? :-) Yup. 8-) That type is used for the index into the NEST registers in my KDF9 emulator. It also uses a mod 17 type for the SJNS index. > My CLU offering is about a more efficient way to implement that > ability within the ISA, not in the base language (though it is nice > to have such language abilities). -- Bill Findlay
[toc] | [prev] | [next] | [standalone]
| From | Terje Mathisen <terje.mathisen@tmsw.no> |
|---|---|
| Date | 2016-01-01 11:30 +0100 |
| Message-ID | <n65kfo$1vg$1@speranza.aioe.org> |
| In reply to | #32366 |
Anonymous wrote: > Rick C. Hodgin <rick.c.hodgin@gmail.com> wrote: >> Bill Findlay wrote: >>> type cyclic is mod 19; >>> a : cyclic := 18; >>> b : cyclic := 0; >>> ... a := a+1; >>> -- with effect a := 0 b := b-1; >>> -- with effect b := 18 >> >> (sorry for loss of formatting, my phone lost it on copy/paste) >> >>> Guess the language! >> >> Ada? :-) > > Yup. 8-) > That type is used for the index into the NEST registers in my KDF9 > emulator. > It also uses a mod 17 type for the SJNS index. Having a modulo type as native to the language means that the compiler probably know how to optimize those mod operations, with various approaches depending upon the operation, right? c := a + b; can then turn into either c = a + b; if (c >= 19) c -= 19; // Fastest when wrapaound is rare or t = a + b; c = (t >= 19) ? t-19 : t; // Using conditional/predicated ops or even c = a + b; mask = (18 - c) >> 5; // Signed arithmetic shift right (SAR) c -= mask & 19; // Fast when wraparound is really unpredictable When the range of the answer is unknown, like after a multiplication, the fastest approach is probably to use a real modulo operation, implemented via reciprocal mul: c = a * b; t = c / 19; c -= t*19; Terje -- - <Terje.Mathisen at tmsw.no> "almost all programming can be viewed as an exercise in caching"
[toc] | [prev] | [next] | [standalone]
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2015-12-31 08:23 -0800 |
| Message-ID | <8fc6f2dc-7656-4430-89fe-390c9a6ea7e3@googlegroups.com> |
| In reply to | #32331 |
On Thursday, December 31, 2015 at 11:08:25 AM UTC-5, MitchAlsup wrote:
> On Wednesday, December 30, 2015 at 11:21:45 AM UTC-6, Rick C. Hodgin wrote:
>
> > Consider:
> >
> > extern int a[1000000];
> > extern int b[1000000];
> >
> > for (int i = 0; i < 1000000; i++)
> > a[i] += b[i];
> >
> > In this example, the cache would not do well.
>
> The above code "strip mines" memory.
>
> This is easy to get around by adding loops:
>
> for (int i = 0; i < 1000000; i++)
> for( int j = 0; j < CacheSize/4; j++, i++ )
> a[i] += b[i];
I believe you would need this (no need for the first "i++"):
for (int i = 0; i < 1000000; )
for (int j = 0; j < CacheSize/4; j++, i++)
a[i] += b[i];
And how would this change anything? a[] and b[] are still being
traversed sequentially, identically as before. In fact, I would
be surprised if the compiler didn't optimize both of those bits
of source code down to the same exact sequence of asm instructions.
Best regards,
Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2015-12-31 08:29 -0800 |
| Message-ID | <c1d69434-70e7-4675-a7d7-8e863ad3bdaf@googlegroups.com> |
| In reply to | #32335 |
On Thursday, December 31, 2015 at 11:23:28 AM UTC-5, Rick C. Hodgin wrote:
> On Thursday, December 31, 2015 at 11:08:25 AM UTC-5, MitchAlsup wrote:
> > On Wednesday, December 30, 2015 at 11:21:45 AM UTC-6, Rick C. Hodgin wrote:
> >
> > > Consider:
> > >
> > > extern int a[1000000];
> > > extern int b[1000000];
> > >
> > > for (int i = 0; i < 1000000; i++)
> > > a[i] += b[i];
> > >
> > > In this example, the cache would not do well.
> >
> > The above code "strip mines" memory.
> >
> > This is easy to get around by adding loops:
> >
> > for (int i = 0; i < 1000000; i++)
> > for( int j = 0; j < CacheSize/4; j++, i++ )
> > a[i] += b[i];
>
> I believe you would need this (no need for the first "i++"):
>
> for (int i = 0; i < 1000000; )
> for (int j = 0; j < CacheSize/4; j++, i++)
> a[i] += b[i];
>
> And how would this change anything? a[] and b[] are still being
> traversed sequentially, identically as before. In fact, I would
> be surprised if the compiler didn't optimize both of those bits
> of source code down to the same exact sequence of asm instructions.
I think you meant:
volatile int m, n;
for (int i = 0; i < 1000000; m = a[i + CacheSize]], n = b[i + CacheSize])
for (int j = 0; j < CacheSize/4; j++, i++)
a[i] += b[i];
That would prefetch in advance, and that's the purpose of introducing
this ccache instruction, and the CLU. The CLU would operate in parallel
and pre-compute the cincf and cdecf values, so that when cincf, cdecf,
or ccache are encountered in the instruction on a previously accessed
register value that has not changed, it can be pulled in the decode
phase allowing a 0-clock-cycle intrusion into the instruction stream.
In the example above you're using several asm instructions to handle
the prefetch mechanically, which is what the CLU is trying to avoid.
In addition, the CLU would allow lesser-periodic iterative operations
on loops to be computed far more easilyi and without several asm
instructions, and also arbitrarily on a wide range of "mod N" values,
such that every time it clamps, it signals.
Best regards,
Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | Quadibloc <jsavard@ecn.ab.ca> |
|---|---|
| Date | 2015-12-31 11:33 -0800 |
| Message-ID | <f254a124-d530-433d-9059-61a5170dabbc@googlegroups.com> |
| In reply to | #32335 |
On Thursday, December 31, 2015 at 9:23:28 AM UTC-7, Rick C. Hodgin wrote: > I believe you would need this (no need for the first "i++"): > > for (int i = 0; i < 1000000; ) > for (int j = 0; j < CacheSize/4; j++, i++) > a[i] += b[i]; I didn't even notice the bug: skipping one element at the end of each cache quarter! John Savard
[toc] | [prev] | [next] | [standalone]
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2016-01-02 11:21 -0800 |
| Message-ID | <ef116e33-a68a-433d-a200-12b209cb2ae4@googlegroups.com> |
| In reply to | #32331 |
On Thursday, December 31, 2015 at 11:08:25 AM UTC-5, MitchAlsup wrote: > On Wednesday, December 30, 2015 at 11:21:45 AM UTC-6, Rick C. Hodgin wrote: > > Consider: > > > > extern int a[1000000]; > > extern int b[1000000]; > > > > for (int i = 0; i < 1000000; i++) > > a[i] += b[i]; > > > > In this example, the cache would not do well. > > The above code "strip mines" memory. What do you mean by "strip mines" memory? Best regards, Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | MitchAlsup <MitchAlsup@aol.com> |
|---|---|
| Date | 2016-01-02 12:04 -0800 |
| Message-ID | <ac8afa0f-cadc-4cc3-8a0d-fff64b6de129@googlegroups.com> |
| In reply to | #32438 |
On Saturday, January 2, 2016 at 1:21:34 PM UTC-6, Rick C. Hodgin wrote: > On Thursday, December 31, 2015 at 11:08:25 AM UTC-5, MitchAlsup wrote: > > On Wednesday, December 30, 2015 at 11:21:45 AM UTC-6, Rick C. Hodgin wrote: > > > Consider: > > > > > > extern int a[1000000]; > > > extern int b[1000000]; > > > > > > for (int i = 0; i < 1000000; i++) > > > a[i] += b[i]; > > > > > > In this example, the cache would not do well. > > > > The above code "strip mines" memory. > > What do you mean by "strip mines" memory? You read a[0], b[0], a[1], b[1] ... a[1000000], b[1000000], never reusing a single item. This is why vector machines did not have caches, and much of the codes they were really good at "strip mined memory". This kind of memory reference pattern is not amenable to caching as it displays no temporal or spatial reuse.
[toc] | [prev] | [next] | [standalone]
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2016-01-02 12:24 -0800 |
| Message-ID | <c5ae946f-8c48-4932-b45c-b6d8bed70603@googlegroups.com> |
| In reply to | #32440 |
On Saturday, January 2, 2016 at 3:04:24 PM UTC-5, MitchAlsup wrote:
> On Saturday, January 2, 2016 at 1:21:34 PM UTC-6, Rick C. Hodgin wrote:
> > On Thursday, December 31, 2015 at 11:08:25 AM UTC-5, MitchAlsup wrote:
> > > On Wednesday, December 30, 2015 at 11:21:45 AM UTC-6, Rick C. Hodgin wrote:
> > > > Consider:
> > > >
> > > > extern int a[1000000];
> > > > extern int b[1000000];
> > > >
> > > > for (int i = 0; i < 1000000; i++)
> > > > a[i] += b[i];
> > > >
> > > > In this example, the cache would not do well.
> > >
> > > The above code "strip mines" memory.
> >
> > What do you mean by "strip mines" memory?
>
> You read a[0], b[0], a[1], b[1] ... a[1000000], b[1000000],
> never reusing a single item.
>
> This is why vector machines did not have caches, and much of the codes
> they were really good at "strip mined memory". This kind of memory reference
> pattern is not amenable to caching as it displays no temporal or spatial
> reuse.
That is what I thought, so I was confused of your use of "strip mine"
in the other thread regarding unums. I don't see how unum processing
would strip mine the cache unless it was a truly huge computation. I
believe the nK scratch space was introduced to allow these types of
computations within the unit itself without even reaching into L1 for
many computations.
-----
I had a solution for "strip mining" (what I would call) "thrashing the
cache" case, and that would be to introduce an ISA hint to the CPU that
the following code results in operations which result in that type of
non-reuse access on data, and therefore should not thrash the cache.
The idea was to introduce a cache reuse instruction which truncates
which part of the cache can be used until changed to an explicit width,
or line count. This would cause that smaller window of the entire
cache to be re-used when a cache miss is encountered, and data has to
be loaded from main memory.
I had this idea as an derivative to the "fence" instructions seen in
Itanium and later x86, though in this case they're explicitly applied
to "fencing off" a portion of the cache that is to be used.
ISA support goes like this:
crfence -- Read the cache fence register
csfence -- Set the cache fence register
The looping operation above would go like this:
crfence temp ; Read current fence value
csfence 4 ; Set cache access to only 4 cache lines,
; enough to handle the ccache stride
; Perform the code for the loop here
csfence tmp ; Restore its previous value
Interrupts would inherit the existing constraint, but any OS that
is aware of this CPU and the cache fence abilities would be able
to read and restore the value if it wanted to temporarily access
a larger cache during servicing.
Best regards,
Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2016-01-03 15:34 +0000 |
| Message-ID | <2016Jan3.163427@mips.complang.tuwien.ac.at> |
| In reply to | #32440 |
MitchAlsup <MitchAlsup@aol.com> writes: >On Saturday, January 2, 2016 at 1:21:34 PM UTC-6, Rick C. Hodgin wrote: >> On Thursday, December 31, 2015 at 11:08:25 AM UTC-5, MitchAlsup wrote: >> > On Wednesday, December 30, 2015 at 11:21:45 AM UTC-6, Rick C. Hodgin wrote: >> > > Consider: >> > > >> > > extern int a[1000000]; >> > > extern int b[1000000]; >> > > >> > > for (int i = 0; i < 1000000; i++) >> > > a[i] += b[i]; >> > > >> > > In this example, the cache would not do well. >> > >> > The above code "strip mines" memory. >> >> What do you mean by "strip mines" memory? > >You read a[0], b[0], a[1], b[1] ... a[1000000], b[1000000], >never reusing a single item. > >This is why vector machines did not have caches, and much of the codes >they were really good at "strip mined memory". This kind of memory reference >pattern is not amenable to caching as it displays no temporal or spatial >reuse. What is "spatial reuse"? This memory reference pattern exhibits spatial locality and benefits from caching: The first access to each cache line is a miss, but the other accesses happen with 0 or 1 intervening accesses, so they will hit the cache; and this loop accesses all the data in the cache line. - anton -- M. Anton Ertl Some things have to be seen to be believed anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen http://www.complang.tuwien.ac.at/anton/home.html
[toc] | [prev] | [next] | [standalone]
| From | MitchAlsup <MitchAlsup@aol.com> |
|---|---|
| Date | 2016-01-03 14:33 -0800 |
| Message-ID | <29b5d048-55db-4e5e-a420-c859c5eddc44@googlegroups.com> |
| In reply to | #32469 |
On Sunday, January 3, 2016 at 9:46:57 AM UTC-6, Anton Ertl wrote: > What is "spatial reuse"? This memory reference pattern exhibits > spatial locality and benefits from caching: The first access to each > cache line is a miss, but the other accesses happen with 0 or 1 > intervening accesses, so they will hit the cache; and this loop > accesses all the data in the cache line. Under the condition that the data from DRAM is arriving faster then the calculations consume it, I will grant that the code above has spatial reuse. On the other hand, most caches do not deliver the critical word until the cache coherence has been verified (that is data should be arriving from DRAM and not from another processor cache.)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.arch
csiph-web