Skip to content

Commit 7202eec

Browse files
committed
bump llama.cpp
1 parent bf963f5 commit 7202eec

File tree

2 files changed

+109
-14
lines changed

2 files changed

+109
-14
lines changed

include/shards/shards.swift

+108-13
Original file line numberDiff line numberDiff line change
@@ -1409,25 +1409,120 @@ func createSwiftShard<T: IShard>(_: T.Type) -> UnsafeMutablePointer<Shard>? {
14091409
return UnsafeMutableRawPointer(cwrapper).assumingMemoryBound(to: Shard.self)
14101410
}
14111411

1412-
class ParameterInfo {
1413-
init(name: String, types: SHTypesInfo, index: Int) {
1414-
self.name = name
1415-
help = ""
1412+
class TypeInfo {
1413+
var native = SHTypeInfo()
1414+
1415+
init(type: VarType) {
1416+
native.basicType = type.asSHType()
1417+
}
1418+
}
1419+
1420+
class Types {
1421+
var types: [TypeInfo] // to keep alive
1422+
var typesStorage: [SHTypeInfo] = []
1423+
1424+
init(types: [TypeInfo]) {
14161425
self.types = types
1417-
self.index = index
1426+
for t in types {
1427+
typesStorage.append(t.native)
1428+
}
14181429
}
14191430

1420-
init(name: String, help: String, types: SHTypesInfo, index: Int) {
1421-
self.name = name
1422-
self.help = help
1431+
func get() -> [SHTypeInfo] {
1432+
typesStorage
1433+
}
1434+
}
1435+
1436+
class ParameterInfo {
1437+
var name: ContiguousArray<CChar>
1438+
var help: ContiguousArray<CChar>
1439+
var types: [TypeInfo] // to keep alive
1440+
var typesStorage: ContiguousArray<SHTypeInfo> = []
1441+
1442+
init(name: String, help: String, types: [TypeInfo]) {
1443+
self.name = name.utf8CString
1444+
self.help = help.utf8CString
14231445
self.types = types
1424-
self.index = index
1446+
for t in types {
1447+
typesStorage.append(t.native)
1448+
}
14251449
}
14261450

1427-
var name: String
1428-
var help: String
1429-
var types: SHTypesInfo
1430-
var index: Int
1451+
func toSHParameterInfo() -> SHParameterInfo {
1452+
var result = SHParameterInfo()
1453+
1454+
name.withUnsafeBufferPointer {
1455+
result.name = $0.baseAddress
1456+
}
1457+
help.withUnsafeBufferPointer {
1458+
result.help = SHOptionalString(string: $0.baseAddress, crc: 0)
1459+
}
1460+
withUnsafeMutablePointer(to: &typesStorage[0]) { ptr in
1461+
result.valueTypes.elements = ptr
1462+
}
1463+
result.valueTypes.len = UInt32(types.count)
1464+
result.valueTypes.cap = 0
1465+
1466+
return result
1467+
}
1468+
}
1469+
1470+
class Parameters {
1471+
// pod C type, so contiguous array is not needed anyway, this is compatible with the IShard interface
1472+
private var storage: [SHParameterInfo] = []
1473+
private var infos: [ParameterInfo] = [] // to keep alive
1474+
1475+
func add(name: String, help: String, types: [TypeInfo]) {
1476+
let info = ParameterInfo(name: name, help: help, types: types)
1477+
storage.append(info.toSHParameterInfo())
1478+
infos.append(info)
1479+
}
1480+
1481+
func get() -> [SHParameterInfo] {
1482+
storage
1483+
}
1484+
}
1485+
1486+
class ExposedTypeInfo {
1487+
var name: ContiguousArray<CChar>
1488+
var help: ContiguousArray<CChar>
1489+
var exposedType: TypeInfo
1490+
var isMutable: Bool
1491+
var isProtected: Bool
1492+
var global: Bool
1493+
var tracked: Bool
1494+
var declared: Bool
1495+
1496+
init(name: String, help: String, exposedType: TypeInfo, isMutable: Bool = false, isProtected: Bool = false, global: Bool = false, tracked: Bool = false, declared: Bool = false) {
1497+
self.name = name.utf8CString
1498+
self.help = help.utf8CString
1499+
self.exposedType = exposedType
1500+
self.isMutable = isMutable
1501+
self.isProtected = isProtected
1502+
self.global = global
1503+
self.tracked = tracked
1504+
self.declared = declared
1505+
}
1506+
1507+
func toSHExposedTypeInfo() -> SHExposedTypeInfo {
1508+
var result = SHExposedTypeInfo()
1509+
1510+
name.withUnsafeBufferPointer {
1511+
result.name = $0.baseAddress
1512+
}
1513+
help.withUnsafeBufferPointer {
1514+
result.help = SHOptionalString(string: $0.baseAddress, crc: 0)
1515+
}
1516+
result.exposedType = exposedType.native
1517+
1518+
result.isMutable = isMutable
1519+
result.isProtected = isProtected
1520+
result.global = global
1521+
result.tracked = tracked
1522+
result.declared = declared
1523+
1524+
return result
1525+
}
14311526
}
14321527

14331528
class WireController {

0 commit comments

Comments
 (0)