Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randomness #550

Open
MaardinK522 opened this issue Sep 6, 2024 · 8 comments
Open

Randomness #550

MaardinK522 opened this issue Sep 6, 2024 · 8 comments
Assignees
Labels
API bug Something isn't working question Further information is requested

Comments

@MaardinK522
Copy link

Hello, Juan Fumero.
I am really excited to complete my custom implementation of a JNeuralNetwork from scratch on my NVidia 1050Ti GPU. But, In the implementation I needed an object of random number generator class. Is there any way I can implement randomness into my code?
Or Should I just go sequentially on my GPU?
I hope I am able to explain you my request.
And again Thank you very much for releasing TornadoVM build scripts.

@jjfumero jjfumero added API question Further information is requested labels Sep 6, 2024
@jjfumero
Copy link
Member

jjfumero commented Sep 6, 2024

Hi @MaardinK522 . Thanks for your interest. This is a topic I personally would like to explore but unfortunately, no immediate plans.

So, to answer your question, TornadoVM does not have any utility for random number generators, but we have examples that can help, for instance the Montecarlo-based for pseudo random number genenerator:

https://github.com/beehive-lab/TornadoVM/blob/master/tornado-examples/src/main/java/uk/ac/manchester/tornado/examples/compute/MonteCarlo.java#L41-L64
Hope this helps.

Also, as feedback for us (TornadoVM team), is there anything specific you would like to see?

@MaardinK522
Copy link
Author

Yes.
Every time I am executing something it says:
[Bailout] Running the sequential implementation. Enable --debug to see the reason.
I don't how to fix it?

@jjfumero
Copy link
Member

jjfumero commented Sep 6, 2024

This means that the code gen failed. Which code are you running? Is it possible to share a test-case that breaks?

You can use the --debug and --fullDebug to see the cause.

@MaardinK522
Copy link
Author

MaardinK522 commented Sep 6, 2024

`public class Demo {
    public static void main(String[] args) {
        // TornadoVM version: 1.0.7
        Matrix2DDouble matrix1 = new Matrix2DDouble(5, 5);
        Matrix2DDouble matrix2 = new Matrix2DDouble(5, 5);
        Matrix2DDouble matrix3 = new Matrix2DDouble(5, 5);

        TornadoAPIProvider.loadScheduleRuntime("s0");
        var device = TornadoExecutionPlan.getDevice(0, 0);
        System.out.println(device);

        TaskGraph taskGraph = new TaskGraph("Testing")
                .transferToDevice(DataTransferMode.FIRST_EXECUTION, matrix1, matrix2)
                .task("", MatrixOperationSolver::fill, 1.0, matrix1, matrix2, matrix3)
                .task("addition", MatrixOperationSolver::solveAddition, matrix1, matrix2, matrix3)
                .transferToDevice(DataTransferMode.EVERY_EXECUTION, matrix1);
        ImmutableTaskGraph immutableTaskGraph = taskGraph.snapshot();
        try (TornadoExecutionPlan plan = new TornadoExecutionPlan(immutableTaskGraph)) {
            plan.withDevice(device).withProfiler(ProfilerMode.CONSOLE).execute();
        } catch (TornadoExecutionPlanException e) {
            throw new RuntimeException(e);
        }
        System.out.println(matrix3);
    }
}
public class MatrixOperationSolver{
   public static void solveAddition(Matrix2DDouble matrix1, Matrix2DDouble matrix2, Matrix2DDouble result) {
        if (matrix1.getNumRows() != matrix2.getNumRows() && matrix2.getNumColumns() != matrix2.getNumColumns())
            return;
        for (@Parallel int i = 0; i < result.getNumRows(); i++)
            for (@Parallel int j = 0; j < result.getNumColumns(); j++)
                result.set(i, j, matrix1.get(i, j) + matrix2.get(i, j));
    }
}
`

Here is the code I am trying to execute.

@jjfumero
Copy link
Member

jjfumero commented Sep 6, 2024

I suspect the error in the codegen is related to the if condition within the solveAddition method, since it is before a parallel region. This is clearly a bug in TornadoVM. As a work-around, I would remove the if and do the checks on the host side (on the CPU) before invoking TornadoVM.

public class MatrixOperationSolver{
   public static void solveAddition(Matrix2DDouble matrix1, Matrix2DDouble matrix2, Matrix2DDouble result) {
        for (@Parallel int i = 0; i < result.getNumRows(); i++) {
            for (@Parallel int j = 0; j < result.getNumColumns(); j++) {
                result.set(i, j, matrix1.get(i, j) + matrix2.get(i, j));
            }
        }
   }
}

@jjfumero jjfumero added the bug Something isn't working label Sep 6, 2024
@jjfumero
Copy link
Member

jjfumero commented Sep 6, 2024

We will look into this bug.

@jjfumero jjfumero assigned mairooni and unassigned gigiblender Sep 9, 2024
@jjfumero
Copy link
Member

jjfumero commented Sep 9, 2024

@mairooni is taking a look to this issue

@mairooni
Copy link
Collaborator

mairooni commented Sep 9, 2024

Hi @MaardinK522, could you also provide the code of the function MatrixOperationSolver::fill?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API bug Something isn't working question Further information is requested
Projects
Status: No status
Development

No branches or pull requests

4 participants