questions about implementing intrinsics

Venkatachalam, Vasanth Vasanth.Venkatachalam at
Sun Dec 1 09:52:29 PST 2013

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

2)      In the above package, define a class (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 which is similar to the MathIntrinsicNode but defines the operations that will be treated as intrinsics in the HSAIL backend.

a.       The substitutions in will call the MathIntrinsicHSAILNode.compute( ) routine for the math operations we are interested in intrinsifying.

4)      Define a ReplacementsProvider called under . 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.

b)      From looking at VMToCompilerImpl.startCompiler(), it appears that the substitutions used in the host backend (x86) as well as substitutions used in the GPU target backend (HSAIL) will all get registered with the compiler if I take the approach in a) above. How can I ensure that my math intrinsics are the ones that get used instead of the host  backend intrinsics?  In particular, how do I ensure that my intrinsic for Math.sqrt is what gets used (instead of the host backend's version) when I'm generating HSAIL code?


More information about the graal-dev mailing list