fn buffer(&self, device: &wgpu::Device, readable: bool) -> Result<Buffer, GpuError> {
        let scalar_type = ScalarType::from_i32(self.get_data_type())?;
        let input_shape = Shape::from(scalar_type, self.get_dims());
        log::info!(
            "creating buffer for tensor {} shape {}",
            self.get_name(),
            input_shape
        );

        match scalar_type {
            ScalarType::F32 => {
                let data = self.get_float_data();
                buffer_with_bytes(
                    device,
                    readable,
                    self.get_name(),
                    if !data.is_empty() {
                        bytemuck::cast_slice(data)
                    } else {
                        self.get_raw_data()
                    },
                )
            }
            ScalarType::I64 => {
                // WGSL doesn't support 64 bit integers, so we load 64 bit tensors as 32 bit ints
                log::warn!("initializers with int64 data type are not supported, converting into int32 initializer");
                let ints: Vec<i32> = self
                    .get_int64_data()
                    .iter()
                    .map(|x| (*x).try_into())
                    .collect::<Result<Vec<i32>, _>>()
                    .map_err(|_e| GpuError::OutOfBoundsError)?;
                let raw_data = bytemuck::cast_slice(&ints);
                buffer_with_bytes(device, readable, self.get_name(), raw_data)
            }
            ScalarType::I32 => {
                let data = self.get_int32_data();
                buffer_with_bytes(
                    device,
                    readable,
                    self.get_name(),
                    if !data.is_empty() {
                        bytemuck::cast_slice(data)
                    } else {
                        self.get_raw_data()
                    },
                )
            }
        }
    }
/// Create a GPU buffer containing the data of this initializer
Create a GPU buffer containing the data of this initializer
Create a GPU buffer containing the data of this initializer
fn buffer(&self, device: &wgpu::Device, readable: bool) -> Result<Buffer, GpuError> {
        let scalar_type = ScalarType::from_i32(self.get_data_type())?;
        let input_shape = Shape::from(scalar_type, self.get_dims());
        log::info!(
            "creating buffer for tensor {} shape {}",
            self.get_name(),
            input_shape
        );
        match scalar_type {
            ScalarType::F32 => {
                let data = self.get_float_data();
                buffer_with_bytes(
                    device,
                    readable,
                    self.get_name(),
                    if !data.is_empty() {
                        bytemuck::cast_slice(data)
                    } else {
                        self.get_raw_data()
                    },
                )
            }
            ScalarType::I64 => {
                // WGSL doesn't support 64 bit integers, so we load 64 bit tensors as 32 bit ints
                log::warn!("initializers with int64 data type are not supported, converting into int32 initializer");
                let ints: Vec<i32> = self
                    .get_int64_data()
                    .iter()
                    .map(|x| (*x).try_into())
                    .collect::<Result<Vec<i32>, _>>()
                    .map_err(|_e| GpuError::OutOfBoundsError)?;
                let raw_data = bytemuck::cast_slice(&ints);
                buffer_with_bytes(device, readable, self.get_name(), raw_data)
            }
            ScalarType::I32 => {
                let data = self.get_int32_data();
                buffer_with_bytes(
                    device,
                    readable,
                    self.get_name(),
                    if !data.is_empty() {
                        bytemuck::cast_slice(data)
                    } else {
                        self.get_raw_data()
                    },
                )
            }
        }
    }
fn buffer ( & self , device : & wgpu :: Device , readable : bool ) -> Result < Buffer , GpuError > { let scalar_type = ScalarType :: from_i32 ( self . get_data_type ( ) ) ? ; let input_shape = Shape :: from ( scalar_type , self . get_dims ( ) ) ; log :: info ! ( " " self get_name ( ) input_shape ) ; match scalar_type { ScalarType :: F32 => { let data = self . get_float_data ( ) ; buffer_with_bytes ( device , readable , self . get_name ( ) , if ! data . is_empty ( ) { bytemuck :: cast_slice ( data ) } else { self . get_raw_data ( ) } , ) } ScalarType :: I64 => { // WGSL doesn't support 64 bit integers, so we load 64 bit tensors as 32 bit ints log :: warn ! ( " " ) ; let ints : Vec < i32 > = self . get_int64_data ( ) . iter ( ) . map ( | x | ( * x ) . try_into ( ) ) . collect :: < Result < Vec < i32 > , _ > > ( ) . map_err ( | _e | GpuError :: OutOfBoundsError ) ? ; let raw_data = bytemuck :: cast_slice ( & ints ) ; buffer_with_bytes ( device , readable , self . get_name ( ) , raw_data ) } ScalarType :: I32 => { let data = self . get_int32_data ( ) ; buffer_with_bytes ( device , readable , self . get_name ( ) , if ! data . is_empty ( ) { bytemuck :: cast_slice ( data ) } else { self . get_raw_data ( ) } , ) } } }
Create a GPU buffer containing the data of this initializer
Create a GPU buffer containing the data of this initializer
&self
device
&wgpu::Device
readable
bool
&self
device
&wgpu::Device
readable
bool