| 35 | } |
| 36 | |
| 37 | export class MathBackendCPU extends KernelBackend { |
| 38 | public blockSize = 48; |
| 39 | |
| 40 | data: DataStorage<TensorData<DataType>>; |
| 41 | private firstUse = true; |
| 42 | private static nextDataId = 0; |
| 43 | private nextDataId(): number { |
| 44 | return MathBackendCPU.nextDataId++; |
| 45 | } |
| 46 | |
| 47 | constructor() { |
| 48 | super(); |
| 49 | this.data = new DataStorage(this, engine()); |
| 50 | } |
| 51 | |
| 52 | override write( |
| 53 | values: backend_util.BackendValues, shape: number[], |
| 54 | dtype: DataType): DataId { |
| 55 | if (this.firstUse) { |
| 56 | this.firstUse = false; |
| 57 | if (env().get('IS_NODE')) { |
| 58 | backend_util.warn( |
| 59 | '\n============================\n' + |
| 60 | 'Hi, looks like you are running TensorFlow.js in ' + |
| 61 | 'Node.js. To speed things up dramatically, install our node ' + |
| 62 | 'backend, visit https://github.com/tensorflow/tfjs-node for more details. ' + |
| 63 | '\n============================'); |
| 64 | } |
| 65 | } |
| 66 | const dataId = {id: this.nextDataId()}; |
| 67 | |
| 68 | this.data.set(dataId, {values, dtype, refCount: 1}); |
| 69 | |
| 70 | return dataId; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Create a data bucket in cpu backend. |
| 75 | * @param shape Shape of the `TensorInfo`. |
| 76 | * @param dtype DType of the `TensorInfo`. |
| 77 | * @param values The value of the `TensorInfo` stored as a flattened array. |
| 78 | */ |
| 79 | makeTensorInfo( |
| 80 | shape: number[], dtype: DataType, |
| 81 | values?: backend_util.BackendValues|string[]): TensorInfo { |
| 82 | let outId; |
| 83 | if (dtype === 'string' && values != null && values.length > 0 && |
| 84 | util.isString(values[0])) { |
| 85 | const encodedValues = |
| 86 | (values as unknown as string[]).map(d => util.encodeString(d)); |
| 87 | |
| 88 | outId = this.write(encodedValues, shape, dtype); |
| 89 | } else { |
| 90 | outId = this.write(values as TypedArray, shape, dtype); |
| 91 | } |
| 92 | |
| 93 | return {dataId: outId, shape, dtype}; |
| 94 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…