Neural Network/Brain/node_modules/gpu.js/src/gpu.js
/**
   * Choose kernel type and save on .Kernel property of GPU
   */
Choose kernel type and save on .Kernel property of GPU
Choose kernel type and save on . Kernel property of GPU
chooseKernel() {
    if (this.Kernel) return;
    let Kernel = null;
    if (this.context) {
      for (let i = 0; i < kernelOrder.length; i++) {
        const ExternalKernel = kernelOrder[i];
        if (ExternalKernel.isContextMatch(this.context)) {
          if (!ExternalKernel.isSupported) {
            throw new Error(`Kernel type ${ExternalKernel.name} not supported`);
          }
          Kernel = ExternalKernel;
          break;
        }
      }
      if (Kernel === null) {
        throw new Error('unknown Context');
      }
    } else if (this.mode) {
      if (this.mode in internalKernels) {
        if (!validate || internalKernels[this.mode].isSupported) {
          Kernel = internalKernels[this.mode];
        }
      } else if (this.mode === 'gpu') {
        for (let i = 0; i < kernelOrder.length; i++) {
          if (kernelOrder[i].isSupported) {
            Kernel = kernelOrder[i];
            break;
          }
        }
      } else if (this.mode === 'cpu') {
        Kernel = CPUKernel;
      }
      if (!Kernel) {
        throw new Error(`A requested mode of "${this.mode}" and is not supported`);
      }
    } else {
      for (let i = 0; i < kernelOrder.length; i++) {
        if (kernelOrder[i].isSupported) {
          Kernel = kernelOrder[i];
          break;
        }
      }
      if (!Kernel) {
        Kernel = CPUKernel;
      }
    }
    if (!this.mode) {
      this.mode = Kernel.mode;
    }
    this.Kernel = Kernel;
  }
chooseKernel ( ) { if ( this . Kernel ) return ; let Kernel = null ; if ( this . context ) { for ( let i = 0 ; i < kernelOrder . length ; i ++ ) { const ExternalKernel = kernelOrder [ i ] ; if ( ExternalKernel . isContextMatch ( this . context ) ) { if ( ! ExternalKernel . isSupported ) { throw new Error ( ` ${ ExternalKernel . name } ` ) ; } Kernel = ExternalKernel ; break ; } } if ( Kernel === null ) { throw new Error ( 'unknown Context' ) ; } } else if ( this . mode ) { if ( this . mode in internalKernels ) { if ( ! validate || internalKernels [ this . mode ] . isSupported ) { Kernel = internalKernels [ this . mode ] ; } } else if ( this . mode === 'gpu' ) { for ( let i = 0 ; i < kernelOrder . length ; i ++ ) { if ( kernelOrder [ i ] . isSupported ) { Kernel = kernelOrder [ i ] ; break ; } } } else if ( this . mode === 'cpu' ) { Kernel = CPUKernel ; } if ( ! Kernel ) { throw new Error ( ` ${ this . mode } ` ) ; } } else { for ( let i = 0 ; i < kernelOrder . length ; i ++ ) { if ( kernelOrder [ i ] . isSupported ) { Kernel = kernelOrder [ i ] ; break ; } } if ( ! Kernel ) { Kernel = CPUKernel ; } } if ( ! this . mode ) { this . mode = Kernel . mode ; } this . Kernel = Kernel ; }
Choose kernel type and save on .Kernel property of GPU
Choose kernel type and save on . Kernel property of GPU