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

webgpu: Support AdapterInfo #6862

Merged
merged 7 commits into from
Sep 30, 2022
Merged

webgpu: Support AdapterInfo #6862

merged 7 commits into from
Sep 30, 2022

Conversation

qjia7
Copy link
Contributor

@qjia7 qjia7 commented Sep 27, 2022

Upgrade webgpu/types
Support sequential access mode
Use sequential mode for intel device

To see the logs from the Cloud Build CI, please join either our discussion or announcement mailing list.


This change is Reviewable

@@ -146,6 +147,7 @@ export class WebGPUBackend extends KernelBackend {
this.currentCommandEncoder = null;
this.currentComputePass = null;
this.supportTimeQuery = device.features.has('timestamp-query');
this.adapterInfo = adapterInfo;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WebGPUBackend is already very crowded. Can we put this and related methods in a standalone class, e.g., adapter?

splitedDimInner = 32): string {
transposeA = false, tileInner = 32, splitK = false, splitedDimInner = 32,
sequentialAccess =
false /**By default, it's interval access in threads */): string {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to move this comment to the earliest place we set this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the place that we introduce the sequentialAccess concept. So I think it's better to put the comments here. Also updated it with more details.

@@ -220,7 +220,7 @@ export function conv2DImpl({

const program = new Conv2DMMProgram(
convInfo, dimAOuter, dimBOuter, dimInner, hasBias, activation,
hasPreluActivationWeights);
hasPreluActivationWeights, backend.isIntel());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to have a variable (e.g., sequentialAccess), and set it explicitly with backend.isIntel(). Some more comments are also needed here about this concept.

@qjia7 qjia7 requested a review from gyagp September 27, 2022 08:58
@@ -270,10 +268,13 @@ const readDataFromSubASnippet = (transposeA: boolean) => {
'let ACached = mm_Asub[tileRow + innerRow][k];';
};

// sequentialAccess means that the adjacent threads are accessing contiguous
// data in memory. By default, it's interval access in threads, which means that
// the access is continuous in one thread, but not in theads.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theads -> threads. Maybe it's better to name it as sequentialAccessByThreads, and change the description as "sequentialAccessByThreads means sequential data in memory is accessed by threads, instead of a single thread (default behavior)".

*/

export class AdapterInfo {
constructor(private adapterInfo: GPUAdapterInfo) {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need some class members here and initialize them with GPUAdapterInfo. I suggest to use vendor and architecture directly.

@@ -50,7 +50,8 @@ if (isWebGPUSupported()) {
deviceDescriptor.requiredFeatures = ['timestamp-query'];
}
const device: GPUDevice = await adapter.requestDevice(deviceDescriptor);
return new WebGPUBackend(device);
const adapterInfo = await adapter.requestAdapterInfo();
return new WebGPUBackend(device, adapterInfo);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Can we only pass adapter to WebGPUBackend?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to allow the user to specify the same device with tfjs to do interop. However, we can't do it if passing adapter to WebGPUBackend.

return false;
}

isGen12GPU(): boolean {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this used? If this is for other feature, we can add this later.
isGen12GPU is a bit too specific. What about Gen13 and future GPU gens?

upgrade webgpu/types
Support sequential access mode
Use sequential mode for intel device
Copy link

@gyagp gyagp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@xhcao xhcao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you.

Copy link
Collaborator

@Linchenn Linchenn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's great to know you are using vendor info to optimize. LGTM, thank you and sorry for the delayed reviewing!

Copy link

@gyagp gyagp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one nit

@@ -0,0 +1,37 @@
/**
* @license
* Copyright 2022 Google LLC. All Rights Reserved.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to #6871 (review), please remove "All Rights Reserved." for the new files.

@qjia7 qjia7 merged commit d94faba into tensorflow:master Sep 30, 2022
@qjia7 qjia7 deleted the adapterInfo branch October 10, 2022 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants