Skip to content

Commit

Permalink
Fix some more minor issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuliu committed Mar 13, 2024
1 parent 21ee122 commit 5b35c6d
Showing 1 changed file with 59 additions and 29 deletions.
88 changes: 59 additions & 29 deletions nnc/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3206,14 +3206,12 @@ private let q4pDecodeJitWithExternalOnDemand:
data, dataSize, dataType, dimensions, dimensionCount, identifier, context, params,
tensorOut, decoded, decodedSize)
}
assert((identifier & 0x1000_0000) != 0)
let identifier = identifier & 0x0fff_ffff
let blockSize = Int(data.load(as: UInt32.self))
let offset = Int((data + MemoryLayout<UInt64>.size).load(as: UInt64.self))
let length = Int((data + MemoryLayout<UInt64>.size * 2).load(as: UInt64.self))
let store = Unmanaged<DynamicGraph._Store>.fromOpaque(context!).takeUnretainedValue()
let mappedData = store.loadBytes(offset: offset, length: length)
defer {
store.offloadBytes(mappedData, length: length)
}
var numberOfElements = Int(dimensions[0])
for i in 1..<Int(dimensionCount) {
numberOfElements *= Int(dimensions[i])
Expand All @@ -3222,15 +3220,23 @@ private let q4pDecodeJitWithExternalOnDemand:
TensorShape(dims: params.dim).reduce(1, *) == numberOfElements
&& (numberOfElements % blockSize) == 0
else {
let mappedData = store.loadBytes(offset: offset, length: length)
defer {
store.offloadBytes(mappedData, length: length)
}
return q4pDecodeJit(
blockSize: blockSize, mappedData, length, dataType, dimensions, dimensionCount, identifier,
context, params, tensorOut, decoded, decodedSize)
}
let palettizeParams = ccv_nnc_tensor_palettize(params, 4, Int32(blockSize))
let decodedDataSize = ccv_nnc_tensor_data_size_without_padding(palettizeParams)
guard
dataSize >= decodedDataSize && decodedSize[0] >= decodedDataSize
length >= decodedDataSize && decodedSize[0] >= decodedDataSize
else {
let mappedData = store.loadBytes(offset: offset, length: length)
defer {
store.offloadBytes(mappedData, length: length)
}
return q4pDecodeJit(
blockSize: blockSize, mappedData, length, dataType, dimensions, dimensionCount, identifier,
context, params, tensorOut, decoded, decodedSize)
Expand Down Expand Up @@ -3259,14 +3265,12 @@ private let q5pDecodeJitWithExternalOnDemand:
data, dataSize, dataType, dimensions, dimensionCount, identifier, context, params,
tensorOut, decoded, decodedSize)
}
assert((identifier & 0x1000_0000) != 0)
let identifier = identifier & 0x0fff_ffff
let blockSize = Int(data.load(as: UInt32.self))
let offset = Int((data + MemoryLayout<UInt64>.size).load(as: UInt64.self))
let length = Int((data + MemoryLayout<UInt64>.size * 2).load(as: UInt64.self))
let store = Unmanaged<DynamicGraph._Store>.fromOpaque(context!).takeUnretainedValue()
let mappedData = store.loadBytes(offset: offset, length: length)
defer {
store.offloadBytes(mappedData, length: length)
}
var numberOfElements = Int(dimensions[0])
for i in 1..<Int(dimensionCount) {
numberOfElements *= Int(dimensions[i])
Expand All @@ -3275,15 +3279,23 @@ private let q5pDecodeJitWithExternalOnDemand:
TensorShape(dims: params.dim).reduce(1, *) == numberOfElements
&& (numberOfElements % blockSize) == 0
else {
let mappedData = store.loadBytes(offset: offset, length: length)
defer {
store.offloadBytes(mappedData, length: length)
}
return q5pDecodeJit(
blockSize: blockSize, mappedData, length, dataType, dimensions, dimensionCount, identifier,
context, params, tensorOut, decoded, decodedSize)
}
let palettizeParams = ccv_nnc_tensor_palettize(params, 4, Int32(blockSize))
let decodedDataSize = ccv_nnc_tensor_data_size_without_padding(palettizeParams)
guard
dataSize >= decodedDataSize && decodedSize[0] >= decodedDataSize
length >= decodedDataSize && decodedSize[0] >= decodedDataSize
else {
let mappedData = store.loadBytes(offset: offset, length: length)
defer {
store.offloadBytes(mappedData, length: length)
}
return q5pDecodeJit(
blockSize: blockSize, mappedData, length, dataType, dimensions, dimensionCount, identifier,
context, params, tensorOut, decoded, decodedSize)
Expand Down Expand Up @@ -3312,14 +3324,12 @@ private let q6pDecodeJitWithExternalOnDemand:
data, dataSize, dataType, dimensions, dimensionCount, identifier, context, params,
tensorOut, decoded, decodedSize)
}
assert((identifier & 0x1000_0000) != 0)
let identifier = identifier & 0x0fff_ffff
let blockSize = Int(data.load(as: UInt32.self))
let offset = Int((data + MemoryLayout<UInt64>.size).load(as: UInt64.self))
let length = Int((data + MemoryLayout<UInt64>.size * 2).load(as: UInt64.self))
let store = Unmanaged<DynamicGraph._Store>.fromOpaque(context!).takeUnretainedValue()
let mappedData = store.loadBytes(offset: offset, length: length)
defer {
store.offloadBytes(mappedData, length: length)
}
var numberOfElements = Int(dimensions[0])
for i in 1..<Int(dimensionCount) {
numberOfElements *= Int(dimensions[i])
Expand All @@ -3328,15 +3338,23 @@ private let q6pDecodeJitWithExternalOnDemand:
TensorShape(dims: params.dim).reduce(1, *) == numberOfElements
&& (numberOfElements % blockSize) == 0
else {
let mappedData = store.loadBytes(offset: offset, length: length)
defer {
store.offloadBytes(mappedData, length: length)
}
return q6pDecodeJit(
blockSize: blockSize, mappedData, length, dataType, dimensions, dimensionCount, identifier,
context, params, tensorOut, decoded, decodedSize)
}
let palettizeParams = ccv_nnc_tensor_palettize(params, 4, Int32(blockSize))
let decodedDataSize = ccv_nnc_tensor_data_size_without_padding(palettizeParams)
guard
dataSize >= decodedDataSize && decodedSize[0] >= decodedDataSize
length >= decodedDataSize && decodedSize[0] >= decodedDataSize
else {
let mappedData = store.loadBytes(offset: offset, length: length)
defer {
store.offloadBytes(mappedData, length: length)
}
return q6pDecodeJit(
blockSize: blockSize, mappedData, length, dataType, dimensions, dimensionCount, identifier,
context, params, tensorOut, decoded, decodedSize)
Expand Down Expand Up @@ -3365,14 +3383,12 @@ private let q7pDecodeJitWithExternalOnDemand:
data, dataSize, dataType, dimensions, dimensionCount, identifier, context, params,
tensorOut, decoded, decodedSize)
}
assert((identifier & 0x1000_0000) != 0)
let identifier = identifier & 0x0fff_ffff
let blockSize = Int(data.load(as: UInt32.self))
let offset = Int((data + MemoryLayout<UInt64>.size).load(as: UInt64.self))
let length = Int((data + MemoryLayout<UInt64>.size * 2).load(as: UInt64.self))
let store = Unmanaged<DynamicGraph._Store>.fromOpaque(context!).takeUnretainedValue()
let mappedData = store.loadBytes(offset: offset, length: length)
defer {
store.offloadBytes(mappedData, length: length)
}
var numberOfElements = Int(dimensions[0])
for i in 1..<Int(dimensionCount) {
numberOfElements *= Int(dimensions[i])
Expand All @@ -3381,15 +3397,23 @@ private let q7pDecodeJitWithExternalOnDemand:
TensorShape(dims: params.dim).reduce(1, *) == numberOfElements
&& (numberOfElements % blockSize) == 0
else {
let mappedData = store.loadBytes(offset: offset, length: length)
defer {
store.offloadBytes(mappedData, length: length)
}
return q7pDecodeJit(
blockSize: blockSize, mappedData, length, dataType, dimensions, dimensionCount, identifier,
context, params, tensorOut, decoded, decodedSize)
}
let palettizeParams = ccv_nnc_tensor_palettize(params, 4, Int32(blockSize))
let decodedDataSize = ccv_nnc_tensor_data_size_without_padding(palettizeParams)
guard
dataSize >= decodedDataSize && decodedSize[0] >= decodedDataSize
length >= decodedDataSize && decodedSize[0] >= decodedDataSize
else {
let mappedData = store.loadBytes(offset: offset, length: length)
defer {
store.offloadBytes(mappedData, length: length)
}
return q7pDecodeJit(
blockSize: blockSize, mappedData, length, dataType, dimensions, dimensionCount, identifier,
context, params, tensorOut, decoded, decodedSize)
Expand Down Expand Up @@ -3418,14 +3442,12 @@ private let q8pDecodeJitWithExternalOnDemand:
data, dataSize, dataType, dimensions, dimensionCount, identifier, context, params,
tensorOut, decoded, decodedSize)
}
assert((identifier & 0x1000_0000) != 0)
let identifier = identifier & 0x0fff_ffff
let blockSize = Int(data.load(as: UInt32.self))
let offset = Int((data + MemoryLayout<UInt64>.size).load(as: UInt64.self))
let length = Int((data + MemoryLayout<UInt64>.size * 2).load(as: UInt64.self))
let store = Unmanaged<DynamicGraph._Store>.fromOpaque(context!).takeUnretainedValue()
let mappedData = store.loadBytes(offset: offset, length: length)
defer {
store.offloadBytes(mappedData, length: length)
}
var numberOfElements = Int(dimensions[0])
for i in 1..<Int(dimensionCount) {
numberOfElements *= Int(dimensions[i])
Expand All @@ -3434,15 +3456,23 @@ private let q8pDecodeJitWithExternalOnDemand:
TensorShape(dims: params.dim).reduce(1, *) == numberOfElements
&& (numberOfElements % blockSize) == 0
else {
let mappedData = store.loadBytes(offset: offset, length: length)
defer {
store.offloadBytes(mappedData, length: length)
}
return q8pDecodeJit(
blockSize: blockSize, mappedData, length, dataType, dimensions, dimensionCount, identifier,
context, params, tensorOut, decoded, decodedSize)
}
let palettizeParams = ccv_nnc_tensor_palettize(params, 4, Int32(blockSize))
let decodedDataSize = ccv_nnc_tensor_data_size_without_padding(palettizeParams)
guard
dataSize >= decodedDataSize && decodedSize[0] >= decodedDataSize
length >= decodedDataSize && decodedSize[0] >= decodedDataSize
else {
let mappedData = store.loadBytes(offset: offset, length: length)
defer {
store.offloadBytes(mappedData, length: length)
}
return q8pDecodeJit(
blockSize: blockSize, mappedData, length, dataType, dimensions, dimensionCount, identifier,
context, params, tensorOut, decoded, decodedSize)
Expand Down Expand Up @@ -3508,19 +3538,19 @@ private let uDecodeJitWithExternalOnDemand:
data, dataSize, dataType, dimensions, dimensionCount, identifier, context, params,
tensorOut, decoded, decodedSize)
case 0x8a1e5b:
return q5pDecodeJitWithExternalStore(
return q5pDecodeJitWithExternalOnDemand(
data, dataSize, dataType, dimensions, dimensionCount, identifier, context, params,
tensorOut, decoded, decodedSize)
case 0x8a1e6b:
return q6pDecodeJitWithExternalStore(
return q6pDecodeJitWithExternalOnDemand(
data, dataSize, dataType, dimensions, dimensionCount, identifier, context, params,
tensorOut, decoded, decodedSize)
case 0x8a1e7b:
return q7pDecodeJitWithExternalStore(
return q7pDecodeJitWithExternalOnDemand(
data, dataSize, dataType, dimensions, dimensionCount, identifier, context, params,
tensorOut, decoded, decodedSize)
case 0x8a1e8b:
return q8pDecodeJitWithExternalStore(
return q8pDecodeJitWithExternalOnDemand(
data, dataSize, dataType, dimensions, dimensionCount, identifier, context, params,
tensorOut, decoded, decodedSize)
default:
Expand Down

0 comments on commit 5b35c6d

Please sign in to comment.