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

Add config for getGPUTier method in cornerstone.init #633

Merged
merged 9 commits into from
Jul 4, 2023
5 changes: 4 additions & 1 deletion common/reviews/api/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

```ts

import type { GetGPUTier } from 'detect-gpu';
import { mat4 } from 'gl-matrix';
import type { TierResult } from 'detect-gpu';
import { vec3 } from 'gl-matrix';
import type vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
import type { vtkCamera } from '@kitware/vtk.js/Rendering/Core/Camera';
Expand Down Expand Up @@ -209,7 +211,8 @@ enum ContourType {

// @public (undocumented)
type Cornerstone3DConfig = {
detectGPU: any;
gpuTier?: TierResult;
detectGPUConfig: GetGPUTier;
rendering: {
preferSizeOverAccuracy: boolean;
useNorm16Texture: boolean;
Expand Down
5 changes: 4 additions & 1 deletion common/reviews/api/streaming-image-volume-loader.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
```ts

import { default as default_2 } from 'packages/core/dist/esm/enums/RequestType';
import type { GetGPUTier } from 'detect-gpu';
import type { mat4 } from 'gl-matrix';
import type { TierResult } from 'detect-gpu';
import type vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
import type { vtkImageData } from '@kitware/vtk.js/Common/DataModel/ImageData';
import vtkImageSlice from '@kitware/vtk.js/Rendering/Core/ImageSlice';
Expand Down Expand Up @@ -102,7 +104,8 @@ enum ContourType {

// @public (undocumented)
type Cornerstone3DConfig = {
detectGPU: any;
gpuTier?: TierResult;
detectGPUConfig: GetGPUTier;
rendering: {
// vtk.js supports 8bit integer textures and 32bit float textures.
// However, if the client has norm16 textures (it can be seen by visiting
Expand Down
5 changes: 4 additions & 1 deletion common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

```ts

import type { GetGPUTier } from 'detect-gpu';
import type { mat4 } from 'gl-matrix';
import type { TierResult } from 'detect-gpu';
import type vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
import type { vtkColorTransferFunction } from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction';
import type { vtkImageData } from '@kitware/vtk.js/Common/DataModel/ImageData';
Expand Down Expand Up @@ -924,7 +926,8 @@ function copyPointsList(points: ITouchPoints[]): ITouchPoints[];

// @public (undocumented)
type Cornerstone3DConfig = {
detectGPU: any;
gpuTier?: TierResult;
detectGPUConfig: GetGPUTier;
rendering: {
// vtk.js supports 8bit integer textures and 32bit float textures.
// However, if the client has norm16 textures (it can be seen by visiting
Expand Down
20 changes: 11 additions & 9 deletions packages/core/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { deepMerge } from './utilities';
import { Cornerstone3DConfig } from './types';
// TODO: move sharedArrayBuffer into config.
// TODO: change config into a class with methods to better control get/set
const defaultConfig = {
detectGPU: {},
const defaultConfig: Cornerstone3DConfig = {
gpuTier: undefined,
detectGPUConfig: {},
rendering: {
useCPURendering: false,
// GPU rendering options
Expand All @@ -21,8 +22,9 @@ const defaultConfig = {
// ...
};

let config = {
detectGPU: {},
let config: Cornerstone3DConfig = {
gpuTier: undefined,
detectGPUConfig: {},
rendering: {
useCPURendering: false,
// GPU rendering options
Expand Down Expand Up @@ -106,19 +108,19 @@ async function init(configuration = {}): Promise<boolean> {
// merge configs
config = deepMerge(defaultConfig, configuration);

// detectGPU
// gpuTier
const hasWebGLContext = _hasActiveWebGLContext();
if (!hasWebGLContext) {
console.log('CornerstoneRender: GPU not detected, using CPU rendering');
config.rendering.useCPURendering = true;
} else {
const gpuTier = await getGPUTier();
config.detectGPU = gpuTier;
config.gpuTier =
config.gpuTier || (await getGPUTier(config.detectGPUConfig));
console.log(
'CornerstoneRender: Using detect-gpu to get the GPU benchmark:',
gpuTier
config.gpuTier
);
if (gpuTier.tier < 1) {
if (config.gpuTier.tier < 1) {
console.log(
'CornerstoneRender: GPU is not powerful enough, using CPU rendering'
);
Expand Down
17 changes: 16 additions & 1 deletion packages/core/src/types/Cornerstone3DConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import type { TierResult, GetGPUTier } from 'detect-gpu';

type Cornerstone3DConfig = {
detectGPU: any;
/**
* It is used to store the device information,
* we use it if provided if not a network call is performed.
* Its type is the `TierResult` in the `detect-gpu` library.
* https://github.com/pmndrs/detect-gpu/blob/master/src/index.ts#L82
*/
gpuTier?: TierResult;
Copy link
Member

Choose a reason for hiding this comment

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

can you please add some documentation here for these two properties?

for gpuTier, that we use it if provided if not a network call is performed

more important one is the detectGPUConfig with some reference to the detect-gpu repo of what confis are available

Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course, it has already been added.

/**
* When the `gpuTier` is not provided, the `detectGPUConfig` is passed as
* an argument to the `getGPUTier` method.
* Its type is the `GetGPUTier` in the `detect-gpu` library.
* https://github.com/pmndrs/detect-gpu/blob/master/src/index.ts#L20
*/
detectGPUConfig: GetGPUTier;
rendering: {
// vtk.js supports 8bit integer textures and 32bit float textures.
// However, if the client has norm16 textures (it can be seen by visiting
Expand Down