Skip to content
This repository has been archived by the owner on Aug 15, 2019. It is now read-only.

Add ndarray.getValuesAsync() method which returns a promise that resolves when values are ready. #146

Merged
merged 9 commits into from
Sep 23, 2017

Conversation

nsthorat
Copy link
Contributor

@nsthorat nsthorat commented Sep 22, 2017

This implementation will poll the GPU for the availability of the disjoint query object as if we were benchmarking. The cost of polling is negligible, so we can use a setTimeout(fn, 0) to check.

I also removed the exponential backoff in the benchmarks, we can just poll as fast as possible since it's pretty cheap.

When the extension isn't enabled, we just call getValues and resolve immediately.

This change also allows flags to depend on each other, and values get cached so we don't have to construct lots of canvases when evaluating flags.

This change is Reviewable

@nsthorat nsthorat changed the title Add getValuesAsync Add ndarray.getValuesAsync() method which returns a promise that resolves when values are ready. Sep 22, 2017
@dsmilkov
Copy link
Contributor

:lgtm_strong: Just few tiny comments. Great work!


Reviewed 14 of 14 files at r1.
Review status: all files reviewed at latest revision, 7 unresolved discussions.


src/environment.ts, line 27 at r1 (raw file):

export interface Features {
  'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_ENABLED'?: boolean;

Add short one liner comment on top of each feature explaining what each feature means (e.g. want to understand the diff between the two query time extensions)


src/environment_test.ts, line 42 at r1 (raw file):

                return {loseContext: () => {}};
              }
              console.log('returning null');

remove console.log


src/util.ts, line 226 at r1 (raw file):

(counter: number) => 0

this looks strange, shouldn't it be (counter: number) => number ?


src/util.ts, line 227 at r1 (raw file):

export function repeatedTry(
    checkFn: () => boolean, delayFn = (counter: number) => 0,
    maxCounter?: number) {

re-add the return type of repeatedTry()


src/math/webgl/gpgpu_context.ts, line 266 at r1 (raw file):

   * the command buffer has finished executing the query.
   * @param queryFn The query function containing GL commands to execute.
   * @return a promise that resolves with the ellapsed time.

s/ellapsed time/ellapsed time in ms/


src/math/webgl/gpgpu_context.ts, line 311 at r1 (raw file):

                .getQueryParameter(query, (this.gl as any).QUERY_RESULT);
        // Return milliseconds.
        resolve(timeElapsedMicros / 1000000);

same here: 1ms = 1000 micro seconds. Why divide by 1 million?


src/math/webgl/gpgpu_context.ts, line 349 at r1 (raw file):

timeElapsedMicros / 1000000

1 ms = 1000 micro seconds. Divide by 1000 instead of 1 million ?


Comments from Reviewable

@nsthorat
Copy link
Contributor Author

Thanks! Fixed your comments. It's so nice to have a thorough reviewer :)


Review status: 9 of 14 files reviewed at latest revision, 7 unresolved discussions, some commit checks pending.


src/environment.ts, line 27 at r1 (raw file):

Previously, dsmilkov (Daniel Smilkov) wrote…

Add short one liner comment on top of each feature explaining what each feature means (e.g. want to understand the diff between the two query time extensions)

Done.


src/environment_test.ts, line 42 at r1 (raw file):

Previously, dsmilkov (Daniel Smilkov) wrote…

remove console.log

Done.


src/util.ts, line 226 at r1 (raw file):

Previously, dsmilkov (Daniel Smilkov) wrote…

(counter: number) => 0

this looks strange, shouldn't it be (counter: number) => number ?

Ah it's not a type here. This argument is a function that maps the step counter to the timeout (so you could do exponential backoff). Here, we always return 0 so we have a setTimeout(fn, 0) loop


src/util.ts, line 227 at r1 (raw file):

Previously, dsmilkov (Daniel Smilkov) wrote…

re-add the return type of repeatedTry()

Done.


src/math/webgl/gpgpu_context.ts, line 266 at r1 (raw file):

Previously, dsmilkov (Daniel Smilkov) wrote…

s/ellapsed time/ellapsed time in ms/

Done.


src/math/webgl/gpgpu_context.ts, line 311 at r1 (raw file):

Previously, dsmilkov (Daniel Smilkov) wrote…

same here: 1ms = 1000 micro seconds. Why divide by 1 million?

Done.


src/math/webgl/gpgpu_context.ts, line 349 at r1 (raw file):

Previously, dsmilkov (Daniel Smilkov) wrote…

timeElapsedMicros / 1000000

1 ms = 1000 micro seconds. Divide by 1000 instead of 1 million ?

Renamed it, it's actually nanoseconds :)


Comments from Reviewable

@nsthorat nsthorat merged commit 78431ed into master Sep 23, 2017
@nsthorat nsthorat deleted the async-values branch September 23, 2017 15:02
mnottheone pushed a commit to mnottheone/deeplearnjs that referenced this pull request Dec 1, 2018
…lves when values are ready. (tensorflow#146)

* async values

* merge

* fix unit tests

* remove loop demo

* remove line from ndarray.ts

* throw when lose context not supported

* WEBGL_lose_context

* respond to comments
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants