questions about implementing intrinsics

Doug Simon doug.simon at oracle.com
Mon Dec 2 23:36:41 PST 2013


On Dec 3, 2013, at 3:32 AM, Christian Thalinger <christian.thalinger at oracle.com> wrote:

> 
> On Dec 2, 2013, at 2:16 AM, Doug Simon <doug.simon at oracle.com> wrote:
> 
>> 
>> On Dec 1, 2013, at 6:52 PM, Venkatachalam, Vasanth <Vasanth.Venkatachalam at amd.com> wrote:
>> 
>>> Doug or others-
>>> 
>>> I'm trying to understand the process of implementing intrinsics (for the HSAIL backend) for some java.lang.Math routines that x86 doesn't necessarily intrinsify.
>>> As a toy example, I'm trying to implement my own intrinsic for Math.sqrt( ). Below are the steps I tried to take to hack a small prototype.
>>> Can you tell me whether I'm on the right track? I also had some questions below.
>>> 
>>> 
>>> 1)      Define a package com.oracle.graal.replacements.hsail.
>>> 
>>> 2)      In the above package, define a class MathSubstitutionsHSAIL.java (similar to MathSubstitutionsX86) which contains substitutions for methods of the java.lang.Math class.
>>> 
>>> I currently just have a substitution for Math.sqrt( ), but I  could list substitutions here for other java.lang.Math routines that aren't in MathSubstitutionsX86.
>>> 
>>> 3)      Define a MathIntrinsicHSAILNode (under com.oracle.graal.replacements.hsail) which is similar to the MathIntrinsicNode but defines the operations that will be treated as intrinsics in the HSAIL backend.
>>> 
>>> a.       The substitutions in MathSubsitutionsHSAIL.java will call the MathIntrinsicHSAILNode.compute( ) routine for the math operations we are interested in intrinsifying.
>>> 
>>> 4)      Define a ReplacementsProvider called GraalHSAILMethodSubstitutions.java under com.oracle.graal.replacements.hsail/ . Implement the registerReplacements method( ) to register specific replacements with the compiler. My version of registerReplacements() just calls replacements.registerSubstitutions(MathSubstitutionsHSAIL.class).
>>> 
>>> 5)      Override HSAILHotspotBackend.completeInitialization( ) to call ReplacementsProvider.registerReplacements( ) similar to the way it's being done in the host backend, so that the substitutions I have defined get registered in the compiler.
>>> 
>>> Some questions:
>>> 
>>> 
>>> a)      The part that's fuzzy to me is step 5). VMToCompilerImpl.startCompiler() is calling completeInitialization( ) for the host backend (x86) and for each of the GPU target backends (including HSAIL). The completeInitialization( ) routine in the host backend is calling ReplacementsProvider.registerReplacements() to register all the x86 replacements. Am I supposed to override HSAILHotSpotBackend.completeInitialization( ) to do something similar so that the HSAIL substitutions get registered? Can you explain this process a bit? I'm not clear on who is supposed to call ReplacementsProvider.registerReplacements() to register my intrinsics.
>> 
>> You need to do the registration yourself in HSAILHotspotBackend.completeInitialization(). However, you should not use the ServiceLoader mechanism that HotSpotHostBackend does. This means you don’t need a ReplacementsProvider (such as GraalHSAILMethodSubstitutions) at all. GPU-specific replacements should be explicitly registered with something like:
>> 
>> try (Scope s = Debug.scope("RegisterReplacements", new DebugDumpScope("RegisterReplacements"))) {
>>   Replacements replacements = providers.getReplacements();
>>   replacements.registerSubstitutions(MathSubstitutionsHSAIL.class)
> 
> General question:  why is the architecture name at the end of the class name?  All others have the architecture name in the front.  And why is it x86 for AMD64?

Good point. The above class should definitely be named HSAILMathSubstitutions.

With respect to MathSubstitutionsX86, this class needs some attention in any case given that it includes substitutions that may be supported on more than just x86/x64. For example, I see that SPARCMathIntrinsicOp support sqrt. In general, I think the class should be renamed to drop the X86 suffix and CPU specific subclasses of HotSpotReplacementsImpl should be created to filter the defined substitutions as applicable.

-Doug


More information about the graal-dev mailing list