questions on Word operations
Christian Wimmer
christian.wimmer at oracle.com
Fri Oct 11 09:26:42 PDT 2013
I am not overly familiar with the memory checkpointing code, so I leave
that question for someone more qualified.
-Christian
On 10/11/2013 09:19 AM, Deneau, Tom wrote:
> Christian --
>
> OK, I can try this suggestion...
>
> On a similar topic, I believe the AtomicGetAndAddNode should implement MemoryCheckPoint.Single (like CompareAndSwapNode does)
>
> and perhaps like CompareAndSwapNode getLocationIdentity() should return LocationIdentity.ANY_LOCATION??
>
> But for the LoweredAtomicGetAndAddNode, should it still extend AccessNode?
>
> AccessNode requires an object and location and in my case a Word base + offset as the address instead of an object + offset. Is there a means for handling this?
>
> -- Tom
>
>
> -----Original Message-----
> From: graal-dev-bounces at openjdk.java.net [mailto:graal-dev-bounces at openjdk.java.net] On Behalf Of Christian Wimmer
> Sent: Friday, October 11, 2013 11:05 AM
> To: graal-dev at openjdk.java.net
> Subject: Re: questions on Word operations
>
> You can define the @NodeIntrinsic in another class, e.g., the class where you want to call it (and there you have per definition the Word class available).
>
> @NodeIntrinsic has a parameter that specifies the Node class that it is creating, so you can write
>
> @NodeIntrinsics(AtomicGetAndAddNode.class)
> public static native void atomicGetAndAdd(Word param, ...)
>
> I'm not sure if the return type of your method is Word, but if it is, you also have to be careful with the stamp that the node gets: it needs to be the correct wordKind (Kind.Int or Kind.Long). Use the property setStampFromReturnType then, i.e,
>
> @NodeIntrinsics(value = AtomicGetAndAddNode.class, setStampFromReturnType = true) public static native Word atomicGetAndAdd(Word param, ...)
>
> -Christian
>
>
>
> On 10/11/2013 07:55 AM, Deneau, Tom wrote:
>> I am working on adding a new AtomicGetAndAddNode as Christian described below.
>>
>> One obstacle I am hitting...
>> I would like to have a @NodeIntrinsic in this AtomicGetAndAddNode class that takes Word parameters. But com.oracle.graal.nodes does not have com.oracle.graal.word as a dependency, and when I add it as a dependency I get a loop.
>>
>> What is the best way around this?
>>
>> -- Tom
>>
>>
>> -----Original Message-----
>> From: graal-dev-bounces at openjdk.java.net
>> [mailto:graal-dev-bounces at openjdk.java.net] On Behalf Of Christian
>> Wimmer
>> Sent: Saturday, September 14, 2013 6:30 PM
>> Cc: graal-dev at openjdk.java.net
>> Subject: Re: questions on Word operations
>>
>> Tom,
>>
>> So you want to use a atomicGetAndAdd instruction from a snippet,
>> similarly to the CompareAndSwap that is already in Graal (because it
>> is accessible via sun.misc.Unsafe).
>>
>> I would say the easiest way is to create a new AtomicGetAndAddNode,
>> and provide the proper lowering to a new LIR Operation.
>>
>> You can access the new node from a snippet via a node intrinsic - a
>> method annotated with @NodeIntrinsic in the node class. The parameter
>> list of the node intrinsic corresponds with the constructor parameters
>> of the node class, and the pre-processing that Graal is doing for the
>> snippet replaces the call to the node intrinsic method with an actual
>> node instance.
>>
>> -Christian
>>
>>
>> On 9/13/2013 11:30 AM, Deneau, Tom wrote:
>>> Christian --
>>>
>>> Yes, I should have stated the final goal and maybe there is a better way to do what we want to do...
>>>
>>> We want to support object allocation from an HSA GPU. (or at least to get an idea whether it is worth supporting it).
>>>
>>> At a high level, there would be a bunch of TLABS available for the gpu to use.
>>> For the initial prototype these could be the TLABs from actual java
>>> "donor threads" whose only purpose is to supply their TLAB (the java donor threads wouldn't allocate into their own TLAB).
>>>
>>> Since the HSA GPU has the same view of memory as the cpu, we thought
>>> perhaps we could just use the non-atomic pointer bump snippet that is used with HotspotRuntime.
>>> We confirmed this works for small numbers of workitems but the high
>>> parallelism of the gpu means an unreasonably high number of donor threads would be needed for the general case.
>>>
>>> So we are now experimenting with multiple GPU workitems sharing a TLAB and allocatin using an atomic pointer bump.
>>> We know the HSAIL code we want to end up with, but I just don't have
>>> any experience with Graal Snippets and such to make graal emit this HSAIL code (as you can tell from my questions).
>>>
>>> But maybe there is an easier way to get graal to emit this allocation code?
>>>
>>> -- Tom
>>>
>>>
>>> -----Original Message-----
>>> From: graal-dev-bounces at openjdk.java.net
>>> [mailto:graal-dev-bounces at openjdk.java.net] On Behalf Of Christian
>>> Wimmer
>>> Sent: Friday, September 13, 2013 12:19 PM
>>> To: graal-dev at openjdk.java.net
>>> Subject: Re: questions on Word operations
>>>
>>> All functions on word types (everything implementing the interface
>>> WordBase) are compiler intrinsics. If you use Word in a snippet, and call one of the methods on it, the body of these methods is actually irrelevant. The only thing that matters is how the WordTypeRewriterPhase replaces the method call with low-level compiler nodes. The @Operation annotation is used by the WordTypeRewriterPhase to distinguish what to do.
>>>
>>> Word only provides the very basic arithmetic and memory operations (+, -, * , /, read, write). Adding methods for atomic operations like you want is possible, but I don't think it is the easiest way to achieve what you want to do.
>>>
>>> Can you explain what your final goal is?
>>>
>>> -Christian
>>>
>>>
>>> On 09/13/2013 09:47 AM, Deneau, Tom wrote:
>>>> I would like to add a new Word method that can be used from an allocation Snippet I am trying to write.
>>>>
>>>> The new method would look like:
>>>>
>>>> public Word atomicGetAndAddWord(int offset, int delta) {
>>>>
>>>> }
>>>>
>>>> So given a Word (address), this would do an atomic get and add of delta on the word located at the address this.rawValue + offset. Like j.u.c.atomic.getAndAdd, it would return the original word value at that address.
>>>>
>>>> A couple of questions:
>>>>
>>>> * Is the following a legal body for such a method? I see
>>>> that it compiles but is it legal to call toObject() on a Word value?
>>>> As used in the snippet the Word value would be the pointer returned
>>>> by thread(). I noticed there is no unsafe.getAndAddLong(long
>>>> address, long delta), only unsafe.getAndAddLong(Object o, long
>>>> offset, long
>>>> delta)
>>>>
>>>> return box(unsafe.getAndAddLong(toObject(), offset,
>>>> delta));
>>>>
>>>> * I notice all the Word methods have @Operation annotations but I don't really understand the semantics of this annotation. What should be the annotation for this method?
>>>>
>>>>
>>>> * What is the purpose of the locationIdentity parameter on
>>>> some of the word operations such as
>>>>
>>>> @Operation(opcode = Opcode.READ)
>>>> public Word readWord(WordBase offset, LocationIdentity locationIdentity) {
>>>> return box(unsafe.getAddress(add((Word) offset).unbox()));
>>>> }
>>>>
>>>> -- Tom
>>>>
>>>
>>>
>>
>>
>>
>
>
More information about the graal-dev
mailing list