Substitutions in Graal

Juan Jose Fumero juan.fumero at ed.ac.uk
Fri May 30 09:19:32 UTC 2014


Hi Doug, 
    Ok you are right. It works now. 

Thanks
Juanjo

On Thu, 2014-05-29 at 21:50 +0200, Doug Simon wrote:

> On May 29, 2014, at 5:48 PM, Juan Jose Fumero <juan.fumero at ed.ac.uk> wrote:
> 
> > Hi Doug, 
> >    In our OpenCL backend we created the OCLMath class with basically returns a float and double of Java maths operations. So, instead of using
> > Math.log for example, the user writes OCLMath.log . 
> > 
> > But, in order to be this implementation legal from Java code, OCLMath is actually a wrapper that calls to Math.* methods. 
> > 
> > 
> > public class OCLMath {
> > 
> >     public static float fabs(float a) {
> >         return Math.abs(a);
> >     }
> >   ....
> > 
> > } 
> > 
> > 
> > And then our OCLMathSubstitution 
> > 
> > @ClassSubstitution(com.edinburgh.opencl.math.OCLMath.class)
> > public class OCLMathSubstitutions {
> > 
> >     @MethodSubstitution
> >     public static float fabs(float x) {
> >         return OCLMathIntrinsicNode.compute(x, Operation.FABS);
> >     }
> > ... 
> > 
> > 
> > This approach is quite similar to HSAIL. 
> > 
> > 
> > My register substitution inherits from ReplacementImpl class. 
> > 
> > public class OCLHotSpotReplacementsImpl extends ReplacementsImpl {
> > 
> >     public OCLHotSpotReplacementsImpl(Providers providers, SnippetReflectionProvider snippetReflection, Assumptions assumptions, TargetDescription target) {
> >         super(providers, snippetReflection, assumptions, target);
> >         registerSubstitutions(Math.class, OCLMathSubstitutions.class);
> 
> This above line should be:
> 
>     registerSubstitutions(OCLMath.class, OCLMathSubstitutions.class);
> 
> You want to register substitutions for OCLMath, not Math. If you run with -esa enabled, this assert on ReplacementsImpl.java:322 should fire:
> 
>         assert getOriginalInternalName(substitutionClass).equals(internalName) : getOriginalInternalName(substitutionClass) + " != " + (internalName);
> 
> -Doug
> 
> > On Thu, 2014-05-29 at 15:34 +0200, Doug Simon wrote:
> >> Hi Juan,
> >> 
> >> What’s in OCLMathSubstitutions? Does it override substitutions provide by MathSubstitutionsX86?
> >> 
> >> And where is your call to registerSubstitutions(Math.class, OCLMathSubstitutions.class)?
> >> 
> >> In standard Graal, I don’t think we have a multiple substitutions for a single method so have never thought about which substitution takes precedence in the case of conflicts.
> >> 
> >> -Doug
> >> 
> >> On May 29, 2014, at 11:52 AM, Juan Jose Fumero <
> >> juan.fumero at ed.ac.uk
> >> > wrote:
> >> 
> >> 
> >> > Hi,
> >> > 
> >> > after this merge [1]  with my fork, I had to change the replacements
> >> > from this
> >> > 
> >> > registerSubstitutions(OCLMathSubstitutions.class);
> >> > 
> >> > for this one:
> >> > 
> >> > registerSubstitutions(Math.class, OCLMathSubstitutions.class);
> >> > 
> >> > But, when I apply the replacements and inlining,  the MatIntrinsics is
> >> > still my graph. 
> >> > 
> >> > ...
> >> > 114|MathIntrinsic
> >> > 119|Const(0.31938154)
> >> > 120|Const(-0.35656378)
> >> > 121|Const(1.7814779)
> >> > ...
> >> > 
> >> > I want to substitute MathIntrinsic for OCLMathIntrinsic. 
> >> > With my previous version (merge with Graal 839cb35354e8 [2] ) it works. 
> >> > 
> >> > Any idea?
> >> > 
> >> > Many thanks
> >> > 
> >> > 
> >> > [1] http://hg.openjdk.java.net/graal/graal/rev/5c73b162eec2
> >> > [2] http://hg.openjdk.java.net/graal/graal/rev/839cb35354e8
> >> > 
> >> > The University of Edinburgh is a charitable body, registered in
> >> > Scotland, with registration number SC005336.
> >> 
> >> 
> >> 
> >> 
> > 
> > The University of Edinburgh is a charitable body, registered in
> > Scotland, with registration number SC005336.
> 
> 


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: not available
URL: <http://mail.openjdk.java.net/pipermail/sumatra-dev/attachments/20140530/7398c056/attachment.ksh>


More information about the sumatra-dev mailing list