• Home
    • View
    • Login
    This page
    • Normal
    • Export PDF
    • Page Information

    Loading...
  1. Dashboard
  2. Undefined Space
  3. Sumatra
  4. Experiments with Allocation on Sumatra

Experiments with Allocation on Sumatra

  • Created by Tom Deneau on Apr 14, 2014

Experiments with Allocation on Sumatra

In order to widen the types of lambda expressions that could be offloaded to the GPU, we wanted to be able to handle lambdas that used object allocation.   The following describes some experiments with allocation using the HSAIL Backend to graal.

Note: As is true of many modern compilers, graal can avoid the actual allocation when it can use escape analysis to prove that the allocated objects do not escape.  Here's an example junit test where graal can successfully use escape analysis.

But we also wanted to handle lambdas where allocated objects really did escape.  Here is a simple example where we start with an array of longs and we want to produce an array of Strings, one for each long.

package simplealloc;

import java.util.stream.IntStream;

public class SimpleAlloc {

    public static void main(String[] args) {
        final int length = 20;
        long[] input = new long[length];
        String[] output = new String[length];
Random rand = new Random();

   
        // Initialize the input array - not offloaded
        IntStream.range(0, length).parallel().forEach(p -> {
            input[p] = rand.nextLong();
        });

        // call toString on each input element - this is offloadable
        IntStream.range(0, length).parallel().forEach(p -> {
            output[p] = Long.toString(input[p]);
        });

        // Print results - not offloadable since it is
        // calling native code etc.
        IntStream.range(0, length).forEach(p -> {
            System.out.println(output[p]);
        });
    }
}
 
Overview
Content Tools
ThemeBuilder
  • No labels

Terms of Use
• License: GPLv2
• Privacy • Trademarks • Contact Us

Powered by a free Atlassian Confluence Open Source Project License granted to https://www.atlassian.com/software/views/opensource-community-additional-license-offer. Evaluate Confluence today.

  • Kolekti ThemeBuilder Powered by Atlassian Confluence 8.5.23
  • Kolekti ThemeBuilder printed.by.atlassian.confluence
  • Report a bug
  • Atlassian News
Atlassian
Kolekti ThemeBuilder EngineAtlassian Confluence
{"serverDuration": 181, "requestCorrelationId": "3690a36cd1070cff"}