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
2 changes: 2 additions & 0 deletions common/reviews/api/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import vtkImageSlice from '@kitware/vtk.js/Rendering/Core/ImageSlice';
import type { vtkObject } from '@kitware/vtk.js/interfaces';
import vtkPlane from '@kitware/vtk.js/Common/DataModel/Plane';
import type vtkVolume from '@kitware/vtk.js/Rendering/Core/Volume';
import type { GetGPUTier } from 'detect-gpu';

// @public (undocumented)
type Actor = vtkActor;
Expand Down Expand Up @@ -210,6 +211,7 @@ enum ContourType {
// @public (undocumented)
type Cornerstone3DConfig = {
detectGPU: any;
iamiota marked this conversation as resolved.
Show resolved Hide resolved
getGPUTierConfig: GetGPUTier;
rendering: {
preferSizeOverAccuracy: boolean;
useNorm16Texture: boolean;
Expand Down
2 changes: 2 additions & 0 deletions common/reviews/api/streaming-image-volume-loader.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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';
import type vtkVolume from '@kitware/vtk.js/Rendering/Core/Volume';
import type { GetGPUTier } from 'detect-gpu';

// @public (undocumented)
type Actor = vtkActor;
Expand Down Expand Up @@ -103,6 +104,7 @@ enum ContourType {
// @public (undocumented)
type Cornerstone3DConfig = {
detectGPU: any;
getGPUTierConfig: 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
2 changes: 2 additions & 0 deletions common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { vtkImageData } from '@kitware/vtk.js/Common/DataModel/ImageData';
import vtkImageSlice from '@kitware/vtk.js/Rendering/Core/ImageSlice';
import type { vtkPiecewiseFunction } from '@kitware/vtk.js/Common/DataModel/PiecewiseFunction';
import type vtkVolume from '@kitware/vtk.js/Rendering/Core/Volume';
import type { GetGPUTier } from 'detect-gpu';

declare namespace activeSegmentation {
export {
Expand Down Expand Up @@ -925,6 +926,7 @@ function copyPointsList(points: ITouchPoints[]): ITouchPoints[];
// @public (undocumented)
type Cornerstone3DConfig = {
detectGPU: any;
getGPUTierConfig: 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
5 changes: 4 additions & 1 deletion packages/core/src/types/Cornerstone3DConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { TierResult, GetGPUTier } from 'detect-gpu';

type Cornerstone3DConfig = {
detectGPU: any;
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.

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