Giter Club home page Giter Club logo

Comments (7)

fuzzie360 avatar fuzzie360 commented on May 12, 2024

Global variables in the kernel? Every variable is already a global variable in the kernel.

Or do you mean captured variables? That would be tricky, but there should be no issues regarding performance.

from gpu.js.

sawman avatar sawman commented on May 12, 2024

Oh sorry, i meant captured variables. E,g,

var a = 1;

function b() {
return a + 1;
}

gpu.makeKernel(
var main = func() {
a = a + 1;
b();
}
}

i capture a in both b and main. How?

from gpu.js.

fuzzie360 avatar fuzzie360 commented on May 12, 2024

I can see how this can be implemented but I'm not sure if you're going to like what I'm going to say.

  1. We can prefix all compiler functions and variables with "___" and reserve that namespace for ourselves. This is to protect the compiler from step 2.
  2. When you reach a dangling variable like "a" inside the compiler, perform var x = eval("a;") inside the compiler to retrieve "a" from the environment and output the variable into the code. This goes the same for functions, gpu.addFunction( eval("myFunc") )...

The variable "a" is going to be a snapshot at the time of compilation and is readonly. Writeback is practically impossible in shaders as it is possible to only write to one texture target (the return value) unless you want to do multiple passes with recalculations.

Thoughts?

from gpu.js.

PicoCreator avatar PicoCreator commented on May 12, 2024

I think the existing constants implementations workflow for GPU would make more sense?

Global modifiable variable as fuzz say is impossible however.

from gpu.js.

robertleeplummerjr avatar robertleeplummerjr commented on May 12, 2024

This is now handled via:

var kernel = gpu.createKernel(function() {
  return mySpecialNumber;
}, { constants: { mySpecialNumber: 100 } });

from gpu.js.

LunarLanding avatar LunarLanding commented on May 12, 2024

As it stands, there is no capture of variables.: functions need to be added manually, same as any global variables we want captured. Worse, to access a global variable one must use the "this.constants' prefix, so the function cannot be tested outside the kernel.
I think the bullet #2 in @fuzzie360 proposed is the most useful.
My use case is an Observable notebook where each parameter is defined by a cell.
When they are changed, the cells defining the kernels are re-run, and the new value would be captured.
The case against this is that changing it will make global variables captured once implicit (and harder to see).

2. When you reach a dangling variable like "a" inside the compiler, perform var x = eval("a;") inside the compiler to retrieve "a" from the environment and output the variable into the code. This goes the same for functions, gpu.addFunction( eval("myFunc") )...

from gpu.js.

robertleeplummerjr avatar robertleeplummerjr commented on May 12, 2024

Worse, to access a global variable one must use the "this.constants' prefix, so the function cannot be tested outside the kernel.

I can only reply with what was stated:

Global modifiable variable as fuzz say is impossible however.

Do you have a proof of concept that you'd like to propose?

from gpu.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.