Skip to content

Commit e4648ed

Browse files
committed
Adding GraphDefOptions.setUniquify(names, prefix).
Also allowing local cache on apple/swift-protobuf.
1 parent 434bbe6 commit e4648ed

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

Package.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
//
2121

2222
import PackageDescription
23+
#if os(OSX)
24+
import Darwin
25+
#else
26+
import Glibc
27+
#endif
28+
29+
var url = "https://github.com/apple/swift-protobuf.git"
30+
if let cache = getenv("URL_PERFECT"), let local = String(validatingUTF8: cache) {
31+
url = "\(local)/swift-protobuf/.git"
32+
}
2333

2434
let package = Package(
2535
name: "PerfectTensorFlow",
@@ -29,7 +39,7 @@ let package = Package(
2939
targets: ["PerfectTensorFlow"]),
3040
],
3141
dependencies: [
32-
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.0.0")
42+
.package(url: url, from: "1.0.0")
3343
],
3444
targets: [
3545
.target(

Sources/PerfectTensorFlow/APILoader.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,23 @@ public class TFLib {
929929
// Deleting a function does not remove it from any graphs it was copied to.
930930
public static var DeleteFunction: @convention(c) (OpaquePointer?) -> Void = { _ in }
931931

932+
// Set whether to uniquify imported operation names. If true, imported operation
933+
// names will be modified if their name already exists in the graph. If false,
934+
// conflicting names will be treated as an error. Note that this option has no
935+
// effect if a prefix is set, since the prefix will guarantee all names are
936+
// unique. Defaults to false.
937+
//TF_CAPI_EXPORT extern void TF_ImportGraphDefOptionsSetUniquifyNames(
938+
//TF_ImportGraphDefOptions* opts, unsigned char uniquify_names);
939+
public static var ImportGraphDefOptionsSetUniquifyNames: @convention(c) (OpaquePointer, UInt8) -> Void = { _, _ in }
940+
941+
// If true, the specified prefix will be modified if it already exists as an
942+
// operation name or prefix in the graph. If false, a conflicting prefix will be
943+
// treated as an error. This option has no effect if no prefix is specified.
944+
// TF_CAPI_EXPORT extern void TF_ImportGraphDefOptionsSetUniquifyPrefix(
945+
// TF_ImportGraphDefOptions* opts, unsigned char uniquify_prefix);
946+
public static var ImportGraphDefOptionsSetUniquifyPrefix: @convention(c) (OpaquePointer, UInt8) -> Void = { _, _ in }
947+
948+
932949
/// Bootstrap of tensorflow library open, **MUST BE CALL BEFORE ANY OPERATIONS**
933950
/// - parameters
934951
/// - library: the installation path of library TensorFlow for C, /usr/local/lib/libtensorflow.so by default
@@ -950,6 +967,11 @@ public class TFLib {
950967
throw Panic.DLL(reason: "Version \(ver) is obsolete and out of support.")
951968
}
952969

970+
if ver >= "1.4.1" {
971+
ImportGraphDefOptionsSetUniquifyNames = try LoadFunction(lib, "TF_ImportGraphDefOptionsSetUniquifyNames")
972+
ImportGraphDefOptionsSetUniquifyPrefix = try LoadFunction(lib, "TF_ImportGraphDefOptionsSetUniquifyPrefix")
973+
}
974+
953975
if ver >= "1.4.0" {
954976
GraphCopyFunction = try LoadFunction(lib, "TF_GraphCopyFunction")
955977
GraphToFunction = try LoadFunction(lib, "TF_GraphToFunction")

Sources/PerfectTensorFlow/PerfectTensorFlow.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,14 @@ public class TensorFlow {
20402040
TFLib.DeleteImportGraphDefOptions(options)
20412041
}//end init
20422042

2043+
public func setNames(uniquified: Bool = false) {
2044+
TFLib.ImportGraphDefOptionsSetUniquifyNames(options, uniquified ? 1 : 0)
2045+
}
2046+
2047+
public func setPrefix(uniquified: Bool = false) {
2048+
TFLib.ImportGraphDefOptionsSetUniquifyPrefix(options, uniquified ? 1 : 0)
2049+
}
2050+
20432051
/// Set the prefix to be prepended to the names of nodes in graph_def that will be imported into graph.
20442052
/// - parameters:
20452053
/// - prefix: the prefix to add to all the names of nodes.

0 commit comments

Comments
 (0)