From 559d880f83925a42d383d58b95da2be0cabe7714 Mon Sep 17 00:00:00 2001 From: Rafael Almeida Date: Mon, 20 Jun 2016 17:01:02 +1200 Subject: [PATCH 01/10] chore - added Xcode project for library code --- CommonForAllPlatforms/Makefile | 11 - CommonForAllPlatforms/README.md | 6 - DeepLearningKit.xcodeproj/project.pbxproj | 442 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcschemes/DeepLearningKit.xcscheme | 99 ++++ .../ConvolutionLayer.swift | 0 DeepLearningKit/DeepLearningKit.h | 19 + .../DeepNetwork+JSON.swift | 0 .../DeepNetwork+SetupNetworkFromDict.swift | 0 .../DeepNetwork.swift | 0 DeepLearningKit/Info.plist | 26 ++ .../MetalDataStructures.swift | 0 .../MetalUtilityFunctions.swift | 0 .../PoolingLayer.swift | 0 .../RectifierLayer.swift | 0 .../Shaders.metal | 0 .../DeepLearningKitTests.swift | 36 ++ DeepLearningKitTests/Info.plist | 24 + 18 files changed, 653 insertions(+), 17 deletions(-) delete mode 100644 CommonForAllPlatforms/Makefile delete mode 100644 CommonForAllPlatforms/README.md create mode 100644 DeepLearningKit.xcodeproj/project.pbxproj create mode 100644 DeepLearningKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit.xcscheme rename {CommonForAllPlatforms => DeepLearningKit}/ConvolutionLayer.swift (100%) create mode 100644 DeepLearningKit/DeepLearningKit.h rename {CommonForAllPlatforms => DeepLearningKit}/DeepNetwork+JSON.swift (100%) rename {CommonForAllPlatforms => DeepLearningKit}/DeepNetwork+SetupNetworkFromDict.swift (100%) rename {CommonForAllPlatforms => DeepLearningKit}/DeepNetwork.swift (100%) create mode 100644 DeepLearningKit/Info.plist rename {CommonForAllPlatforms => DeepLearningKit}/MetalDataStructures.swift (100%) rename {CommonForAllPlatforms => DeepLearningKit}/MetalUtilityFunctions.swift (100%) rename {CommonForAllPlatforms => DeepLearningKit}/PoolingLayer.swift (100%) rename {CommonForAllPlatforms => DeepLearningKit}/RectifierLayer.swift (100%) rename {CommonForAllPlatforms => DeepLearningKit}/Shaders.metal (100%) create mode 100644 DeepLearningKitTests/DeepLearningKitTests.swift create mode 100644 DeepLearningKitTests/Info.plist diff --git a/CommonForAllPlatforms/Makefile b/CommonForAllPlatforms/Makefile deleted file mode 100644 index aaf4d61..0000000 --- a/CommonForAllPlatforms/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -all: - cp *.swift ../DeepLearningKitForiOS/DeepLearningKitForiOS/ - cp *.metal ../DeepLearningKitForiOS/DeepLearningKitForiOS/ - - cp *.swift ../DeepLearningKitFortvOS/DeepLearningKitFortvOS/ - cp *.metal ../DeepLearningKitFortvOS/DeepLearningKitFortvOS/ - - cp *.swift ../DeepLearningKitForOSX/DeepLearningKitForOSX/ - cp *.metal ../DeepLearningKitForOSX/DeepLearningKitForOSX/ - - diff --git a/CommonForAllPlatforms/README.md b/CommonForAllPlatforms/README.md deleted file mode 100644 index ab1754d..0000000 --- a/CommonForAllPlatforms/README.md +++ /dev/null @@ -1,6 +0,0 @@ -![DeepLearningKit](http://deeplearningkit.github.io/DeepLearningKit/imgs/DeepLearningKitWebLogo.png) - -## Instructions -Edit common Swift and Metal files here and type make to distribute to iOS, tvOS and OS X directories - - diff --git a/DeepLearningKit.xcodeproj/project.pbxproj b/DeepLearningKit.xcodeproj/project.pbxproj new file mode 100644 index 0000000..b9685e4 --- /dev/null +++ b/DeepLearningKit.xcodeproj/project.pbxproj @@ -0,0 +1,442 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 53AC8A381D17AC2000778BB5 /* DeepLearningKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 53AC8A371D17AC2000778BB5 /* DeepLearningKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 53AC8A3F1D17AC2000778BB5 /* DeepLearningKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 53AC8A341D17AC2000778BB5 /* DeepLearningKit.framework */; }; + 53AC8A441D17AC2000778BB5 /* DeepLearningKitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A431D17AC2000778BB5 /* DeepLearningKitTests.swift */; }; + 53AC8A571D17AD3500778BB5 /* ConvolutionLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A4E1D17AD3500778BB5 /* ConvolutionLayer.swift */; }; + 53AC8A581D17AD3500778BB5 /* DeepNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A4F1D17AD3500778BB5 /* DeepNetwork.swift */; }; + 53AC8A591D17AD3500778BB5 /* DeepNetwork+JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A501D17AD3500778BB5 /* DeepNetwork+JSON.swift */; }; + 53AC8A5A1D17AD3500778BB5 /* DeepNetwork+SetupNetworkFromDict.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A511D17AD3500778BB5 /* DeepNetwork+SetupNetworkFromDict.swift */; }; + 53AC8A5B1D17AD3500778BB5 /* MetalDataStructures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A521D17AD3500778BB5 /* MetalDataStructures.swift */; }; + 53AC8A5C1D17AD3500778BB5 /* MetalUtilityFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A531D17AD3500778BB5 /* MetalUtilityFunctions.swift */; }; + 53AC8A5D1D17AD3500778BB5 /* PoolingLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A541D17AD3500778BB5 /* PoolingLayer.swift */; }; + 53AC8A5E1D17AD3500778BB5 /* RectifierLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A551D17AD3500778BB5 /* RectifierLayer.swift */; }; + 53AC8A5F1D17AD3500778BB5 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A561D17AD3500778BB5 /* Shaders.metal */; }; + 53AC8A621D17AF4300778BB5 /* test in Resources */ = {isa = PBXBuildFile; fileRef = 53AC8A611D17AF4300778BB5 /* test */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 53AC8A401D17AC2000778BB5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 53AC8A2B1D17AC2000778BB5 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 53AC8A331D17AC2000778BB5; + remoteInfo = DeepLearningKit; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 53AC8A341D17AC2000778BB5 /* DeepLearningKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DeepLearningKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 53AC8A371D17AC2000778BB5 /* DeepLearningKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeepLearningKit.h; sourceTree = ""; }; + 53AC8A391D17AC2000778BB5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 53AC8A3E1D17AC2000778BB5 /* DeepLearningKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DeepLearningKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 53AC8A431D17AC2000778BB5 /* DeepLearningKitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeepLearningKitTests.swift; sourceTree = ""; }; + 53AC8A451D17AC2000778BB5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 53AC8A4E1D17AD3500778BB5 /* ConvolutionLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConvolutionLayer.swift; sourceTree = ""; }; + 53AC8A4F1D17AD3500778BB5 /* DeepNetwork.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeepNetwork.swift; sourceTree = ""; }; + 53AC8A501D17AD3500778BB5 /* DeepNetwork+JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DeepNetwork+JSON.swift"; sourceTree = ""; }; + 53AC8A511D17AD3500778BB5 /* DeepNetwork+SetupNetworkFromDict.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DeepNetwork+SetupNetworkFromDict.swift"; sourceTree = ""; }; + 53AC8A521D17AD3500778BB5 /* MetalDataStructures.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalDataStructures.swift; sourceTree = ""; }; + 53AC8A531D17AD3500778BB5 /* MetalUtilityFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalUtilityFunctions.swift; sourceTree = ""; }; + 53AC8A541D17AD3500778BB5 /* PoolingLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PoolingLayer.swift; sourceTree = ""; }; + 53AC8A551D17AD3500778BB5 /* RectifierLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RectifierLayer.swift; sourceTree = ""; }; + 53AC8A561D17AD3500778BB5 /* Shaders.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Shaders.metal; sourceTree = ""; }; + 53AC8A601D17AEDE00778BB5 /* .travis.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .travis.yml; sourceTree = ""; }; + 53AC8A611D17AF4300778BB5 /* test */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = test; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 53AC8A301D17AC2000778BB5 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 53AC8A3B1D17AC2000778BB5 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 53AC8A3F1D17AC2000778BB5 /* DeepLearningKit.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 53AC8A2A1D17AC2000778BB5 = { + isa = PBXGroup; + children = ( + 53AC8A611D17AF4300778BB5 /* test */, + 53AC8A601D17AEDE00778BB5 /* .travis.yml */, + 53AC8A361D17AC2000778BB5 /* DeepLearningKit */, + 53AC8A421D17AC2000778BB5 /* DeepLearningKitTests */, + 53AC8A351D17AC2000778BB5 /* Products */, + ); + sourceTree = ""; + }; + 53AC8A351D17AC2000778BB5 /* Products */ = { + isa = PBXGroup; + children = ( + 53AC8A341D17AC2000778BB5 /* DeepLearningKit.framework */, + 53AC8A3E1D17AC2000778BB5 /* DeepLearningKitTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 53AC8A361D17AC2000778BB5 /* DeepLearningKit */ = { + isa = PBXGroup; + children = ( + 53AC8A371D17AC2000778BB5 /* DeepLearningKit.h */, + 53AC8A4F1D17AD3500778BB5 /* DeepNetwork.swift */, + 53AC8A4E1D17AD3500778BB5 /* ConvolutionLayer.swift */, + 53AC8A501D17AD3500778BB5 /* DeepNetwork+JSON.swift */, + 53AC8A511D17AD3500778BB5 /* DeepNetwork+SetupNetworkFromDict.swift */, + 53AC8A521D17AD3500778BB5 /* MetalDataStructures.swift */, + 53AC8A531D17AD3500778BB5 /* MetalUtilityFunctions.swift */, + 53AC8A541D17AD3500778BB5 /* PoolingLayer.swift */, + 53AC8A551D17AD3500778BB5 /* RectifierLayer.swift */, + 53AC8A561D17AD3500778BB5 /* Shaders.metal */, + 53AC8A391D17AC2000778BB5 /* Info.plist */, + ); + path = DeepLearningKit; + sourceTree = ""; + }; + 53AC8A421D17AC2000778BB5 /* DeepLearningKitTests */ = { + isa = PBXGroup; + children = ( + 53AC8A431D17AC2000778BB5 /* DeepLearningKitTests.swift */, + 53AC8A451D17AC2000778BB5 /* Info.plist */, + ); + path = DeepLearningKitTests; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 53AC8A311D17AC2000778BB5 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 53AC8A381D17AC2000778BB5 /* DeepLearningKit.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 53AC8A331D17AC2000778BB5 /* DeepLearningKit */ = { + isa = PBXNativeTarget; + buildConfigurationList = 53AC8A481D17AC2000778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit" */; + buildPhases = ( + 53AC8A2F1D17AC2000778BB5 /* Sources */, + 53AC8A301D17AC2000778BB5 /* Frameworks */, + 53AC8A311D17AC2000778BB5 /* Headers */, + 53AC8A321D17AC2000778BB5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = DeepLearningKit; + productName = DeepLearningKit; + productReference = 53AC8A341D17AC2000778BB5 /* DeepLearningKit.framework */; + productType = "com.apple.product-type.framework"; + }; + 53AC8A3D1D17AC2000778BB5 /* DeepLearningKitTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 53AC8A4B1D17AC2000778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKitTests" */; + buildPhases = ( + 53AC8A3A1D17AC2000778BB5 /* Sources */, + 53AC8A3B1D17AC2000778BB5 /* Frameworks */, + 53AC8A3C1D17AC2000778BB5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 53AC8A411D17AC2000778BB5 /* PBXTargetDependency */, + ); + name = DeepLearningKitTests; + productName = DeepLearningKitTests; + productReference = 53AC8A3E1D17AC2000778BB5 /* DeepLearningKitTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 53AC8A2B1D17AC2000778BB5 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0730; + LastUpgradeCheck = 0730; + ORGANIZATIONNAME = DeepLearningKit; + TargetAttributes = { + 53AC8A331D17AC2000778BB5 = { + CreatedOnToolsVersion = 7.3.1; + }; + 53AC8A3D1D17AC2000778BB5 = { + CreatedOnToolsVersion = 7.3.1; + }; + }; + }; + buildConfigurationList = 53AC8A2E1D17AC2000778BB5 /* Build configuration list for PBXProject "DeepLearningKit" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 53AC8A2A1D17AC2000778BB5; + productRefGroup = 53AC8A351D17AC2000778BB5 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 53AC8A331D17AC2000778BB5 /* DeepLearningKit */, + 53AC8A3D1D17AC2000778BB5 /* DeepLearningKitTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 53AC8A321D17AC2000778BB5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 53AC8A621D17AF4300778BB5 /* test in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 53AC8A3C1D17AC2000778BB5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 53AC8A2F1D17AC2000778BB5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 53AC8A581D17AD3500778BB5 /* DeepNetwork.swift in Sources */, + 53AC8A5E1D17AD3500778BB5 /* RectifierLayer.swift in Sources */, + 53AC8A5B1D17AD3500778BB5 /* MetalDataStructures.swift in Sources */, + 53AC8A591D17AD3500778BB5 /* DeepNetwork+JSON.swift in Sources */, + 53AC8A5D1D17AD3500778BB5 /* PoolingLayer.swift in Sources */, + 53AC8A571D17AD3500778BB5 /* ConvolutionLayer.swift in Sources */, + 53AC8A5F1D17AD3500778BB5 /* Shaders.metal in Sources */, + 53AC8A5C1D17AD3500778BB5 /* MetalUtilityFunctions.swift in Sources */, + 53AC8A5A1D17AD3500778BB5 /* DeepNetwork+SetupNetworkFromDict.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 53AC8A3A1D17AC2000778BB5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 53AC8A441D17AC2000778BB5 /* DeepLearningKitTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 53AC8A411D17AC2000778BB5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 53AC8A331D17AC2000778BB5 /* DeepLearningKit */; + targetProxy = 53AC8A401D17AC2000778BB5 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 53AC8A461D17AC2000778BB5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + 53AC8A471D17AC2000778BB5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + 53AC8A491D17AC2000778BB5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; + CLANG_ENABLE_MODULES = YES; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = DeepLearningKit/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = nz.co.iswe.labs.DeepLearningKit; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 53AC8A4A1D17AC2000778BB5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; + CLANG_ENABLE_MODULES = YES; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = DeepLearningKit/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = nz.co.iswe.labs.DeepLearningKit; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Release; + }; + 53AC8A4C1D17AC2000778BB5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + INFOPLIST_FILE = DeepLearningKitTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = nz.co.iswe.labs.DeepLearningKitTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 53AC8A4D1D17AC2000778BB5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + INFOPLIST_FILE = DeepLearningKitTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = nz.co.iswe.labs.DeepLearningKitTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 53AC8A2E1D17AC2000778BB5 /* Build configuration list for PBXProject "DeepLearningKit" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 53AC8A461D17AC2000778BB5 /* Debug */, + 53AC8A471D17AC2000778BB5 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 53AC8A481D17AC2000778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 53AC8A491D17AC2000778BB5 /* Debug */, + 53AC8A4A1D17AC2000778BB5 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 53AC8A4B1D17AC2000778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKitTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 53AC8A4C1D17AC2000778BB5 /* Debug */, + 53AC8A4D1D17AC2000778BB5 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 53AC8A2B1D17AC2000778BB5 /* Project object */; +} diff --git a/DeepLearningKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/DeepLearningKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..9bcc2aa --- /dev/null +++ b/DeepLearningKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit.xcscheme b/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit.xcscheme new file mode 100644 index 0000000..883e04d --- /dev/null +++ b/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit.xcscheme @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CommonForAllPlatforms/ConvolutionLayer.swift b/DeepLearningKit/ConvolutionLayer.swift similarity index 100% rename from CommonForAllPlatforms/ConvolutionLayer.swift rename to DeepLearningKit/ConvolutionLayer.swift diff --git a/DeepLearningKit/DeepLearningKit.h b/DeepLearningKit/DeepLearningKit.h new file mode 100644 index 0000000..963b015 --- /dev/null +++ b/DeepLearningKit/DeepLearningKit.h @@ -0,0 +1,19 @@ +// +// DeepLearningKit.h +// DeepLearningKit +// +// Created by Rafael Almeida on 20/06/16. +// Copyright © 2016 DeepLearningKit. All rights reserved. +// + +#import + +//! Project version number for DeepLearningKit. +FOUNDATION_EXPORT double DeepLearningKitVersionNumber; + +//! Project version string for DeepLearningKit. +FOUNDATION_EXPORT const unsigned char DeepLearningKitVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + + diff --git a/CommonForAllPlatforms/DeepNetwork+JSON.swift b/DeepLearningKit/DeepNetwork+JSON.swift similarity index 100% rename from CommonForAllPlatforms/DeepNetwork+JSON.swift rename to DeepLearningKit/DeepNetwork+JSON.swift diff --git a/CommonForAllPlatforms/DeepNetwork+SetupNetworkFromDict.swift b/DeepLearningKit/DeepNetwork+SetupNetworkFromDict.swift similarity index 100% rename from CommonForAllPlatforms/DeepNetwork+SetupNetworkFromDict.swift rename to DeepLearningKit/DeepNetwork+SetupNetworkFromDict.swift diff --git a/CommonForAllPlatforms/DeepNetwork.swift b/DeepLearningKit/DeepNetwork.swift similarity index 100% rename from CommonForAllPlatforms/DeepNetwork.swift rename to DeepLearningKit/DeepNetwork.swift diff --git a/DeepLearningKit/Info.plist b/DeepLearningKit/Info.plist new file mode 100644 index 0000000..d3de8ee --- /dev/null +++ b/DeepLearningKit/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSPrincipalClass + + + diff --git a/CommonForAllPlatforms/MetalDataStructures.swift b/DeepLearningKit/MetalDataStructures.swift similarity index 100% rename from CommonForAllPlatforms/MetalDataStructures.swift rename to DeepLearningKit/MetalDataStructures.swift diff --git a/CommonForAllPlatforms/MetalUtilityFunctions.swift b/DeepLearningKit/MetalUtilityFunctions.swift similarity index 100% rename from CommonForAllPlatforms/MetalUtilityFunctions.swift rename to DeepLearningKit/MetalUtilityFunctions.swift diff --git a/CommonForAllPlatforms/PoolingLayer.swift b/DeepLearningKit/PoolingLayer.swift similarity index 100% rename from CommonForAllPlatforms/PoolingLayer.swift rename to DeepLearningKit/PoolingLayer.swift diff --git a/CommonForAllPlatforms/RectifierLayer.swift b/DeepLearningKit/RectifierLayer.swift similarity index 100% rename from CommonForAllPlatforms/RectifierLayer.swift rename to DeepLearningKit/RectifierLayer.swift diff --git a/CommonForAllPlatforms/Shaders.metal b/DeepLearningKit/Shaders.metal similarity index 100% rename from CommonForAllPlatforms/Shaders.metal rename to DeepLearningKit/Shaders.metal diff --git a/DeepLearningKitTests/DeepLearningKitTests.swift b/DeepLearningKitTests/DeepLearningKitTests.swift new file mode 100644 index 0000000..88bd340 --- /dev/null +++ b/DeepLearningKitTests/DeepLearningKitTests.swift @@ -0,0 +1,36 @@ +// +// DeepLearningKitTests.swift +// DeepLearningKitTests +// +// Created by Rafael Almeida on 20/06/16. +// Copyright © 2016 DeepLearningKit. All rights reserved. +// + +import XCTest +@testable import DeepLearningKit + +class DeepLearningKitTests: XCTestCase { + + override func setUp() { + super.setUp() + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testExample() { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + func testPerformanceExample() { + // This is an example of a performance test case. + self.measureBlock { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/DeepLearningKitTests/Info.plist b/DeepLearningKitTests/Info.plist new file mode 100644 index 0000000..ba72822 --- /dev/null +++ b/DeepLearningKitTests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + From e433ae654c16385462b24e161a6a244007fb8fb6 Mon Sep 17 00:00:00 2001 From: Rafael Almeida Date: Mon, 20 Jun 2016 17:01:21 +1200 Subject: [PATCH 02/10] chore - unit testing and ci setup --- .travis.yml | 3 +++ test | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 .travis.yml create mode 100755 test diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f6c62a2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +osx_image: xcode7.2 +language: objective-c +script: ./test xcode \ No newline at end of file diff --git a/test b/test new file mode 100755 index 0000000..9b575b5 --- /dev/null +++ b/test @@ -0,0 +1,57 @@ +#!/bin/bash + +set -e # exit on failure + +function xcode_tests { + ( + set -e; + set -x; # print commands executed; use subshell to avoid having to print 'set +x' to disable it + # Run Tests via OS X + xcodebuild test -workspace Snorlax.xcworkspace -scheme Snorlax-OSX -destination "platform=OS X" && + + # Run Tests via iOS + xcodebuild test -workspace Snorlax.xcworkspace -scheme Snorlax-iOS -destination "platform=iOS Simulator,name=iPhone 6,OS=9.2" && + + # Run Tests via tvOS + xcodebuild test -workspace Snorlax.xcworkspace -scheme Snorlax-tvOS -destination "platform=tvOS Simulator,name=Apple TV 1080p,OS=9.1" + ) + echo + echo "Xcode tests passed" +} + +function spm_tests { + ( + set -e; + set -x; # print commands executed; use subshell to avoid having to print 'set +x' to disable it + swift build --clean && + swift build && + swift test + ) + echo + echo "SPM tests passed" +} + +function help { + echo "Usage: $0 COMMANDS..." + echo + echo "Runs specific test suites." + echo + echo "COMMANDS:" + echo " spm: runs tests via Swift Package Manager (Linux)" + echo " xcode: runs tests via Xcode (OS X, iOS, tvOS)" + echo " help: Displays this help" + echo +} + +for arg in "$@" +do + case $arg in + "spm") spm_tests;; + "xcode") xcode_tests;; + "help") help;; + esac +done + +if [ $# == 0 ]; then + help +fi From a2d0756ab5acd9791133c611fc4bfe2d91a93955 Mon Sep 17 00:00:00 2001 From: Rafael Almeida Date: Mon, 20 Jun 2016 17:38:20 +1200 Subject: [PATCH 03/10] feat - added basic test - to test ci --- DeepLearningKitTests/DeepLearningKitTests.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DeepLearningKitTests/DeepLearningKitTests.swift b/DeepLearningKitTests/DeepLearningKitTests.swift index 88bd340..b5d4b33 100644 --- a/DeepLearningKitTests/DeepLearningKitTests.swift +++ b/DeepLearningKitTests/DeepLearningKitTests.swift @@ -20,10 +20,10 @@ class DeepLearningKitTests: XCTestCase { // Put teardown code here. This method is called after the invocation of each test method in the class. super.tearDown() } - + func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. + let deepNetwork = DeepNetwork() + XCTAssertNotNil(deepNetwork) } func testPerformanceExample() { From 423e02cd428ecd531baea99abdbec5c60887f76f Mon Sep 17 00:00:00 2001 From: Rafael Almeida Date: Mon, 20 Jun 2016 17:41:06 +1200 Subject: [PATCH 04/10] chore (travis) removed Xcode param from test script --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f6c62a2..4be5357 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ osx_image: xcode7.2 language: objective-c -script: ./test xcode \ No newline at end of file +script: ./test \ No newline at end of file From 53605782daa410bfa7e14196bfa9827ca784020e Mon Sep 17 00:00:00 2001 From: Rafael Almeida Date: Mon, 20 Jun 2016 17:46:00 +1200 Subject: [PATCH 05/10] chore (test.sh) hardwire Xcode tests --- test | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/test b/test index 9b575b5..d1b4a7b 100755 --- a/test +++ b/test @@ -43,15 +43,18 @@ function help { echo } -for arg in "$@" -do - case $arg in - "spm") spm_tests;; - "xcode") xcode_tests;; - "help") help;; - esac -done - -if [ $# == 0 ]; then - help -fi +xcode_tests + +# +#for arg in "$@" +#do +# case $arg in +# "spm") spm_tests;; +# "xcode") xcode_tests;; +## "help") help;; +# esac +#done + +#if [ $# == 0 ]; then +# help +#fi From 36f04217ceffb5c9bb6f827b1aef046143f8187d Mon Sep 17 00:00:00 2001 From: Rafael Almeida Date: Mon, 20 Jun 2016 18:53:59 +1200 Subject: [PATCH 06/10] feat (targets) - setup targets for iOS, OSX and tvOS --- DeepLearningKit-OSX/DeepLearningKit-OSX.h | 19 + DeepLearningKit-OSX/Info.plist | 28 + .../DeepLearningKit_OSXTests.swift | 10 +- DeepLearningKit-OSXTests/Info.plist | 24 + DeepLearningKit-tvOS/DeepLearningKit-tvOS.h | 19 + DeepLearningKit-tvOS/Info.plist | 26 + .../DeepLearningKit_tvOSTests.swift | 36 ++ DeepLearningKit-tvOSTests/Info.plist | 24 + DeepLearningKit.xcodeproj/project.pbxproj | 571 +++++++++++++++++- .../xcschemes/DeepLearningKit-OSX.xcscheme | 113 ++++ ....xcscheme => DeepLearningKit-iOS.xcscheme} | 12 +- .../xcschemes/DeepLearningKit-tvOS.xcscheme | 99 +++ .../contents.xcworkspacedata | 7 + .../DeepLearningKit_iOSTests.swift | 37 ++ test | 6 +- 15 files changed, 984 insertions(+), 47 deletions(-) create mode 100644 DeepLearningKit-OSX/DeepLearningKit-OSX.h create mode 100644 DeepLearningKit-OSX/Info.plist rename DeepLearningKitTests/DeepLearningKitTests.swift => DeepLearningKit-OSXTests/DeepLearningKit_OSXTests.swift (84%) create mode 100644 DeepLearningKit-OSXTests/Info.plist create mode 100644 DeepLearningKit-tvOS/DeepLearningKit-tvOS.h create mode 100644 DeepLearningKit-tvOS/Info.plist create mode 100644 DeepLearningKit-tvOSTests/DeepLearningKit_tvOSTests.swift create mode 100644 DeepLearningKit-tvOSTests/Info.plist create mode 100644 DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-OSX.xcscheme rename DeepLearningKit.xcodeproj/xcshareddata/xcschemes/{DeepLearningKit.xcscheme => DeepLearningKit-iOS.xcscheme} (91%) create mode 100644 DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-tvOS.xcscheme create mode 100644 DeepLearningKit.xcworkspace/contents.xcworkspacedata create mode 100644 DeepLearningKitTests/DeepLearningKit_iOSTests.swift diff --git a/DeepLearningKit-OSX/DeepLearningKit-OSX.h b/DeepLearningKit-OSX/DeepLearningKit-OSX.h new file mode 100644 index 0000000..e763f08 --- /dev/null +++ b/DeepLearningKit-OSX/DeepLearningKit-OSX.h @@ -0,0 +1,19 @@ +// +// DeepLearningKit-OSX.h +// DeepLearningKit-OSX +// +// Created by Rafael Almeida on 20/06/16. +// Copyright © 2016 DeepLearningKit. All rights reserved. +// + +#import + +//! Project version number for DeepLearningKit-OSX. +FOUNDATION_EXPORT double DeepLearningKit_OSXVersionNumber; + +//! Project version string for DeepLearningKit-OSX. +FOUNDATION_EXPORT const unsigned char DeepLearningKit_OSXVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + + diff --git a/DeepLearningKit-OSX/Info.plist b/DeepLearningKit-OSX/Info.plist new file mode 100644 index 0000000..8ea7a88 --- /dev/null +++ b/DeepLearningKit-OSX/Info.plist @@ -0,0 +1,28 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSHumanReadableCopyright + Copyright © 2016 DeepLearningKit. All rights reserved. + NSPrincipalClass + + + diff --git a/DeepLearningKitTests/DeepLearningKitTests.swift b/DeepLearningKit-OSXTests/DeepLearningKit_OSXTests.swift similarity index 84% rename from DeepLearningKitTests/DeepLearningKitTests.swift rename to DeepLearningKit-OSXTests/DeepLearningKit_OSXTests.swift index b5d4b33..073476d 100644 --- a/DeepLearningKitTests/DeepLearningKitTests.swift +++ b/DeepLearningKit-OSXTests/DeepLearningKit_OSXTests.swift @@ -1,6 +1,6 @@ // -// DeepLearningKitTests.swift -// DeepLearningKitTests +// DeepLearningKit_OSXTests.swift +// DeepLearningKit-OSXTests // // Created by Rafael Almeida on 20/06/16. // Copyright © 2016 DeepLearningKit. All rights reserved. @@ -9,7 +9,7 @@ import XCTest @testable import DeepLearningKit -class DeepLearningKitTests: XCTestCase { +class DeepLearningKit_OSXTests: XCTestCase { override func setUp() { super.setUp() @@ -20,8 +20,8 @@ class DeepLearningKitTests: XCTestCase { // Put teardown code here. This method is called after the invocation of each test method in the class. super.tearDown() } - - func testExample() { + + func testDeepNetwork() { let deepNetwork = DeepNetwork() XCTAssertNotNil(deepNetwork) } diff --git a/DeepLearningKit-OSXTests/Info.plist b/DeepLearningKit-OSXTests/Info.plist new file mode 100644 index 0000000..ba72822 --- /dev/null +++ b/DeepLearningKit-OSXTests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/DeepLearningKit-tvOS/DeepLearningKit-tvOS.h b/DeepLearningKit-tvOS/DeepLearningKit-tvOS.h new file mode 100644 index 0000000..fb1160b --- /dev/null +++ b/DeepLearningKit-tvOS/DeepLearningKit-tvOS.h @@ -0,0 +1,19 @@ +// +// DeepLearningKit-tvOS.h +// DeepLearningKit-tvOS +// +// Created by Rafael Almeida on 20/06/16. +// Copyright © 2016 DeepLearningKit. All rights reserved. +// + +#import + +//! Project version number for DeepLearningKit-tvOS. +FOUNDATION_EXPORT double DeepLearningKit_tvOSVersionNumber; + +//! Project version string for DeepLearningKit-tvOS. +FOUNDATION_EXPORT const unsigned char DeepLearningKit_tvOSVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + + diff --git a/DeepLearningKit-tvOS/Info.plist b/DeepLearningKit-tvOS/Info.plist new file mode 100644 index 0000000..d3de8ee --- /dev/null +++ b/DeepLearningKit-tvOS/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSPrincipalClass + + + diff --git a/DeepLearningKit-tvOSTests/DeepLearningKit_tvOSTests.swift b/DeepLearningKit-tvOSTests/DeepLearningKit_tvOSTests.swift new file mode 100644 index 0000000..d1a31ae --- /dev/null +++ b/DeepLearningKit-tvOSTests/DeepLearningKit_tvOSTests.swift @@ -0,0 +1,36 @@ +// +// DeepLearningKit_tvOSTests.swift +// DeepLearningKit-tvOSTests +// +// Created by Rafael Almeida on 20/06/16. +// Copyright © 2016 DeepLearningKit. All rights reserved. +// + +import XCTest +@testable import DeepLearningKit + +class DeepLearningKit_tvOSTests: XCTestCase { + + override func setUp() { + super.setUp() + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testExample() { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + func testPerformanceExample() { + // This is an example of a performance test case. + self.measureBlock { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/DeepLearningKit-tvOSTests/Info.plist b/DeepLearningKit-tvOSTests/Info.plist new file mode 100644 index 0000000..ba72822 --- /dev/null +++ b/DeepLearningKit-tvOSTests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/DeepLearningKit.xcodeproj/project.pbxproj b/DeepLearningKit.xcodeproj/project.pbxproj index b9685e4..b16d3a0 100644 --- a/DeepLearningKit.xcodeproj/project.pbxproj +++ b/DeepLearningKit.xcodeproj/project.pbxproj @@ -9,7 +9,7 @@ /* Begin PBXBuildFile section */ 53AC8A381D17AC2000778BB5 /* DeepLearningKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 53AC8A371D17AC2000778BB5 /* DeepLearningKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 53AC8A3F1D17AC2000778BB5 /* DeepLearningKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 53AC8A341D17AC2000778BB5 /* DeepLearningKit.framework */; }; - 53AC8A441D17AC2000778BB5 /* DeepLearningKitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A431D17AC2000778BB5 /* DeepLearningKitTests.swift */; }; + 53AC8A441D17AC2000778BB5 /* DeepLearningKit_iOSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A431D17AC2000778BB5 /* DeepLearningKit_iOSTests.swift */; }; 53AC8A571D17AD3500778BB5 /* ConvolutionLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A4E1D17AD3500778BB5 /* ConvolutionLayer.swift */; }; 53AC8A581D17AD3500778BB5 /* DeepNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A4F1D17AD3500778BB5 /* DeepNetwork.swift */; }; 53AC8A591D17AD3500778BB5 /* DeepNetwork+JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A501D17AD3500778BB5 /* DeepNetwork+JSON.swift */; }; @@ -20,6 +20,30 @@ 53AC8A5E1D17AD3500778BB5 /* RectifierLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A551D17AD3500778BB5 /* RectifierLayer.swift */; }; 53AC8A5F1D17AD3500778BB5 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A561D17AD3500778BB5 /* Shaders.metal */; }; 53AC8A621D17AF4300778BB5 /* test in Resources */ = {isa = PBXBuildFile; fileRef = 53AC8A611D17AF4300778BB5 /* test */; }; + 53AC8A801D17BFF400778BB5 /* DeepLearningKit-OSX.h in Headers */ = {isa = PBXBuildFile; fileRef = 53AC8A7F1D17BFF400778BB5 /* DeepLearningKit-OSX.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 53AC8A871D17BFF400778BB5 /* DeepLearningKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 53AC8A7D1D17BFF400778BB5 /* DeepLearningKit.framework */; }; + 53AC8A8C1D17BFF400778BB5 /* DeepLearningKit_OSXTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A8B1D17BFF400778BB5 /* DeepLearningKit_OSXTests.swift */; }; + 53AC8A9C1D17C02E00778BB5 /* DeepLearningKit-tvOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 53AC8A9B1D17C02E00778BB5 /* DeepLearningKit-tvOS.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 53AC8AA31D17C02E00778BB5 /* DeepLearningKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 53AC8A991D17C02E00778BB5 /* DeepLearningKit.framework */; }; + 53AC8AA81D17C02E00778BB5 /* DeepLearningKit_tvOSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8AA71D17C02E00778BB5 /* DeepLearningKit_tvOSTests.swift */; }; + 53AC8AB11D17C10400778BB5 /* DeepNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A4F1D17AD3500778BB5 /* DeepNetwork.swift */; }; + 53AC8AB21D17C10400778BB5 /* ConvolutionLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A4E1D17AD3500778BB5 /* ConvolutionLayer.swift */; }; + 53AC8AB31D17C10400778BB5 /* DeepNetwork+JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A501D17AD3500778BB5 /* DeepNetwork+JSON.swift */; }; + 53AC8AB41D17C10400778BB5 /* DeepNetwork+SetupNetworkFromDict.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A511D17AD3500778BB5 /* DeepNetwork+SetupNetworkFromDict.swift */; }; + 53AC8AB51D17C10400778BB5 /* MetalDataStructures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A521D17AD3500778BB5 /* MetalDataStructures.swift */; }; + 53AC8AB61D17C10400778BB5 /* MetalUtilityFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A531D17AD3500778BB5 /* MetalUtilityFunctions.swift */; }; + 53AC8AB71D17C10400778BB5 /* PoolingLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A541D17AD3500778BB5 /* PoolingLayer.swift */; }; + 53AC8AB81D17C10400778BB5 /* RectifierLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A551D17AD3500778BB5 /* RectifierLayer.swift */; }; + 53AC8AB91D17C10400778BB5 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A561D17AD3500778BB5 /* Shaders.metal */; }; + 53AC8ABA1D17C11C00778BB5 /* DeepNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A4F1D17AD3500778BB5 /* DeepNetwork.swift */; }; + 53AC8ABB1D17C11C00778BB5 /* ConvolutionLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A4E1D17AD3500778BB5 /* ConvolutionLayer.swift */; }; + 53AC8ABC1D17C11C00778BB5 /* DeepNetwork+JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A501D17AD3500778BB5 /* DeepNetwork+JSON.swift */; }; + 53AC8ABD1D17C11C00778BB5 /* DeepNetwork+SetupNetworkFromDict.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A511D17AD3500778BB5 /* DeepNetwork+SetupNetworkFromDict.swift */; }; + 53AC8ABE1D17C11C00778BB5 /* MetalDataStructures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A521D17AD3500778BB5 /* MetalDataStructures.swift */; }; + 53AC8ABF1D17C11C00778BB5 /* MetalUtilityFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A531D17AD3500778BB5 /* MetalUtilityFunctions.swift */; }; + 53AC8AC01D17C11C00778BB5 /* PoolingLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A541D17AD3500778BB5 /* PoolingLayer.swift */; }; + 53AC8AC11D17C11C00778BB5 /* RectifierLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A551D17AD3500778BB5 /* RectifierLayer.swift */; }; + 53AC8AC21D17C11C00778BB5 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 53AC8A561D17AD3500778BB5 /* Shaders.metal */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -30,14 +54,28 @@ remoteGlobalIDString = 53AC8A331D17AC2000778BB5; remoteInfo = DeepLearningKit; }; + 53AC8A881D17BFF400778BB5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 53AC8A2B1D17AC2000778BB5 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 53AC8A7C1D17BFF400778BB5; + remoteInfo = "DeepLearningKit-OSX"; + }; + 53AC8AA41D17C02E00778BB5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 53AC8A2B1D17AC2000778BB5 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 53AC8A981D17C02E00778BB5; + remoteInfo = "DeepLearningKit-tvOS"; + }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ 53AC8A341D17AC2000778BB5 /* DeepLearningKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DeepLearningKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 53AC8A371D17AC2000778BB5 /* DeepLearningKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeepLearningKit.h; sourceTree = ""; }; 53AC8A391D17AC2000778BB5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 53AC8A3E1D17AC2000778BB5 /* DeepLearningKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DeepLearningKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 53AC8A431D17AC2000778BB5 /* DeepLearningKitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeepLearningKitTests.swift; sourceTree = ""; }; + 53AC8A3E1D17AC2000778BB5 /* DeepLearningKit-iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "DeepLearningKit-iOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + 53AC8A431D17AC2000778BB5 /* DeepLearningKit_iOSTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeepLearningKit_iOSTests.swift; sourceTree = ""; }; 53AC8A451D17AC2000778BB5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 53AC8A4E1D17AD3500778BB5 /* ConvolutionLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConvolutionLayer.swift; sourceTree = ""; }; 53AC8A4F1D17AD3500778BB5 /* DeepNetwork.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeepNetwork.swift; sourceTree = ""; }; @@ -50,6 +88,18 @@ 53AC8A561D17AD3500778BB5 /* Shaders.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Shaders.metal; sourceTree = ""; }; 53AC8A601D17AEDE00778BB5 /* .travis.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .travis.yml; sourceTree = ""; }; 53AC8A611D17AF4300778BB5 /* test */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = test; sourceTree = ""; }; + 53AC8A7D1D17BFF400778BB5 /* DeepLearningKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DeepLearningKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 53AC8A7F1D17BFF400778BB5 /* DeepLearningKit-OSX.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "DeepLearningKit-OSX.h"; sourceTree = ""; }; + 53AC8A811D17BFF400778BB5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 53AC8A861D17BFF400778BB5 /* DeepLearningKit-OSXTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "DeepLearningKit-OSXTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + 53AC8A8B1D17BFF400778BB5 /* DeepLearningKit_OSXTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeepLearningKit_OSXTests.swift; sourceTree = ""; }; + 53AC8A8D1D17BFF400778BB5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 53AC8A991D17C02E00778BB5 /* DeepLearningKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DeepLearningKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 53AC8A9B1D17C02E00778BB5 /* DeepLearningKit-tvOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "DeepLearningKit-tvOS.h"; sourceTree = ""; }; + 53AC8A9D1D17C02E00778BB5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 53AC8AA21D17C02E00778BB5 /* DeepLearningKit-tvOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "DeepLearningKit-tvOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + 53AC8AA71D17C02E00778BB5 /* DeepLearningKit_tvOSTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeepLearningKit_tvOSTests.swift; sourceTree = ""; }; + 53AC8AA91D17C02E00778BB5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -68,6 +118,36 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 53AC8A791D17BFF400778BB5 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 53AC8A831D17BFF400778BB5 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 53AC8A871D17BFF400778BB5 /* DeepLearningKit.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 53AC8A951D17C02E00778BB5 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 53AC8A9F1D17C02E00778BB5 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 53AC8AA31D17C02E00778BB5 /* DeepLearningKit.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -77,7 +157,11 @@ 53AC8A611D17AF4300778BB5 /* test */, 53AC8A601D17AEDE00778BB5 /* .travis.yml */, 53AC8A361D17AC2000778BB5 /* DeepLearningKit */, - 53AC8A421D17AC2000778BB5 /* DeepLearningKitTests */, + 53AC8A421D17AC2000778BB5 /* DeepLearningKit-iOSTests */, + 53AC8A7E1D17BFF400778BB5 /* DeepLearningKit-OSX */, + 53AC8A8A1D17BFF400778BB5 /* DeepLearningKit-OSXTests */, + 53AC8A9A1D17C02E00778BB5 /* DeepLearningKit-tvOS */, + 53AC8AA61D17C02E00778BB5 /* DeepLearningKit-tvOSTests */, 53AC8A351D17AC2000778BB5 /* Products */, ); sourceTree = ""; @@ -86,7 +170,11 @@ isa = PBXGroup; children = ( 53AC8A341D17AC2000778BB5 /* DeepLearningKit.framework */, - 53AC8A3E1D17AC2000778BB5 /* DeepLearningKitTests.xctest */, + 53AC8A3E1D17AC2000778BB5 /* DeepLearningKit-iOSTests.xctest */, + 53AC8A7D1D17BFF400778BB5 /* DeepLearningKit.framework */, + 53AC8A861D17BFF400778BB5 /* DeepLearningKit-OSXTests.xctest */, + 53AC8A991D17C02E00778BB5 /* DeepLearningKit.framework */, + 53AC8AA21D17C02E00778BB5 /* DeepLearningKit-tvOSTests.xctest */, ); name = Products; sourceTree = ""; @@ -95,27 +183,88 @@ isa = PBXGroup; children = ( 53AC8A371D17AC2000778BB5 /* DeepLearningKit.h */, - 53AC8A4F1D17AD3500778BB5 /* DeepNetwork.swift */, + 53AC8AC51D17C7CC00778BB5 /* PUBLIC_API */, + 53AC8AC41D17C7B500778BB5 /* INTERNAL_API */, + 53AC8AC31D17C77B00778BB5 /* GPU_METAL */, + 53AC8A391D17AC2000778BB5 /* Info.plist */, + ); + path = DeepLearningKit; + sourceTree = ""; + }; + 53AC8A421D17AC2000778BB5 /* DeepLearningKit-iOSTests */ = { + isa = PBXGroup; + children = ( + 53AC8A431D17AC2000778BB5 /* DeepLearningKit_iOSTests.swift */, + 53AC8A451D17AC2000778BB5 /* Info.plist */, + ); + name = "DeepLearningKit-iOSTests"; + path = DeepLearningKitTests; + sourceTree = ""; + }; + 53AC8A7E1D17BFF400778BB5 /* DeepLearningKit-OSX */ = { + isa = PBXGroup; + children = ( + 53AC8A7F1D17BFF400778BB5 /* DeepLearningKit-OSX.h */, + 53AC8A811D17BFF400778BB5 /* Info.plist */, + ); + path = "DeepLearningKit-OSX"; + sourceTree = ""; + }; + 53AC8A8A1D17BFF400778BB5 /* DeepLearningKit-OSXTests */ = { + isa = PBXGroup; + children = ( + 53AC8A8B1D17BFF400778BB5 /* DeepLearningKit_OSXTests.swift */, + 53AC8A8D1D17BFF400778BB5 /* Info.plist */, + ); + path = "DeepLearningKit-OSXTests"; + sourceTree = ""; + }; + 53AC8A9A1D17C02E00778BB5 /* DeepLearningKit-tvOS */ = { + isa = PBXGroup; + children = ( + 53AC8A9B1D17C02E00778BB5 /* DeepLearningKit-tvOS.h */, + 53AC8A9D1D17C02E00778BB5 /* Info.plist */, + ); + path = "DeepLearningKit-tvOS"; + sourceTree = ""; + }; + 53AC8AA61D17C02E00778BB5 /* DeepLearningKit-tvOSTests */ = { + isa = PBXGroup; + children = ( + 53AC8AA71D17C02E00778BB5 /* DeepLearningKit_tvOSTests.swift */, + 53AC8AA91D17C02E00778BB5 /* Info.plist */, + ); + path = "DeepLearningKit-tvOSTests"; + sourceTree = ""; + }; + 53AC8AC31D17C77B00778BB5 /* GPU_METAL */ = { + isa = PBXGroup; + children = ( + 53AC8A521D17AD3500778BB5 /* MetalDataStructures.swift */, + 53AC8A531D17AD3500778BB5 /* MetalUtilityFunctions.swift */, + 53AC8A561D17AD3500778BB5 /* Shaders.metal */, + ); + name = GPU_METAL; + sourceTree = ""; + }; + 53AC8AC41D17C7B500778BB5 /* INTERNAL_API */ = { + isa = PBXGroup; + children = ( 53AC8A4E1D17AD3500778BB5 /* ConvolutionLayer.swift */, 53AC8A501D17AD3500778BB5 /* DeepNetwork+JSON.swift */, 53AC8A511D17AD3500778BB5 /* DeepNetwork+SetupNetworkFromDict.swift */, - 53AC8A521D17AD3500778BB5 /* MetalDataStructures.swift */, - 53AC8A531D17AD3500778BB5 /* MetalUtilityFunctions.swift */, 53AC8A541D17AD3500778BB5 /* PoolingLayer.swift */, 53AC8A551D17AD3500778BB5 /* RectifierLayer.swift */, - 53AC8A561D17AD3500778BB5 /* Shaders.metal */, - 53AC8A391D17AC2000778BB5 /* Info.plist */, ); - path = DeepLearningKit; + name = INTERNAL_API; sourceTree = ""; }; - 53AC8A421D17AC2000778BB5 /* DeepLearningKitTests */ = { + 53AC8AC51D17C7CC00778BB5 /* PUBLIC_API */ = { isa = PBXGroup; children = ( - 53AC8A431D17AC2000778BB5 /* DeepLearningKitTests.swift */, - 53AC8A451D17AC2000778BB5 /* Info.plist */, + 53AC8A4F1D17AD3500778BB5 /* DeepNetwork.swift */, ); - path = DeepLearningKitTests; + name = PUBLIC_API; sourceTree = ""; }; /* End PBXGroup section */ @@ -129,12 +278,28 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 53AC8A7A1D17BFF400778BB5 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 53AC8A801D17BFF400778BB5 /* DeepLearningKit-OSX.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 53AC8A961D17C02E00778BB5 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 53AC8A9C1D17C02E00778BB5 /* DeepLearningKit-tvOS.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ - 53AC8A331D17AC2000778BB5 /* DeepLearningKit */ = { + 53AC8A331D17AC2000778BB5 /* DeepLearningKit-iOS */ = { isa = PBXNativeTarget; - buildConfigurationList = 53AC8A481D17AC2000778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit" */; + buildConfigurationList = 53AC8A481D17AC2000778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit-iOS" */; buildPhases = ( 53AC8A2F1D17AC2000778BB5 /* Sources */, 53AC8A301D17AC2000778BB5 /* Frameworks */, @@ -145,14 +310,14 @@ ); dependencies = ( ); - name = DeepLearningKit; + name = "DeepLearningKit-iOS"; productName = DeepLearningKit; productReference = 53AC8A341D17AC2000778BB5 /* DeepLearningKit.framework */; productType = "com.apple.product-type.framework"; }; - 53AC8A3D1D17AC2000778BB5 /* DeepLearningKitTests */ = { + 53AC8A3D1D17AC2000778BB5 /* DeepLearningKit-iOSTests */ = { isa = PBXNativeTarget; - buildConfigurationList = 53AC8A4B1D17AC2000778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKitTests" */; + buildConfigurationList = 53AC8A4B1D17AC2000778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit-iOSTests" */; buildPhases = ( 53AC8A3A1D17AC2000778BB5 /* Sources */, 53AC8A3B1D17AC2000778BB5 /* Frameworks */, @@ -163,9 +328,81 @@ dependencies = ( 53AC8A411D17AC2000778BB5 /* PBXTargetDependency */, ); - name = DeepLearningKitTests; + name = "DeepLearningKit-iOSTests"; productName = DeepLearningKitTests; - productReference = 53AC8A3E1D17AC2000778BB5 /* DeepLearningKitTests.xctest */; + productReference = 53AC8A3E1D17AC2000778BB5 /* DeepLearningKit-iOSTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + 53AC8A7C1D17BFF400778BB5 /* DeepLearningKit-OSX */ = { + isa = PBXNativeTarget; + buildConfigurationList = 53AC8A8E1D17BFF400778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit-OSX" */; + buildPhases = ( + 53AC8A781D17BFF400778BB5 /* Sources */, + 53AC8A791D17BFF400778BB5 /* Frameworks */, + 53AC8A7A1D17BFF400778BB5 /* Headers */, + 53AC8A7B1D17BFF400778BB5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "DeepLearningKit-OSX"; + productName = "DeepLearningKit-OSX"; + productReference = 53AC8A7D1D17BFF400778BB5 /* DeepLearningKit.framework */; + productType = "com.apple.product-type.framework"; + }; + 53AC8A851D17BFF400778BB5 /* DeepLearningKit-OSXTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 53AC8A911D17BFF400778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit-OSXTests" */; + buildPhases = ( + 53AC8A821D17BFF400778BB5 /* Sources */, + 53AC8A831D17BFF400778BB5 /* Frameworks */, + 53AC8A841D17BFF400778BB5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 53AC8A891D17BFF400778BB5 /* PBXTargetDependency */, + ); + name = "DeepLearningKit-OSXTests"; + productName = "DeepLearningKit-OSXTests"; + productReference = 53AC8A861D17BFF400778BB5 /* DeepLearningKit-OSXTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + 53AC8A981D17C02E00778BB5 /* DeepLearningKit-tvOS */ = { + isa = PBXNativeTarget; + buildConfigurationList = 53AC8AAA1D17C02E00778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit-tvOS" */; + buildPhases = ( + 53AC8A941D17C02E00778BB5 /* Sources */, + 53AC8A951D17C02E00778BB5 /* Frameworks */, + 53AC8A961D17C02E00778BB5 /* Headers */, + 53AC8A971D17C02E00778BB5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "DeepLearningKit-tvOS"; + productName = "DeepLearningKit-tvOS"; + productReference = 53AC8A991D17C02E00778BB5 /* DeepLearningKit.framework */; + productType = "com.apple.product-type.framework"; + }; + 53AC8AA11D17C02E00778BB5 /* DeepLearningKit-tvOSTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 53AC8AAD1D17C02E00778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit-tvOSTests" */; + buildPhases = ( + 53AC8A9E1D17C02E00778BB5 /* Sources */, + 53AC8A9F1D17C02E00778BB5 /* Frameworks */, + 53AC8AA01D17C02E00778BB5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 53AC8AA51D17C02E00778BB5 /* PBXTargetDependency */, + ); + name = "DeepLearningKit-tvOSTests"; + productName = "DeepLearningKit-tvOSTests"; + productReference = 53AC8AA21D17C02E00778BB5 /* DeepLearningKit-tvOSTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; /* End PBXNativeTarget section */ @@ -184,6 +421,18 @@ 53AC8A3D1D17AC2000778BB5 = { CreatedOnToolsVersion = 7.3.1; }; + 53AC8A7C1D17BFF400778BB5 = { + CreatedOnToolsVersion = 7.3.1; + }; + 53AC8A851D17BFF400778BB5 = { + CreatedOnToolsVersion = 7.3.1; + }; + 53AC8A981D17C02E00778BB5 = { + CreatedOnToolsVersion = 7.3.1; + }; + 53AC8AA11D17C02E00778BB5 = { + CreatedOnToolsVersion = 7.3.1; + }; }; }; buildConfigurationList = 53AC8A2E1D17AC2000778BB5 /* Build configuration list for PBXProject "DeepLearningKit" */; @@ -198,8 +447,12 @@ projectDirPath = ""; projectRoot = ""; targets = ( - 53AC8A331D17AC2000778BB5 /* DeepLearningKit */, - 53AC8A3D1D17AC2000778BB5 /* DeepLearningKitTests */, + 53AC8A331D17AC2000778BB5 /* DeepLearningKit-iOS */, + 53AC8A3D1D17AC2000778BB5 /* DeepLearningKit-iOSTests */, + 53AC8A7C1D17BFF400778BB5 /* DeepLearningKit-OSX */, + 53AC8A851D17BFF400778BB5 /* DeepLearningKit-OSXTests */, + 53AC8A981D17C02E00778BB5 /* DeepLearningKit-tvOS */, + 53AC8AA11D17C02E00778BB5 /* DeepLearningKit-tvOSTests */, ); }; /* End PBXProject section */ @@ -220,6 +473,34 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 53AC8A7B1D17BFF400778BB5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 53AC8A841D17BFF400778BB5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 53AC8A971D17C02E00778BB5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 53AC8AA01D17C02E00778BB5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -227,13 +508,13 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 53AC8A5F1D17AD3500778BB5 /* Shaders.metal in Sources */, 53AC8A581D17AD3500778BB5 /* DeepNetwork.swift in Sources */, 53AC8A5E1D17AD3500778BB5 /* RectifierLayer.swift in Sources */, 53AC8A5B1D17AD3500778BB5 /* MetalDataStructures.swift in Sources */, 53AC8A591D17AD3500778BB5 /* DeepNetwork+JSON.swift in Sources */, 53AC8A5D1D17AD3500778BB5 /* PoolingLayer.swift in Sources */, 53AC8A571D17AD3500778BB5 /* ConvolutionLayer.swift in Sources */, - 53AC8A5F1D17AD3500778BB5 /* Shaders.metal in Sources */, 53AC8A5C1D17AD3500778BB5 /* MetalUtilityFunctions.swift in Sources */, 53AC8A5A1D17AD3500778BB5 /* DeepNetwork+SetupNetworkFromDict.swift in Sources */, ); @@ -243,7 +524,55 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 53AC8A441D17AC2000778BB5 /* DeepLearningKitTests.swift in Sources */, + 53AC8A441D17AC2000778BB5 /* DeepLearningKit_iOSTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 53AC8A781D17BFF400778BB5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 53AC8AB91D17C10400778BB5 /* Shaders.metal in Sources */, + 53AC8AB11D17C10400778BB5 /* DeepNetwork.swift in Sources */, + 53AC8AB21D17C10400778BB5 /* ConvolutionLayer.swift in Sources */, + 53AC8AB31D17C10400778BB5 /* DeepNetwork+JSON.swift in Sources */, + 53AC8AB41D17C10400778BB5 /* DeepNetwork+SetupNetworkFromDict.swift in Sources */, + 53AC8AB51D17C10400778BB5 /* MetalDataStructures.swift in Sources */, + 53AC8AB61D17C10400778BB5 /* MetalUtilityFunctions.swift in Sources */, + 53AC8AB71D17C10400778BB5 /* PoolingLayer.swift in Sources */, + 53AC8AB81D17C10400778BB5 /* RectifierLayer.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 53AC8A821D17BFF400778BB5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 53AC8A8C1D17BFF400778BB5 /* DeepLearningKit_OSXTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 53AC8A941D17C02E00778BB5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 53AC8AC21D17C11C00778BB5 /* Shaders.metal in Sources */, + 53AC8ABA1D17C11C00778BB5 /* DeepNetwork.swift in Sources */, + 53AC8ABB1D17C11C00778BB5 /* ConvolutionLayer.swift in Sources */, + 53AC8ABC1D17C11C00778BB5 /* DeepNetwork+JSON.swift in Sources */, + 53AC8ABD1D17C11C00778BB5 /* DeepNetwork+SetupNetworkFromDict.swift in Sources */, + 53AC8ABE1D17C11C00778BB5 /* MetalDataStructures.swift in Sources */, + 53AC8ABF1D17C11C00778BB5 /* MetalUtilityFunctions.swift in Sources */, + 53AC8AC01D17C11C00778BB5 /* PoolingLayer.swift in Sources */, + 53AC8AC11D17C11C00778BB5 /* RectifierLayer.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 53AC8A9E1D17C02E00778BB5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 53AC8AA81D17C02E00778BB5 /* DeepLearningKit_tvOSTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -252,9 +581,19 @@ /* Begin PBXTargetDependency section */ 53AC8A411D17AC2000778BB5 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = 53AC8A331D17AC2000778BB5 /* DeepLearningKit */; + target = 53AC8A331D17AC2000778BB5 /* DeepLearningKit-iOS */; targetProxy = 53AC8A401D17AC2000778BB5 /* PBXContainerItemProxy */; }; + 53AC8A891D17BFF400778BB5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 53AC8A7C1D17BFF400778BB5 /* DeepLearningKit-OSX */; + targetProxy = 53AC8A881D17BFF400778BB5 /* PBXContainerItemProxy */; + }; + 53AC8AA51D17C02E00778BB5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 53AC8A981D17C02E00778BB5 /* DeepLearningKit-tvOS */; + targetProxy = 53AC8AA41D17C02E00778BB5 /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ @@ -361,8 +700,8 @@ INFOPLIST_FILE = DeepLearningKit/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = nz.co.iswe.labs.DeepLearningKit; - PRODUCT_NAME = "$(TARGET_NAME)"; + PRODUCT_BUNDLE_IDENTIFIER = "nz.co.iswe.labs.DeepLearningKit-iOS"; + PRODUCT_NAME = DeepLearningKit; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; @@ -380,8 +719,8 @@ INFOPLIST_FILE = DeepLearningKit/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = nz.co.iswe.labs.DeepLearningKit; - PRODUCT_NAME = "$(TARGET_NAME)"; + PRODUCT_BUNDLE_IDENTIFIER = "nz.co.iswe.labs.DeepLearningKit-iOS"; + PRODUCT_NAME = DeepLearningKit; SKIP_INSTALL = YES; }; name = Release; @@ -406,6 +745,140 @@ }; name = Release; }; + 53AC8A8F1D17BFF400778BB5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; + CODE_SIGN_IDENTITY = "-"; + COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + INFOPLIST_FILE = "DeepLearningKit-OSX/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.11; + PRODUCT_BUNDLE_IDENTIFIER = "nz.co.iswe.labs.DeepLearningKit-OSX"; + PRODUCT_NAME = DeepLearningKit; + SDKROOT = macosx; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 53AC8A901D17BFF400778BB5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; + CODE_SIGN_IDENTITY = "-"; + COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + INFOPLIST_FILE = "DeepLearningKit-OSX/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.11; + PRODUCT_BUNDLE_IDENTIFIER = "nz.co.iswe.labs.DeepLearningKit-OSX"; + PRODUCT_NAME = DeepLearningKit; + SDKROOT = macosx; + SKIP_INSTALL = YES; + }; + name = Release; + }; + 53AC8A921D17BFF400778BB5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_IDENTITY = "-"; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = "DeepLearningKit-OSXTests/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.11; + PRODUCT_BUNDLE_IDENTIFIER = "nz.co.iswe.labs.DeepLearningKit-OSXTests"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + }; + name = Debug; + }; + 53AC8A931D17BFF400778BB5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_IDENTITY = "-"; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = "DeepLearningKit-OSXTests/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.11; + PRODUCT_BUNDLE_IDENTIFIER = "nz.co.iswe.labs.DeepLearningKit-OSXTests"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + }; + name = Release; + }; + 53AC8AAB1D17C02E00778BB5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = "DeepLearningKit-tvOS/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "nz.co.iswe.labs.DeepLearningKit-tvOS"; + PRODUCT_NAME = DeepLearningKit; + SDKROOT = appletvos; + SKIP_INSTALL = YES; + TARGETED_DEVICE_FAMILY = 3; + TVOS_DEPLOYMENT_TARGET = 9.2; + }; + name = Debug; + }; + 53AC8AAC1D17C02E00778BB5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = "DeepLearningKit-tvOS/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "nz.co.iswe.labs.DeepLearningKit-tvOS"; + PRODUCT_NAME = DeepLearningKit; + SDKROOT = appletvos; + SKIP_INSTALL = YES; + TARGETED_DEVICE_FAMILY = 3; + TVOS_DEPLOYMENT_TARGET = 9.2; + }; + name = Release; + }; + 53AC8AAE1D17C02E00778BB5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + INFOPLIST_FILE = "DeepLearningKit-tvOSTests/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "nz.co.iswe.labs.DeepLearningKit-tvOSTests"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = appletvos; + TVOS_DEPLOYMENT_TARGET = 9.2; + }; + name = Debug; + }; + 53AC8AAF1D17C02E00778BB5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + INFOPLIST_FILE = "DeepLearningKit-tvOSTests/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "nz.co.iswe.labs.DeepLearningKit-tvOSTests"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = appletvos; + TVOS_DEPLOYMENT_TARGET = 9.2; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -418,7 +891,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 53AC8A481D17AC2000778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit" */ = { + 53AC8A481D17AC2000778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit-iOS" */ = { isa = XCConfigurationList; buildConfigurations = ( 53AC8A491D17AC2000778BB5 /* Debug */, @@ -427,7 +900,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 53AC8A4B1D17AC2000778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKitTests" */ = { + 53AC8A4B1D17AC2000778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit-iOSTests" */ = { isa = XCConfigurationList; buildConfigurations = ( 53AC8A4C1D17AC2000778BB5 /* Debug */, @@ -436,6 +909,38 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 53AC8A8E1D17BFF400778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit-OSX" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 53AC8A8F1D17BFF400778BB5 /* Debug */, + 53AC8A901D17BFF400778BB5 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; + 53AC8A911D17BFF400778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit-OSXTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 53AC8A921D17BFF400778BB5 /* Debug */, + 53AC8A931D17BFF400778BB5 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; + 53AC8AAA1D17C02E00778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit-tvOS" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 53AC8AAB1D17C02E00778BB5 /* Debug */, + 53AC8AAC1D17C02E00778BB5 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; + 53AC8AAD1D17C02E00778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit-tvOSTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 53AC8AAE1D17C02E00778BB5 /* Debug */, + 53AC8AAF1D17C02E00778BB5 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; /* End XCConfigurationList section */ }; rootObject = 53AC8A2B1D17AC2000778BB5 /* Project object */; diff --git a/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-OSX.xcscheme b/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-OSX.xcscheme new file mode 100644 index 0000000..7e31cfc --- /dev/null +++ b/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-OSX.xcscheme @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit.xcscheme b/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-iOS.xcscheme similarity index 91% rename from DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit.xcscheme rename to DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-iOS.xcscheme index 883e04d..d25ebb9 100644 --- a/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit.xcscheme +++ b/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-iOS.xcscheme @@ -16,7 +16,7 @@ BuildableIdentifier = "primary" BlueprintIdentifier = "53AC8A331D17AC2000778BB5" BuildableName = "DeepLearningKit.framework" - BlueprintName = "DeepLearningKit" + BlueprintName = "DeepLearningKit-iOS" ReferencedContainer = "container:DeepLearningKit.xcodeproj"> @@ -33,8 +33,8 @@ @@ -44,7 +44,7 @@ BuildableIdentifier = "primary" BlueprintIdentifier = "53AC8A331D17AC2000778BB5" BuildableName = "DeepLearningKit.framework" - BlueprintName = "DeepLearningKit" + BlueprintName = "DeepLearningKit-iOS" ReferencedContainer = "container:DeepLearningKit.xcodeproj"> @@ -66,7 +66,7 @@ BuildableIdentifier = "primary" BlueprintIdentifier = "53AC8A331D17AC2000778BB5" BuildableName = "DeepLearningKit.framework" - BlueprintName = "DeepLearningKit" + BlueprintName = "DeepLearningKit-iOS" ReferencedContainer = "container:DeepLearningKit.xcodeproj"> @@ -84,7 +84,7 @@ BuildableIdentifier = "primary" BlueprintIdentifier = "53AC8A331D17AC2000778BB5" BuildableName = "DeepLearningKit.framework" - BlueprintName = "DeepLearningKit" + BlueprintName = "DeepLearningKit-iOS" ReferencedContainer = "container:DeepLearningKit.xcodeproj"> diff --git a/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-tvOS.xcscheme b/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-tvOS.xcscheme new file mode 100644 index 0000000..3c41f56 --- /dev/null +++ b/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-tvOS.xcscheme @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DeepLearningKit.xcworkspace/contents.xcworkspacedata b/DeepLearningKit.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..9ab4d92 --- /dev/null +++ b/DeepLearningKit.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/DeepLearningKitTests/DeepLearningKit_iOSTests.swift b/DeepLearningKitTests/DeepLearningKit_iOSTests.swift new file mode 100644 index 0000000..e57aa81 --- /dev/null +++ b/DeepLearningKitTests/DeepLearningKit_iOSTests.swift @@ -0,0 +1,37 @@ +// +// DeepLearningKitTests.swift +// DeepLearningKitTests +// +// Created by Rafael Almeida on 20/06/16. +// Copyright © 2016 DeepLearningKit. All rights reserved. +// + +import XCTest +@testable import DeepLearningKit + +class DeepLearningKit_iOSTests: XCTestCase { + + override func setUp() { + super.setUp() + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testExample() { + //Metal not available in simulator + //let deepNetwork = DeepNetwork() + //XCTAssertNotNil(deepNetwork) + } + + func testPerformanceExample() { + // This is an example of a performance test case. + self.measureBlock { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/test b/test index d1b4a7b..9a4b85a 100755 --- a/test +++ b/test @@ -7,13 +7,13 @@ function xcode_tests { set -e; set -x; # print commands executed; use subshell to avoid having to print 'set +x' to disable it # Run Tests via OS X - xcodebuild test -workspace Snorlax.xcworkspace -scheme Snorlax-OSX -destination "platform=OS X" && + xcodebuild test -workspace DeepLearningKit.xcworkspace -scheme DeepLearningKit-OSX -destination "platform=OS X" && # Run Tests via iOS - xcodebuild test -workspace Snorlax.xcworkspace -scheme Snorlax-iOS -destination "platform=iOS Simulator,name=iPhone 6,OS=9.2" && + xcodebuild test -workspace DeepLearningKit.xcworkspace -scheme DeepLearningKit-iOS -destination "platform=iOS Simulator,name=iPhone 6,OS=9.2" && # Run Tests via tvOS - xcodebuild test -workspace Snorlax.xcworkspace -scheme Snorlax-tvOS -destination "platform=tvOS Simulator,name=Apple TV 1080p,OS=9.1" + xcodebuild test -workspace DeepLearningKit.xcworkspace -scheme DeepLearningKit-tvOS -destination "platform=tvOS Simulator,name=Apple TV 1080p,OS=9.1" ) echo echo "Xcode tests passed" From 412f5c9993df736e326543088e2b60b6ba19d6b1 Mon Sep 17 00:00:00 2001 From: Rafael Almeida Date: Mon, 20 Jun 2016 18:58:58 +1200 Subject: [PATCH 07/10] chore (Examples) moved example projects --- .../project.pbxproj | 461 ----------------- .../contents.xcworkspacedata | 7 - .../ConvolutionLayer.swift | 237 --------- .../DeepLearningKitForOSX.h | 19 - .../DeepNetwork+JSON.swift | 26 - .../DeepNetwork+SetupNetworkFromDict.swift | 86 ---- .../DeepLearningKitForOSX/DeepNetwork.swift | 76 --- .../DeepLearningKitForOSX/Info.plist | 28 - .../MetalDataStructures.swift | 62 --- .../MetalUtilityFunctions.swift | 173 ------- .../DeepLearningKitForOSX/PoolingLayer.swift | 141 ----- .../RectifierLayer.swift | 53 -- .../DeepLearningKitForOSX/Shaders.metal | 224 -------- .../DeepLearningKitForOSXTests.swift | 36 -- .../DeepLearningKitForOSXTests/Info.plist | 24 - .../project.pbxproj | 484 ------------------ .../contents.xcworkspacedata | 7 - .../ConvolutionLayer.swift | 237 --------- .../DeepLearningKitForiOS.h | 19 - .../DeepNetwork+JSON.swift | 26 - .../DeepNetwork+SetupNetworkFromDict.swift | 86 ---- .../DeepLearningKitForiOS/DeepNetwork.swift | 76 --- .../DeepLearningKitForiOS/Info.plist | 26 - .../MetalDataStructures.swift | 62 --- .../MetalUtilityFunctions.swift | 173 ------- .../DeepLearningKitForiOS/PoolingLayer.swift | 141 ----- .../RectifierLayer.swift | 53 -- .../DeepLearningKitForiOS/Shaders.metal | 224 -------- .../ViewController.swift | 41 -- .../DeepLearningKitForiOSTests.swift | 36 -- .../DeepLearningKitForiOSTests/Info.plist | 24 - .../project.pbxproj | 458 ----------------- .../contents.xcworkspacedata | 7 - .../ConvolutionLayer.swift | 237 --------- .../DeepLearningKitFortvOS.h | 19 - .../DeepNetwork+JSON.swift | 26 - .../DeepNetwork+SetupNetworkFromDict.swift | 86 ---- .../DeepLearningKitFortvOS/DeepNetwork.swift | 76 --- .../DeepLearningKitFortvOS/Info.plist | 26 - .../MetalDataStructures.swift | 62 --- .../MetalUtilityFunctions.swift | 173 ------- .../DeepLearningKitFortvOS/PoolingLayer.swift | 141 ----- .../RectifierLayer.swift | 53 -- .../DeepLearningKitFortvOS/Shaders.metal | 224 -------- .../DeepLearningKitFortvOSTests.swift | 36 -- .../DeepLearningKitFortvOSTests/Info.plist | 24 - .../DeepLearningKit_iOSTests.swift | 37 -- DeepLearningKitTests/Info.plist | 24 - .../project.pbxproj | 0 .../contents.xcworkspacedata | 0 .../OSXDeepLearningKitApp/AppDelegate.swift | 0 .../AppIcon.appiconset/Contents.json | 0 .../Base.lproj/Main.storyboard | 0 .../ConvolutionLayer.swift | 0 .../DeepNetwork+Classify.swift | 0 .../DeepNetwork+JSON.swift | 0 .../DeepNetwork+SetupNetworkFromDict.swift | 0 .../OSXDeepLearningKitApp/DeepNetwork.swift | 0 .../OSXDeepLearningKitApp/Info.plist | 0 .../MetalDataStructures.swift | 0 .../MetalUtilityFunctions.swift | 0 .../OSXDeepLearningKitApp/PoolingLayer.swift | 0 .../RectifierLayer.swift | 0 .../OSXDeepLearningKitApp/Shaders.metal | 0 .../ViewController.swift | 0 .../OSXDeepLearningKitApp/conv1.json | 0 .../nin_cifar10_full.json | 0 .../project.pbxproj | 0 .../contents.xcworkspacedata | 0 .../iOSDeepLearningKitApp/AppDelegate.swift | 0 .../AppIcon.appiconset/Contents.json | 0 .../Base.lproj/LaunchScreen.storyboard | 0 .../Base.lproj/Main.storyboard | 0 .../ConvolutionLayer.swift | 0 .../DeepNetwork+Classify.swift | 0 .../DeepNetwork+JSON.swift | 0 .../DeepNetwork+SetupNetworkFromDict.swift | 0 .../iOSDeepLearningKitApp/DeepNetwork.swift | 0 .../ImageUtilityFunctions.swift | 0 .../iOSDeepLearningKitApp/Info.plist | 0 .../MetalDataStructures.swift | 0 .../MetalUtilityFunctions.swift | 0 .../iOSDeepLearningKitApp/PoolingLayer.swift | 0 .../RectifierLayer.swift | 0 .../iOSDeepLearningKitApp/Shaders.metal | 0 .../UIImageExtension.swift | 0 .../ViewController.swift | 0 .../iOSDeepLearningKitApp/conv1.json | 0 .../nin_cifar10_full.json | 0 .../iOSDeepLearningKitApp/pool1.json | 0 .../project.pbxproj | 0 .../contents.xcworkspacedata | 0 .../tvOSDeepLearningKitApp/AppDelegate.swift | 0 .../Content.imageset/Contents.json | 0 .../Back.imagestacklayer/Contents.json | 0 .../App Icon - Large.imagestack/Contents.json | 0 .../Content.imageset/Contents.json | 0 .../Front.imagestacklayer/Contents.json | 0 .../Content.imageset/Contents.json | 0 .../Middle.imagestacklayer/Contents.json | 0 .../Content.imageset/Contents.json | 0 .../Back.imagestacklayer/Contents.json | 0 .../App Icon - Small.imagestack/Contents.json | 0 .../Content.imageset/Contents.json | 0 .../Front.imagestacklayer/Contents.json | 0 .../Content.imageset/Contents.json | 0 .../Middle.imagestacklayer/Contents.json | 0 .../Contents.json | 0 .../Top Shelf Image.imageset/Contents.json | 0 .../Assets.xcassets/Contents.json | 0 .../LaunchImage.launchimage/Contents.json | 0 .../Base.lproj/Main.storyboard | 0 .../ConvolutionLayer.swift | 0 .../DeepNetwork+Classify.swift | 0 .../DeepNetwork+JSON.swift | 0 .../DeepNetwork+SetupNetworkFromDict.swift | 0 .../tvOSDeepLearningKitApp/DeepNetwork.swift | 0 .../ImageUtilityFunctions.swift | 0 .../tvOSDeepLearningKitApp/Info.plist | 0 .../MetalDataStructures.swift | 0 .../MetalUtilityFunctions.swift | 0 .../tvOSDeepLearningKitApp/PoolingLayer.swift | 0 .../RectifierLayer.swift | 0 .../tvOSDeepLearningKitApp/Shaders.metal | 0 .../UIImageExtension.swift | 0 .../ViewController.swift | 0 .../tvOSDeepLearningKitApp/conv1.json | 0 .../nin_cifar10_full.json | 0 128 files changed, 5077 deletions(-) delete mode 100644 DeepLearningKitForOSX/DeepLearningKitForOSX.xcodeproj/project.pbxproj delete mode 100644 DeepLearningKitForOSX/DeepLearningKitForOSX.xcodeproj/project.xcworkspace/contents.xcworkspacedata delete mode 100644 DeepLearningKitForOSX/DeepLearningKitForOSX/ConvolutionLayer.swift delete mode 100644 DeepLearningKitForOSX/DeepLearningKitForOSX/DeepLearningKitForOSX.h delete mode 100644 DeepLearningKitForOSX/DeepLearningKitForOSX/DeepNetwork+JSON.swift delete mode 100644 DeepLearningKitForOSX/DeepLearningKitForOSX/DeepNetwork+SetupNetworkFromDict.swift delete mode 100644 DeepLearningKitForOSX/DeepLearningKitForOSX/DeepNetwork.swift delete mode 100644 DeepLearningKitForOSX/DeepLearningKitForOSX/Info.plist delete mode 100644 DeepLearningKitForOSX/DeepLearningKitForOSX/MetalDataStructures.swift delete mode 100644 DeepLearningKitForOSX/DeepLearningKitForOSX/MetalUtilityFunctions.swift delete mode 100644 DeepLearningKitForOSX/DeepLearningKitForOSX/PoolingLayer.swift delete mode 100644 DeepLearningKitForOSX/DeepLearningKitForOSX/RectifierLayer.swift delete mode 100644 DeepLearningKitForOSX/DeepLearningKitForOSX/Shaders.metal delete mode 100644 DeepLearningKitForOSX/DeepLearningKitForOSXTests/DeepLearningKitForOSXTests.swift delete mode 100644 DeepLearningKitForOSX/DeepLearningKitForOSXTests/Info.plist delete mode 100644 DeepLearningKitForiOS/DeepLearningKitForiOS.xcodeproj/project.pbxproj delete mode 100644 DeepLearningKitForiOS/DeepLearningKitForiOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata delete mode 100644 DeepLearningKitForiOS/DeepLearningKitForiOS/ConvolutionLayer.swift delete mode 100644 DeepLearningKitForiOS/DeepLearningKitForiOS/DeepLearningKitForiOS.h delete mode 100644 DeepLearningKitForiOS/DeepLearningKitForiOS/DeepNetwork+JSON.swift delete mode 100644 DeepLearningKitForiOS/DeepLearningKitForiOS/DeepNetwork+SetupNetworkFromDict.swift delete mode 100644 DeepLearningKitForiOS/DeepLearningKitForiOS/DeepNetwork.swift delete mode 100644 DeepLearningKitForiOS/DeepLearningKitForiOS/Info.plist delete mode 100644 DeepLearningKitForiOS/DeepLearningKitForiOS/MetalDataStructures.swift delete mode 100644 DeepLearningKitForiOS/DeepLearningKitForiOS/MetalUtilityFunctions.swift delete mode 100644 DeepLearningKitForiOS/DeepLearningKitForiOS/PoolingLayer.swift delete mode 100644 DeepLearningKitForiOS/DeepLearningKitForiOS/RectifierLayer.swift delete mode 100644 DeepLearningKitForiOS/DeepLearningKitForiOS/Shaders.metal delete mode 100644 DeepLearningKitForiOS/DeepLearningKitForiOS/ViewController.swift delete mode 100644 DeepLearningKitForiOS/DeepLearningKitForiOSTests/DeepLearningKitForiOSTests.swift delete mode 100644 DeepLearningKitForiOS/DeepLearningKitForiOSTests/Info.plist delete mode 100644 DeepLearningKitFortvOS/DeepLearningKitFortvOS.xcodeproj/project.pbxproj delete mode 100644 DeepLearningKitFortvOS/DeepLearningKitFortvOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata delete mode 100644 DeepLearningKitFortvOS/DeepLearningKitFortvOS/ConvolutionLayer.swift delete mode 100644 DeepLearningKitFortvOS/DeepLearningKitFortvOS/DeepLearningKitFortvOS.h delete mode 100644 DeepLearningKitFortvOS/DeepLearningKitFortvOS/DeepNetwork+JSON.swift delete mode 100644 DeepLearningKitFortvOS/DeepLearningKitFortvOS/DeepNetwork+SetupNetworkFromDict.swift delete mode 100644 DeepLearningKitFortvOS/DeepLearningKitFortvOS/DeepNetwork.swift delete mode 100644 DeepLearningKitFortvOS/DeepLearningKitFortvOS/Info.plist delete mode 100644 DeepLearningKitFortvOS/DeepLearningKitFortvOS/MetalDataStructures.swift delete mode 100644 DeepLearningKitFortvOS/DeepLearningKitFortvOS/MetalUtilityFunctions.swift delete mode 100644 DeepLearningKitFortvOS/DeepLearningKitFortvOS/PoolingLayer.swift delete mode 100644 DeepLearningKitFortvOS/DeepLearningKitFortvOS/RectifierLayer.swift delete mode 100644 DeepLearningKitFortvOS/DeepLearningKitFortvOS/Shaders.metal delete mode 100644 DeepLearningKitFortvOS/DeepLearningKitFortvOSTests/DeepLearningKitFortvOSTests.swift delete mode 100644 DeepLearningKitFortvOS/DeepLearningKitFortvOSTests/Info.plist delete mode 100644 DeepLearningKitTests/DeepLearningKit_iOSTests.swift delete mode 100644 DeepLearningKitTests/Info.plist rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.pbxproj (100%) rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata (100%) rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp/AppDelegate.swift (100%) rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Assets.xcassets/AppIcon.appiconset/Contents.json (100%) rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Base.lproj/Main.storyboard (100%) rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp/ConvolutionLayer.swift (100%) rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+Classify.swift (100%) rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+JSON.swift (100%) rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift (100%) rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork.swift (100%) rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Info.plist (100%) rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp/MetalDataStructures.swift (100%) rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp/MetalUtilityFunctions.swift (100%) rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp/PoolingLayer.swift (100%) rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp/RectifierLayer.swift (100%) rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Shaders.metal (100%) rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp/ViewController.swift (100%) rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp/conv1.json (100%) rename {OSXDeepLearningKitApp => Examples/OSXDeepLearningKitApp}/OSXDeepLearningKitApp/OSXDeepLearningKitApp/nin_cifar10_full.json (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp.xcodeproj/project.pbxproj (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/AppDelegate.swift (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Assets.xcassets/AppIcon.appiconset/Contents.json (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Base.lproj/LaunchScreen.storyboard (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Base.lproj/Main.storyboard (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ConvolutionLayer.swift (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+Classify.swift (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+JSON.swift (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork.swift (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ImageUtilityFunctions.swift (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Info.plist (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/MetalDataStructures.swift (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/MetalUtilityFunctions.swift (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/PoolingLayer.swift (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/RectifierLayer.swift (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Shaders.metal (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/UIImageExtension.swift (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ViewController.swift (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/conv1.json (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/nin_cifar10_full.json (100%) rename {iOSDeepLearningKitApp => Examples/iOSDeepLearningKitApp}/iOSDeepLearningKitApp/iOSDeepLearningKitApp/pool1.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp.xcodeproj/project.pbxproj (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/AppDelegate.swift (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Content.imageset/Contents.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Contents.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Contents.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Content.imageset/Contents.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Contents.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Contents.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Content.imageset/Contents.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Contents.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Contents.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Contents.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image.imageset/Contents.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/Contents.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/LaunchImage.launchimage/Contents.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Base.lproj/Main.storyboard (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ConvolutionLayer.swift (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+Classify.swift (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+JSON.swift (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork.swift (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ImageUtilityFunctions.swift (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Info.plist (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/MetalDataStructures.swift (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/MetalUtilityFunctions.swift (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/PoolingLayer.swift (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/RectifierLayer.swift (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Shaders.metal (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/UIImageExtension.swift (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ViewController.swift (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/conv1.json (100%) rename {tvOSDeepLearningKitApp => Examples/tvOSDeepLearningKitApp}/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/nin_cifar10_full.json (100%) diff --git a/DeepLearningKitForOSX/DeepLearningKitForOSX.xcodeproj/project.pbxproj b/DeepLearningKitForOSX/DeepLearningKitForOSX.xcodeproj/project.pbxproj deleted file mode 100644 index a0c4044..0000000 --- a/DeepLearningKitForOSX/DeepLearningKitForOSX.xcodeproj/project.pbxproj +++ /dev/null @@ -1,461 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 67A73D431C1B0AAE001FD9F8 /* DeepLearningKitForOSX.h in Headers */ = {isa = PBXBuildFile; fileRef = 67A73D421C1B0AAE001FD9F8 /* DeepLearningKitForOSX.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 67A73D4A1C1B0AAE001FD9F8 /* DeepLearningKitForOSX.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 67A73D3F1C1B0AAE001FD9F8 /* DeepLearningKitForOSX.framework */; }; - 67A73D4F1C1B0AAE001FD9F8 /* DeepLearningKitForOSXTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D4E1C1B0AAE001FD9F8 /* DeepLearningKitForOSXTests.swift */; }; - 67A73D621C1B0AC0001FD9F8 /* ConvolutionLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D591C1B0AC0001FD9F8 /* ConvolutionLayer.swift */; }; - 67A73D631C1B0AC0001FD9F8 /* DeepNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D5A1C1B0AC0001FD9F8 /* DeepNetwork.swift */; }; - 67A73D641C1B0AC0001FD9F8 /* DeepNetwork+JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D5B1C1B0AC0001FD9F8 /* DeepNetwork+JSON.swift */; }; - 67A73D651C1B0AC0001FD9F8 /* DeepNetwork+SetupNetworkFromDict.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D5C1C1B0AC0001FD9F8 /* DeepNetwork+SetupNetworkFromDict.swift */; }; - 67A73D661C1B0AC0001FD9F8 /* MetalDataStructures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D5D1C1B0AC0001FD9F8 /* MetalDataStructures.swift */; }; - 67A73D671C1B0AC0001FD9F8 /* MetalUtilityFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D5E1C1B0AC0001FD9F8 /* MetalUtilityFunctions.swift */; }; - 67A73D681C1B0AC0001FD9F8 /* PoolingLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D5F1C1B0AC0001FD9F8 /* PoolingLayer.swift */; }; - 67A73D691C1B0AC0001FD9F8 /* RectifierLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D601C1B0AC0001FD9F8 /* RectifierLayer.swift */; }; - 67A73D6A1C1B0AC0001FD9F8 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D611C1B0AC0001FD9F8 /* Shaders.metal */; }; - 67A73D6F1C1B0B67001FD9F8 /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 67A73D6E1C1B0B67001FD9F8 /* Metal.framework */; }; -/* End PBXBuildFile section */ - -/* Begin PBXContainerItemProxy section */ - 67A73D4B1C1B0AAE001FD9F8 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 67A73D361C1B0AAE001FD9F8 /* Project object */; - proxyType = 1; - remoteGlobalIDString = 67A73D3E1C1B0AAE001FD9F8; - remoteInfo = DeepLearningKitForOSX; - }; -/* End PBXContainerItemProxy section */ - -/* Begin PBXFileReference section */ - 67A73D3F1C1B0AAE001FD9F8 /* DeepLearningKitForOSX.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DeepLearningKitForOSX.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 67A73D421C1B0AAE001FD9F8 /* DeepLearningKitForOSX.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeepLearningKitForOSX.h; sourceTree = ""; }; - 67A73D441C1B0AAE001FD9F8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 67A73D491C1B0AAE001FD9F8 /* DeepLearningKitForOSXTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DeepLearningKitForOSXTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 67A73D4E1C1B0AAE001FD9F8 /* DeepLearningKitForOSXTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeepLearningKitForOSXTests.swift; sourceTree = ""; }; - 67A73D501C1B0AAE001FD9F8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 67A73D591C1B0AC0001FD9F8 /* ConvolutionLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConvolutionLayer.swift; sourceTree = ""; }; - 67A73D5A1C1B0AC0001FD9F8 /* DeepNetwork.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeepNetwork.swift; sourceTree = ""; }; - 67A73D5B1C1B0AC0001FD9F8 /* DeepNetwork+JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DeepNetwork+JSON.swift"; sourceTree = ""; }; - 67A73D5C1C1B0AC0001FD9F8 /* DeepNetwork+SetupNetworkFromDict.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DeepNetwork+SetupNetworkFromDict.swift"; sourceTree = ""; }; - 67A73D5D1C1B0AC0001FD9F8 /* MetalDataStructures.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalDataStructures.swift; sourceTree = ""; }; - 67A73D5E1C1B0AC0001FD9F8 /* MetalUtilityFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalUtilityFunctions.swift; sourceTree = ""; }; - 67A73D5F1C1B0AC0001FD9F8 /* PoolingLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PoolingLayer.swift; sourceTree = ""; }; - 67A73D601C1B0AC0001FD9F8 /* RectifierLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RectifierLayer.swift; sourceTree = ""; }; - 67A73D611C1B0AC0001FD9F8 /* Shaders.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Shaders.metal; sourceTree = ""; }; - 67A73D6E1C1B0B67001FD9F8 /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 67A73D3B1C1B0AAE001FD9F8 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 67A73D6F1C1B0B67001FD9F8 /* Metal.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 67A73D461C1B0AAE001FD9F8 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 67A73D4A1C1B0AAE001FD9F8 /* DeepLearningKitForOSX.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 67A73D351C1B0AAE001FD9F8 = { - isa = PBXGroup; - children = ( - 67A73D6E1C1B0B67001FD9F8 /* Metal.framework */, - 67A73D411C1B0AAE001FD9F8 /* DeepLearningKitForOSX */, - 67A73D4D1C1B0AAE001FD9F8 /* DeepLearningKitForOSXTests */, - 67A73D401C1B0AAE001FD9F8 /* Products */, - ); - sourceTree = ""; - }; - 67A73D401C1B0AAE001FD9F8 /* Products */ = { - isa = PBXGroup; - children = ( - 67A73D3F1C1B0AAE001FD9F8 /* DeepLearningKitForOSX.framework */, - 67A73D491C1B0AAE001FD9F8 /* DeepLearningKitForOSXTests.xctest */, - ); - name = Products; - sourceTree = ""; - }; - 67A73D411C1B0AAE001FD9F8 /* DeepLearningKitForOSX */ = { - isa = PBXGroup; - children = ( - 67A73D421C1B0AAE001FD9F8 /* DeepLearningKitForOSX.h */, - 67A73D6D1C1B0AEF001FD9F8 /* PUBLIC_API */, - 67A73D6B1C1B0AD5001FD9F8 /* INTERNAL_API */, - 67A73D6C1C1B0AE4001FD9F8 /* GPU_METAL */, - 67A73D441C1B0AAE001FD9F8 /* Info.plist */, - ); - path = DeepLearningKitForOSX; - sourceTree = ""; - }; - 67A73D4D1C1B0AAE001FD9F8 /* DeepLearningKitForOSXTests */ = { - isa = PBXGroup; - children = ( - 67A73D4E1C1B0AAE001FD9F8 /* DeepLearningKitForOSXTests.swift */, - 67A73D501C1B0AAE001FD9F8 /* Info.plist */, - ); - path = DeepLearningKitForOSXTests; - sourceTree = ""; - }; - 67A73D6B1C1B0AD5001FD9F8 /* INTERNAL_API */ = { - isa = PBXGroup; - children = ( - 67A73D5B1C1B0AC0001FD9F8 /* DeepNetwork+JSON.swift */, - 67A73D5C1C1B0AC0001FD9F8 /* DeepNetwork+SetupNetworkFromDict.swift */, - 67A73D591C1B0AC0001FD9F8 /* ConvolutionLayer.swift */, - 67A73D5F1C1B0AC0001FD9F8 /* PoolingLayer.swift */, - 67A73D601C1B0AC0001FD9F8 /* RectifierLayer.swift */, - ); - name = INTERNAL_API; - sourceTree = ""; - }; - 67A73D6C1C1B0AE4001FD9F8 /* GPU_METAL */ = { - isa = PBXGroup; - children = ( - 67A73D5D1C1B0AC0001FD9F8 /* MetalDataStructures.swift */, - 67A73D5E1C1B0AC0001FD9F8 /* MetalUtilityFunctions.swift */, - 67A73D611C1B0AC0001FD9F8 /* Shaders.metal */, - ); - name = GPU_METAL; - sourceTree = ""; - }; - 67A73D6D1C1B0AEF001FD9F8 /* PUBLIC_API */ = { - isa = PBXGroup; - children = ( - 67A73D5A1C1B0AC0001FD9F8 /* DeepNetwork.swift */, - ); - name = PUBLIC_API; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXHeadersBuildPhase section */ - 67A73D3C1C1B0AAE001FD9F8 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 67A73D431C1B0AAE001FD9F8 /* DeepLearningKitForOSX.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXHeadersBuildPhase section */ - -/* Begin PBXNativeTarget section */ - 67A73D3E1C1B0AAE001FD9F8 /* DeepLearningKitForOSX */ = { - isa = PBXNativeTarget; - buildConfigurationList = 67A73D531C1B0AAE001FD9F8 /* Build configuration list for PBXNativeTarget "DeepLearningKitForOSX" */; - buildPhases = ( - 67A73D3A1C1B0AAE001FD9F8 /* Sources */, - 67A73D3B1C1B0AAE001FD9F8 /* Frameworks */, - 67A73D3C1C1B0AAE001FD9F8 /* Headers */, - 67A73D3D1C1B0AAE001FD9F8 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = DeepLearningKitForOSX; - productName = DeepLearningKitForOSX; - productReference = 67A73D3F1C1B0AAE001FD9F8 /* DeepLearningKitForOSX.framework */; - productType = "com.apple.product-type.framework"; - }; - 67A73D481C1B0AAE001FD9F8 /* DeepLearningKitForOSXTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 67A73D561C1B0AAE001FD9F8 /* Build configuration list for PBXNativeTarget "DeepLearningKitForOSXTests" */; - buildPhases = ( - 67A73D451C1B0AAE001FD9F8 /* Sources */, - 67A73D461C1B0AAE001FD9F8 /* Frameworks */, - 67A73D471C1B0AAE001FD9F8 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - 67A73D4C1C1B0AAE001FD9F8 /* PBXTargetDependency */, - ); - name = DeepLearningKitForOSXTests; - productName = DeepLearningKitForOSXTests; - productReference = 67A73D491C1B0AAE001FD9F8 /* DeepLearningKitForOSXTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 67A73D361C1B0AAE001FD9F8 /* Project object */ = { - isa = PBXProject; - attributes = { - LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0720; - ORGANIZATIONNAME = "Amund Tveit"; - TargetAttributes = { - 67A73D3E1C1B0AAE001FD9F8 = { - CreatedOnToolsVersion = 7.2; - }; - 67A73D481C1B0AAE001FD9F8 = { - CreatedOnToolsVersion = 7.2; - }; - }; - }; - buildConfigurationList = 67A73D391C1B0AAE001FD9F8 /* Build configuration list for PBXProject "DeepLearningKitForOSX" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = 67A73D351C1B0AAE001FD9F8; - productRefGroup = 67A73D401C1B0AAE001FD9F8 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 67A73D3E1C1B0AAE001FD9F8 /* DeepLearningKitForOSX */, - 67A73D481C1B0AAE001FD9F8 /* DeepLearningKitForOSXTests */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 67A73D3D1C1B0AAE001FD9F8 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 67A73D471C1B0AAE001FD9F8 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 67A73D3A1C1B0AAE001FD9F8 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 67A73D631C1B0AC0001FD9F8 /* DeepNetwork.swift in Sources */, - 67A73D691C1B0AC0001FD9F8 /* RectifierLayer.swift in Sources */, - 67A73D661C1B0AC0001FD9F8 /* MetalDataStructures.swift in Sources */, - 67A73D641C1B0AC0001FD9F8 /* DeepNetwork+JSON.swift in Sources */, - 67A73D681C1B0AC0001FD9F8 /* PoolingLayer.swift in Sources */, - 67A73D621C1B0AC0001FD9F8 /* ConvolutionLayer.swift in Sources */, - 67A73D6A1C1B0AC0001FD9F8 /* Shaders.metal in Sources */, - 67A73D671C1B0AC0001FD9F8 /* MetalUtilityFunctions.swift in Sources */, - 67A73D651C1B0AC0001FD9F8 /* DeepNetwork+SetupNetworkFromDict.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 67A73D451C1B0AAE001FD9F8 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 67A73D4F1C1B0AAE001FD9F8 /* DeepLearningKitForOSXTests.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXTargetDependency section */ - 67A73D4C1C1B0AAE001FD9F8 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 67A73D3E1C1B0AAE001FD9F8 /* DeepLearningKitForOSX */; - targetProxy = 67A73D4B1C1B0AAE001FD9F8 /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - -/* Begin XCBuildConfiguration section */ - 67A73D511C1B0AAE001FD9F8 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "-"; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = macosx; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Debug; - }; - 67A73D521C1B0AAE001FD9F8 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "-"; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = macosx; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Release; - }; - 67A73D541C1B0AAE001FD9F8 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_MODULES = YES; - COMBINE_HIDPI_IMAGES = YES; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_VERSION = A; - INFOPLIST_FILE = DeepLearningKitForOSX/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = org.deeplearningkit.DeepLearningKitForOSX; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - }; - name = Debug; - }; - 67A73D551C1B0AAE001FD9F8 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_MODULES = YES; - COMBINE_HIDPI_IMAGES = YES; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_VERSION = A; - INFOPLIST_FILE = DeepLearningKitForOSX/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = org.deeplearningkit.DeepLearningKitForOSX; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - }; - name = Release; - }; - 67A73D571C1B0AAE001FD9F8 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - COMBINE_HIDPI_IMAGES = YES; - INFOPLIST_FILE = DeepLearningKitForOSXTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = org.deeplearningkit.DeepLearningKitForOSXTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - 67A73D581C1B0AAE001FD9F8 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - COMBINE_HIDPI_IMAGES = YES; - INFOPLIST_FILE = DeepLearningKitForOSXTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = org.deeplearningkit.DeepLearningKitForOSXTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 67A73D391C1B0AAE001FD9F8 /* Build configuration list for PBXProject "DeepLearningKitForOSX" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 67A73D511C1B0AAE001FD9F8 /* Debug */, - 67A73D521C1B0AAE001FD9F8 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 67A73D531C1B0AAE001FD9F8 /* Build configuration list for PBXNativeTarget "DeepLearningKitForOSX" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 67A73D541C1B0AAE001FD9F8 /* Debug */, - 67A73D551C1B0AAE001FD9F8 /* Release */, - ); - defaultConfigurationIsVisible = 0; - }; - 67A73D561C1B0AAE001FD9F8 /* Build configuration list for PBXNativeTarget "DeepLearningKitForOSXTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 67A73D571C1B0AAE001FD9F8 /* Debug */, - 67A73D581C1B0AAE001FD9F8 /* Release */, - ); - defaultConfigurationIsVisible = 0; - }; -/* End XCConfigurationList section */ - }; - rootObject = 67A73D361C1B0AAE001FD9F8 /* Project object */; -} diff --git a/DeepLearningKitForOSX/DeepLearningKitForOSX.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/DeepLearningKitForOSX/DeepLearningKitForOSX.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 1cba58a..0000000 --- a/DeepLearningKitForOSX/DeepLearningKitForOSX.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/DeepLearningKitForOSX/DeepLearningKitForOSX/ConvolutionLayer.swift b/DeepLearningKitForOSX/DeepLearningKitForOSX/ConvolutionLayer.swift deleted file mode 100644 index 45709d0..0000000 --- a/DeepLearningKitForOSX/DeepLearningKitForOSX/ConvolutionLayer.swift +++ /dev/null @@ -1,237 +0,0 @@ -// -// ConvolutionLayer.swift -// MemkiteMetal -// -// Created by Torb Morland & Amund Tveit on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - -func getDataFromBlob(blob: NSDictionary) -> ([Float], [Float]) { - print(" ==> getDataFromBlob") - - let shape = blob["shape"] as! NSDictionary - let data = blob["data"] as! [Float] - var FloatData = createFloatNumbersArray(data.count) - for i in 0 ..< data.count { - FloatData[i] = data[i] - } - return (shape["dim"] as! [Float], FloatData) -} - - - -func createConvolutionLayerCached(layer: NSDictionary, - inputBuffer: MTLBuffer, - inputShape: [Float], - metalCommandQueue: MTLCommandQueue, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout layer_data_caches: [Dictionary], - inout blob_cache: [Dictionary], - layer_number: Int, - layer_string: String) -> (MTLBuffer, MTLCommandBuffer, [Float]) { - - let start = NSDate() - - print("CREATECONVLAYERCACHED") - -// let metalCommandBuffer = metalCommandQueue.commandBuffer() - let metalCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() - - var convolution_params_dict:NSDictionary = NSDictionary() - var pad:Float = 0.0 - var kernel_size:Float = 1.0 - var stride:Float = 1.0 - var blobs:[NSDictionary] = [] - var weights:[Float] = [] - var weight_shape:[Float] = [] - var bias_data:[Float] = [] - var h:Float = 0.0 - var w:Float = 0.0 - var result_shape:[Float] = [] - var outputCount:Int = 0 - - var input_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var weight_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var result_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var tensor_dimensions:[MetalTensorDimensions] = [] - var col_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var col_output:[Float] = [] - var convolution_params:MetalConvolutionParameters = MetalConvolutionParameters(pad:0, kernel_size: 0, stride: 0) - - - print("NOTCACHINGMODE") - convolution_params_dict = layer["convolution_param"] as! NSDictionary - pad = 0.0 - kernel_size = 1.0 - stride = 1.0 - if let val = convolution_params_dict["pad"] as? Float { - pad = val - } - if let val = convolution_params_dict["kernel_size"] as? Float { - kernel_size = val - } - - let startblob = NSDate() - - - if let tmpval = blob_cache[layer_number]["0"] { - print("found blob key = 0 in cache") - (weight_shape, weights) = tmpval - } else { - print("didnt find blob key = 0 in cache") - blobs = layer["blobs"] as! [NSDictionary] - (weight_shape, weights) = getDataFromBlob(blobs[0]) - blob_cache[layer_number]["0"] = (weight_shape, weights) - } - -// this can be optimized - blobs = layer["blobs"] as! [NSDictionary] - (_, bias_data) = getDataFromBlob(blobs[1]) - - print("### Time to blob: \(NSDate().timeIntervalSinceDate(startblob))") - - - /* - let startblob = NSDate() - blobs = layer["blobs"] as! [NSDictionary] - (weight_shape, weights) = getDataFromBlob(blobs[0]) - (_, bias_data) = getDataFromBlob(blobs[1]) - print("### Time to blob: \(NSDate().timeIntervalSinceDate(startblob))") -*/ - - - h = (inputShape[2] + 2 * pad - kernel_size) / stride + 1 - w = (inputShape[3] + 2 * pad - kernel_size) / stride + 1 - result_shape = [inputShape[0], weight_shape[0], h, w] - outputCount = Int(result_shape.reduce(1, combine: *)) - - // Create input and output vectors, and corresponding metal buffer - input_dimensions = MetalTensorDimensions(n: inputShape[0], channels: inputShape[1], width: inputShape[2], height: inputShape[3]) - weight_dimensions = MetalTensorDimensions(n: weight_shape[0], channels: weight_shape[1], width: weight_shape[2], height: weight_shape[3]) - col_dimensions = MetalTensorDimensions(n: inputShape[0], channels: inputShape[1] * weight_shape[2] * weight_shape[3], width: inputShape[2], height: inputShape[3]) - result_dimensions = MetalTensorDimensions(n: result_shape[0], channels: result_shape[1], width: result_shape[2], height: result_shape[3]) - tensor_dimensions = [input_dimensions, weight_dimensions, col_dimensions, result_dimensions] - - - col_output = createFloatNumbersArray(Int(col_dimensions.n * col_dimensions.channels * col_dimensions.height * col_dimensions.width)) - - - convolution_params = MetalConvolutionParameters(pad: pad, kernel_size: kernel_size, stride: stride) - print("AFTER NOTCACHINGMODE") - - - print("BEFORE THE BIG CALL") - - let resultBuffer = addConvolutionCommandToCommandBufferCached(metalCommandBuffer, inputBuffer: inputBuffer, im2ColCount: col_output.count, weights: weights, outputCount: outputCount, convolution_params: convolution_params, tensor_dimensions: tensor_dimensions, bias: bias_data, metalDefaultLibrary: metalDefaultLibrary, metalDevice:metalDevice, layer_data_caches: &layer_data_caches, layer_number: layer_number,layer_string: layer_string) - //metalCommandBuffer.commit() - - print("AFTER BIG CALL") - - print("### Time to setup convolution layer: \(NSDate().timeIntervalSinceDate(start))") - - - return (resultBuffer, metalCommandBuffer, result_shape) - -} - -func addConvolutionCommandToCommandBufferCached(commandBuffer: MTLCommandBuffer, - inputBuffer: MTLBuffer, - im2ColCount: Int, - weights: [Float], - outputCount: Int, - convolution_params: MetalConvolutionParameters, - tensor_dimensions: [MetalTensorDimensions], - bias: [Float], - metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout layer_data_caches: [Dictionary], - layer_number: Int, - layer_string: String) -> MTLBuffer { - - let start = NSDate() - - print("before output and col_output") - - var output:[Float] = [] - var col_output:[Float] = [] - - output = createFloatNumbersArray(outputCount) - col_output = createFloatNumbersArray(im2ColCount) - - print("before setupshaderinpipeline") - - let (_, im2colComputePipelineState, _) = setupShaderInMetalPipeline("im2col", metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice) - - let resultMetalBuffer = createOrReuseFloatMetalBuffer("resultMetalBuffer", data: output, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - - print("after resultmetalbuffer") - - let weightMetalBuffer = createOrReuseFloatMetalBuffer("weightMetalBuffer", data: weights, cache: &layer_data_caches, layer_number:layer_number, metalDevice: metalDevice) - - - let convolutionParamsMetalBuffer = createOrReuseConvolutionParametersMetalBuffer("convolutionParamsMetalBuffer", data: convolution_params, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - let tensorDimensionsMetalBuffer = createOrReuseTensorDimensionsVectorMetalBuffer("tensorDimensionsMetalBuffer", data: tensor_dimensions, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - - let colOutputMetalBuffer = createOrReuseFloatMetalBuffer("colOutputMetalBuffer", data: col_output, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - let biasMetalBuffer = createOrReuseFloatMetalBuffer("bias", data: bias, cache: &layer_data_caches, layer_number:layer_number, metalDevice: metalDevice) - - - // Create Metal compute command encoder for im2col - var metalComputeCommandEncoder = commandBuffer.computeCommandEncoder() - metalComputeCommandEncoder.setBuffer(inputBuffer, offset: 0, atIndex: 0) - metalComputeCommandEncoder.setBuffer(tensorDimensionsMetalBuffer, offset: 0, atIndex: 1) - metalComputeCommandEncoder.setBuffer(convolutionParamsMetalBuffer, offset: 0, atIndex: 2) - metalComputeCommandEncoder.setBuffer(colOutputMetalBuffer, offset: 0, atIndex: 3) - //metalComputeCommandEncoder.setComputePipelineState(im2colComputePipelineState) - - - // Set the shader function that Metal will use - metalComputeCommandEncoder.setComputePipelineState(im2colComputePipelineState) - - // Set up thread groups on GPU - var threadsPerGroup = MTLSize(width:im2colComputePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - print("before mtlsize 2") - var numThreadgroups = MTLSize(width:(col_output.count-1)/im2colComputePipelineState.threadExecutionWidth + 1, height:1, depth:1) - metalComputeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - print("after dispatch") - - // Finalize configuration - metalComputeCommandEncoder.endEncoding() - - - - - let (_, convolutionComputePipelineState, _) = setupShaderInMetalPipeline("convolution_layer", metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice) - metalComputeCommandEncoder = commandBuffer.computeCommandEncoder() - - // Create Metal Compute Command Encoder and add input and output buffers to it - metalComputeCommandEncoder.setBuffer(resultMetalBuffer, offset: 0, atIndex: 0) - metalComputeCommandEncoder.setBuffer(weightMetalBuffer, offset: 0, atIndex: 1) - metalComputeCommandEncoder.setBuffer(tensorDimensionsMetalBuffer, offset: 0, atIndex: 2) - metalComputeCommandEncoder.setBuffer(colOutputMetalBuffer, offset: 0, atIndex: 3) - metalComputeCommandEncoder.setBuffer(biasMetalBuffer, offset: 0, atIndex: 4) - - // Set the shader function that Metal will use - metalComputeCommandEncoder.setComputePipelineState(convolutionComputePipelineState) - - // Set up thread groups on GPU - threadsPerGroup = MTLSize(width:convolutionComputePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - numThreadgroups = MTLSize(width:(outputCount-1)/convolutionComputePipelineState.threadExecutionWidth + 1, height:1, depth:1) - metalComputeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - // Finalize configuration - metalComputeCommandEncoder.endEncoding() - - print("after endencoding") - - print("#### Time to add convolution layer: \(NSDate().timeIntervalSinceDate(start))") - - - return resultMetalBuffer - -} - diff --git a/DeepLearningKitForOSX/DeepLearningKitForOSX/DeepLearningKitForOSX.h b/DeepLearningKitForOSX/DeepLearningKitForOSX/DeepLearningKitForOSX.h deleted file mode 100644 index 1b29196..0000000 --- a/DeepLearningKitForOSX/DeepLearningKitForOSX/DeepLearningKitForOSX.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// DeepLearningKitForOSX.h -// DeepLearningKitForOSX -// -// Created by Amund Tveit on 11/12/15. -// Copyright © 2015 Amund Tveit. All rights reserved. -// - -#import - -//! Project version number for DeepLearningKitForOSX. -FOUNDATION_EXPORT double DeepLearningKitForOSXVersionNumber; - -//! Project version string for DeepLearningKitForOSX. -FOUNDATION_EXPORT const unsigned char DeepLearningKitForOSXVersionString[]; - -// In this header, you should import all the public headers of your framework using statements like #import - - diff --git a/DeepLearningKitForOSX/DeepLearningKitForOSX/DeepNetwork+JSON.swift b/DeepLearningKitForOSX/DeepLearningKitForOSX/DeepNetwork+JSON.swift deleted file mode 100644 index 9755f49..0000000 --- a/DeepLearningKitForOSX/DeepLearningKitForOSX/DeepNetwork+JSON.swift +++ /dev/null @@ -1,26 +0,0 @@ -// -// DeepNetwork+JSON.swift -// MemkiteMetal -// -// Created by Amund Tveit & Torb Morland on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation - -public extension DeepNetwork { - -func loadJSONFile(filename: String) -> NSDictionary? { - print(" ==> loadJSONFile(filename=\(filename)") - - do { - let bundle = NSBundle.mainBundle() - let path = bundle.pathForResource(filename, ofType: "json")! - let jsonData = NSData(contentsOfFile: path) - print(" <== loadJSONFile") - return try NSJSONSerialization.JSONObjectWithData(jsonData!, options: .AllowFragments) as? NSDictionary - } catch _ { - return nil - } -} -} \ No newline at end of file diff --git a/DeepLearningKitForOSX/DeepLearningKitForOSX/DeepNetwork+SetupNetworkFromDict.swift b/DeepLearningKitForOSX/DeepLearningKitForOSX/DeepNetwork+SetupNetworkFromDict.swift deleted file mode 100644 index e0e0934..0000000 --- a/DeepLearningKitForOSX/DeepLearningKitForOSX/DeepNetwork+SetupNetworkFromDict.swift +++ /dev/null @@ -1,86 +0,0 @@ -// -// DeepNetwork+SetupNetworkFromDict.swift -// MemkiteMetal -// -// Created by Amund Tveit & Torb Morland on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - -public extension DeepNetwork { - - func setupNetworkFromDict(deepNetworkAsDict: NSDictionary, inputimage: MTLBuffer, inputshape: [Float]) { - - let start = NSDate() - - gpuCommandLayers = [] - - print(" ==> setupNetworkFromDict()") - // Add input image - var layer_number = 0 - layer_data_caches.append(Dictionary()) // for input - pool_type_caches.append(Dictionary()) - blob_cache.append(Dictionary()) - namedDataLayers.append(("input", inputimage)) - ++layer_number - - - // Add remaining network - var previousBuffer:MTLBuffer = inputimage - var previousShape:[Float] = inputshape - - self.deepNetworkAsDict = deepNetworkAsDict - - // create new command buffer for next layer - var currentCommandBuffer: MTLCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() - - var t = NSDate() - for layer in deepNetworkAsDict["layer"] as! [NSDictionary] { - if let type = layer["type"] as? String { - let layer_string = layer["name"] as! String - - layer_data_caches.append(Dictionary()) - pool_type_caches.append(Dictionary()) - blob_cache.append(Dictionary()) - - - if type == "ReLU" { - self.gpuCommandLayers.append(currentCommandBuffer) - //(previousBuffer, currentCommandBuffer) = createRectifierLayer(previousBuffer) - (previousBuffer, currentCommandBuffer) = createRectifierLayer(previousBuffer, metalCommandQueue:metalCommandQueue, metalDefaultLibrary:metalDefaultLibrary, metalDevice:metalDevice) - self.namedDataLayers.append((layer["name"]! as! String, previousBuffer)) - } else if type == "Pooling" { - self.gpuCommandLayers.append(currentCommandBuffer) - // (previousBuffer, currentCommandBuffer, previousShape) = createPoolingLayer(layer, inputBuffer: previousBuffer, inputShape: previousShape) - (previousBuffer, currentCommandBuffer, previousShape) = createPoolingLayerCached(layer, inputBuffer: previousBuffer, inputShape: previousShape, metalCommandQueue: metalCommandQueue, metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice, pool_type_caches: &pool_type_caches, layer_data_caches: &layer_data_caches, layer_number: layer_number, layer_string: layer_string) - self.namedDataLayers.append((layer["name"]! as! String, previousBuffer)) - } else if type == "Convolution" { - self.gpuCommandLayers.append(currentCommandBuffer) - // (previousBuffer, currentCommandBuffer, previousShape) = createConvolutionLayer(layer, inputBuffer: previousBuffer, inputShape: previousShape) - (previousBuffer, currentCommandBuffer, previousShape) = createConvolutionLayerCached(layer, inputBuffer: previousBuffer, inputShape: previousShape, metalCommandQueue: metalCommandQueue, metalDefaultLibrary:metalDefaultLibrary, metalDevice:metalDevice, layer_data_caches: &layer_data_caches, blob_cache: &blob_cache, layer_number: layer_number, layer_string: layer_string) - - - self.namedDataLayers.append((layer["name"]! as! String, previousBuffer)) - } - let name = layer["name"] as! String - print("\(name): \(NSDate().timeIntervalSinceDate(t))") - t = NSDate() - ++layer_number - - } - } - - self.gpuCommandLayers.append(currentCommandBuffer) - - print("bar") - - print("AFTER LAYER DATA CHACES = \(layer_data_caches[0])") - - print("POOL TYPE CACHES = \(pool_type_caches)") - - print("Time to set up network: \(NSDate().timeIntervalSinceDate(start))") - - } -} diff --git a/DeepLearningKitForOSX/DeepLearningKitForOSX/DeepNetwork.swift b/DeepLearningKitForOSX/DeepLearningKitForOSX/DeepNetwork.swift deleted file mode 100644 index 4f5de2b..0000000 --- a/DeepLearningKitForOSX/DeepLearningKitForOSX/DeepNetwork.swift +++ /dev/null @@ -1,76 +0,0 @@ -// -// DeepNetwork.swift -// MemkiteMetal -// -// Created by Amund Tveit & Torb Morland on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - -public class DeepNetwork { - var gpuCommandLayers: [MTLCommandBuffer] = [] - var namedDataLayers: [(String, MTLBuffer)] = [] - var imageBuffer: MTLBuffer! - var metalDevice: MTLDevice! - var metalDefaultLibrary: MTLLibrary! - var metalCommandQueue: MTLCommandQueue! - var deepNetworkAsDict: NSDictionary! // for debugging perhaps - var layer_data_caches: [Dictionary] = [] - var pool_type_caches: [Dictionary] = [] - var dummy_image: [Float]! - var previous_shape: [Float]! - var blob_cache: [Dictionary] = [] - - public init() { - // Get access to iPhone or iPad GPU - metalDevice = MTLCreateSystemDefaultDevice() - - // Queue to handle an ordered list of command buffers - metalCommandQueue = metalDevice.newCommandQueue() - print("metalCommandQueue = \(unsafeAddressOf(metalCommandQueue))") - - // Access to Metal functions that are stored in Shaders.metal file, e.g. sigmoid() - metalDefaultLibrary = metalDevice.newDefaultLibrary() - } - - public func loadNetworkFromJson(jsonNetworkFileName: String) { - deepNetworkAsDict = loadJSONFile(jsonNetworkFileName)! - } - - public func classify(image: [Float], shape:[Float]) -> Int { - let imageTensor = createMetalBuffer(image, metalDevice: metalDevice) - - gpuCommandLayers = [] - setupNetworkFromDict(deepNetworkAsDict, inputimage: imageTensor, inputshape: shape) - - let start = NSDate() - for commandBuffer in gpuCommandLayers { - commandBuffer.commit() - } - - // wait until last layer in conv.net is finished - gpuCommandLayers.last!.waitUntilCompleted() - print("Time to run network: \(NSDate().timeIntervalSinceDate(start))") - - var classification_results = [Float](count: 10, repeatedValue: 0.0) - let (lastLayerName, lastMetalBuffer) = namedDataLayers.last! - NSLog(lastLayerName) - let data = NSData(bytesNoCopy: lastMetalBuffer.contents(), - length: classification_results.count*sizeof(Float), freeWhenDone: false) - data.getBytes(&classification_results, length:(Int(classification_results.count)) * sizeof(Float)) - print(classification_results) - let maxValue:Float = classification_results.maxElement()! - let indexOfMaxValue:Int = classification_results.indexOf(maxValue)! - - print("maxValue = \(maxValue), indexofMaxValue = \(indexOfMaxValue)") - - // empty command buffers! - - // return index - return indexOfMaxValue - - } -} - diff --git a/DeepLearningKitForOSX/DeepLearningKitForOSX/Info.plist b/DeepLearningKitForOSX/DeepLearningKitForOSX/Info.plist deleted file mode 100644 index 8247622..0000000 --- a/DeepLearningKitForOSX/DeepLearningKitForOSX/Info.plist +++ /dev/null @@ -1,28 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - FMWK - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - $(CURRENT_PROJECT_VERSION) - NSHumanReadableCopyright - Copyright © 2015 Amund Tveit. All rights reserved. - NSPrincipalClass - - - diff --git a/DeepLearningKitForOSX/DeepLearningKitForOSX/MetalDataStructures.swift b/DeepLearningKitForOSX/DeepLearningKitForOSX/MetalDataStructures.swift deleted file mode 100644 index c53d61c..0000000 --- a/DeepLearningKitForOSX/DeepLearningKitForOSX/MetalDataStructures.swift +++ /dev/null @@ -1,62 +0,0 @@ -// -// MetalDataStructures.swift -// MemkiteMetal -// -// Created by Amund Tveit & Torb Morland on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - -////////////////////////////////////////// -// Metal Data Types - their SWIFT Counterparts -////////////////////////////////////////// -public struct MetalComplexNumberType { - var real: Float = 0.0 - var imag: Float = 0.0 -} - -public struct MetalShaderParameters { - let image_xdim: Float - let image_ydim: Float - let num_images: Float - let filter_xdim: Float - let filter_ydim: Float - let num_filters: Float - let conv_xdim: Float // image_xdim - filter_xdim + 1 without striding - let conv_ydim: Float // image_ydim - filter_ydim + 1 without striding - let pool_xdim: Float - let pool_ydim: Float - var b: Float -} - -public struct MetalMatrixVectorParameters { - let x_xdim: Float - let x_ydim: Float - let w_xdim: Float - let w_ydim: Float - let b_xdim: Float - let b_ydim: Float - let result_xdim: Float - let result_ydim: Float -} - -public struct MetalPoolingParameters { - let kernel_size: Float - let pool_stride: Float - let pad: Float -} - -public struct MetalTensorDimensions { - let n: Float - let channels: Float - let width: Float - let height: Float -} - -public struct MetalConvolutionParameters { - let pad: Float - let kernel_size: Float - let stride: Float -} diff --git a/DeepLearningKitForOSX/DeepLearningKitForOSX/MetalUtilityFunctions.swift b/DeepLearningKitForOSX/DeepLearningKitForOSX/MetalUtilityFunctions.swift deleted file mode 100644 index 1ed4d80..0000000 --- a/DeepLearningKitForOSX/DeepLearningKitForOSX/MetalUtilityFunctions.swift +++ /dev/null @@ -1,173 +0,0 @@ -// -// MetalUtilFunctions.swift -// MemkiteMetal -// -// Created by Amund Tveit & Torb Morland on 24/11/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - -func createComplexNumbersArray(count: Int) -> [MetalComplexNumberType] { - let zeroComplexNumber = MetalComplexNumberType() - return [MetalComplexNumberType](count: count, repeatedValue: zeroComplexNumber) -} - -func createFloatNumbersArray(count: Int) -> [Float] { - return [Float](count: count, repeatedValue: 0.0) -} - -func createFloatMetalBuffer(var vector: [Float], let metalDevice:MTLDevice) -> MTLBuffer { - let byteLength = vector.count*sizeof(Float) // future: MTLResourceStorageModePrivate - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createComplexMetalBuffer(var vector:[MetalComplexNumberType], let metalDevice:MTLDevice) -> MTLBuffer { - let byteLength = vector.count*sizeof(MetalComplexNumberType) // or size of and actual 1st element object? - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createShaderParametersMetalBuffer(var shaderParameters:MetalShaderParameters, metalDevice:MTLDevice) -> MTLBuffer { - let byteLength = sizeof(MetalShaderParameters) - return metalDevice.newBufferWithBytes(&shaderParameters, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createMatrixShaderParametersMetalBuffer(var params: MetalMatrixVectorParameters, metalDevice: MTLDevice) -> MTLBuffer { - let byteLength = sizeof(MetalMatrixVectorParameters) - return metalDevice.newBufferWithBytes(¶ms, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) - -} - -func createPoolingParametersMetalBuffer(var params: MetalPoolingParameters, metalDevice: MTLDevice) -> MTLBuffer { - let byteLength = sizeof(MetalPoolingParameters) - return metalDevice.newBufferWithBytes(¶ms, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createConvolutionParametersMetalBuffer(var params: MetalConvolutionParameters, metalDevice: MTLDevice) -> MTLBuffer { - let byteLength = sizeof(MetalConvolutionParameters) - return metalDevice.newBufferWithBytes(¶ms, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createTensorDimensionsVectorMetalBuffer(var vector: [MetalTensorDimensions], metalDevice: MTLDevice) -> MTLBuffer { - let byteLength = vector.count * sizeof(MetalTensorDimensions) - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func setupShaderInMetalPipeline(shaderName:String, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice) -> (shader:MTLFunction!, - computePipelineState:MTLComputePipelineState!, - computePipelineErrors:NSErrorPointer!) { - let shader = metalDefaultLibrary.newFunctionWithName(shaderName) - let computePipeLineDescriptor = MTLComputePipelineDescriptor() - computePipeLineDescriptor.computeFunction = shader - // var computePipelineErrors = NSErrorPointer() - // let computePipelineState:MTLComputePipelineState = metalDevice.newComputePipelineStateWithFunction(shader!, completionHandler: {(}) - let computePipelineErrors = NSErrorPointer() - var computePipelineState:MTLComputePipelineState? = nil - do { - computePipelineState = try metalDevice.newComputePipelineStateWithFunction(shader!) - } catch { - print("catching..") - } - return (shader, computePipelineState, computePipelineErrors) - -} - -func createMetalBuffer(var vector:[Float], metalDevice:MTLDevice) -> MTLBuffer { - let byteLength = vector.count*sizeof(Float) - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func preLoadMetalShaders(metalDevice: MTLDevice, metalDefaultLibrary: MTLLibrary) { - let shaders = ["avg_pool", "max_pool", "rectifier_linear", "convolution_layer", "im2col"] - for shader in shaders { - setupShaderInMetalPipeline(shader, metalDefaultLibrary: metalDefaultLibrary,metalDevice: metalDevice) // TODO: this returns stuff - } -} - -func createOrReuseFloatMetalBuffer(name:String, data: [Float], inout cache:[Dictionary], layer_number:Int, metalDevice:MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { - print("found key = \(name) in cache") - result = tmpval - } else { - print("didnt find key = \(name) in cache") - result = createFloatMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - // print("DEBUG: cache = \(cache)") - } - - return result -} - - -func createOrReuseConvolutionParametersMetalBuffer(name:String, - data: MetalConvolutionParameters, - inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { - print("found key = \(name) in cache") - result = tmpval - } else { - print("didnt find key = \(name) in cache") - result = createConvolutionParametersMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - -func createOrReuseTensorDimensionsVectorMetalBuffer(name:String, - data:[MetalTensorDimensions],inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { - print("found key = \(name) in cache") - result = tmpval - } else { - print("didnt find key = \(name) in cache") - result = createTensorDimensionsVectorMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - -// -//let sizeParamMetalBuffer = createShaderParametersMetalBuffer(size_params, metalDevice: metalDevice) -//let poolingParamMetalBuffer = createPoolingParametersMetalBuffer(pooling_params, metalDevice: metalDevice) - -func createOrReuseShaderParametersMetalBuffer(name:String, - data:MetalShaderParameters,inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { -// print("found key = \(name) in cache") - result = tmpval - } else { -// print("didnt find key = \(name) in cache") - result = createShaderParametersMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - -func createOrReusePoolingParametersMetalBuffer(name:String, - data:MetalPoolingParameters,inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { -// print("found key = \(name) in cache") - result = tmpval - } else { -// print("didnt find key = \(name) in cache") - result = createPoolingParametersMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - - diff --git a/DeepLearningKitForOSX/DeepLearningKitForOSX/PoolingLayer.swift b/DeepLearningKitForOSX/DeepLearningKitForOSX/PoolingLayer.swift deleted file mode 100644 index fd4f589..0000000 --- a/DeepLearningKitForOSX/DeepLearningKitForOSX/PoolingLayer.swift +++ /dev/null @@ -1,141 +0,0 @@ -// -// PoolingLayer.swift -// MemkiteMetal -// -// Created by Torb Morland & Amund Tveit on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - - -func createPoolingLayerCached(layer: NSDictionary, - inputBuffer: MTLBuffer, - inputShape: [Float], - metalCommandQueue: MTLCommandQueue, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout pool_type_caches: [Dictionary], - inout layer_data_caches: [Dictionary], - layer_number: Int, - layer_string: String) -> (MTLBuffer, MTLCommandBuffer, [Float]) { - - print(" ==> createPoolingLayerCached") - let metalCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() -// let metalCommandBuffer = metalCommandQueue.commandBuffer() - - var params = NSDictionary() - var stride:Float = 1.0 - var kernel_size: Float = 1.0 - var pad: Float = 0.0 - var pooling_params = MetalPoolingParameters(kernel_size: kernel_size, pool_stride: stride, pad: pad) - var pool_type = 0 - var h:Float = 0.0 - var w:Float = 0.0 - var shape:[Float] = [] - var outputCount:Float = 0 - var pool_width = 0 - var pool_height = 0 - var size_params:MetalShaderParameters = MetalShaderParameters(image_xdim:0.0, image_ydim:0.0, num_images: 0.0, filter_xdim: 0.0, filter_ydim: 0.0, num_filters: 0.0, conv_xdim: 0.0, conv_ydim: 0.0, pool_xdim: 0.0, pool_ydim: 0.0, b:0.0) - var outputBuffer:MTLBuffer - - - params = layer["pooling_param"] as! NSDictionary - stride = 1.0 - kernel_size = 1.0 - pad = 0.0 - if let val = params["stride"] { - stride = val as! Float - } - if let val = params["kernel_size"] { - kernel_size = val as! Float - if val as! NSNumber != 3 { - pad = 0 - } - } - pooling_params = MetalPoolingParameters(kernel_size: kernel_size, pool_stride: stride, pad: pad) - pool_type = params["pool"] as! Int - - // STORE pool type in cache! - pool_type_caches[layer_number]["pool_type"] = String(pool_type) - - h = ceil((inputShape[2] + 2.0 * pad - kernel_size) / stride) + 1.0 - w = ceil((Float(inputShape[3]) + 2.0 * pad - kernel_size) / stride) + 1.0 - shape = [inputShape[0], inputShape[1], h, w] - outputCount = shape.reduce(1, combine: *) - pool_width = Int(shape[2]) - pool_height = Int(shape[3]) - size_params = MetalShaderParameters(image_xdim: Float(inputShape[2]), image_ydim: Float(inputShape[3]), - num_images: Float(inputShape[0]), - filter_xdim: 1.0, filter_ydim: 1.0, num_filters: Float(inputShape[1]), - conv_xdim:0.0, conv_ydim: 0.0, - pool_xdim: Float(pool_width), pool_ydim: Float(pool_height), b:0.0) - - if pool_type == 1 { - outputBuffer = addPoolingCommandToCommandBufferCached(metalCommandBuffer, poolingMethod: "avg_pool", inputBuffer: inputBuffer, outputCount: Int(outputCount), size_params: size_params, pooling_params: pooling_params, metalDefaultLibrary: metalDefaultLibrary, metalDevice:metalDevice, - layer_data_caches: &layer_data_caches, layer_number: layer_number, layer_string: layer_string) - } else { - outputBuffer = addPoolingCommandToCommandBufferCached(metalCommandBuffer, poolingMethod: "max_pool", inputBuffer: inputBuffer, outputCount: Int(outputCount), size_params: size_params, pooling_params: pooling_params,metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice, - layer_data_caches: &layer_data_caches, layer_number: layer_number, layer_string: layer_string) - - } - //metalCommandBuffer.commit() - - print(" <== createPoolingLayerCached") - - - return (outputBuffer, metalCommandBuffer, shape) -} - - -func addPoolingCommandToCommandBufferCached(commandBuffer: MTLCommandBuffer, - poolingMethod: String, - inputBuffer: MTLBuffer, - outputCount: Int, - size_params: MetalShaderParameters, - pooling_params: MetalPoolingParameters, - metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout layer_data_caches: [Dictionary], - layer_number: Int, - layer_string: String) -> MTLBuffer { - - - print(" ==> addPoolingCommandtoCommandBufferCached") - - - let output = createFloatNumbersArray(outputCount) - let (_, computePipelineState, _) = setupShaderInMetalPipeline(poolingMethod, metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice) - - let outputMetalBuffer = createOrReuseFloatMetalBuffer("outputMetalBuffer", data: output, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - // let outputMetalBuffer = createFloatMetalBuffer(output, metalDevice: metalDevice) - - let sizeParamMetalBuffer = createOrReuseShaderParametersMetalBuffer("sizeParamMetalBuffer", data: size_params, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - - // let sizeParamMetalBuffer = createShaderParametersMetalBuffer(size_params, metalDevice: metalDevice) - - - // let poolingParamMetalBuffer = createPoolingParametersMetalBuffer(pooling_params, metalDevice: metalDevice) - let poolingParamMetalBuffer = createOrReusePoolingParametersMetalBuffer("poolingParamMetalBuffer", data: pooling_params, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - // Create Metal Compute Command Encoder and add input and output buffers to it - let metalComputeCommandEncoder = commandBuffer.computeCommandEncoder() - metalComputeCommandEncoder.setBuffer(outputMetalBuffer, offset: 0, atIndex: 0) - metalComputeCommandEncoder.setBuffer(inputBuffer, offset: 0, atIndex: 1) - metalComputeCommandEncoder.setBuffer(sizeParamMetalBuffer, offset: 0, atIndex: 2) - metalComputeCommandEncoder.setBuffer(poolingParamMetalBuffer, offset: 0, atIndex: 3) - - // Set the shader function that Metal will use - metalComputeCommandEncoder.setComputePipelineState(computePipelineState) - - // Set up thread groups on GPU - let threadsPerGroup = MTLSize(width:computePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - let numThreadgroups = MTLSize(width:(outputCount-1)/computePipelineState.threadExecutionWidth + 1, height:1, depth:1) - metalComputeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - // Finalize configuration - metalComputeCommandEncoder.endEncoding() - - print(" <== addPoolingCommandtoCommandBufferCached") - - - return outputMetalBuffer -} diff --git a/DeepLearningKitForOSX/DeepLearningKitForOSX/RectifierLayer.swift b/DeepLearningKitForOSX/DeepLearningKitForOSX/RectifierLayer.swift deleted file mode 100644 index 7d3478d..0000000 --- a/DeepLearningKitForOSX/DeepLearningKitForOSX/RectifierLayer.swift +++ /dev/null @@ -1,53 +0,0 @@ -// -// RectifierLayer.swift -// MemkiteMetal -// -// Created by Torb Morland & Amund Tveit on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - -func createRectifierLayer(inputBuffer: MTLBuffer, metalCommandQueue: MTLCommandQueue, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice) -> (MTLBuffer,MTLCommandBuffer) { - print(" ==> createrectifierlayer") -// let metalCommandBuffer = metalCommandQueue.commandBuffer() - let metalCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() - - let result = addRectifierCommandToCommandBuffer(metalCommandBuffer, inputBuffer: inputBuffer, - metalDefaultLibrary: metalDefaultLibrary, metalDevice:metalDevice) - //metalCommandBuffer.commit() - - print(" <== createrectifierlayer") - return (result, metalCommandBuffer) -} - - -func addRectifierCommandToCommandBuffer(commandBuffer: MTLCommandBuffer, inputBuffer: MTLBuffer, - metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice) -> MTLBuffer { - - print("==> addRectifierToCommandBuffer") - - let count = inputBuffer.length / sizeof(Float) - let (_, computePipelineState, _) = setupShaderInMetalPipeline("rectifier_linear", metalDefaultLibrary: metalDefaultLibrary, - metalDevice: metalDevice) - - // Create Metal Compute Command Encoder and add input and output buffers to it - let computeCommandEncoder = commandBuffer.computeCommandEncoder() - computeCommandEncoder.setBuffer(inputBuffer, offset: 0, atIndex: 0) - // Set the shader function that Metal will use - computeCommandEncoder.setComputePipelineState(computePipelineState) - - // Set up thread groups on GPU - let threadsPerGroup = MTLSize(width:computePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - let numThreadgroups = MTLSize(width:(count-1)/computePipelineState.threadExecutionWidth + 1, height:1, depth:1) - computeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - // Finalize configuration - computeCommandEncoder.endEncoding() - - print(" <== addRectifierToCommandBuffer") - - return inputBuffer -} diff --git a/DeepLearningKitForOSX/DeepLearningKitForOSX/Shaders.metal b/DeepLearningKitForOSX/DeepLearningKitForOSX/Shaders.metal deleted file mode 100644 index d8d27f8..0000000 --- a/DeepLearningKitForOSX/DeepLearningKitForOSX/Shaders.metal +++ /dev/null @@ -1,224 +0,0 @@ -// -// Shaders.metal -// -// Created by Torb Morland & Amund Tveit on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -#include -#include -#include -#include -#include -#include -#include -#include -using namespace metal; - -//////////////////////////////// -// DATA TYPES -//////////////////////////////// - -struct MetalComplexNumberType { // needs to map to float2 in Metal - float real; - float imag; -}; - -struct MetalShaderParameters { - float image_xdim; - float image_ydim; - float num_images; - float filter_xdim; // e.g. 5 - float filter_ydim; // e.g. 5 - float num_filters; // e.g. 20 -> W = 20*1*5*5 - float conv_xdim; // image_xdim - filter_xdim + 1 without striding - float conv_ydim; // image_ydim - filter_ydim + 1 without striding - float pool_xdim; - float pool_ydim; - float b; -}; - -struct MetalMatrixVectorParameters { - float x_xdim; - float x_ydim; - float w_xdim; - float w_ydim; - float b_xdim; - float b_ydim; - float result_xdim; - float result_ydim; -}; - -struct MetalPoolingParameters { - float kernel_size; - float pool_stride; - float pad; -}; - -struct MetalTensorDimensions { - float n; - float channels; - float width; - float height; -}; - -struct MetalConvolutionParameters { - float pad; - float kernel_size; - float stride; -}; - -//////////////////////////////// -// SHADER FUNCTIONS -//////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////// - - -// Returns max(0, X[id]) -kernel void rectifier_linear(device float* X [[ buffer(0)]], - uint id [[ thread_position_in_grid ]]) { - X[id] = fmax(0.0, X[id]); -} - -//////////////////////////////////////////////////////////////////////////////////////////// - -kernel void max_pool(device float* result [[ buffer(0) ]], - const device float* input [[ buffer(1) ]], - const device MetalShaderParameters* size_params [[ buffer(2) ]], - const device MetalPoolingParameters* pooling_params [[ buffer(3) ]], - uint id [[ thread_position_in_grid ]]) { - int channels = int(size_params[0].num_filters); - int in_width = int(size_params[0].image_xdim); - int in_height = int(size_params[0].image_ydim); - - float kernel_size = float(pooling_params[0].kernel_size); - int pool_stride = int(pooling_params[0].pool_stride); - int pad = int(pooling_params[0].pad); - - int out_width = int(size_params[0].pool_xdim); - int out_height = int(size_params[0].pool_ydim); - - int i = (id / out_height) % out_width; - int j = id % out_height; - int n = id / (channels * out_width * out_height); - int c = (id / (out_width * out_height)) % channels; - int wstart = i * pool_stride - pad; - int hstart = j * pool_stride - pad; - int wend = fmin(wstart + kernel_size, in_width + pad); - int hend = fmin(hstart + kernel_size, in_height + pad); - wstart = fmax(0.0, wstart); - hstart = fmax(0.0, hstart); - thread float pool = -100000.0; - for (int ii = wstart; ii < wend; ++ii) { - for (int jj = hstart; jj < hend; ++jj) { - pool = fmax(pool, input[(n * channels * in_height + c * in_height + ii) * in_width + jj]); - } - } - result[id] = pool; -} - -//////////////////////////////////////////////////////////////////////////////////////////// - -kernel void avg_pool(device float* result [[ buffer(0) ]], - const device float* input [[ buffer(1) ]], - const device MetalShaderParameters* size_params [[ buffer(2) ]], - const device MetalPoolingParameters* pooling_params [[ buffer(3) ]], - uint id [[ thread_position_in_grid ]]) { - int channels = int(size_params[0].num_filters); - int in_width = int(size_params[0].image_xdim); - int in_height = int(size_params[0].image_ydim); - - float kernel_size = float(pooling_params[0].kernel_size); - int pool_stride = int(pooling_params[0].pool_stride); - int pad = int(pooling_params[0].pad); - - int out_width = int(size_params[0].pool_xdim); - int out_height = int(size_params[0].pool_ydim); - - int i = (id / out_height) % out_width; - int j = id % out_height; - int n = id / (channels * out_width * out_height); - int c = (id / (out_width * out_height)) % channels; - int wstart = i * pool_stride - pad; - int hstart = j * pool_stride - pad; - int wend = fmin(wstart + kernel_size, in_width + pad); - int hend = fmin(hstart + kernel_size, in_height + pad); - float pool_size = (hend - hstart) * (wend - wstart); - wstart = fmax(0.0, wstart); - hstart = fmax(0.0, hstart); - thread float pool = 0.0; - for (int ii = wstart; ii < wend; ++ii) { - for (int jj = hstart; jj < hend; ++jj) { - pool += input[(n * channels * in_height + c * in_height + ii) * in_width + jj]/pool_size; - } - } - result[id] = pool; -} - -//////////////////////////////////////////////////////////////////////////////////////////// - -kernel void im2col(const device float* convolution_input [[ buffer(0)]], - const device MetalTensorDimensions* tensor_dimensions [[ buffer(1) ]], - const device MetalConvolutionParameters* convolution_params [[ buffer(2) ]], - device float* col_output [[ buffer(3) ]], - uint id [[ thread_position_in_grid ]]) { - int channels_in = int(tensor_dimensions[0].channels); - int in_width = int(tensor_dimensions[0].width); - int in_height = int(tensor_dimensions[0].height); - - int channels_col = int(tensor_dimensions[2].channels); - int width_col = int(tensor_dimensions[2].width); - int height_col = int(tensor_dimensions[2].height); - - - // 1. do an im2col transformation - int pad = int(convolution_params[0].pad); - int kernel_size = int(convolution_params[0].kernel_size); - - int n = id / (channels_col * height_col * width_col); - int c = (id / (width_col * height_col)) % channels_col; - int h = (id / width_col) % height_col; - int w = id % width_col; - int w_offset = c % kernel_size; - int h_offset = (c / kernel_size) % kernel_size; - int h_pad = h - pad + h_offset; - int w_pad = w - pad + w_offset; - int c_im = c / (kernel_size * kernel_size); - if (h_pad >= 0 && h_pad < in_height && w_pad >= 0 && w_pad < in_width) { - col_output[id] = convolution_input[(n * channels_in * in_height + c_im * in_height + h_pad) * in_width + w_pad]; - } -} - -//////////////////////////////////////////////////////////////////////////////////////////// - -// Tensor dimensions = { input_dimensions, weight_dimensions, col_dimensions, result_dimensions } -kernel void convolution_layer(device float* result [[ buffer(0) ]], - const device float* weights [[ buffer(1)]], - const device MetalTensorDimensions* tensor_dimensions [[ buffer(2) ]], - const device float* col_output [[ buffer(3) ]], - const device float* bias [[ buffer(4) ]], - uint id [[ thread_position_in_grid ]]) { - int channels_col = int(tensor_dimensions[2].channels); - int width_col = int(tensor_dimensions[2].width); - int height_col = int(tensor_dimensions[2].height); - - int channels_out = int(tensor_dimensions[3].channels); - int width_out = int(tensor_dimensions[3].width); - int height_out = int(tensor_dimensions[3].height); - - int n = id / (channels_out * height_out * width_out); - int a = (id / (height_out * width_out)) % channels_out; - int b = id % (height_out * width_out); - - thread float tmp_result = bias[a]; - - for (int c = 0; c < channels_col; ++c) { - tmp_result += weights[a * channels_col + c] * col_output[(n * channels_col * width_col + c * width_col) * height_col + b]; - } - - result[id] = tmp_result; -} - - - diff --git a/DeepLearningKitForOSX/DeepLearningKitForOSXTests/DeepLearningKitForOSXTests.swift b/DeepLearningKitForOSX/DeepLearningKitForOSXTests/DeepLearningKitForOSXTests.swift deleted file mode 100644 index b91526d..0000000 --- a/DeepLearningKitForOSX/DeepLearningKitForOSXTests/DeepLearningKitForOSXTests.swift +++ /dev/null @@ -1,36 +0,0 @@ -// -// DeepLearningKitForOSXTests.swift -// DeepLearningKitForOSXTests -// -// Created by Amund Tveit on 11/12/15. -// Copyright © 2015 Amund Tveit. All rights reserved. -// - -import XCTest -@testable import DeepLearningKitForOSX - -class DeepLearningKitForOSXTests: XCTestCase { - - override func setUp() { - super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - } - - func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. - } - - func testPerformanceExample() { - // This is an example of a performance test case. - self.measureBlock { - // Put the code you want to measure the time of here. - } - } - -} diff --git a/DeepLearningKitForOSX/DeepLearningKitForOSXTests/Info.plist b/DeepLearningKitForOSX/DeepLearningKitForOSXTests/Info.plist deleted file mode 100644 index ba72822..0000000 --- a/DeepLearningKitForOSX/DeepLearningKitForOSXTests/Info.plist +++ /dev/null @@ -1,24 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - - diff --git a/DeepLearningKitForiOS/DeepLearningKitForiOS.xcodeproj/project.pbxproj b/DeepLearningKitForiOS/DeepLearningKitForiOS.xcodeproj/project.pbxproj deleted file mode 100644 index 64742c5..0000000 --- a/DeepLearningKitForiOS/DeepLearningKitForiOS.xcodeproj/project.pbxproj +++ /dev/null @@ -1,484 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 67A73C7D1C1AF160001FD9F8 /* DeepLearningKitForiOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 67A73C7C1C1AF160001FD9F8 /* DeepLearningKitForiOS.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 67A73C841C1AF160001FD9F8 /* DeepLearningKitForiOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 67A73C791C1AF160001FD9F8 /* DeepLearningKitForiOS.framework */; }; - 67A73C891C1AF160001FD9F8 /* DeepLearningKitForiOSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73C881C1AF160001FD9F8 /* DeepLearningKitForiOSTests.swift */; }; - 67A73C941C1AF1B1001FD9F8 /* ConvolutionLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73C931C1AF1B1001FD9F8 /* ConvolutionLayer.swift */; }; - 67A73C951C1AF1B1001FD9F8 /* ConvolutionLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73C931C1AF1B1001FD9F8 /* ConvolutionLayer.swift */; }; - 67A73C9A1C1AF1C7001FD9F8 /* DeepNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73C961C1AF1C7001FD9F8 /* DeepNetwork.swift */; }; - 67A73C9B1C1AF1C7001FD9F8 /* DeepNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73C961C1AF1C7001FD9F8 /* DeepNetwork.swift */; }; - 67A73C9E1C1AF1C7001FD9F8 /* DeepNetwork+JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73C981C1AF1C7001FD9F8 /* DeepNetwork+JSON.swift */; }; - 67A73C9F1C1AF1C7001FD9F8 /* DeepNetwork+JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73C981C1AF1C7001FD9F8 /* DeepNetwork+JSON.swift */; }; - 67A73CA01C1AF1C7001FD9F8 /* DeepNetwork+SetupNetworkFromDict.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73C991C1AF1C7001FD9F8 /* DeepNetwork+SetupNetworkFromDict.swift */; }; - 67A73CA11C1AF1C7001FD9F8 /* DeepNetwork+SetupNetworkFromDict.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73C991C1AF1C7001FD9F8 /* DeepNetwork+SetupNetworkFromDict.swift */; }; - 67A73CA41C1AF1D3001FD9F8 /* MetalDataStructures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73CA21C1AF1D3001FD9F8 /* MetalDataStructures.swift */; }; - 67A73CA51C1AF1D3001FD9F8 /* MetalDataStructures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73CA21C1AF1D3001FD9F8 /* MetalDataStructures.swift */; }; - 67A73CA61C1AF1D3001FD9F8 /* MetalUtilityFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73CA31C1AF1D3001FD9F8 /* MetalUtilityFunctions.swift */; }; - 67A73CA71C1AF1D3001FD9F8 /* MetalUtilityFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73CA31C1AF1D3001FD9F8 /* MetalUtilityFunctions.swift */; }; - 67A73CAC1C1AF1DF001FD9F8 /* PoolingLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73CA81C1AF1DF001FD9F8 /* PoolingLayer.swift */; }; - 67A73CAD1C1AF1DF001FD9F8 /* PoolingLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73CA81C1AF1DF001FD9F8 /* PoolingLayer.swift */; }; - 67A73CAE1C1AF1DF001FD9F8 /* RectifierLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73CA91C1AF1DF001FD9F8 /* RectifierLayer.swift */; }; - 67A73CAF1C1AF1DF001FD9F8 /* RectifierLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73CA91C1AF1DF001FD9F8 /* RectifierLayer.swift */; }; - 67A73CB01C1AF1DF001FD9F8 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 67A73CAA1C1AF1DF001FD9F8 /* Shaders.metal */; }; - 67A73CB11C1AF1DF001FD9F8 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 67A73CAA1C1AF1DF001FD9F8 /* Shaders.metal */; }; - 67A73CB21C1AF1DF001FD9F8 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73CAB1C1AF1DF001FD9F8 /* ViewController.swift */; }; - 67A73CB31C1AF1DF001FD9F8 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73CAB1C1AF1DF001FD9F8 /* ViewController.swift */; }; - 67A73D2C1C1B09EE001FD9F8 /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 67A73D291C1B09EE001FD9F8 /* Metal.framework */; }; -/* End PBXBuildFile section */ - -/* Begin PBXContainerItemProxy section */ - 67A73C851C1AF160001FD9F8 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 67A73C701C1AF160001FD9F8 /* Project object */; - proxyType = 1; - remoteGlobalIDString = 67A73C781C1AF160001FD9F8; - remoteInfo = DeepLearningKitForiOS; - }; -/* End PBXContainerItemProxy section */ - -/* Begin PBXFileReference section */ - 67A73C791C1AF160001FD9F8 /* DeepLearningKitForiOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DeepLearningKitForiOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 67A73C7C1C1AF160001FD9F8 /* DeepLearningKitForiOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeepLearningKitForiOS.h; sourceTree = ""; }; - 67A73C7E1C1AF160001FD9F8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 67A73C831C1AF160001FD9F8 /* DeepLearningKitForiOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DeepLearningKitForiOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 67A73C881C1AF160001FD9F8 /* DeepLearningKitForiOSTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeepLearningKitForiOSTests.swift; sourceTree = ""; }; - 67A73C8A1C1AF160001FD9F8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 67A73C931C1AF1B1001FD9F8 /* ConvolutionLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConvolutionLayer.swift; sourceTree = ""; }; - 67A73C961C1AF1C7001FD9F8 /* DeepNetwork.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeepNetwork.swift; sourceTree = ""; }; - 67A73C981C1AF1C7001FD9F8 /* DeepNetwork+JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DeepNetwork+JSON.swift"; sourceTree = ""; }; - 67A73C991C1AF1C7001FD9F8 /* DeepNetwork+SetupNetworkFromDict.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DeepNetwork+SetupNetworkFromDict.swift"; sourceTree = ""; }; - 67A73CA21C1AF1D3001FD9F8 /* MetalDataStructures.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalDataStructures.swift; sourceTree = ""; }; - 67A73CA31C1AF1D3001FD9F8 /* MetalUtilityFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalUtilityFunctions.swift; sourceTree = ""; }; - 67A73CA81C1AF1DF001FD9F8 /* PoolingLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PoolingLayer.swift; sourceTree = ""; }; - 67A73CA91C1AF1DF001FD9F8 /* RectifierLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RectifierLayer.swift; sourceTree = ""; }; - 67A73CAA1C1AF1DF001FD9F8 /* Shaders.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Shaders.metal; sourceTree = ""; }; - 67A73CAB1C1AF1DF001FD9F8 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; - 67A73D291C1B09EE001FD9F8 /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 67A73C751C1AF160001FD9F8 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 67A73D2C1C1B09EE001FD9F8 /* Metal.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 67A73C801C1AF160001FD9F8 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 67A73C841C1AF160001FD9F8 /* DeepLearningKitForiOS.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 67A73C6F1C1AF160001FD9F8 = { - isa = PBXGroup; - children = ( - 67A73D291C1B09EE001FD9F8 /* Metal.framework */, - 67A73C7B1C1AF160001FD9F8 /* DeepLearningKitForiOS */, - 67A73C871C1AF160001FD9F8 /* DeepLearningKitForiOSTests */, - 67A73C7A1C1AF160001FD9F8 /* Products */, - ); - sourceTree = ""; - }; - 67A73C7A1C1AF160001FD9F8 /* Products */ = { - isa = PBXGroup; - children = ( - 67A73C791C1AF160001FD9F8 /* DeepLearningKitForiOS.framework */, - 67A73C831C1AF160001FD9F8 /* DeepLearningKitForiOSTests.xctest */, - ); - name = Products; - sourceTree = ""; - }; - 67A73C7B1C1AF160001FD9F8 /* DeepLearningKitForiOS */ = { - isa = PBXGroup; - children = ( - 67A73C7C1C1AF160001FD9F8 /* DeepLearningKitForiOS.h */, - 67A73CBD1C1AF2F2001FD9F8 /* PUBLIC_API */, - 67A73CBF1C1AF4D6001FD9F8 /* INTERNAL_API */, - 67A73CBC1C1AF27F001FD9F8 /* GPU_METAL */, - 67A73CAB1C1AF1DF001FD9F8 /* ViewController.swift */, - 67A73C7E1C1AF160001FD9F8 /* Info.plist */, - ); - path = DeepLearningKitForiOS; - sourceTree = ""; - }; - 67A73C871C1AF160001FD9F8 /* DeepLearningKitForiOSTests */ = { - isa = PBXGroup; - children = ( - 67A73C881C1AF160001FD9F8 /* DeepLearningKitForiOSTests.swift */, - 67A73C8A1C1AF160001FD9F8 /* Info.plist */, - ); - path = DeepLearningKitForiOSTests; - sourceTree = ""; - }; - 67A73CBC1C1AF27F001FD9F8 /* GPU_METAL */ = { - isa = PBXGroup; - children = ( - 67A73CA21C1AF1D3001FD9F8 /* MetalDataStructures.swift */, - 67A73CA31C1AF1D3001FD9F8 /* MetalUtilityFunctions.swift */, - 67A73CAA1C1AF1DF001FD9F8 /* Shaders.metal */, - ); - name = GPU_METAL; - sourceTree = ""; - }; - 67A73CBD1C1AF2F2001FD9F8 /* PUBLIC_API */ = { - isa = PBXGroup; - children = ( - 67A73C961C1AF1C7001FD9F8 /* DeepNetwork.swift */, - ); - name = PUBLIC_API; - sourceTree = ""; - }; - 67A73CBF1C1AF4D6001FD9F8 /* INTERNAL_API */ = { - isa = PBXGroup; - children = ( - 67A73C981C1AF1C7001FD9F8 /* DeepNetwork+JSON.swift */, - 67A73C991C1AF1C7001FD9F8 /* DeepNetwork+SetupNetworkFromDict.swift */, - 67A73C931C1AF1B1001FD9F8 /* ConvolutionLayer.swift */, - 67A73CA81C1AF1DF001FD9F8 /* PoolingLayer.swift */, - 67A73CA91C1AF1DF001FD9F8 /* RectifierLayer.swift */, - ); - name = INTERNAL_API; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXHeadersBuildPhase section */ - 67A73C761C1AF160001FD9F8 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 67A73C7D1C1AF160001FD9F8 /* DeepLearningKitForiOS.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXHeadersBuildPhase section */ - -/* Begin PBXNativeTarget section */ - 67A73C781C1AF160001FD9F8 /* DeepLearningKitForiOS */ = { - isa = PBXNativeTarget; - buildConfigurationList = 67A73C8D1C1AF160001FD9F8 /* Build configuration list for PBXNativeTarget "DeepLearningKitForiOS" */; - buildPhases = ( - 67A73C741C1AF160001FD9F8 /* Sources */, - 67A73C751C1AF160001FD9F8 /* Frameworks */, - 67A73C761C1AF160001FD9F8 /* Headers */, - 67A73C771C1AF160001FD9F8 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = DeepLearningKitForiOS; - productName = DeepLearningKitForiOS; - productReference = 67A73C791C1AF160001FD9F8 /* DeepLearningKitForiOS.framework */; - productType = "com.apple.product-type.framework"; - }; - 67A73C821C1AF160001FD9F8 /* DeepLearningKitForiOSTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 67A73C901C1AF160001FD9F8 /* Build configuration list for PBXNativeTarget "DeepLearningKitForiOSTests" */; - buildPhases = ( - 67A73C7F1C1AF160001FD9F8 /* Sources */, - 67A73C801C1AF160001FD9F8 /* Frameworks */, - 67A73C811C1AF160001FD9F8 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - 67A73C861C1AF160001FD9F8 /* PBXTargetDependency */, - ); - name = DeepLearningKitForiOSTests; - productName = DeepLearningKitForiOSTests; - productReference = 67A73C831C1AF160001FD9F8 /* DeepLearningKitForiOSTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 67A73C701C1AF160001FD9F8 /* Project object */ = { - isa = PBXProject; - attributes = { - LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0720; - ORGANIZATIONNAME = "Amund Tveit"; - TargetAttributes = { - 67A73C781C1AF160001FD9F8 = { - CreatedOnToolsVersion = 7.2; - }; - 67A73C821C1AF160001FD9F8 = { - CreatedOnToolsVersion = 7.2; - }; - }; - }; - buildConfigurationList = 67A73C731C1AF160001FD9F8 /* Build configuration list for PBXProject "DeepLearningKitForiOS" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = 67A73C6F1C1AF160001FD9F8; - productRefGroup = 67A73C7A1C1AF160001FD9F8 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 67A73C781C1AF160001FD9F8 /* DeepLearningKitForiOS */, - 67A73C821C1AF160001FD9F8 /* DeepLearningKitForiOSTests */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 67A73C771C1AF160001FD9F8 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 67A73C811C1AF160001FD9F8 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 67A73C741C1AF160001FD9F8 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 67A73CAE1C1AF1DF001FD9F8 /* RectifierLayer.swift in Sources */, - 67A73C9A1C1AF1C7001FD9F8 /* DeepNetwork.swift in Sources */, - 67A73C941C1AF1B1001FD9F8 /* ConvolutionLayer.swift in Sources */, - 67A73CAC1C1AF1DF001FD9F8 /* PoolingLayer.swift in Sources */, - 67A73CB21C1AF1DF001FD9F8 /* ViewController.swift in Sources */, - 67A73CB01C1AF1DF001FD9F8 /* Shaders.metal in Sources */, - 67A73C9E1C1AF1C7001FD9F8 /* DeepNetwork+JSON.swift in Sources */, - 67A73CA61C1AF1D3001FD9F8 /* MetalUtilityFunctions.swift in Sources */, - 67A73CA41C1AF1D3001FD9F8 /* MetalDataStructures.swift in Sources */, - 67A73CA01C1AF1C7001FD9F8 /* DeepNetwork+SetupNetworkFromDict.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 67A73C7F1C1AF160001FD9F8 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 67A73C951C1AF1B1001FD9F8 /* ConvolutionLayer.swift in Sources */, - 67A73CA11C1AF1C7001FD9F8 /* DeepNetwork+SetupNetworkFromDict.swift in Sources */, - 67A73CA51C1AF1D3001FD9F8 /* MetalDataStructures.swift in Sources */, - 67A73CAD1C1AF1DF001FD9F8 /* PoolingLayer.swift in Sources */, - 67A73C891C1AF160001FD9F8 /* DeepLearningKitForiOSTests.swift in Sources */, - 67A73CAF1C1AF1DF001FD9F8 /* RectifierLayer.swift in Sources */, - 67A73CB31C1AF1DF001FD9F8 /* ViewController.swift in Sources */, - 67A73C9F1C1AF1C7001FD9F8 /* DeepNetwork+JSON.swift in Sources */, - 67A73CB11C1AF1DF001FD9F8 /* Shaders.metal in Sources */, - 67A73CA71C1AF1D3001FD9F8 /* MetalUtilityFunctions.swift in Sources */, - 67A73C9B1C1AF1C7001FD9F8 /* DeepNetwork.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXTargetDependency section */ - 67A73C861C1AF160001FD9F8 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 67A73C781C1AF160001FD9F8 /* DeepLearningKitForiOS */; - targetProxy = 67A73C851C1AF160001FD9F8 /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - -/* Begin XCBuildConfiguration section */ - 67A73C8B1C1AF160001FD9F8 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.2; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - TARGETED_DEVICE_FAMILY = "1,2"; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Debug; - }; - 67A73C8C1C1AF160001FD9F8 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.2; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2"; - VALIDATE_PRODUCT = YES; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Release; - }; - 67A73C8E1C1AF160001FD9F8 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_MODULES = YES; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = DeepLearningKitForiOS/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = org.deeplearningkit.DeepLearningKitForiOS; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - }; - name = Debug; - }; - 67A73C8F1C1AF160001FD9F8 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_MODULES = YES; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = DeepLearningKitForiOS/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = org.deeplearningkit.DeepLearningKitForiOS; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - }; - name = Release; - }; - 67A73C911C1AF160001FD9F8 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - INFOPLIST_FILE = DeepLearningKitForiOSTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = org.deeplearningkit.DeepLearningKitForiOSTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - 67A73C921C1AF160001FD9F8 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - INFOPLIST_FILE = DeepLearningKitForiOSTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = org.deeplearningkit.DeepLearningKitForiOSTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 67A73C731C1AF160001FD9F8 /* Build configuration list for PBXProject "DeepLearningKitForiOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 67A73C8B1C1AF160001FD9F8 /* Debug */, - 67A73C8C1C1AF160001FD9F8 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Debug; - }; - 67A73C8D1C1AF160001FD9F8 /* Build configuration list for PBXNativeTarget "DeepLearningKitForiOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 67A73C8E1C1AF160001FD9F8 /* Debug */, - 67A73C8F1C1AF160001FD9F8 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Debug; - }; - 67A73C901C1AF160001FD9F8 /* Build configuration list for PBXNativeTarget "DeepLearningKitForiOSTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 67A73C911C1AF160001FD9F8 /* Debug */, - 67A73C921C1AF160001FD9F8 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Debug; - }; -/* End XCConfigurationList section */ - }; - rootObject = 67A73C701C1AF160001FD9F8 /* Project object */; -} diff --git a/DeepLearningKitForiOS/DeepLearningKitForiOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/DeepLearningKitForiOS/DeepLearningKitForiOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 2b72ae8..0000000 --- a/DeepLearningKitForiOS/DeepLearningKitForiOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/DeepLearningKitForiOS/DeepLearningKitForiOS/ConvolutionLayer.swift b/DeepLearningKitForiOS/DeepLearningKitForiOS/ConvolutionLayer.swift deleted file mode 100644 index 45709d0..0000000 --- a/DeepLearningKitForiOS/DeepLearningKitForiOS/ConvolutionLayer.swift +++ /dev/null @@ -1,237 +0,0 @@ -// -// ConvolutionLayer.swift -// MemkiteMetal -// -// Created by Torb Morland & Amund Tveit on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - -func getDataFromBlob(blob: NSDictionary) -> ([Float], [Float]) { - print(" ==> getDataFromBlob") - - let shape = blob["shape"] as! NSDictionary - let data = blob["data"] as! [Float] - var FloatData = createFloatNumbersArray(data.count) - for i in 0 ..< data.count { - FloatData[i] = data[i] - } - return (shape["dim"] as! [Float], FloatData) -} - - - -func createConvolutionLayerCached(layer: NSDictionary, - inputBuffer: MTLBuffer, - inputShape: [Float], - metalCommandQueue: MTLCommandQueue, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout layer_data_caches: [Dictionary], - inout blob_cache: [Dictionary], - layer_number: Int, - layer_string: String) -> (MTLBuffer, MTLCommandBuffer, [Float]) { - - let start = NSDate() - - print("CREATECONVLAYERCACHED") - -// let metalCommandBuffer = metalCommandQueue.commandBuffer() - let metalCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() - - var convolution_params_dict:NSDictionary = NSDictionary() - var pad:Float = 0.0 - var kernel_size:Float = 1.0 - var stride:Float = 1.0 - var blobs:[NSDictionary] = [] - var weights:[Float] = [] - var weight_shape:[Float] = [] - var bias_data:[Float] = [] - var h:Float = 0.0 - var w:Float = 0.0 - var result_shape:[Float] = [] - var outputCount:Int = 0 - - var input_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var weight_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var result_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var tensor_dimensions:[MetalTensorDimensions] = [] - var col_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var col_output:[Float] = [] - var convolution_params:MetalConvolutionParameters = MetalConvolutionParameters(pad:0, kernel_size: 0, stride: 0) - - - print("NOTCACHINGMODE") - convolution_params_dict = layer["convolution_param"] as! NSDictionary - pad = 0.0 - kernel_size = 1.0 - stride = 1.0 - if let val = convolution_params_dict["pad"] as? Float { - pad = val - } - if let val = convolution_params_dict["kernel_size"] as? Float { - kernel_size = val - } - - let startblob = NSDate() - - - if let tmpval = blob_cache[layer_number]["0"] { - print("found blob key = 0 in cache") - (weight_shape, weights) = tmpval - } else { - print("didnt find blob key = 0 in cache") - blobs = layer["blobs"] as! [NSDictionary] - (weight_shape, weights) = getDataFromBlob(blobs[0]) - blob_cache[layer_number]["0"] = (weight_shape, weights) - } - -// this can be optimized - blobs = layer["blobs"] as! [NSDictionary] - (_, bias_data) = getDataFromBlob(blobs[1]) - - print("### Time to blob: \(NSDate().timeIntervalSinceDate(startblob))") - - - /* - let startblob = NSDate() - blobs = layer["blobs"] as! [NSDictionary] - (weight_shape, weights) = getDataFromBlob(blobs[0]) - (_, bias_data) = getDataFromBlob(blobs[1]) - print("### Time to blob: \(NSDate().timeIntervalSinceDate(startblob))") -*/ - - - h = (inputShape[2] + 2 * pad - kernel_size) / stride + 1 - w = (inputShape[3] + 2 * pad - kernel_size) / stride + 1 - result_shape = [inputShape[0], weight_shape[0], h, w] - outputCount = Int(result_shape.reduce(1, combine: *)) - - // Create input and output vectors, and corresponding metal buffer - input_dimensions = MetalTensorDimensions(n: inputShape[0], channels: inputShape[1], width: inputShape[2], height: inputShape[3]) - weight_dimensions = MetalTensorDimensions(n: weight_shape[0], channels: weight_shape[1], width: weight_shape[2], height: weight_shape[3]) - col_dimensions = MetalTensorDimensions(n: inputShape[0], channels: inputShape[1] * weight_shape[2] * weight_shape[3], width: inputShape[2], height: inputShape[3]) - result_dimensions = MetalTensorDimensions(n: result_shape[0], channels: result_shape[1], width: result_shape[2], height: result_shape[3]) - tensor_dimensions = [input_dimensions, weight_dimensions, col_dimensions, result_dimensions] - - - col_output = createFloatNumbersArray(Int(col_dimensions.n * col_dimensions.channels * col_dimensions.height * col_dimensions.width)) - - - convolution_params = MetalConvolutionParameters(pad: pad, kernel_size: kernel_size, stride: stride) - print("AFTER NOTCACHINGMODE") - - - print("BEFORE THE BIG CALL") - - let resultBuffer = addConvolutionCommandToCommandBufferCached(metalCommandBuffer, inputBuffer: inputBuffer, im2ColCount: col_output.count, weights: weights, outputCount: outputCount, convolution_params: convolution_params, tensor_dimensions: tensor_dimensions, bias: bias_data, metalDefaultLibrary: metalDefaultLibrary, metalDevice:metalDevice, layer_data_caches: &layer_data_caches, layer_number: layer_number,layer_string: layer_string) - //metalCommandBuffer.commit() - - print("AFTER BIG CALL") - - print("### Time to setup convolution layer: \(NSDate().timeIntervalSinceDate(start))") - - - return (resultBuffer, metalCommandBuffer, result_shape) - -} - -func addConvolutionCommandToCommandBufferCached(commandBuffer: MTLCommandBuffer, - inputBuffer: MTLBuffer, - im2ColCount: Int, - weights: [Float], - outputCount: Int, - convolution_params: MetalConvolutionParameters, - tensor_dimensions: [MetalTensorDimensions], - bias: [Float], - metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout layer_data_caches: [Dictionary], - layer_number: Int, - layer_string: String) -> MTLBuffer { - - let start = NSDate() - - print("before output and col_output") - - var output:[Float] = [] - var col_output:[Float] = [] - - output = createFloatNumbersArray(outputCount) - col_output = createFloatNumbersArray(im2ColCount) - - print("before setupshaderinpipeline") - - let (_, im2colComputePipelineState, _) = setupShaderInMetalPipeline("im2col", metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice) - - let resultMetalBuffer = createOrReuseFloatMetalBuffer("resultMetalBuffer", data: output, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - - print("after resultmetalbuffer") - - let weightMetalBuffer = createOrReuseFloatMetalBuffer("weightMetalBuffer", data: weights, cache: &layer_data_caches, layer_number:layer_number, metalDevice: metalDevice) - - - let convolutionParamsMetalBuffer = createOrReuseConvolutionParametersMetalBuffer("convolutionParamsMetalBuffer", data: convolution_params, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - let tensorDimensionsMetalBuffer = createOrReuseTensorDimensionsVectorMetalBuffer("tensorDimensionsMetalBuffer", data: tensor_dimensions, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - - let colOutputMetalBuffer = createOrReuseFloatMetalBuffer("colOutputMetalBuffer", data: col_output, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - let biasMetalBuffer = createOrReuseFloatMetalBuffer("bias", data: bias, cache: &layer_data_caches, layer_number:layer_number, metalDevice: metalDevice) - - - // Create Metal compute command encoder for im2col - var metalComputeCommandEncoder = commandBuffer.computeCommandEncoder() - metalComputeCommandEncoder.setBuffer(inputBuffer, offset: 0, atIndex: 0) - metalComputeCommandEncoder.setBuffer(tensorDimensionsMetalBuffer, offset: 0, atIndex: 1) - metalComputeCommandEncoder.setBuffer(convolutionParamsMetalBuffer, offset: 0, atIndex: 2) - metalComputeCommandEncoder.setBuffer(colOutputMetalBuffer, offset: 0, atIndex: 3) - //metalComputeCommandEncoder.setComputePipelineState(im2colComputePipelineState) - - - // Set the shader function that Metal will use - metalComputeCommandEncoder.setComputePipelineState(im2colComputePipelineState) - - // Set up thread groups on GPU - var threadsPerGroup = MTLSize(width:im2colComputePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - print("before mtlsize 2") - var numThreadgroups = MTLSize(width:(col_output.count-1)/im2colComputePipelineState.threadExecutionWidth + 1, height:1, depth:1) - metalComputeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - print("after dispatch") - - // Finalize configuration - metalComputeCommandEncoder.endEncoding() - - - - - let (_, convolutionComputePipelineState, _) = setupShaderInMetalPipeline("convolution_layer", metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice) - metalComputeCommandEncoder = commandBuffer.computeCommandEncoder() - - // Create Metal Compute Command Encoder and add input and output buffers to it - metalComputeCommandEncoder.setBuffer(resultMetalBuffer, offset: 0, atIndex: 0) - metalComputeCommandEncoder.setBuffer(weightMetalBuffer, offset: 0, atIndex: 1) - metalComputeCommandEncoder.setBuffer(tensorDimensionsMetalBuffer, offset: 0, atIndex: 2) - metalComputeCommandEncoder.setBuffer(colOutputMetalBuffer, offset: 0, atIndex: 3) - metalComputeCommandEncoder.setBuffer(biasMetalBuffer, offset: 0, atIndex: 4) - - // Set the shader function that Metal will use - metalComputeCommandEncoder.setComputePipelineState(convolutionComputePipelineState) - - // Set up thread groups on GPU - threadsPerGroup = MTLSize(width:convolutionComputePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - numThreadgroups = MTLSize(width:(outputCount-1)/convolutionComputePipelineState.threadExecutionWidth + 1, height:1, depth:1) - metalComputeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - // Finalize configuration - metalComputeCommandEncoder.endEncoding() - - print("after endencoding") - - print("#### Time to add convolution layer: \(NSDate().timeIntervalSinceDate(start))") - - - return resultMetalBuffer - -} - diff --git a/DeepLearningKitForiOS/DeepLearningKitForiOS/DeepLearningKitForiOS.h b/DeepLearningKitForiOS/DeepLearningKitForiOS/DeepLearningKitForiOS.h deleted file mode 100644 index d5ee910..0000000 --- a/DeepLearningKitForiOS/DeepLearningKitForiOS/DeepLearningKitForiOS.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// DeepLearningKitForiOS.h -// DeepLearningKitForiOS -// -// Created by Amund Tveit on 11/12/15. -// Copyright © 2015 Amund Tveit. All rights reserved. -// - -#import - -//! Project version number for DeepLearningKitForiOS. -FOUNDATION_EXPORT double DeepLearningKitForiOSVersionNumber; - -//! Project version string for DeepLearningKitForiOS. -FOUNDATION_EXPORT const unsigned char DeepLearningKitForiOSVersionString[]; - -// In this header, you should import all the public headers of your framework using statements like #import - - diff --git a/DeepLearningKitForiOS/DeepLearningKitForiOS/DeepNetwork+JSON.swift b/DeepLearningKitForiOS/DeepLearningKitForiOS/DeepNetwork+JSON.swift deleted file mode 100644 index 9755f49..0000000 --- a/DeepLearningKitForiOS/DeepLearningKitForiOS/DeepNetwork+JSON.swift +++ /dev/null @@ -1,26 +0,0 @@ -// -// DeepNetwork+JSON.swift -// MemkiteMetal -// -// Created by Amund Tveit & Torb Morland on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation - -public extension DeepNetwork { - -func loadJSONFile(filename: String) -> NSDictionary? { - print(" ==> loadJSONFile(filename=\(filename)") - - do { - let bundle = NSBundle.mainBundle() - let path = bundle.pathForResource(filename, ofType: "json")! - let jsonData = NSData(contentsOfFile: path) - print(" <== loadJSONFile") - return try NSJSONSerialization.JSONObjectWithData(jsonData!, options: .AllowFragments) as? NSDictionary - } catch _ { - return nil - } -} -} \ No newline at end of file diff --git a/DeepLearningKitForiOS/DeepLearningKitForiOS/DeepNetwork+SetupNetworkFromDict.swift b/DeepLearningKitForiOS/DeepLearningKitForiOS/DeepNetwork+SetupNetworkFromDict.swift deleted file mode 100644 index e0e0934..0000000 --- a/DeepLearningKitForiOS/DeepLearningKitForiOS/DeepNetwork+SetupNetworkFromDict.swift +++ /dev/null @@ -1,86 +0,0 @@ -// -// DeepNetwork+SetupNetworkFromDict.swift -// MemkiteMetal -// -// Created by Amund Tveit & Torb Morland on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - -public extension DeepNetwork { - - func setupNetworkFromDict(deepNetworkAsDict: NSDictionary, inputimage: MTLBuffer, inputshape: [Float]) { - - let start = NSDate() - - gpuCommandLayers = [] - - print(" ==> setupNetworkFromDict()") - // Add input image - var layer_number = 0 - layer_data_caches.append(Dictionary()) // for input - pool_type_caches.append(Dictionary()) - blob_cache.append(Dictionary()) - namedDataLayers.append(("input", inputimage)) - ++layer_number - - - // Add remaining network - var previousBuffer:MTLBuffer = inputimage - var previousShape:[Float] = inputshape - - self.deepNetworkAsDict = deepNetworkAsDict - - // create new command buffer for next layer - var currentCommandBuffer: MTLCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() - - var t = NSDate() - for layer in deepNetworkAsDict["layer"] as! [NSDictionary] { - if let type = layer["type"] as? String { - let layer_string = layer["name"] as! String - - layer_data_caches.append(Dictionary()) - pool_type_caches.append(Dictionary()) - blob_cache.append(Dictionary()) - - - if type == "ReLU" { - self.gpuCommandLayers.append(currentCommandBuffer) - //(previousBuffer, currentCommandBuffer) = createRectifierLayer(previousBuffer) - (previousBuffer, currentCommandBuffer) = createRectifierLayer(previousBuffer, metalCommandQueue:metalCommandQueue, metalDefaultLibrary:metalDefaultLibrary, metalDevice:metalDevice) - self.namedDataLayers.append((layer["name"]! as! String, previousBuffer)) - } else if type == "Pooling" { - self.gpuCommandLayers.append(currentCommandBuffer) - // (previousBuffer, currentCommandBuffer, previousShape) = createPoolingLayer(layer, inputBuffer: previousBuffer, inputShape: previousShape) - (previousBuffer, currentCommandBuffer, previousShape) = createPoolingLayerCached(layer, inputBuffer: previousBuffer, inputShape: previousShape, metalCommandQueue: metalCommandQueue, metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice, pool_type_caches: &pool_type_caches, layer_data_caches: &layer_data_caches, layer_number: layer_number, layer_string: layer_string) - self.namedDataLayers.append((layer["name"]! as! String, previousBuffer)) - } else if type == "Convolution" { - self.gpuCommandLayers.append(currentCommandBuffer) - // (previousBuffer, currentCommandBuffer, previousShape) = createConvolutionLayer(layer, inputBuffer: previousBuffer, inputShape: previousShape) - (previousBuffer, currentCommandBuffer, previousShape) = createConvolutionLayerCached(layer, inputBuffer: previousBuffer, inputShape: previousShape, metalCommandQueue: metalCommandQueue, metalDefaultLibrary:metalDefaultLibrary, metalDevice:metalDevice, layer_data_caches: &layer_data_caches, blob_cache: &blob_cache, layer_number: layer_number, layer_string: layer_string) - - - self.namedDataLayers.append((layer["name"]! as! String, previousBuffer)) - } - let name = layer["name"] as! String - print("\(name): \(NSDate().timeIntervalSinceDate(t))") - t = NSDate() - ++layer_number - - } - } - - self.gpuCommandLayers.append(currentCommandBuffer) - - print("bar") - - print("AFTER LAYER DATA CHACES = \(layer_data_caches[0])") - - print("POOL TYPE CACHES = \(pool_type_caches)") - - print("Time to set up network: \(NSDate().timeIntervalSinceDate(start))") - - } -} diff --git a/DeepLearningKitForiOS/DeepLearningKitForiOS/DeepNetwork.swift b/DeepLearningKitForiOS/DeepLearningKitForiOS/DeepNetwork.swift deleted file mode 100644 index 4f5de2b..0000000 --- a/DeepLearningKitForiOS/DeepLearningKitForiOS/DeepNetwork.swift +++ /dev/null @@ -1,76 +0,0 @@ -// -// DeepNetwork.swift -// MemkiteMetal -// -// Created by Amund Tveit & Torb Morland on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - -public class DeepNetwork { - var gpuCommandLayers: [MTLCommandBuffer] = [] - var namedDataLayers: [(String, MTLBuffer)] = [] - var imageBuffer: MTLBuffer! - var metalDevice: MTLDevice! - var metalDefaultLibrary: MTLLibrary! - var metalCommandQueue: MTLCommandQueue! - var deepNetworkAsDict: NSDictionary! // for debugging perhaps - var layer_data_caches: [Dictionary] = [] - var pool_type_caches: [Dictionary] = [] - var dummy_image: [Float]! - var previous_shape: [Float]! - var blob_cache: [Dictionary] = [] - - public init() { - // Get access to iPhone or iPad GPU - metalDevice = MTLCreateSystemDefaultDevice() - - // Queue to handle an ordered list of command buffers - metalCommandQueue = metalDevice.newCommandQueue() - print("metalCommandQueue = \(unsafeAddressOf(metalCommandQueue))") - - // Access to Metal functions that are stored in Shaders.metal file, e.g. sigmoid() - metalDefaultLibrary = metalDevice.newDefaultLibrary() - } - - public func loadNetworkFromJson(jsonNetworkFileName: String) { - deepNetworkAsDict = loadJSONFile(jsonNetworkFileName)! - } - - public func classify(image: [Float], shape:[Float]) -> Int { - let imageTensor = createMetalBuffer(image, metalDevice: metalDevice) - - gpuCommandLayers = [] - setupNetworkFromDict(deepNetworkAsDict, inputimage: imageTensor, inputshape: shape) - - let start = NSDate() - for commandBuffer in gpuCommandLayers { - commandBuffer.commit() - } - - // wait until last layer in conv.net is finished - gpuCommandLayers.last!.waitUntilCompleted() - print("Time to run network: \(NSDate().timeIntervalSinceDate(start))") - - var classification_results = [Float](count: 10, repeatedValue: 0.0) - let (lastLayerName, lastMetalBuffer) = namedDataLayers.last! - NSLog(lastLayerName) - let data = NSData(bytesNoCopy: lastMetalBuffer.contents(), - length: classification_results.count*sizeof(Float), freeWhenDone: false) - data.getBytes(&classification_results, length:(Int(classification_results.count)) * sizeof(Float)) - print(classification_results) - let maxValue:Float = classification_results.maxElement()! - let indexOfMaxValue:Int = classification_results.indexOf(maxValue)! - - print("maxValue = \(maxValue), indexofMaxValue = \(indexOfMaxValue)") - - // empty command buffers! - - // return index - return indexOfMaxValue - - } -} - diff --git a/DeepLearningKitForiOS/DeepLearningKitForiOS/Info.plist b/DeepLearningKitForiOS/DeepLearningKitForiOS/Info.plist deleted file mode 100644 index 5f59404..0000000 --- a/DeepLearningKitForiOS/DeepLearningKitForiOS/Info.plist +++ /dev/null @@ -1,26 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - FMWK - CFBundleShortVersionString - 0.0.1 - CFBundleSignature - ???? - CFBundleVersion - $(CURRENT_PROJECT_VERSION) - NSPrincipalClass - - - diff --git a/DeepLearningKitForiOS/DeepLearningKitForiOS/MetalDataStructures.swift b/DeepLearningKitForiOS/DeepLearningKitForiOS/MetalDataStructures.swift deleted file mode 100644 index c53d61c..0000000 --- a/DeepLearningKitForiOS/DeepLearningKitForiOS/MetalDataStructures.swift +++ /dev/null @@ -1,62 +0,0 @@ -// -// MetalDataStructures.swift -// MemkiteMetal -// -// Created by Amund Tveit & Torb Morland on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - -////////////////////////////////////////// -// Metal Data Types - their SWIFT Counterparts -////////////////////////////////////////// -public struct MetalComplexNumberType { - var real: Float = 0.0 - var imag: Float = 0.0 -} - -public struct MetalShaderParameters { - let image_xdim: Float - let image_ydim: Float - let num_images: Float - let filter_xdim: Float - let filter_ydim: Float - let num_filters: Float - let conv_xdim: Float // image_xdim - filter_xdim + 1 without striding - let conv_ydim: Float // image_ydim - filter_ydim + 1 without striding - let pool_xdim: Float - let pool_ydim: Float - var b: Float -} - -public struct MetalMatrixVectorParameters { - let x_xdim: Float - let x_ydim: Float - let w_xdim: Float - let w_ydim: Float - let b_xdim: Float - let b_ydim: Float - let result_xdim: Float - let result_ydim: Float -} - -public struct MetalPoolingParameters { - let kernel_size: Float - let pool_stride: Float - let pad: Float -} - -public struct MetalTensorDimensions { - let n: Float - let channels: Float - let width: Float - let height: Float -} - -public struct MetalConvolutionParameters { - let pad: Float - let kernel_size: Float - let stride: Float -} diff --git a/DeepLearningKitForiOS/DeepLearningKitForiOS/MetalUtilityFunctions.swift b/DeepLearningKitForiOS/DeepLearningKitForiOS/MetalUtilityFunctions.swift deleted file mode 100644 index 1ed4d80..0000000 --- a/DeepLearningKitForiOS/DeepLearningKitForiOS/MetalUtilityFunctions.swift +++ /dev/null @@ -1,173 +0,0 @@ -// -// MetalUtilFunctions.swift -// MemkiteMetal -// -// Created by Amund Tveit & Torb Morland on 24/11/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - -func createComplexNumbersArray(count: Int) -> [MetalComplexNumberType] { - let zeroComplexNumber = MetalComplexNumberType() - return [MetalComplexNumberType](count: count, repeatedValue: zeroComplexNumber) -} - -func createFloatNumbersArray(count: Int) -> [Float] { - return [Float](count: count, repeatedValue: 0.0) -} - -func createFloatMetalBuffer(var vector: [Float], let metalDevice:MTLDevice) -> MTLBuffer { - let byteLength = vector.count*sizeof(Float) // future: MTLResourceStorageModePrivate - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createComplexMetalBuffer(var vector:[MetalComplexNumberType], let metalDevice:MTLDevice) -> MTLBuffer { - let byteLength = vector.count*sizeof(MetalComplexNumberType) // or size of and actual 1st element object? - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createShaderParametersMetalBuffer(var shaderParameters:MetalShaderParameters, metalDevice:MTLDevice) -> MTLBuffer { - let byteLength = sizeof(MetalShaderParameters) - return metalDevice.newBufferWithBytes(&shaderParameters, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createMatrixShaderParametersMetalBuffer(var params: MetalMatrixVectorParameters, metalDevice: MTLDevice) -> MTLBuffer { - let byteLength = sizeof(MetalMatrixVectorParameters) - return metalDevice.newBufferWithBytes(¶ms, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) - -} - -func createPoolingParametersMetalBuffer(var params: MetalPoolingParameters, metalDevice: MTLDevice) -> MTLBuffer { - let byteLength = sizeof(MetalPoolingParameters) - return metalDevice.newBufferWithBytes(¶ms, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createConvolutionParametersMetalBuffer(var params: MetalConvolutionParameters, metalDevice: MTLDevice) -> MTLBuffer { - let byteLength = sizeof(MetalConvolutionParameters) - return metalDevice.newBufferWithBytes(¶ms, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createTensorDimensionsVectorMetalBuffer(var vector: [MetalTensorDimensions], metalDevice: MTLDevice) -> MTLBuffer { - let byteLength = vector.count * sizeof(MetalTensorDimensions) - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func setupShaderInMetalPipeline(shaderName:String, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice) -> (shader:MTLFunction!, - computePipelineState:MTLComputePipelineState!, - computePipelineErrors:NSErrorPointer!) { - let shader = metalDefaultLibrary.newFunctionWithName(shaderName) - let computePipeLineDescriptor = MTLComputePipelineDescriptor() - computePipeLineDescriptor.computeFunction = shader - // var computePipelineErrors = NSErrorPointer() - // let computePipelineState:MTLComputePipelineState = metalDevice.newComputePipelineStateWithFunction(shader!, completionHandler: {(}) - let computePipelineErrors = NSErrorPointer() - var computePipelineState:MTLComputePipelineState? = nil - do { - computePipelineState = try metalDevice.newComputePipelineStateWithFunction(shader!) - } catch { - print("catching..") - } - return (shader, computePipelineState, computePipelineErrors) - -} - -func createMetalBuffer(var vector:[Float], metalDevice:MTLDevice) -> MTLBuffer { - let byteLength = vector.count*sizeof(Float) - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func preLoadMetalShaders(metalDevice: MTLDevice, metalDefaultLibrary: MTLLibrary) { - let shaders = ["avg_pool", "max_pool", "rectifier_linear", "convolution_layer", "im2col"] - for shader in shaders { - setupShaderInMetalPipeline(shader, metalDefaultLibrary: metalDefaultLibrary,metalDevice: metalDevice) // TODO: this returns stuff - } -} - -func createOrReuseFloatMetalBuffer(name:String, data: [Float], inout cache:[Dictionary], layer_number:Int, metalDevice:MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { - print("found key = \(name) in cache") - result = tmpval - } else { - print("didnt find key = \(name) in cache") - result = createFloatMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - // print("DEBUG: cache = \(cache)") - } - - return result -} - - -func createOrReuseConvolutionParametersMetalBuffer(name:String, - data: MetalConvolutionParameters, - inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { - print("found key = \(name) in cache") - result = tmpval - } else { - print("didnt find key = \(name) in cache") - result = createConvolutionParametersMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - -func createOrReuseTensorDimensionsVectorMetalBuffer(name:String, - data:[MetalTensorDimensions],inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { - print("found key = \(name) in cache") - result = tmpval - } else { - print("didnt find key = \(name) in cache") - result = createTensorDimensionsVectorMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - -// -//let sizeParamMetalBuffer = createShaderParametersMetalBuffer(size_params, metalDevice: metalDevice) -//let poolingParamMetalBuffer = createPoolingParametersMetalBuffer(pooling_params, metalDevice: metalDevice) - -func createOrReuseShaderParametersMetalBuffer(name:String, - data:MetalShaderParameters,inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { -// print("found key = \(name) in cache") - result = tmpval - } else { -// print("didnt find key = \(name) in cache") - result = createShaderParametersMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - -func createOrReusePoolingParametersMetalBuffer(name:String, - data:MetalPoolingParameters,inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { -// print("found key = \(name) in cache") - result = tmpval - } else { -// print("didnt find key = \(name) in cache") - result = createPoolingParametersMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - - diff --git a/DeepLearningKitForiOS/DeepLearningKitForiOS/PoolingLayer.swift b/DeepLearningKitForiOS/DeepLearningKitForiOS/PoolingLayer.swift deleted file mode 100644 index fd4f589..0000000 --- a/DeepLearningKitForiOS/DeepLearningKitForiOS/PoolingLayer.swift +++ /dev/null @@ -1,141 +0,0 @@ -// -// PoolingLayer.swift -// MemkiteMetal -// -// Created by Torb Morland & Amund Tveit on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - - -func createPoolingLayerCached(layer: NSDictionary, - inputBuffer: MTLBuffer, - inputShape: [Float], - metalCommandQueue: MTLCommandQueue, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout pool_type_caches: [Dictionary], - inout layer_data_caches: [Dictionary], - layer_number: Int, - layer_string: String) -> (MTLBuffer, MTLCommandBuffer, [Float]) { - - print(" ==> createPoolingLayerCached") - let metalCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() -// let metalCommandBuffer = metalCommandQueue.commandBuffer() - - var params = NSDictionary() - var stride:Float = 1.0 - var kernel_size: Float = 1.0 - var pad: Float = 0.0 - var pooling_params = MetalPoolingParameters(kernel_size: kernel_size, pool_stride: stride, pad: pad) - var pool_type = 0 - var h:Float = 0.0 - var w:Float = 0.0 - var shape:[Float] = [] - var outputCount:Float = 0 - var pool_width = 0 - var pool_height = 0 - var size_params:MetalShaderParameters = MetalShaderParameters(image_xdim:0.0, image_ydim:0.0, num_images: 0.0, filter_xdim: 0.0, filter_ydim: 0.0, num_filters: 0.0, conv_xdim: 0.0, conv_ydim: 0.0, pool_xdim: 0.0, pool_ydim: 0.0, b:0.0) - var outputBuffer:MTLBuffer - - - params = layer["pooling_param"] as! NSDictionary - stride = 1.0 - kernel_size = 1.0 - pad = 0.0 - if let val = params["stride"] { - stride = val as! Float - } - if let val = params["kernel_size"] { - kernel_size = val as! Float - if val as! NSNumber != 3 { - pad = 0 - } - } - pooling_params = MetalPoolingParameters(kernel_size: kernel_size, pool_stride: stride, pad: pad) - pool_type = params["pool"] as! Int - - // STORE pool type in cache! - pool_type_caches[layer_number]["pool_type"] = String(pool_type) - - h = ceil((inputShape[2] + 2.0 * pad - kernel_size) / stride) + 1.0 - w = ceil((Float(inputShape[3]) + 2.0 * pad - kernel_size) / stride) + 1.0 - shape = [inputShape[0], inputShape[1], h, w] - outputCount = shape.reduce(1, combine: *) - pool_width = Int(shape[2]) - pool_height = Int(shape[3]) - size_params = MetalShaderParameters(image_xdim: Float(inputShape[2]), image_ydim: Float(inputShape[3]), - num_images: Float(inputShape[0]), - filter_xdim: 1.0, filter_ydim: 1.0, num_filters: Float(inputShape[1]), - conv_xdim:0.0, conv_ydim: 0.0, - pool_xdim: Float(pool_width), pool_ydim: Float(pool_height), b:0.0) - - if pool_type == 1 { - outputBuffer = addPoolingCommandToCommandBufferCached(metalCommandBuffer, poolingMethod: "avg_pool", inputBuffer: inputBuffer, outputCount: Int(outputCount), size_params: size_params, pooling_params: pooling_params, metalDefaultLibrary: metalDefaultLibrary, metalDevice:metalDevice, - layer_data_caches: &layer_data_caches, layer_number: layer_number, layer_string: layer_string) - } else { - outputBuffer = addPoolingCommandToCommandBufferCached(metalCommandBuffer, poolingMethod: "max_pool", inputBuffer: inputBuffer, outputCount: Int(outputCount), size_params: size_params, pooling_params: pooling_params,metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice, - layer_data_caches: &layer_data_caches, layer_number: layer_number, layer_string: layer_string) - - } - //metalCommandBuffer.commit() - - print(" <== createPoolingLayerCached") - - - return (outputBuffer, metalCommandBuffer, shape) -} - - -func addPoolingCommandToCommandBufferCached(commandBuffer: MTLCommandBuffer, - poolingMethod: String, - inputBuffer: MTLBuffer, - outputCount: Int, - size_params: MetalShaderParameters, - pooling_params: MetalPoolingParameters, - metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout layer_data_caches: [Dictionary], - layer_number: Int, - layer_string: String) -> MTLBuffer { - - - print(" ==> addPoolingCommandtoCommandBufferCached") - - - let output = createFloatNumbersArray(outputCount) - let (_, computePipelineState, _) = setupShaderInMetalPipeline(poolingMethod, metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice) - - let outputMetalBuffer = createOrReuseFloatMetalBuffer("outputMetalBuffer", data: output, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - // let outputMetalBuffer = createFloatMetalBuffer(output, metalDevice: metalDevice) - - let sizeParamMetalBuffer = createOrReuseShaderParametersMetalBuffer("sizeParamMetalBuffer", data: size_params, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - - // let sizeParamMetalBuffer = createShaderParametersMetalBuffer(size_params, metalDevice: metalDevice) - - - // let poolingParamMetalBuffer = createPoolingParametersMetalBuffer(pooling_params, metalDevice: metalDevice) - let poolingParamMetalBuffer = createOrReusePoolingParametersMetalBuffer("poolingParamMetalBuffer", data: pooling_params, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - // Create Metal Compute Command Encoder and add input and output buffers to it - let metalComputeCommandEncoder = commandBuffer.computeCommandEncoder() - metalComputeCommandEncoder.setBuffer(outputMetalBuffer, offset: 0, atIndex: 0) - metalComputeCommandEncoder.setBuffer(inputBuffer, offset: 0, atIndex: 1) - metalComputeCommandEncoder.setBuffer(sizeParamMetalBuffer, offset: 0, atIndex: 2) - metalComputeCommandEncoder.setBuffer(poolingParamMetalBuffer, offset: 0, atIndex: 3) - - // Set the shader function that Metal will use - metalComputeCommandEncoder.setComputePipelineState(computePipelineState) - - // Set up thread groups on GPU - let threadsPerGroup = MTLSize(width:computePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - let numThreadgroups = MTLSize(width:(outputCount-1)/computePipelineState.threadExecutionWidth + 1, height:1, depth:1) - metalComputeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - // Finalize configuration - metalComputeCommandEncoder.endEncoding() - - print(" <== addPoolingCommandtoCommandBufferCached") - - - return outputMetalBuffer -} diff --git a/DeepLearningKitForiOS/DeepLearningKitForiOS/RectifierLayer.swift b/DeepLearningKitForiOS/DeepLearningKitForiOS/RectifierLayer.swift deleted file mode 100644 index 7d3478d..0000000 --- a/DeepLearningKitForiOS/DeepLearningKitForiOS/RectifierLayer.swift +++ /dev/null @@ -1,53 +0,0 @@ -// -// RectifierLayer.swift -// MemkiteMetal -// -// Created by Torb Morland & Amund Tveit on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - -func createRectifierLayer(inputBuffer: MTLBuffer, metalCommandQueue: MTLCommandQueue, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice) -> (MTLBuffer,MTLCommandBuffer) { - print(" ==> createrectifierlayer") -// let metalCommandBuffer = metalCommandQueue.commandBuffer() - let metalCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() - - let result = addRectifierCommandToCommandBuffer(metalCommandBuffer, inputBuffer: inputBuffer, - metalDefaultLibrary: metalDefaultLibrary, metalDevice:metalDevice) - //metalCommandBuffer.commit() - - print(" <== createrectifierlayer") - return (result, metalCommandBuffer) -} - - -func addRectifierCommandToCommandBuffer(commandBuffer: MTLCommandBuffer, inputBuffer: MTLBuffer, - metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice) -> MTLBuffer { - - print("==> addRectifierToCommandBuffer") - - let count = inputBuffer.length / sizeof(Float) - let (_, computePipelineState, _) = setupShaderInMetalPipeline("rectifier_linear", metalDefaultLibrary: metalDefaultLibrary, - metalDevice: metalDevice) - - // Create Metal Compute Command Encoder and add input and output buffers to it - let computeCommandEncoder = commandBuffer.computeCommandEncoder() - computeCommandEncoder.setBuffer(inputBuffer, offset: 0, atIndex: 0) - // Set the shader function that Metal will use - computeCommandEncoder.setComputePipelineState(computePipelineState) - - // Set up thread groups on GPU - let threadsPerGroup = MTLSize(width:computePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - let numThreadgroups = MTLSize(width:(count-1)/computePipelineState.threadExecutionWidth + 1, height:1, depth:1) - computeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - // Finalize configuration - computeCommandEncoder.endEncoding() - - print(" <== addRectifierToCommandBuffer") - - return inputBuffer -} diff --git a/DeepLearningKitForiOS/DeepLearningKitForiOS/Shaders.metal b/DeepLearningKitForiOS/DeepLearningKitForiOS/Shaders.metal deleted file mode 100644 index d8d27f8..0000000 --- a/DeepLearningKitForiOS/DeepLearningKitForiOS/Shaders.metal +++ /dev/null @@ -1,224 +0,0 @@ -// -// Shaders.metal -// -// Created by Torb Morland & Amund Tveit on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -#include -#include -#include -#include -#include -#include -#include -#include -using namespace metal; - -//////////////////////////////// -// DATA TYPES -//////////////////////////////// - -struct MetalComplexNumberType { // needs to map to float2 in Metal - float real; - float imag; -}; - -struct MetalShaderParameters { - float image_xdim; - float image_ydim; - float num_images; - float filter_xdim; // e.g. 5 - float filter_ydim; // e.g. 5 - float num_filters; // e.g. 20 -> W = 20*1*5*5 - float conv_xdim; // image_xdim - filter_xdim + 1 without striding - float conv_ydim; // image_ydim - filter_ydim + 1 without striding - float pool_xdim; - float pool_ydim; - float b; -}; - -struct MetalMatrixVectorParameters { - float x_xdim; - float x_ydim; - float w_xdim; - float w_ydim; - float b_xdim; - float b_ydim; - float result_xdim; - float result_ydim; -}; - -struct MetalPoolingParameters { - float kernel_size; - float pool_stride; - float pad; -}; - -struct MetalTensorDimensions { - float n; - float channels; - float width; - float height; -}; - -struct MetalConvolutionParameters { - float pad; - float kernel_size; - float stride; -}; - -//////////////////////////////// -// SHADER FUNCTIONS -//////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////// - - -// Returns max(0, X[id]) -kernel void rectifier_linear(device float* X [[ buffer(0)]], - uint id [[ thread_position_in_grid ]]) { - X[id] = fmax(0.0, X[id]); -} - -//////////////////////////////////////////////////////////////////////////////////////////// - -kernel void max_pool(device float* result [[ buffer(0) ]], - const device float* input [[ buffer(1) ]], - const device MetalShaderParameters* size_params [[ buffer(2) ]], - const device MetalPoolingParameters* pooling_params [[ buffer(3) ]], - uint id [[ thread_position_in_grid ]]) { - int channels = int(size_params[0].num_filters); - int in_width = int(size_params[0].image_xdim); - int in_height = int(size_params[0].image_ydim); - - float kernel_size = float(pooling_params[0].kernel_size); - int pool_stride = int(pooling_params[0].pool_stride); - int pad = int(pooling_params[0].pad); - - int out_width = int(size_params[0].pool_xdim); - int out_height = int(size_params[0].pool_ydim); - - int i = (id / out_height) % out_width; - int j = id % out_height; - int n = id / (channels * out_width * out_height); - int c = (id / (out_width * out_height)) % channels; - int wstart = i * pool_stride - pad; - int hstart = j * pool_stride - pad; - int wend = fmin(wstart + kernel_size, in_width + pad); - int hend = fmin(hstart + kernel_size, in_height + pad); - wstart = fmax(0.0, wstart); - hstart = fmax(0.0, hstart); - thread float pool = -100000.0; - for (int ii = wstart; ii < wend; ++ii) { - for (int jj = hstart; jj < hend; ++jj) { - pool = fmax(pool, input[(n * channels * in_height + c * in_height + ii) * in_width + jj]); - } - } - result[id] = pool; -} - -//////////////////////////////////////////////////////////////////////////////////////////// - -kernel void avg_pool(device float* result [[ buffer(0) ]], - const device float* input [[ buffer(1) ]], - const device MetalShaderParameters* size_params [[ buffer(2) ]], - const device MetalPoolingParameters* pooling_params [[ buffer(3) ]], - uint id [[ thread_position_in_grid ]]) { - int channels = int(size_params[0].num_filters); - int in_width = int(size_params[0].image_xdim); - int in_height = int(size_params[0].image_ydim); - - float kernel_size = float(pooling_params[0].kernel_size); - int pool_stride = int(pooling_params[0].pool_stride); - int pad = int(pooling_params[0].pad); - - int out_width = int(size_params[0].pool_xdim); - int out_height = int(size_params[0].pool_ydim); - - int i = (id / out_height) % out_width; - int j = id % out_height; - int n = id / (channels * out_width * out_height); - int c = (id / (out_width * out_height)) % channels; - int wstart = i * pool_stride - pad; - int hstart = j * pool_stride - pad; - int wend = fmin(wstart + kernel_size, in_width + pad); - int hend = fmin(hstart + kernel_size, in_height + pad); - float pool_size = (hend - hstart) * (wend - wstart); - wstart = fmax(0.0, wstart); - hstart = fmax(0.0, hstart); - thread float pool = 0.0; - for (int ii = wstart; ii < wend; ++ii) { - for (int jj = hstart; jj < hend; ++jj) { - pool += input[(n * channels * in_height + c * in_height + ii) * in_width + jj]/pool_size; - } - } - result[id] = pool; -} - -//////////////////////////////////////////////////////////////////////////////////////////// - -kernel void im2col(const device float* convolution_input [[ buffer(0)]], - const device MetalTensorDimensions* tensor_dimensions [[ buffer(1) ]], - const device MetalConvolutionParameters* convolution_params [[ buffer(2) ]], - device float* col_output [[ buffer(3) ]], - uint id [[ thread_position_in_grid ]]) { - int channels_in = int(tensor_dimensions[0].channels); - int in_width = int(tensor_dimensions[0].width); - int in_height = int(tensor_dimensions[0].height); - - int channels_col = int(tensor_dimensions[2].channels); - int width_col = int(tensor_dimensions[2].width); - int height_col = int(tensor_dimensions[2].height); - - - // 1. do an im2col transformation - int pad = int(convolution_params[0].pad); - int kernel_size = int(convolution_params[0].kernel_size); - - int n = id / (channels_col * height_col * width_col); - int c = (id / (width_col * height_col)) % channels_col; - int h = (id / width_col) % height_col; - int w = id % width_col; - int w_offset = c % kernel_size; - int h_offset = (c / kernel_size) % kernel_size; - int h_pad = h - pad + h_offset; - int w_pad = w - pad + w_offset; - int c_im = c / (kernel_size * kernel_size); - if (h_pad >= 0 && h_pad < in_height && w_pad >= 0 && w_pad < in_width) { - col_output[id] = convolution_input[(n * channels_in * in_height + c_im * in_height + h_pad) * in_width + w_pad]; - } -} - -//////////////////////////////////////////////////////////////////////////////////////////// - -// Tensor dimensions = { input_dimensions, weight_dimensions, col_dimensions, result_dimensions } -kernel void convolution_layer(device float* result [[ buffer(0) ]], - const device float* weights [[ buffer(1)]], - const device MetalTensorDimensions* tensor_dimensions [[ buffer(2) ]], - const device float* col_output [[ buffer(3) ]], - const device float* bias [[ buffer(4) ]], - uint id [[ thread_position_in_grid ]]) { - int channels_col = int(tensor_dimensions[2].channels); - int width_col = int(tensor_dimensions[2].width); - int height_col = int(tensor_dimensions[2].height); - - int channels_out = int(tensor_dimensions[3].channels); - int width_out = int(tensor_dimensions[3].width); - int height_out = int(tensor_dimensions[3].height); - - int n = id / (channels_out * height_out * width_out); - int a = (id / (height_out * width_out)) % channels_out; - int b = id % (height_out * width_out); - - thread float tmp_result = bias[a]; - - for (int c = 0; c < channels_col; ++c) { - tmp_result += weights[a * channels_col + c] * col_output[(n * channels_col * width_col + c * width_col) * height_col + b]; - } - - result[id] = tmp_result; -} - - - diff --git a/DeepLearningKitForiOS/DeepLearningKitForiOS/ViewController.swift b/DeepLearningKitForiOS/DeepLearningKitForiOS/ViewController.swift deleted file mode 100644 index 020f89d..0000000 --- a/DeepLearningKitForiOS/DeepLearningKitForiOS/ViewController.swift +++ /dev/null @@ -1,41 +0,0 @@ -// -// ViewController.swift -// memkite -// -// Created by Amund Tveit on 13/08/15. -// Copyright © 2015 Amund Tveit. All rights reserved. -// - -import UIKit - -class ViewController: UIViewController { - - var deepNetwork: DeepNetwork! - - override func viewDidLoad() { - super.viewDidLoad() - - deepNetwork = DeepNetwork() - - var randomimage = createFloatNumbersArray(3072) - for i in 0.. - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - - diff --git a/DeepLearningKitFortvOS/DeepLearningKitFortvOS.xcodeproj/project.pbxproj b/DeepLearningKitFortvOS/DeepLearningKitFortvOS.xcodeproj/project.pbxproj deleted file mode 100644 index 163042a..0000000 --- a/DeepLearningKitFortvOS/DeepLearningKitFortvOS.xcodeproj/project.pbxproj +++ /dev/null @@ -1,458 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 67A73CFE1C1B0941001FD9F8 /* DeepLearningKitFortvOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 67A73CFD1C1B0941001FD9F8 /* DeepLearningKitFortvOS.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 67A73D051C1B0941001FD9F8 /* DeepLearningKitFortvOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 67A73CFA1C1B0941001FD9F8 /* DeepLearningKitFortvOS.framework */; }; - 67A73D0A1C1B0941001FD9F8 /* DeepLearningKitFortvOSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D091C1B0941001FD9F8 /* DeepLearningKitFortvOSTests.swift */; }; - 67A73D1D1C1B0956001FD9F8 /* ConvolutionLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D141C1B0956001FD9F8 /* ConvolutionLayer.swift */; }; - 67A73D1E1C1B0956001FD9F8 /* DeepNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D151C1B0956001FD9F8 /* DeepNetwork.swift */; }; - 67A73D1F1C1B0956001FD9F8 /* DeepNetwork+JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D161C1B0956001FD9F8 /* DeepNetwork+JSON.swift */; }; - 67A73D201C1B0956001FD9F8 /* DeepNetwork+SetupNetworkFromDict.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D171C1B0956001FD9F8 /* DeepNetwork+SetupNetworkFromDict.swift */; }; - 67A73D211C1B0956001FD9F8 /* MetalDataStructures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D181C1B0956001FD9F8 /* MetalDataStructures.swift */; }; - 67A73D221C1B0956001FD9F8 /* MetalUtilityFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D191C1B0956001FD9F8 /* MetalUtilityFunctions.swift */; }; - 67A73D231C1B0956001FD9F8 /* PoolingLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D1A1C1B0956001FD9F8 /* PoolingLayer.swift */; }; - 67A73D241C1B0956001FD9F8 /* RectifierLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D1B1C1B0956001FD9F8 /* RectifierLayer.swift */; }; - 67A73D251C1B0956001FD9F8 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 67A73D1C1C1B0956001FD9F8 /* Shaders.metal */; }; - 67A73D321C1B09F7001FD9F8 /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 67A73D2F1C1B09F6001FD9F8 /* Metal.framework */; }; -/* End PBXBuildFile section */ - -/* Begin PBXContainerItemProxy section */ - 67A73D061C1B0941001FD9F8 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 67A73CF11C1B0941001FD9F8 /* Project object */; - proxyType = 1; - remoteGlobalIDString = 67A73CF91C1B0941001FD9F8; - remoteInfo = DeepLearningKitFortvOS; - }; -/* End PBXContainerItemProxy section */ - -/* Begin PBXFileReference section */ - 67A73CFA1C1B0941001FD9F8 /* DeepLearningKitFortvOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DeepLearningKitFortvOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 67A73CFD1C1B0941001FD9F8 /* DeepLearningKitFortvOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = DeepLearningKitFortvOS.h; path = DeepLearningKitFortvOS/DeepLearningKitFortvOS.h; sourceTree = ""; }; - 67A73CFF1C1B0941001FD9F8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 67A73D041C1B0941001FD9F8 /* DeepLearningKitFortvOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DeepLearningKitFortvOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 67A73D091C1B0941001FD9F8 /* DeepLearningKitFortvOSTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeepLearningKitFortvOSTests.swift; sourceTree = ""; }; - 67A73D0B1C1B0941001FD9F8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 67A73D141C1B0956001FD9F8 /* ConvolutionLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConvolutionLayer.swift; sourceTree = ""; }; - 67A73D151C1B0956001FD9F8 /* DeepNetwork.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeepNetwork.swift; sourceTree = ""; }; - 67A73D161C1B0956001FD9F8 /* DeepNetwork+JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DeepNetwork+JSON.swift"; sourceTree = ""; }; - 67A73D171C1B0956001FD9F8 /* DeepNetwork+SetupNetworkFromDict.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DeepNetwork+SetupNetworkFromDict.swift"; sourceTree = ""; }; - 67A73D181C1B0956001FD9F8 /* MetalDataStructures.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalDataStructures.swift; sourceTree = ""; }; - 67A73D191C1B0956001FD9F8 /* MetalUtilityFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalUtilityFunctions.swift; sourceTree = ""; }; - 67A73D1A1C1B0956001FD9F8 /* PoolingLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PoolingLayer.swift; sourceTree = ""; }; - 67A73D1B1C1B0956001FD9F8 /* RectifierLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RectifierLayer.swift; sourceTree = ""; }; - 67A73D1C1C1B0956001FD9F8 /* Shaders.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Shaders.metal; sourceTree = ""; }; - 67A73D2F1C1B09F6001FD9F8 /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 67A73CF61C1B0941001FD9F8 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 67A73D321C1B09F7001FD9F8 /* Metal.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 67A73D011C1B0941001FD9F8 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 67A73D051C1B0941001FD9F8 /* DeepLearningKitFortvOS.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 67A73CF01C1B0941001FD9F8 = { - isa = PBXGroup; - children = ( - 67A73D2F1C1B09F6001FD9F8 /* Metal.framework */, - 67A73CFD1C1B0941001FD9F8 /* DeepLearningKitFortvOS.h */, - 67A73CFC1C1B0941001FD9F8 /* DeepLearningKitFortvOS */, - 67A73D081C1B0941001FD9F8 /* DeepLearningKitFortvOSTests */, - 67A73CFB1C1B0941001FD9F8 /* Products */, - ); - sourceTree = ""; - }; - 67A73CFB1C1B0941001FD9F8 /* Products */ = { - isa = PBXGroup; - children = ( - 67A73CFA1C1B0941001FD9F8 /* DeepLearningKitFortvOS.framework */, - 67A73D041C1B0941001FD9F8 /* DeepLearningKitFortvOSTests.xctest */, - ); - name = Products; - sourceTree = ""; - }; - 67A73CFC1C1B0941001FD9F8 /* DeepLearningKitFortvOS */ = { - isa = PBXGroup; - children = ( - 67A73D281C1B0997001FD9F8 /* PUBLIC_API */, - 67A73D271C1B098F001FD9F8 /* INTERNAL_API */, - 67A73D261C1B097D001FD9F8 /* GPU_METAL */, - 67A73CFF1C1B0941001FD9F8 /* Info.plist */, - ); - path = DeepLearningKitFortvOS; - sourceTree = ""; - }; - 67A73D081C1B0941001FD9F8 /* DeepLearningKitFortvOSTests */ = { - isa = PBXGroup; - children = ( - 67A73D091C1B0941001FD9F8 /* DeepLearningKitFortvOSTests.swift */, - 67A73D0B1C1B0941001FD9F8 /* Info.plist */, - ); - path = DeepLearningKitFortvOSTests; - sourceTree = ""; - }; - 67A73D261C1B097D001FD9F8 /* GPU_METAL */ = { - isa = PBXGroup; - children = ( - 67A73D181C1B0956001FD9F8 /* MetalDataStructures.swift */, - 67A73D191C1B0956001FD9F8 /* MetalUtilityFunctions.swift */, - 67A73D1C1C1B0956001FD9F8 /* Shaders.metal */, - ); - name = GPU_METAL; - sourceTree = ""; - }; - 67A73D271C1B098F001FD9F8 /* INTERNAL_API */ = { - isa = PBXGroup; - children = ( - 67A73D161C1B0956001FD9F8 /* DeepNetwork+JSON.swift */, - 67A73D171C1B0956001FD9F8 /* DeepNetwork+SetupNetworkFromDict.swift */, - 67A73D141C1B0956001FD9F8 /* ConvolutionLayer.swift */, - 67A73D1A1C1B0956001FD9F8 /* PoolingLayer.swift */, - 67A73D1B1C1B0956001FD9F8 /* RectifierLayer.swift */, - ); - name = INTERNAL_API; - sourceTree = ""; - }; - 67A73D281C1B0997001FD9F8 /* PUBLIC_API */ = { - isa = PBXGroup; - children = ( - 67A73D151C1B0956001FD9F8 /* DeepNetwork.swift */, - ); - name = PUBLIC_API; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXHeadersBuildPhase section */ - 67A73CF71C1B0941001FD9F8 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 67A73CFE1C1B0941001FD9F8 /* DeepLearningKitFortvOS.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXHeadersBuildPhase section */ - -/* Begin PBXNativeTarget section */ - 67A73CF91C1B0941001FD9F8 /* DeepLearningKitFortvOS */ = { - isa = PBXNativeTarget; - buildConfigurationList = 67A73D0E1C1B0941001FD9F8 /* Build configuration list for PBXNativeTarget "DeepLearningKitFortvOS" */; - buildPhases = ( - 67A73CF51C1B0941001FD9F8 /* Sources */, - 67A73CF61C1B0941001FD9F8 /* Frameworks */, - 67A73CF71C1B0941001FD9F8 /* Headers */, - 67A73CF81C1B0941001FD9F8 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = DeepLearningKitFortvOS; - productName = DeepLearningKitFortvOS; - productReference = 67A73CFA1C1B0941001FD9F8 /* DeepLearningKitFortvOS.framework */; - productType = "com.apple.product-type.framework"; - }; - 67A73D031C1B0941001FD9F8 /* DeepLearningKitFortvOSTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 67A73D111C1B0941001FD9F8 /* Build configuration list for PBXNativeTarget "DeepLearningKitFortvOSTests" */; - buildPhases = ( - 67A73D001C1B0941001FD9F8 /* Sources */, - 67A73D011C1B0941001FD9F8 /* Frameworks */, - 67A73D021C1B0941001FD9F8 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - 67A73D071C1B0941001FD9F8 /* PBXTargetDependency */, - ); - name = DeepLearningKitFortvOSTests; - productName = DeepLearningKitFortvOSTests; - productReference = 67A73D041C1B0941001FD9F8 /* DeepLearningKitFortvOSTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 67A73CF11C1B0941001FD9F8 /* Project object */ = { - isa = PBXProject; - attributes = { - LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0720; - ORGANIZATIONNAME = "Amund Tveit"; - TargetAttributes = { - 67A73CF91C1B0941001FD9F8 = { - CreatedOnToolsVersion = 7.2; - }; - 67A73D031C1B0941001FD9F8 = { - CreatedOnToolsVersion = 7.2; - }; - }; - }; - buildConfigurationList = 67A73CF41C1B0941001FD9F8 /* Build configuration list for PBXProject "DeepLearningKitFortvOS" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = 67A73CF01C1B0941001FD9F8; - productRefGroup = 67A73CFB1C1B0941001FD9F8 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 67A73CF91C1B0941001FD9F8 /* DeepLearningKitFortvOS */, - 67A73D031C1B0941001FD9F8 /* DeepLearningKitFortvOSTests */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 67A73CF81C1B0941001FD9F8 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 67A73D021C1B0941001FD9F8 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 67A73CF51C1B0941001FD9F8 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 67A73D1E1C1B0956001FD9F8 /* DeepNetwork.swift in Sources */, - 67A73D241C1B0956001FD9F8 /* RectifierLayer.swift in Sources */, - 67A73D211C1B0956001FD9F8 /* MetalDataStructures.swift in Sources */, - 67A73D1F1C1B0956001FD9F8 /* DeepNetwork+JSON.swift in Sources */, - 67A73D231C1B0956001FD9F8 /* PoolingLayer.swift in Sources */, - 67A73D1D1C1B0956001FD9F8 /* ConvolutionLayer.swift in Sources */, - 67A73D251C1B0956001FD9F8 /* Shaders.metal in Sources */, - 67A73D221C1B0956001FD9F8 /* MetalUtilityFunctions.swift in Sources */, - 67A73D201C1B0956001FD9F8 /* DeepNetwork+SetupNetworkFromDict.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 67A73D001C1B0941001FD9F8 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 67A73D0A1C1B0941001FD9F8 /* DeepLearningKitFortvOSTests.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXTargetDependency section */ - 67A73D071C1B0941001FD9F8 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 67A73CF91C1B0941001FD9F8 /* DeepLearningKitFortvOS */; - targetProxy = 67A73D061C1B0941001FD9F8 /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - -/* Begin XCBuildConfiguration section */ - 67A73D0C1C1B0941001FD9F8 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = appletvos; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - TARGETED_DEVICE_FAMILY = 3; - TVOS_DEPLOYMENT_TARGET = 9.1; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Debug; - }; - 67A73D0D1C1B0941001FD9F8 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = appletvos; - TARGETED_DEVICE_FAMILY = 3; - TVOS_DEPLOYMENT_TARGET = 9.1; - VALIDATE_PRODUCT = YES; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Release; - }; - 67A73D0F1C1B0941001FD9F8 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_MODULES = YES; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = DeepLearningKitFortvOS/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = org.deeplearningkit.DeepLearningKitFortvOS; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - }; - name = Debug; - }; - 67A73D101C1B0941001FD9F8 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_MODULES = YES; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = DeepLearningKitFortvOS/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = org.deeplearningkit.DeepLearningKitFortvOS; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - }; - name = Release; - }; - 67A73D121C1B0941001FD9F8 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - INFOPLIST_FILE = DeepLearningKitFortvOSTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = org.deeplearningkit.DeepLearningKitFortvOSTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - 67A73D131C1B0941001FD9F8 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - INFOPLIST_FILE = DeepLearningKitFortvOSTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = org.deeplearningkit.DeepLearningKitFortvOSTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 67A73CF41C1B0941001FD9F8 /* Build configuration list for PBXProject "DeepLearningKitFortvOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 67A73D0C1C1B0941001FD9F8 /* Debug */, - 67A73D0D1C1B0941001FD9F8 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 67A73D0E1C1B0941001FD9F8 /* Build configuration list for PBXNativeTarget "DeepLearningKitFortvOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 67A73D0F1C1B0941001FD9F8 /* Debug */, - 67A73D101C1B0941001FD9F8 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 67A73D111C1B0941001FD9F8 /* Build configuration list for PBXNativeTarget "DeepLearningKitFortvOSTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 67A73D121C1B0941001FD9F8 /* Debug */, - 67A73D131C1B0941001FD9F8 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 67A73CF11C1B0941001FD9F8 /* Project object */; -} diff --git a/DeepLearningKitFortvOS/DeepLearningKitFortvOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/DeepLearningKitFortvOS/DeepLearningKitFortvOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index a89b623..0000000 --- a/DeepLearningKitFortvOS/DeepLearningKitFortvOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/ConvolutionLayer.swift b/DeepLearningKitFortvOS/DeepLearningKitFortvOS/ConvolutionLayer.swift deleted file mode 100644 index 45709d0..0000000 --- a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/ConvolutionLayer.swift +++ /dev/null @@ -1,237 +0,0 @@ -// -// ConvolutionLayer.swift -// MemkiteMetal -// -// Created by Torb Morland & Amund Tveit on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - -func getDataFromBlob(blob: NSDictionary) -> ([Float], [Float]) { - print(" ==> getDataFromBlob") - - let shape = blob["shape"] as! NSDictionary - let data = blob["data"] as! [Float] - var FloatData = createFloatNumbersArray(data.count) - for i in 0 ..< data.count { - FloatData[i] = data[i] - } - return (shape["dim"] as! [Float], FloatData) -} - - - -func createConvolutionLayerCached(layer: NSDictionary, - inputBuffer: MTLBuffer, - inputShape: [Float], - metalCommandQueue: MTLCommandQueue, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout layer_data_caches: [Dictionary], - inout blob_cache: [Dictionary], - layer_number: Int, - layer_string: String) -> (MTLBuffer, MTLCommandBuffer, [Float]) { - - let start = NSDate() - - print("CREATECONVLAYERCACHED") - -// let metalCommandBuffer = metalCommandQueue.commandBuffer() - let metalCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() - - var convolution_params_dict:NSDictionary = NSDictionary() - var pad:Float = 0.0 - var kernel_size:Float = 1.0 - var stride:Float = 1.0 - var blobs:[NSDictionary] = [] - var weights:[Float] = [] - var weight_shape:[Float] = [] - var bias_data:[Float] = [] - var h:Float = 0.0 - var w:Float = 0.0 - var result_shape:[Float] = [] - var outputCount:Int = 0 - - var input_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var weight_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var result_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var tensor_dimensions:[MetalTensorDimensions] = [] - var col_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var col_output:[Float] = [] - var convolution_params:MetalConvolutionParameters = MetalConvolutionParameters(pad:0, kernel_size: 0, stride: 0) - - - print("NOTCACHINGMODE") - convolution_params_dict = layer["convolution_param"] as! NSDictionary - pad = 0.0 - kernel_size = 1.0 - stride = 1.0 - if let val = convolution_params_dict["pad"] as? Float { - pad = val - } - if let val = convolution_params_dict["kernel_size"] as? Float { - kernel_size = val - } - - let startblob = NSDate() - - - if let tmpval = blob_cache[layer_number]["0"] { - print("found blob key = 0 in cache") - (weight_shape, weights) = tmpval - } else { - print("didnt find blob key = 0 in cache") - blobs = layer["blobs"] as! [NSDictionary] - (weight_shape, weights) = getDataFromBlob(blobs[0]) - blob_cache[layer_number]["0"] = (weight_shape, weights) - } - -// this can be optimized - blobs = layer["blobs"] as! [NSDictionary] - (_, bias_data) = getDataFromBlob(blobs[1]) - - print("### Time to blob: \(NSDate().timeIntervalSinceDate(startblob))") - - - /* - let startblob = NSDate() - blobs = layer["blobs"] as! [NSDictionary] - (weight_shape, weights) = getDataFromBlob(blobs[0]) - (_, bias_data) = getDataFromBlob(blobs[1]) - print("### Time to blob: \(NSDate().timeIntervalSinceDate(startblob))") -*/ - - - h = (inputShape[2] + 2 * pad - kernel_size) / stride + 1 - w = (inputShape[3] + 2 * pad - kernel_size) / stride + 1 - result_shape = [inputShape[0], weight_shape[0], h, w] - outputCount = Int(result_shape.reduce(1, combine: *)) - - // Create input and output vectors, and corresponding metal buffer - input_dimensions = MetalTensorDimensions(n: inputShape[0], channels: inputShape[1], width: inputShape[2], height: inputShape[3]) - weight_dimensions = MetalTensorDimensions(n: weight_shape[0], channels: weight_shape[1], width: weight_shape[2], height: weight_shape[3]) - col_dimensions = MetalTensorDimensions(n: inputShape[0], channels: inputShape[1] * weight_shape[2] * weight_shape[3], width: inputShape[2], height: inputShape[3]) - result_dimensions = MetalTensorDimensions(n: result_shape[0], channels: result_shape[1], width: result_shape[2], height: result_shape[3]) - tensor_dimensions = [input_dimensions, weight_dimensions, col_dimensions, result_dimensions] - - - col_output = createFloatNumbersArray(Int(col_dimensions.n * col_dimensions.channels * col_dimensions.height * col_dimensions.width)) - - - convolution_params = MetalConvolutionParameters(pad: pad, kernel_size: kernel_size, stride: stride) - print("AFTER NOTCACHINGMODE") - - - print("BEFORE THE BIG CALL") - - let resultBuffer = addConvolutionCommandToCommandBufferCached(metalCommandBuffer, inputBuffer: inputBuffer, im2ColCount: col_output.count, weights: weights, outputCount: outputCount, convolution_params: convolution_params, tensor_dimensions: tensor_dimensions, bias: bias_data, metalDefaultLibrary: metalDefaultLibrary, metalDevice:metalDevice, layer_data_caches: &layer_data_caches, layer_number: layer_number,layer_string: layer_string) - //metalCommandBuffer.commit() - - print("AFTER BIG CALL") - - print("### Time to setup convolution layer: \(NSDate().timeIntervalSinceDate(start))") - - - return (resultBuffer, metalCommandBuffer, result_shape) - -} - -func addConvolutionCommandToCommandBufferCached(commandBuffer: MTLCommandBuffer, - inputBuffer: MTLBuffer, - im2ColCount: Int, - weights: [Float], - outputCount: Int, - convolution_params: MetalConvolutionParameters, - tensor_dimensions: [MetalTensorDimensions], - bias: [Float], - metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout layer_data_caches: [Dictionary], - layer_number: Int, - layer_string: String) -> MTLBuffer { - - let start = NSDate() - - print("before output and col_output") - - var output:[Float] = [] - var col_output:[Float] = [] - - output = createFloatNumbersArray(outputCount) - col_output = createFloatNumbersArray(im2ColCount) - - print("before setupshaderinpipeline") - - let (_, im2colComputePipelineState, _) = setupShaderInMetalPipeline("im2col", metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice) - - let resultMetalBuffer = createOrReuseFloatMetalBuffer("resultMetalBuffer", data: output, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - - print("after resultmetalbuffer") - - let weightMetalBuffer = createOrReuseFloatMetalBuffer("weightMetalBuffer", data: weights, cache: &layer_data_caches, layer_number:layer_number, metalDevice: metalDevice) - - - let convolutionParamsMetalBuffer = createOrReuseConvolutionParametersMetalBuffer("convolutionParamsMetalBuffer", data: convolution_params, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - let tensorDimensionsMetalBuffer = createOrReuseTensorDimensionsVectorMetalBuffer("tensorDimensionsMetalBuffer", data: tensor_dimensions, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - - let colOutputMetalBuffer = createOrReuseFloatMetalBuffer("colOutputMetalBuffer", data: col_output, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - let biasMetalBuffer = createOrReuseFloatMetalBuffer("bias", data: bias, cache: &layer_data_caches, layer_number:layer_number, metalDevice: metalDevice) - - - // Create Metal compute command encoder for im2col - var metalComputeCommandEncoder = commandBuffer.computeCommandEncoder() - metalComputeCommandEncoder.setBuffer(inputBuffer, offset: 0, atIndex: 0) - metalComputeCommandEncoder.setBuffer(tensorDimensionsMetalBuffer, offset: 0, atIndex: 1) - metalComputeCommandEncoder.setBuffer(convolutionParamsMetalBuffer, offset: 0, atIndex: 2) - metalComputeCommandEncoder.setBuffer(colOutputMetalBuffer, offset: 0, atIndex: 3) - //metalComputeCommandEncoder.setComputePipelineState(im2colComputePipelineState) - - - // Set the shader function that Metal will use - metalComputeCommandEncoder.setComputePipelineState(im2colComputePipelineState) - - // Set up thread groups on GPU - var threadsPerGroup = MTLSize(width:im2colComputePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - print("before mtlsize 2") - var numThreadgroups = MTLSize(width:(col_output.count-1)/im2colComputePipelineState.threadExecutionWidth + 1, height:1, depth:1) - metalComputeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - print("after dispatch") - - // Finalize configuration - metalComputeCommandEncoder.endEncoding() - - - - - let (_, convolutionComputePipelineState, _) = setupShaderInMetalPipeline("convolution_layer", metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice) - metalComputeCommandEncoder = commandBuffer.computeCommandEncoder() - - // Create Metal Compute Command Encoder and add input and output buffers to it - metalComputeCommandEncoder.setBuffer(resultMetalBuffer, offset: 0, atIndex: 0) - metalComputeCommandEncoder.setBuffer(weightMetalBuffer, offset: 0, atIndex: 1) - metalComputeCommandEncoder.setBuffer(tensorDimensionsMetalBuffer, offset: 0, atIndex: 2) - metalComputeCommandEncoder.setBuffer(colOutputMetalBuffer, offset: 0, atIndex: 3) - metalComputeCommandEncoder.setBuffer(biasMetalBuffer, offset: 0, atIndex: 4) - - // Set the shader function that Metal will use - metalComputeCommandEncoder.setComputePipelineState(convolutionComputePipelineState) - - // Set up thread groups on GPU - threadsPerGroup = MTLSize(width:convolutionComputePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - numThreadgroups = MTLSize(width:(outputCount-1)/convolutionComputePipelineState.threadExecutionWidth + 1, height:1, depth:1) - metalComputeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - // Finalize configuration - metalComputeCommandEncoder.endEncoding() - - print("after endencoding") - - print("#### Time to add convolution layer: \(NSDate().timeIntervalSinceDate(start))") - - - return resultMetalBuffer - -} - diff --git a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/DeepLearningKitFortvOS.h b/DeepLearningKitFortvOS/DeepLearningKitFortvOS/DeepLearningKitFortvOS.h deleted file mode 100644 index 9e45247..0000000 --- a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/DeepLearningKitFortvOS.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// DeepLearningKitFortvOS.h -// DeepLearningKitFortvOS -// -// Created by Amund Tveit on 11/12/15. -// Copyright © 2015 Amund Tveit. All rights reserved. -// - -#import - -//! Project version number for DeepLearningKitFortvOS. -FOUNDATION_EXPORT double DeepLearningKitFortvOSVersionNumber; - -//! Project version string for DeepLearningKitFortvOS. -FOUNDATION_EXPORT const unsigned char DeepLearningKitFortvOSVersionString[]; - -// In this header, you should import all the public headers of your framework using statements like #import - - diff --git a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/DeepNetwork+JSON.swift b/DeepLearningKitFortvOS/DeepLearningKitFortvOS/DeepNetwork+JSON.swift deleted file mode 100644 index 9755f49..0000000 --- a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/DeepNetwork+JSON.swift +++ /dev/null @@ -1,26 +0,0 @@ -// -// DeepNetwork+JSON.swift -// MemkiteMetal -// -// Created by Amund Tveit & Torb Morland on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation - -public extension DeepNetwork { - -func loadJSONFile(filename: String) -> NSDictionary? { - print(" ==> loadJSONFile(filename=\(filename)") - - do { - let bundle = NSBundle.mainBundle() - let path = bundle.pathForResource(filename, ofType: "json")! - let jsonData = NSData(contentsOfFile: path) - print(" <== loadJSONFile") - return try NSJSONSerialization.JSONObjectWithData(jsonData!, options: .AllowFragments) as? NSDictionary - } catch _ { - return nil - } -} -} \ No newline at end of file diff --git a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/DeepNetwork+SetupNetworkFromDict.swift b/DeepLearningKitFortvOS/DeepLearningKitFortvOS/DeepNetwork+SetupNetworkFromDict.swift deleted file mode 100644 index e0e0934..0000000 --- a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/DeepNetwork+SetupNetworkFromDict.swift +++ /dev/null @@ -1,86 +0,0 @@ -// -// DeepNetwork+SetupNetworkFromDict.swift -// MemkiteMetal -// -// Created by Amund Tveit & Torb Morland on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - -public extension DeepNetwork { - - func setupNetworkFromDict(deepNetworkAsDict: NSDictionary, inputimage: MTLBuffer, inputshape: [Float]) { - - let start = NSDate() - - gpuCommandLayers = [] - - print(" ==> setupNetworkFromDict()") - // Add input image - var layer_number = 0 - layer_data_caches.append(Dictionary()) // for input - pool_type_caches.append(Dictionary()) - blob_cache.append(Dictionary()) - namedDataLayers.append(("input", inputimage)) - ++layer_number - - - // Add remaining network - var previousBuffer:MTLBuffer = inputimage - var previousShape:[Float] = inputshape - - self.deepNetworkAsDict = deepNetworkAsDict - - // create new command buffer for next layer - var currentCommandBuffer: MTLCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() - - var t = NSDate() - for layer in deepNetworkAsDict["layer"] as! [NSDictionary] { - if let type = layer["type"] as? String { - let layer_string = layer["name"] as! String - - layer_data_caches.append(Dictionary()) - pool_type_caches.append(Dictionary()) - blob_cache.append(Dictionary()) - - - if type == "ReLU" { - self.gpuCommandLayers.append(currentCommandBuffer) - //(previousBuffer, currentCommandBuffer) = createRectifierLayer(previousBuffer) - (previousBuffer, currentCommandBuffer) = createRectifierLayer(previousBuffer, metalCommandQueue:metalCommandQueue, metalDefaultLibrary:metalDefaultLibrary, metalDevice:metalDevice) - self.namedDataLayers.append((layer["name"]! as! String, previousBuffer)) - } else if type == "Pooling" { - self.gpuCommandLayers.append(currentCommandBuffer) - // (previousBuffer, currentCommandBuffer, previousShape) = createPoolingLayer(layer, inputBuffer: previousBuffer, inputShape: previousShape) - (previousBuffer, currentCommandBuffer, previousShape) = createPoolingLayerCached(layer, inputBuffer: previousBuffer, inputShape: previousShape, metalCommandQueue: metalCommandQueue, metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice, pool_type_caches: &pool_type_caches, layer_data_caches: &layer_data_caches, layer_number: layer_number, layer_string: layer_string) - self.namedDataLayers.append((layer["name"]! as! String, previousBuffer)) - } else if type == "Convolution" { - self.gpuCommandLayers.append(currentCommandBuffer) - // (previousBuffer, currentCommandBuffer, previousShape) = createConvolutionLayer(layer, inputBuffer: previousBuffer, inputShape: previousShape) - (previousBuffer, currentCommandBuffer, previousShape) = createConvolutionLayerCached(layer, inputBuffer: previousBuffer, inputShape: previousShape, metalCommandQueue: metalCommandQueue, metalDefaultLibrary:metalDefaultLibrary, metalDevice:metalDevice, layer_data_caches: &layer_data_caches, blob_cache: &blob_cache, layer_number: layer_number, layer_string: layer_string) - - - self.namedDataLayers.append((layer["name"]! as! String, previousBuffer)) - } - let name = layer["name"] as! String - print("\(name): \(NSDate().timeIntervalSinceDate(t))") - t = NSDate() - ++layer_number - - } - } - - self.gpuCommandLayers.append(currentCommandBuffer) - - print("bar") - - print("AFTER LAYER DATA CHACES = \(layer_data_caches[0])") - - print("POOL TYPE CACHES = \(pool_type_caches)") - - print("Time to set up network: \(NSDate().timeIntervalSinceDate(start))") - - } -} diff --git a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/DeepNetwork.swift b/DeepLearningKitFortvOS/DeepLearningKitFortvOS/DeepNetwork.swift deleted file mode 100644 index 4f5de2b..0000000 --- a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/DeepNetwork.swift +++ /dev/null @@ -1,76 +0,0 @@ -// -// DeepNetwork.swift -// MemkiteMetal -// -// Created by Amund Tveit & Torb Morland on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - -public class DeepNetwork { - var gpuCommandLayers: [MTLCommandBuffer] = [] - var namedDataLayers: [(String, MTLBuffer)] = [] - var imageBuffer: MTLBuffer! - var metalDevice: MTLDevice! - var metalDefaultLibrary: MTLLibrary! - var metalCommandQueue: MTLCommandQueue! - var deepNetworkAsDict: NSDictionary! // for debugging perhaps - var layer_data_caches: [Dictionary] = [] - var pool_type_caches: [Dictionary] = [] - var dummy_image: [Float]! - var previous_shape: [Float]! - var blob_cache: [Dictionary] = [] - - public init() { - // Get access to iPhone or iPad GPU - metalDevice = MTLCreateSystemDefaultDevice() - - // Queue to handle an ordered list of command buffers - metalCommandQueue = metalDevice.newCommandQueue() - print("metalCommandQueue = \(unsafeAddressOf(metalCommandQueue))") - - // Access to Metal functions that are stored in Shaders.metal file, e.g. sigmoid() - metalDefaultLibrary = metalDevice.newDefaultLibrary() - } - - public func loadNetworkFromJson(jsonNetworkFileName: String) { - deepNetworkAsDict = loadJSONFile(jsonNetworkFileName)! - } - - public func classify(image: [Float], shape:[Float]) -> Int { - let imageTensor = createMetalBuffer(image, metalDevice: metalDevice) - - gpuCommandLayers = [] - setupNetworkFromDict(deepNetworkAsDict, inputimage: imageTensor, inputshape: shape) - - let start = NSDate() - for commandBuffer in gpuCommandLayers { - commandBuffer.commit() - } - - // wait until last layer in conv.net is finished - gpuCommandLayers.last!.waitUntilCompleted() - print("Time to run network: \(NSDate().timeIntervalSinceDate(start))") - - var classification_results = [Float](count: 10, repeatedValue: 0.0) - let (lastLayerName, lastMetalBuffer) = namedDataLayers.last! - NSLog(lastLayerName) - let data = NSData(bytesNoCopy: lastMetalBuffer.contents(), - length: classification_results.count*sizeof(Float), freeWhenDone: false) - data.getBytes(&classification_results, length:(Int(classification_results.count)) * sizeof(Float)) - print(classification_results) - let maxValue:Float = classification_results.maxElement()! - let indexOfMaxValue:Int = classification_results.indexOf(maxValue)! - - print("maxValue = \(maxValue), indexofMaxValue = \(indexOfMaxValue)") - - // empty command buffers! - - // return index - return indexOfMaxValue - - } -} - diff --git a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/Info.plist b/DeepLearningKitFortvOS/DeepLearningKitFortvOS/Info.plist deleted file mode 100644 index 5f59404..0000000 --- a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/Info.plist +++ /dev/null @@ -1,26 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - FMWK - CFBundleShortVersionString - 0.0.1 - CFBundleSignature - ???? - CFBundleVersion - $(CURRENT_PROJECT_VERSION) - NSPrincipalClass - - - diff --git a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/MetalDataStructures.swift b/DeepLearningKitFortvOS/DeepLearningKitFortvOS/MetalDataStructures.swift deleted file mode 100644 index c53d61c..0000000 --- a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/MetalDataStructures.swift +++ /dev/null @@ -1,62 +0,0 @@ -// -// MetalDataStructures.swift -// MemkiteMetal -// -// Created by Amund Tveit & Torb Morland on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - -////////////////////////////////////////// -// Metal Data Types - their SWIFT Counterparts -////////////////////////////////////////// -public struct MetalComplexNumberType { - var real: Float = 0.0 - var imag: Float = 0.0 -} - -public struct MetalShaderParameters { - let image_xdim: Float - let image_ydim: Float - let num_images: Float - let filter_xdim: Float - let filter_ydim: Float - let num_filters: Float - let conv_xdim: Float // image_xdim - filter_xdim + 1 without striding - let conv_ydim: Float // image_ydim - filter_ydim + 1 without striding - let pool_xdim: Float - let pool_ydim: Float - var b: Float -} - -public struct MetalMatrixVectorParameters { - let x_xdim: Float - let x_ydim: Float - let w_xdim: Float - let w_ydim: Float - let b_xdim: Float - let b_ydim: Float - let result_xdim: Float - let result_ydim: Float -} - -public struct MetalPoolingParameters { - let kernel_size: Float - let pool_stride: Float - let pad: Float -} - -public struct MetalTensorDimensions { - let n: Float - let channels: Float - let width: Float - let height: Float -} - -public struct MetalConvolutionParameters { - let pad: Float - let kernel_size: Float - let stride: Float -} diff --git a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/MetalUtilityFunctions.swift b/DeepLearningKitFortvOS/DeepLearningKitFortvOS/MetalUtilityFunctions.swift deleted file mode 100644 index 1ed4d80..0000000 --- a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/MetalUtilityFunctions.swift +++ /dev/null @@ -1,173 +0,0 @@ -// -// MetalUtilFunctions.swift -// MemkiteMetal -// -// Created by Amund Tveit & Torb Morland on 24/11/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - -func createComplexNumbersArray(count: Int) -> [MetalComplexNumberType] { - let zeroComplexNumber = MetalComplexNumberType() - return [MetalComplexNumberType](count: count, repeatedValue: zeroComplexNumber) -} - -func createFloatNumbersArray(count: Int) -> [Float] { - return [Float](count: count, repeatedValue: 0.0) -} - -func createFloatMetalBuffer(var vector: [Float], let metalDevice:MTLDevice) -> MTLBuffer { - let byteLength = vector.count*sizeof(Float) // future: MTLResourceStorageModePrivate - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createComplexMetalBuffer(var vector:[MetalComplexNumberType], let metalDevice:MTLDevice) -> MTLBuffer { - let byteLength = vector.count*sizeof(MetalComplexNumberType) // or size of and actual 1st element object? - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createShaderParametersMetalBuffer(var shaderParameters:MetalShaderParameters, metalDevice:MTLDevice) -> MTLBuffer { - let byteLength = sizeof(MetalShaderParameters) - return metalDevice.newBufferWithBytes(&shaderParameters, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createMatrixShaderParametersMetalBuffer(var params: MetalMatrixVectorParameters, metalDevice: MTLDevice) -> MTLBuffer { - let byteLength = sizeof(MetalMatrixVectorParameters) - return metalDevice.newBufferWithBytes(¶ms, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) - -} - -func createPoolingParametersMetalBuffer(var params: MetalPoolingParameters, metalDevice: MTLDevice) -> MTLBuffer { - let byteLength = sizeof(MetalPoolingParameters) - return metalDevice.newBufferWithBytes(¶ms, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createConvolutionParametersMetalBuffer(var params: MetalConvolutionParameters, metalDevice: MTLDevice) -> MTLBuffer { - let byteLength = sizeof(MetalConvolutionParameters) - return metalDevice.newBufferWithBytes(¶ms, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createTensorDimensionsVectorMetalBuffer(var vector: [MetalTensorDimensions], metalDevice: MTLDevice) -> MTLBuffer { - let byteLength = vector.count * sizeof(MetalTensorDimensions) - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func setupShaderInMetalPipeline(shaderName:String, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice) -> (shader:MTLFunction!, - computePipelineState:MTLComputePipelineState!, - computePipelineErrors:NSErrorPointer!) { - let shader = metalDefaultLibrary.newFunctionWithName(shaderName) - let computePipeLineDescriptor = MTLComputePipelineDescriptor() - computePipeLineDescriptor.computeFunction = shader - // var computePipelineErrors = NSErrorPointer() - // let computePipelineState:MTLComputePipelineState = metalDevice.newComputePipelineStateWithFunction(shader!, completionHandler: {(}) - let computePipelineErrors = NSErrorPointer() - var computePipelineState:MTLComputePipelineState? = nil - do { - computePipelineState = try metalDevice.newComputePipelineStateWithFunction(shader!) - } catch { - print("catching..") - } - return (shader, computePipelineState, computePipelineErrors) - -} - -func createMetalBuffer(var vector:[Float], metalDevice:MTLDevice) -> MTLBuffer { - let byteLength = vector.count*sizeof(Float) - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func preLoadMetalShaders(metalDevice: MTLDevice, metalDefaultLibrary: MTLLibrary) { - let shaders = ["avg_pool", "max_pool", "rectifier_linear", "convolution_layer", "im2col"] - for shader in shaders { - setupShaderInMetalPipeline(shader, metalDefaultLibrary: metalDefaultLibrary,metalDevice: metalDevice) // TODO: this returns stuff - } -} - -func createOrReuseFloatMetalBuffer(name:String, data: [Float], inout cache:[Dictionary], layer_number:Int, metalDevice:MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { - print("found key = \(name) in cache") - result = tmpval - } else { - print("didnt find key = \(name) in cache") - result = createFloatMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - // print("DEBUG: cache = \(cache)") - } - - return result -} - - -func createOrReuseConvolutionParametersMetalBuffer(name:String, - data: MetalConvolutionParameters, - inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { - print("found key = \(name) in cache") - result = tmpval - } else { - print("didnt find key = \(name) in cache") - result = createConvolutionParametersMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - -func createOrReuseTensorDimensionsVectorMetalBuffer(name:String, - data:[MetalTensorDimensions],inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { - print("found key = \(name) in cache") - result = tmpval - } else { - print("didnt find key = \(name) in cache") - result = createTensorDimensionsVectorMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - -// -//let sizeParamMetalBuffer = createShaderParametersMetalBuffer(size_params, metalDevice: metalDevice) -//let poolingParamMetalBuffer = createPoolingParametersMetalBuffer(pooling_params, metalDevice: metalDevice) - -func createOrReuseShaderParametersMetalBuffer(name:String, - data:MetalShaderParameters,inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { -// print("found key = \(name) in cache") - result = tmpval - } else { -// print("didnt find key = \(name) in cache") - result = createShaderParametersMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - -func createOrReusePoolingParametersMetalBuffer(name:String, - data:MetalPoolingParameters,inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { -// print("found key = \(name) in cache") - result = tmpval - } else { -// print("didnt find key = \(name) in cache") - result = createPoolingParametersMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - - diff --git a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/PoolingLayer.swift b/DeepLearningKitFortvOS/DeepLearningKitFortvOS/PoolingLayer.swift deleted file mode 100644 index fd4f589..0000000 --- a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/PoolingLayer.swift +++ /dev/null @@ -1,141 +0,0 @@ -// -// PoolingLayer.swift -// MemkiteMetal -// -// Created by Torb Morland & Amund Tveit on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - - -func createPoolingLayerCached(layer: NSDictionary, - inputBuffer: MTLBuffer, - inputShape: [Float], - metalCommandQueue: MTLCommandQueue, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout pool_type_caches: [Dictionary], - inout layer_data_caches: [Dictionary], - layer_number: Int, - layer_string: String) -> (MTLBuffer, MTLCommandBuffer, [Float]) { - - print(" ==> createPoolingLayerCached") - let metalCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() -// let metalCommandBuffer = metalCommandQueue.commandBuffer() - - var params = NSDictionary() - var stride:Float = 1.0 - var kernel_size: Float = 1.0 - var pad: Float = 0.0 - var pooling_params = MetalPoolingParameters(kernel_size: kernel_size, pool_stride: stride, pad: pad) - var pool_type = 0 - var h:Float = 0.0 - var w:Float = 0.0 - var shape:[Float] = [] - var outputCount:Float = 0 - var pool_width = 0 - var pool_height = 0 - var size_params:MetalShaderParameters = MetalShaderParameters(image_xdim:0.0, image_ydim:0.0, num_images: 0.0, filter_xdim: 0.0, filter_ydim: 0.0, num_filters: 0.0, conv_xdim: 0.0, conv_ydim: 0.0, pool_xdim: 0.0, pool_ydim: 0.0, b:0.0) - var outputBuffer:MTLBuffer - - - params = layer["pooling_param"] as! NSDictionary - stride = 1.0 - kernel_size = 1.0 - pad = 0.0 - if let val = params["stride"] { - stride = val as! Float - } - if let val = params["kernel_size"] { - kernel_size = val as! Float - if val as! NSNumber != 3 { - pad = 0 - } - } - pooling_params = MetalPoolingParameters(kernel_size: kernel_size, pool_stride: stride, pad: pad) - pool_type = params["pool"] as! Int - - // STORE pool type in cache! - pool_type_caches[layer_number]["pool_type"] = String(pool_type) - - h = ceil((inputShape[2] + 2.0 * pad - kernel_size) / stride) + 1.0 - w = ceil((Float(inputShape[3]) + 2.0 * pad - kernel_size) / stride) + 1.0 - shape = [inputShape[0], inputShape[1], h, w] - outputCount = shape.reduce(1, combine: *) - pool_width = Int(shape[2]) - pool_height = Int(shape[3]) - size_params = MetalShaderParameters(image_xdim: Float(inputShape[2]), image_ydim: Float(inputShape[3]), - num_images: Float(inputShape[0]), - filter_xdim: 1.0, filter_ydim: 1.0, num_filters: Float(inputShape[1]), - conv_xdim:0.0, conv_ydim: 0.0, - pool_xdim: Float(pool_width), pool_ydim: Float(pool_height), b:0.0) - - if pool_type == 1 { - outputBuffer = addPoolingCommandToCommandBufferCached(metalCommandBuffer, poolingMethod: "avg_pool", inputBuffer: inputBuffer, outputCount: Int(outputCount), size_params: size_params, pooling_params: pooling_params, metalDefaultLibrary: metalDefaultLibrary, metalDevice:metalDevice, - layer_data_caches: &layer_data_caches, layer_number: layer_number, layer_string: layer_string) - } else { - outputBuffer = addPoolingCommandToCommandBufferCached(metalCommandBuffer, poolingMethod: "max_pool", inputBuffer: inputBuffer, outputCount: Int(outputCount), size_params: size_params, pooling_params: pooling_params,metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice, - layer_data_caches: &layer_data_caches, layer_number: layer_number, layer_string: layer_string) - - } - //metalCommandBuffer.commit() - - print(" <== createPoolingLayerCached") - - - return (outputBuffer, metalCommandBuffer, shape) -} - - -func addPoolingCommandToCommandBufferCached(commandBuffer: MTLCommandBuffer, - poolingMethod: String, - inputBuffer: MTLBuffer, - outputCount: Int, - size_params: MetalShaderParameters, - pooling_params: MetalPoolingParameters, - metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout layer_data_caches: [Dictionary], - layer_number: Int, - layer_string: String) -> MTLBuffer { - - - print(" ==> addPoolingCommandtoCommandBufferCached") - - - let output = createFloatNumbersArray(outputCount) - let (_, computePipelineState, _) = setupShaderInMetalPipeline(poolingMethod, metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice) - - let outputMetalBuffer = createOrReuseFloatMetalBuffer("outputMetalBuffer", data: output, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - // let outputMetalBuffer = createFloatMetalBuffer(output, metalDevice: metalDevice) - - let sizeParamMetalBuffer = createOrReuseShaderParametersMetalBuffer("sizeParamMetalBuffer", data: size_params, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - - // let sizeParamMetalBuffer = createShaderParametersMetalBuffer(size_params, metalDevice: metalDevice) - - - // let poolingParamMetalBuffer = createPoolingParametersMetalBuffer(pooling_params, metalDevice: metalDevice) - let poolingParamMetalBuffer = createOrReusePoolingParametersMetalBuffer("poolingParamMetalBuffer", data: pooling_params, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - // Create Metal Compute Command Encoder and add input and output buffers to it - let metalComputeCommandEncoder = commandBuffer.computeCommandEncoder() - metalComputeCommandEncoder.setBuffer(outputMetalBuffer, offset: 0, atIndex: 0) - metalComputeCommandEncoder.setBuffer(inputBuffer, offset: 0, atIndex: 1) - metalComputeCommandEncoder.setBuffer(sizeParamMetalBuffer, offset: 0, atIndex: 2) - metalComputeCommandEncoder.setBuffer(poolingParamMetalBuffer, offset: 0, atIndex: 3) - - // Set the shader function that Metal will use - metalComputeCommandEncoder.setComputePipelineState(computePipelineState) - - // Set up thread groups on GPU - let threadsPerGroup = MTLSize(width:computePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - let numThreadgroups = MTLSize(width:(outputCount-1)/computePipelineState.threadExecutionWidth + 1, height:1, depth:1) - metalComputeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - // Finalize configuration - metalComputeCommandEncoder.endEncoding() - - print(" <== addPoolingCommandtoCommandBufferCached") - - - return outputMetalBuffer -} diff --git a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/RectifierLayer.swift b/DeepLearningKitFortvOS/DeepLearningKitFortvOS/RectifierLayer.swift deleted file mode 100644 index 7d3478d..0000000 --- a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/RectifierLayer.swift +++ /dev/null @@ -1,53 +0,0 @@ -// -// RectifierLayer.swift -// MemkiteMetal -// -// Created by Torb Morland & Amund Tveit on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -import Foundation -import Metal - -func createRectifierLayer(inputBuffer: MTLBuffer, metalCommandQueue: MTLCommandQueue, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice) -> (MTLBuffer,MTLCommandBuffer) { - print(" ==> createrectifierlayer") -// let metalCommandBuffer = metalCommandQueue.commandBuffer() - let metalCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() - - let result = addRectifierCommandToCommandBuffer(metalCommandBuffer, inputBuffer: inputBuffer, - metalDefaultLibrary: metalDefaultLibrary, metalDevice:metalDevice) - //metalCommandBuffer.commit() - - print(" <== createrectifierlayer") - return (result, metalCommandBuffer) -} - - -func addRectifierCommandToCommandBuffer(commandBuffer: MTLCommandBuffer, inputBuffer: MTLBuffer, - metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice) -> MTLBuffer { - - print("==> addRectifierToCommandBuffer") - - let count = inputBuffer.length / sizeof(Float) - let (_, computePipelineState, _) = setupShaderInMetalPipeline("rectifier_linear", metalDefaultLibrary: metalDefaultLibrary, - metalDevice: metalDevice) - - // Create Metal Compute Command Encoder and add input and output buffers to it - let computeCommandEncoder = commandBuffer.computeCommandEncoder() - computeCommandEncoder.setBuffer(inputBuffer, offset: 0, atIndex: 0) - // Set the shader function that Metal will use - computeCommandEncoder.setComputePipelineState(computePipelineState) - - // Set up thread groups on GPU - let threadsPerGroup = MTLSize(width:computePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - let numThreadgroups = MTLSize(width:(count-1)/computePipelineState.threadExecutionWidth + 1, height:1, depth:1) - computeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - // Finalize configuration - computeCommandEncoder.endEncoding() - - print(" <== addRectifierToCommandBuffer") - - return inputBuffer -} diff --git a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/Shaders.metal b/DeepLearningKitFortvOS/DeepLearningKitFortvOS/Shaders.metal deleted file mode 100644 index d8d27f8..0000000 --- a/DeepLearningKitFortvOS/DeepLearningKitFortvOS/Shaders.metal +++ /dev/null @@ -1,224 +0,0 @@ -// -// Shaders.metal -// -// Created by Torb Morland & Amund Tveit on 12/12/15. -// Copyright © 2015 Memkite. All rights reserved. -// - -#include -#include -#include -#include -#include -#include -#include -#include -using namespace metal; - -//////////////////////////////// -// DATA TYPES -//////////////////////////////// - -struct MetalComplexNumberType { // needs to map to float2 in Metal - float real; - float imag; -}; - -struct MetalShaderParameters { - float image_xdim; - float image_ydim; - float num_images; - float filter_xdim; // e.g. 5 - float filter_ydim; // e.g. 5 - float num_filters; // e.g. 20 -> W = 20*1*5*5 - float conv_xdim; // image_xdim - filter_xdim + 1 without striding - float conv_ydim; // image_ydim - filter_ydim + 1 without striding - float pool_xdim; - float pool_ydim; - float b; -}; - -struct MetalMatrixVectorParameters { - float x_xdim; - float x_ydim; - float w_xdim; - float w_ydim; - float b_xdim; - float b_ydim; - float result_xdim; - float result_ydim; -}; - -struct MetalPoolingParameters { - float kernel_size; - float pool_stride; - float pad; -}; - -struct MetalTensorDimensions { - float n; - float channels; - float width; - float height; -}; - -struct MetalConvolutionParameters { - float pad; - float kernel_size; - float stride; -}; - -//////////////////////////////// -// SHADER FUNCTIONS -//////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////// - - -// Returns max(0, X[id]) -kernel void rectifier_linear(device float* X [[ buffer(0)]], - uint id [[ thread_position_in_grid ]]) { - X[id] = fmax(0.0, X[id]); -} - -//////////////////////////////////////////////////////////////////////////////////////////// - -kernel void max_pool(device float* result [[ buffer(0) ]], - const device float* input [[ buffer(1) ]], - const device MetalShaderParameters* size_params [[ buffer(2) ]], - const device MetalPoolingParameters* pooling_params [[ buffer(3) ]], - uint id [[ thread_position_in_grid ]]) { - int channels = int(size_params[0].num_filters); - int in_width = int(size_params[0].image_xdim); - int in_height = int(size_params[0].image_ydim); - - float kernel_size = float(pooling_params[0].kernel_size); - int pool_stride = int(pooling_params[0].pool_stride); - int pad = int(pooling_params[0].pad); - - int out_width = int(size_params[0].pool_xdim); - int out_height = int(size_params[0].pool_ydim); - - int i = (id / out_height) % out_width; - int j = id % out_height; - int n = id / (channels * out_width * out_height); - int c = (id / (out_width * out_height)) % channels; - int wstart = i * pool_stride - pad; - int hstart = j * pool_stride - pad; - int wend = fmin(wstart + kernel_size, in_width + pad); - int hend = fmin(hstart + kernel_size, in_height + pad); - wstart = fmax(0.0, wstart); - hstart = fmax(0.0, hstart); - thread float pool = -100000.0; - for (int ii = wstart; ii < wend; ++ii) { - for (int jj = hstart; jj < hend; ++jj) { - pool = fmax(pool, input[(n * channels * in_height + c * in_height + ii) * in_width + jj]); - } - } - result[id] = pool; -} - -//////////////////////////////////////////////////////////////////////////////////////////// - -kernel void avg_pool(device float* result [[ buffer(0) ]], - const device float* input [[ buffer(1) ]], - const device MetalShaderParameters* size_params [[ buffer(2) ]], - const device MetalPoolingParameters* pooling_params [[ buffer(3) ]], - uint id [[ thread_position_in_grid ]]) { - int channels = int(size_params[0].num_filters); - int in_width = int(size_params[0].image_xdim); - int in_height = int(size_params[0].image_ydim); - - float kernel_size = float(pooling_params[0].kernel_size); - int pool_stride = int(pooling_params[0].pool_stride); - int pad = int(pooling_params[0].pad); - - int out_width = int(size_params[0].pool_xdim); - int out_height = int(size_params[0].pool_ydim); - - int i = (id / out_height) % out_width; - int j = id % out_height; - int n = id / (channels * out_width * out_height); - int c = (id / (out_width * out_height)) % channels; - int wstart = i * pool_stride - pad; - int hstart = j * pool_stride - pad; - int wend = fmin(wstart + kernel_size, in_width + pad); - int hend = fmin(hstart + kernel_size, in_height + pad); - float pool_size = (hend - hstart) * (wend - wstart); - wstart = fmax(0.0, wstart); - hstart = fmax(0.0, hstart); - thread float pool = 0.0; - for (int ii = wstart; ii < wend; ++ii) { - for (int jj = hstart; jj < hend; ++jj) { - pool += input[(n * channels * in_height + c * in_height + ii) * in_width + jj]/pool_size; - } - } - result[id] = pool; -} - -//////////////////////////////////////////////////////////////////////////////////////////// - -kernel void im2col(const device float* convolution_input [[ buffer(0)]], - const device MetalTensorDimensions* tensor_dimensions [[ buffer(1) ]], - const device MetalConvolutionParameters* convolution_params [[ buffer(2) ]], - device float* col_output [[ buffer(3) ]], - uint id [[ thread_position_in_grid ]]) { - int channels_in = int(tensor_dimensions[0].channels); - int in_width = int(tensor_dimensions[0].width); - int in_height = int(tensor_dimensions[0].height); - - int channels_col = int(tensor_dimensions[2].channels); - int width_col = int(tensor_dimensions[2].width); - int height_col = int(tensor_dimensions[2].height); - - - // 1. do an im2col transformation - int pad = int(convolution_params[0].pad); - int kernel_size = int(convolution_params[0].kernel_size); - - int n = id / (channels_col * height_col * width_col); - int c = (id / (width_col * height_col)) % channels_col; - int h = (id / width_col) % height_col; - int w = id % width_col; - int w_offset = c % kernel_size; - int h_offset = (c / kernel_size) % kernel_size; - int h_pad = h - pad + h_offset; - int w_pad = w - pad + w_offset; - int c_im = c / (kernel_size * kernel_size); - if (h_pad >= 0 && h_pad < in_height && w_pad >= 0 && w_pad < in_width) { - col_output[id] = convolution_input[(n * channels_in * in_height + c_im * in_height + h_pad) * in_width + w_pad]; - } -} - -//////////////////////////////////////////////////////////////////////////////////////////// - -// Tensor dimensions = { input_dimensions, weight_dimensions, col_dimensions, result_dimensions } -kernel void convolution_layer(device float* result [[ buffer(0) ]], - const device float* weights [[ buffer(1)]], - const device MetalTensorDimensions* tensor_dimensions [[ buffer(2) ]], - const device float* col_output [[ buffer(3) ]], - const device float* bias [[ buffer(4) ]], - uint id [[ thread_position_in_grid ]]) { - int channels_col = int(tensor_dimensions[2].channels); - int width_col = int(tensor_dimensions[2].width); - int height_col = int(tensor_dimensions[2].height); - - int channels_out = int(tensor_dimensions[3].channels); - int width_out = int(tensor_dimensions[3].width); - int height_out = int(tensor_dimensions[3].height); - - int n = id / (channels_out * height_out * width_out); - int a = (id / (height_out * width_out)) % channels_out; - int b = id % (height_out * width_out); - - thread float tmp_result = bias[a]; - - for (int c = 0; c < channels_col; ++c) { - tmp_result += weights[a * channels_col + c] * col_output[(n * channels_col * width_col + c * width_col) * height_col + b]; - } - - result[id] = tmp_result; -} - - - diff --git a/DeepLearningKitFortvOS/DeepLearningKitFortvOSTests/DeepLearningKitFortvOSTests.swift b/DeepLearningKitFortvOS/DeepLearningKitFortvOSTests/DeepLearningKitFortvOSTests.swift deleted file mode 100644 index d972265..0000000 --- a/DeepLearningKitFortvOS/DeepLearningKitFortvOSTests/DeepLearningKitFortvOSTests.swift +++ /dev/null @@ -1,36 +0,0 @@ -// -// DeepLearningKitFortvOSTests.swift -// DeepLearningKitFortvOSTests -// -// Created by Amund Tveit on 11/12/15. -// Copyright © 2015 Amund Tveit. All rights reserved. -// - -import XCTest -@testable import DeepLearningKitFortvOS - -class DeepLearningKitFortvOSTests: XCTestCase { - - override func setUp() { - super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - } - - func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. - } - - func testPerformanceExample() { - // This is an example of a performance test case. - self.measureBlock { - // Put the code you want to measure the time of here. - } - } - -} diff --git a/DeepLearningKitFortvOS/DeepLearningKitFortvOSTests/Info.plist b/DeepLearningKitFortvOS/DeepLearningKitFortvOSTests/Info.plist deleted file mode 100644 index ba72822..0000000 --- a/DeepLearningKitFortvOS/DeepLearningKitFortvOSTests/Info.plist +++ /dev/null @@ -1,24 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - - diff --git a/DeepLearningKitTests/DeepLearningKit_iOSTests.swift b/DeepLearningKitTests/DeepLearningKit_iOSTests.swift deleted file mode 100644 index e57aa81..0000000 --- a/DeepLearningKitTests/DeepLearningKit_iOSTests.swift +++ /dev/null @@ -1,37 +0,0 @@ -// -// DeepLearningKitTests.swift -// DeepLearningKitTests -// -// Created by Rafael Almeida on 20/06/16. -// Copyright © 2016 DeepLearningKit. All rights reserved. -// - -import XCTest -@testable import DeepLearningKit - -class DeepLearningKit_iOSTests: XCTestCase { - - override func setUp() { - super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - } - - func testExample() { - //Metal not available in simulator - //let deepNetwork = DeepNetwork() - //XCTAssertNotNil(deepNetwork) - } - - func testPerformanceExample() { - // This is an example of a performance test case. - self.measureBlock { - // Put the code you want to measure the time of here. - } - } - -} diff --git a/DeepLearningKitTests/Info.plist b/DeepLearningKitTests/Info.plist deleted file mode 100644 index ba72822..0000000 --- a/DeepLearningKitTests/Info.plist +++ /dev/null @@ -1,24 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - - diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.pbxproj b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.pbxproj similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.pbxproj rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.pbxproj diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/AppDelegate.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/AppDelegate.swift similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/AppDelegate.swift rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/AppDelegate.swift diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Assets.xcassets/AppIcon.appiconset/Contents.json b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Assets.xcassets/AppIcon.appiconset/Contents.json rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Base.lproj/Main.storyboard b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Base.lproj/Main.storyboard similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Base.lproj/Main.storyboard rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Base.lproj/Main.storyboard diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/ConvolutionLayer.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/ConvolutionLayer.swift similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/ConvolutionLayer.swift rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/ConvolutionLayer.swift diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+Classify.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+Classify.swift similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+Classify.swift rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+Classify.swift diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+JSON.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+JSON.swift similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+JSON.swift rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+JSON.swift diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork.swift similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork.swift rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork.swift diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Info.plist b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Info.plist similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Info.plist rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Info.plist diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/MetalDataStructures.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/MetalDataStructures.swift similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/MetalDataStructures.swift rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/MetalDataStructures.swift diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/MetalUtilityFunctions.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/MetalUtilityFunctions.swift similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/MetalUtilityFunctions.swift rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/MetalUtilityFunctions.swift diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/PoolingLayer.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/PoolingLayer.swift similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/PoolingLayer.swift rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/PoolingLayer.swift diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/RectifierLayer.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/RectifierLayer.swift similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/RectifierLayer.swift rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/RectifierLayer.swift diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Shaders.metal b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Shaders.metal similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Shaders.metal rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Shaders.metal diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/ViewController.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/ViewController.swift similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/ViewController.swift rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/ViewController.swift diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/conv1.json b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/conv1.json similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/conv1.json rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/conv1.json diff --git a/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/nin_cifar10_full.json b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/nin_cifar10_full.json similarity index 100% rename from OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/nin_cifar10_full.json rename to Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/nin_cifar10_full.json diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp.xcodeproj/project.pbxproj b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp.xcodeproj/project.pbxproj similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp.xcodeproj/project.pbxproj rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp.xcodeproj/project.pbxproj diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/AppDelegate.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/AppDelegate.swift similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/AppDelegate.swift rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/AppDelegate.swift diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Assets.xcassets/AppIcon.appiconset/Contents.json b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Assets.xcassets/AppIcon.appiconset/Contents.json rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Base.lproj/LaunchScreen.storyboard b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Base.lproj/LaunchScreen.storyboard rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Base.lproj/LaunchScreen.storyboard diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Base.lproj/Main.storyboard b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Base.lproj/Main.storyboard similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Base.lproj/Main.storyboard rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Base.lproj/Main.storyboard diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ConvolutionLayer.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ConvolutionLayer.swift similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ConvolutionLayer.swift rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ConvolutionLayer.swift diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+Classify.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+Classify.swift similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+Classify.swift rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+Classify.swift diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+JSON.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+JSON.swift similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+JSON.swift rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+JSON.swift diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork.swift similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork.swift rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork.swift diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ImageUtilityFunctions.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ImageUtilityFunctions.swift similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ImageUtilityFunctions.swift rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ImageUtilityFunctions.swift diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Info.plist b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Info.plist similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Info.plist rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Info.plist diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/MetalDataStructures.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/MetalDataStructures.swift similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/MetalDataStructures.swift rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/MetalDataStructures.swift diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/MetalUtilityFunctions.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/MetalUtilityFunctions.swift similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/MetalUtilityFunctions.swift rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/MetalUtilityFunctions.swift diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/PoolingLayer.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/PoolingLayer.swift similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/PoolingLayer.swift rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/PoolingLayer.swift diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/RectifierLayer.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/RectifierLayer.swift similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/RectifierLayer.swift rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/RectifierLayer.swift diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Shaders.metal b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Shaders.metal similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Shaders.metal rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Shaders.metal diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/UIImageExtension.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/UIImageExtension.swift similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/UIImageExtension.swift rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/UIImageExtension.swift diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ViewController.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ViewController.swift similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ViewController.swift rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ViewController.swift diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/conv1.json b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/conv1.json similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/conv1.json rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/conv1.json diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/nin_cifar10_full.json b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/nin_cifar10_full.json similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/nin_cifar10_full.json rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/nin_cifar10_full.json diff --git a/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/pool1.json b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/pool1.json similarity index 100% rename from iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/pool1.json rename to Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/pool1.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp.xcodeproj/project.pbxproj b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp.xcodeproj/project.pbxproj similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp.xcodeproj/project.pbxproj rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp.xcodeproj/project.pbxproj diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/AppDelegate.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/AppDelegate.swift similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/AppDelegate.swift rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/AppDelegate.swift diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Content.imageset/Contents.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Content.imageset/Contents.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Content.imageset/Contents.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Content.imageset/Contents.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Contents.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Contents.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Contents.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Contents.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Contents.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Contents.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Contents.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Contents.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Content.imageset/Contents.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Content.imageset/Contents.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Content.imageset/Contents.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Content.imageset/Contents.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Contents.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Contents.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Contents.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Contents.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Contents.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Contents.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Contents.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Contents.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Content.imageset/Contents.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Content.imageset/Contents.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Content.imageset/Contents.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Content.imageset/Contents.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Contents.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Contents.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Contents.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Contents.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Contents.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Contents.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Contents.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Contents.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Contents.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Contents.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Contents.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Contents.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image.imageset/Contents.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image.imageset/Contents.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image.imageset/Contents.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image.imageset/Contents.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/Contents.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/Contents.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/Contents.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/Contents.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/LaunchImage.launchimage/Contents.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/LaunchImage.launchimage/Contents.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/LaunchImage.launchimage/Contents.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Assets.xcassets/LaunchImage.launchimage/Contents.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Base.lproj/Main.storyboard b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Base.lproj/Main.storyboard similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Base.lproj/Main.storyboard rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Base.lproj/Main.storyboard diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ConvolutionLayer.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ConvolutionLayer.swift similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ConvolutionLayer.swift rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ConvolutionLayer.swift diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+Classify.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+Classify.swift similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+Classify.swift rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+Classify.swift diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+JSON.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+JSON.swift similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+JSON.swift rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+JSON.swift diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork.swift similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork.swift rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork.swift diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ImageUtilityFunctions.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ImageUtilityFunctions.swift similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ImageUtilityFunctions.swift rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ImageUtilityFunctions.swift diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Info.plist b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Info.plist similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Info.plist rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Info.plist diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/MetalDataStructures.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/MetalDataStructures.swift similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/MetalDataStructures.swift rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/MetalDataStructures.swift diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/MetalUtilityFunctions.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/MetalUtilityFunctions.swift similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/MetalUtilityFunctions.swift rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/MetalUtilityFunctions.swift diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/PoolingLayer.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/PoolingLayer.swift similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/PoolingLayer.swift rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/PoolingLayer.swift diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/RectifierLayer.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/RectifierLayer.swift similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/RectifierLayer.swift rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/RectifierLayer.swift diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Shaders.metal b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Shaders.metal similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Shaders.metal rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Shaders.metal diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/UIImageExtension.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/UIImageExtension.swift similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/UIImageExtension.swift rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/UIImageExtension.swift diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ViewController.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ViewController.swift similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ViewController.swift rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ViewController.swift diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/conv1.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/conv1.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/conv1.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/conv1.json diff --git a/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/nin_cifar10_full.json b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/nin_cifar10_full.json similarity index 100% rename from tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/nin_cifar10_full.json rename to Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/nin_cifar10_full.json From 766d580f1e56c0ed05861bb0f61ea4963af76405 Mon Sep 17 00:00:00 2001 From: Rafael Almeida Date: Mon, 20 Jun 2016 19:29:10 +1200 Subject: [PATCH 08/10] chore (examples) setup iOS sample project with library --- DeepLearningKit.xcodeproj/project.pbxproj | 4 + .../xcschemes/DeepLearningKit-OSX.xcscheme | 8 +- .../xcschemes/DeepLearningKit-tvOS.xcscheme | 8 +- .../contents.xcworkspacedata | 10 + DeepLearningKit/MetalUtilityFunctions.swift | 2 +- .../project.pbxproj | 2 - .../project.pbxproj | 62 ++--- .../Base.lproj/LaunchScreen.storyboard | 6 +- .../ConvolutionLayer.swift | 223 ----------------- .../DeepNetwork+Classify.swift | 62 ----- .../DeepNetwork+JSON.swift | 26 -- .../DeepNetwork+SetupNetworkFromDict.swift | 84 ------- .../iOSDeepLearningKitApp/DeepNetwork.swift | 63 ----- .../MetalDataStructures.swift | 65 ----- .../MetalUtilityFunctions.swift | 182 -------------- .../iOSDeepLearningKitApp/PoolingLayer.swift | 151 ------------ .../RectifierLayer.swift | 54 ----- .../iOSDeepLearningKitApp/Shaders.metal | 224 ------------------ .../ViewController.swift | 17 +- 19 files changed, 48 insertions(+), 1205 deletions(-) delete mode 100644 Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ConvolutionLayer.swift delete mode 100644 Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+Classify.swift delete mode 100644 Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+JSON.swift delete mode 100644 Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift delete mode 100644 Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork.swift delete mode 100644 Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/MetalDataStructures.swift delete mode 100644 Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/MetalUtilityFunctions.swift delete mode 100644 Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/PoolingLayer.swift delete mode 100644 Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/RectifierLayer.swift delete mode 100644 Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Shaders.metal diff --git a/DeepLearningKit.xcodeproj/project.pbxproj b/DeepLearningKit.xcodeproj/project.pbxproj index b16d3a0..63a034d 100644 --- a/DeepLearningKit.xcodeproj/project.pbxproj +++ b/DeepLearningKit.xcodeproj/project.pbxproj @@ -916,6 +916,7 @@ 53AC8A901D17BFF400778BB5 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 53AC8A911D17BFF400778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit-OSXTests" */ = { isa = XCConfigurationList; @@ -924,6 +925,7 @@ 53AC8A931D17BFF400778BB5 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 53AC8AAA1D17C02E00778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit-tvOS" */ = { isa = XCConfigurationList; @@ -932,6 +934,7 @@ 53AC8AAC1D17C02E00778BB5 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 53AC8AAD1D17C02E00778BB5 /* Build configuration list for PBXNativeTarget "DeepLearningKit-tvOSTests" */ = { isa = XCConfigurationList; @@ -940,6 +943,7 @@ 53AC8AAF1D17C02E00778BB5 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-OSX.xcscheme b/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-OSX.xcscheme index 7e31cfc..c6799a2 100644 --- a/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-OSX.xcscheme +++ b/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-OSX.xcscheme @@ -15,7 +15,7 @@ @@ -57,7 +57,7 @@ @@ -79,7 +79,7 @@ @@ -97,7 +97,7 @@ diff --git a/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-tvOS.xcscheme b/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-tvOS.xcscheme index 3c41f56..f847382 100644 --- a/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-tvOS.xcscheme +++ b/DeepLearningKit.xcodeproj/xcshareddata/xcschemes/DeepLearningKit-tvOS.xcscheme @@ -15,7 +15,7 @@ @@ -43,7 +43,7 @@ @@ -65,7 +65,7 @@ @@ -83,7 +83,7 @@ diff --git a/DeepLearningKit.xcworkspace/contents.xcworkspacedata b/DeepLearningKit.xcworkspace/contents.xcworkspacedata index 9ab4d92..884834c 100644 --- a/DeepLearningKit.xcworkspace/contents.xcworkspacedata +++ b/DeepLearningKit.xcworkspace/contents.xcworkspacedata @@ -4,4 +4,14 @@ + + + + + + diff --git a/DeepLearningKit/MetalUtilityFunctions.swift b/DeepLearningKit/MetalUtilityFunctions.swift index 1ed4d80..bcb72ed 100644 --- a/DeepLearningKit/MetalUtilityFunctions.swift +++ b/DeepLearningKit/MetalUtilityFunctions.swift @@ -14,7 +14,7 @@ func createComplexNumbersArray(count: Int) -> [MetalComplexNumberType] { return [MetalComplexNumberType](count: count, repeatedValue: zeroComplexNumber) } -func createFloatNumbersArray(count: Int) -> [Float] { +public func createFloatNumbersArray(count: Int) -> [Float] { return [Float](count: count, repeatedValue: 0.0) } diff --git a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.pbxproj b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.pbxproj index d56ac01..c34c14c 100644 --- a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.pbxproj +++ b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.pbxproj @@ -291,7 +291,6 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_IDENTITY = "Developer ID Application"; COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = OSXDeepLearningKitApp/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; @@ -304,7 +303,6 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_IDENTITY = "Developer ID Application"; COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = OSXDeepLearningKitApp/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; diff --git a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp.xcodeproj/project.pbxproj b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp.xcodeproj/project.pbxproj index f06e220..5c0de06 100644 --- a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp.xcodeproj/project.pbxproj +++ b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp.xcodeproj/project.pbxproj @@ -7,23 +7,14 @@ objects = { /* Begin PBXBuildFile section */ + 53AC8AC81D17CD0300778BB5 /* DeepLearningKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 53AC8AC71D17CD0300778BB5 /* DeepLearningKit.framework */; }; + 53AC8AC91D17D0F200778BB5 /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 67B14E401C6FEAA600FCB69C /* Metal.framework */; }; 67B14E2F1C6FE91400FCB69C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67B14E2E1C6FE91400FCB69C /* AppDelegate.swift */; }; 67B14E311C6FE91400FCB69C /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67B14E301C6FE91400FCB69C /* ViewController.swift */; }; 67B14E341C6FE91400FCB69C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 67B14E321C6FE91400FCB69C /* Main.storyboard */; }; 67B14E361C6FE91400FCB69C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 67B14E351C6FE91400FCB69C /* Assets.xcassets */; }; 67B14E391C6FE91400FCB69C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 67B14E371C6FE91400FCB69C /* LaunchScreen.storyboard */; }; - 67B14E411C6FEAA600FCB69C /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 67B14E401C6FEAA600FCB69C /* Metal.framework */; }; 67B14E431C6FEAAC00FCB69C /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 67B14E421C6FEAAC00FCB69C /* QuartzCore.framework */; }; - 67B14E451C6FEC9400FCB69C /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 67B14E441C6FEC9400FCB69C /* Shaders.metal */; }; - 67B14E471C6FECA400FCB69C /* MetalDataStructures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67B14E461C6FECA400FCB69C /* MetalDataStructures.swift */; }; - 67B14E491C6FECAD00FCB69C /* MetalUtilityFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67B14E481C6FECAD00FCB69C /* MetalUtilityFunctions.swift */; }; - 67B14E4B1C6FECD800FCB69C /* DeepNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67B14E4A1C6FECD800FCB69C /* DeepNetwork.swift */; }; - 67B14E4D1C6FECDE00FCB69C /* DeepNetwork+Classify.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67B14E4C1C6FECDE00FCB69C /* DeepNetwork+Classify.swift */; }; - 67B14E4F1C6FECE500FCB69C /* DeepNetwork+JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67B14E4E1C6FECE500FCB69C /* DeepNetwork+JSON.swift */; }; - 67B14E511C6FECF000FCB69C /* DeepNetwork+SetupNetworkFromDict.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67B14E501C6FECF000FCB69C /* DeepNetwork+SetupNetworkFromDict.swift */; }; - 67B14E531C6FED0300FCB69C /* ConvolutionLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67B14E521C6FED0300FCB69C /* ConvolutionLayer.swift */; }; - 67B14E551C6FED0D00FCB69C /* PoolingLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67B14E541C6FED0D00FCB69C /* PoolingLayer.swift */; }; - 67B14E571C6FED1200FCB69C /* RectifierLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67B14E561C6FED1200FCB69C /* RectifierLayer.swift */; }; 67B14E591C6FED2800FCB69C /* nin_cifar10_full.json in Resources */ = {isa = PBXBuildFile; fileRef = 67B14E581C6FED2800FCB69C /* nin_cifar10_full.json */; }; 67B14E5B1C6FED2D00FCB69C /* pool1.json in Resources */ = {isa = PBXBuildFile; fileRef = 67B14E5A1C6FED2D00FCB69C /* pool1.json */; }; 67B14E5D1C6FED8A00FCB69C /* conv1.json in Resources */ = {isa = PBXBuildFile; fileRef = 67B14E5C1C6FED8A00FCB69C /* conv1.json */; }; @@ -32,6 +23,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 53AC8AC71D17CD0300778BB5 /* DeepLearningKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DeepLearningKit.framework; path = "../../../../../../../Users/rafael/Library/Developer/Xcode/DerivedData/DeepLearningKit-csfprtnhalzpycftepmcgcebvxbt/Build/Products/Debug-iphoneos/DeepLearningKit.framework"; sourceTree = ""; }; 67B14E2B1C6FE91400FCB69C /* iOSDeepLearningKitApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iOSDeepLearningKitApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 67B14E2E1C6FE91400FCB69C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 67B14E301C6FE91400FCB69C /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; @@ -41,16 +33,6 @@ 67B14E3A1C6FE91400FCB69C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 67B14E401C6FEAA600FCB69C /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; }; 67B14E421C6FEAAC00FCB69C /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; - 67B14E441C6FEC9400FCB69C /* Shaders.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Shaders.metal; sourceTree = ""; }; - 67B14E461C6FECA400FCB69C /* MetalDataStructures.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalDataStructures.swift; sourceTree = ""; }; - 67B14E481C6FECAD00FCB69C /* MetalUtilityFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalUtilityFunctions.swift; sourceTree = ""; }; - 67B14E4A1C6FECD800FCB69C /* DeepNetwork.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeepNetwork.swift; sourceTree = ""; }; - 67B14E4C1C6FECDE00FCB69C /* DeepNetwork+Classify.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DeepNetwork+Classify.swift"; sourceTree = ""; }; - 67B14E4E1C6FECE500FCB69C /* DeepNetwork+JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DeepNetwork+JSON.swift"; sourceTree = ""; }; - 67B14E501C6FECF000FCB69C /* DeepNetwork+SetupNetworkFromDict.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DeepNetwork+SetupNetworkFromDict.swift"; sourceTree = ""; }; - 67B14E521C6FED0300FCB69C /* ConvolutionLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConvolutionLayer.swift; sourceTree = ""; }; - 67B14E541C6FED0D00FCB69C /* PoolingLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PoolingLayer.swift; sourceTree = ""; }; - 67B14E561C6FED1200FCB69C /* RectifierLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RectifierLayer.swift; sourceTree = ""; }; 67B14E581C6FED2800FCB69C /* nin_cifar10_full.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = nin_cifar10_full.json; sourceTree = ""; }; 67B14E5A1C6FED2D00FCB69C /* pool1.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = pool1.json; sourceTree = ""; }; 67B14E5C1C6FED8A00FCB69C /* conv1.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = conv1.json; sourceTree = ""; }; @@ -63,8 +45,9 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 53AC8AC91D17D0F200778BB5 /* Metal.framework in Frameworks */, + 53AC8AC81D17CD0300778BB5 /* DeepLearningKit.framework in Frameworks */, 67B14E431C6FEAAC00FCB69C /* QuartzCore.framework in Frameworks */, - 67B14E411C6FEAA600FCB69C /* Metal.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -74,6 +57,7 @@ 67B14E221C6FE91400FCB69C = { isa = PBXGroup; children = ( + 53AC8AC71D17CD0300778BB5 /* DeepLearningKit.framework */, 67B14E421C6FEAAC00FCB69C /* QuartzCore.framework */, 67B14E401C6FEAA600FCB69C /* Metal.framework */, 67B14E2D1C6FE91400FCB69C /* iOSDeepLearningKitApp */, @@ -101,16 +85,6 @@ 67B14E371C6FE91400FCB69C /* LaunchScreen.storyboard */, 67B14E581C6FED2800FCB69C /* nin_cifar10_full.json */, 67B14E5A1C6FED2D00FCB69C /* pool1.json */, - 67B14E441C6FEC9400FCB69C /* Shaders.metal */, - 67B14E461C6FECA400FCB69C /* MetalDataStructures.swift */, - 67B14E481C6FECAD00FCB69C /* MetalUtilityFunctions.swift */, - 67B14E4A1C6FECD800FCB69C /* DeepNetwork.swift */, - 67B14E4C1C6FECDE00FCB69C /* DeepNetwork+Classify.swift */, - 67B14E4E1C6FECE500FCB69C /* DeepNetwork+JSON.swift */, - 67B14E501C6FECF000FCB69C /* DeepNetwork+SetupNetworkFromDict.swift */, - 67B14E521C6FED0300FCB69C /* ConvolutionLayer.swift */, - 67B14E541C6FED0D00FCB69C /* PoolingLayer.swift */, - 67B14E561C6FED1200FCB69C /* RectifierLayer.swift */, 67B14E3A1C6FE91400FCB69C /* Info.plist */, 6B57D6381C831ED60082387B /* ImageUtilityFunctions.swift */, ); @@ -157,7 +131,7 @@ TargetAttributes = { 67B14E2A1C6FE91400FCB69C = { CreatedOnToolsVersion = 7.2; - DevelopmentTeam = PVJ976FS8J; + DevelopmentTeam = K8ZY6W8PC2; }; }; }; @@ -201,19 +175,9 @@ buildActionMask = 2147483647; files = ( 6B57D6391C831ED60082387B /* ImageUtilityFunctions.swift in Sources */, - 67B14E451C6FEC9400FCB69C /* Shaders.metal in Sources */, - 67B14E471C6FECA400FCB69C /* MetalDataStructures.swift in Sources */, - 67B14E4D1C6FECDE00FCB69C /* DeepNetwork+Classify.swift in Sources */, - 67B14E4B1C6FECD800FCB69C /* DeepNetwork.swift in Sources */, - 67B14E511C6FECF000FCB69C /* DeepNetwork+SetupNetworkFromDict.swift in Sources */, 67B14E311C6FE91400FCB69C /* ViewController.swift in Sources */, 67B14E2F1C6FE91400FCB69C /* AppDelegate.swift in Sources */, - 67B14E4F1C6FECE500FCB69C /* DeepNetwork+JSON.swift in Sources */, - 67B14E531C6FED0300FCB69C /* ConvolutionLayer.swift in Sources */, 6B57D62F1C82E16F0082387B /* UIImageExtension.swift in Sources */, - 67B14E571C6FED1200FCB69C /* RectifierLayer.swift in Sources */, - 67B14E551C6FED0D00FCB69C /* PoolingLayer.swift in Sources */, - 67B14E491C6FECAD00FCB69C /* MetalUtilityFunctions.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -275,7 +239,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.2; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -313,7 +277,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.2; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; @@ -325,10 +289,12 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = iOSDeepLearningKitApp/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = org.deeplearningkit.iOSDeepLearningKitApp; + PRODUCT_BUNDLE_IDENTIFIER = "nz.co.iswe.labs.DeepLearningKit-iOS-Sample"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; }; name = Debug; }; @@ -337,10 +303,12 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = iOSDeepLearningKitApp/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = org.deeplearningkit.iOSDeepLearningKitApp; + PRODUCT_BUNDLE_IDENTIFIER = "nz.co.iswe.labs.DeepLearningKit-iOS-Sample"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; }; name = Release; }; diff --git a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Base.lproj/LaunchScreen.storyboard b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Base.lproj/LaunchScreen.storyboard index 2e721e1..be7c4d2 100644 --- a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Base.lproj/LaunchScreen.storyboard +++ b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Base.lproj/LaunchScreen.storyboard @@ -1,7 +1,8 @@ - + - + + @@ -15,7 +16,6 @@ - diff --git a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ConvolutionLayer.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ConvolutionLayer.swift deleted file mode 100644 index 474f100..0000000 --- a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ConvolutionLayer.swift +++ /dev/null @@ -1,223 +0,0 @@ -// -// ConvolutionLayer.swift -// MemkiteMetal -// -// Created by Amund Tveit on 25/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - - - -func getDataFromBlob(blob: NSDictionary) -> ([Float], [Float]) { - - let shape = blob["shape"] as! NSDictionary - let data = blob["data"] as! [Float] - var FloatData = createFloatNumbersArray(data.count) - for i in 0 ..< data.count { - FloatData[i] = data[i] - } - return (shape["dim"] as! [Float], FloatData) -} - - - -func createConvolutionLayerCached(layer: NSDictionary, - inputBuffer: MTLBuffer, - inputShape: [Float], - metalCommandQueue: MTLCommandQueue, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout layer_data_caches: [Dictionary], - inout blob_cache: [Dictionary], - layer_number: Int, - layer_string: String, caching_mode:Bool) -> (MTLBuffer, MTLCommandBuffer, [Float]) { - - _ = NSDate() - - -// let metalCommandBuffer = metalCommandQueue.commandBuffer() - let metalCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() - - var convolution_params_dict:NSDictionary = NSDictionary() - var pad:Float = 0.0 - var kernel_size:Float = 1.0 - var stride:Float = 1.0 - var blobs:[NSDictionary] = [] - var weights:[Float] = [] - var weight_shape:[Float] = [] - var bias_data:[Float] = [] - var h:Float = 0.0 - var w:Float = 0.0 - var result_shape:[Float] = [] - var outputCount:Int = 0 - - var input_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var weight_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var result_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var tensor_dimensions:[MetalTensorDimensions] = [] - var col_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var col_output:[Float] = [] - var convolution_params:MetalConvolutionParameters = MetalConvolutionParameters(pad:0, kernel_size: 0, stride: 0) - - - if(!caching_mode) { - print("NOTCACHINGMODE") - convolution_params_dict = layer["convolution_param"] as! NSDictionary - pad = 0.0 - kernel_size = 1.0 - stride = 1.0 - if let val = convolution_params_dict["pad"] as? Float { - pad = val - } - if let val = convolution_params_dict["kernel_size"] as? Float { - kernel_size = val - } - - _ = NSDate() - - - if let tmpval = blob_cache[layer_number]["0"] { - (weight_shape, weights) = tmpval - } else { - blobs = layer["blobs"] as! [NSDictionary] - (weight_shape, weights) = getDataFromBlob(blobs[0]) - blob_cache[layer_number]["0"] = (weight_shape, weights) - } - - blobs = layer["blobs"] as! [NSDictionary] - (_, bias_data) = getDataFromBlob(blobs[1]) - - - - h = (inputShape[2] + 2 * pad - kernel_size) / stride + 1 - w = (inputShape[3] + 2 * pad - kernel_size) / stride + 1 - result_shape = [inputShape[0], weight_shape[0], h, w] - outputCount = Int(result_shape.reduce(1, combine: *)) - - // Create input and output vectors, and corresponding metal buffer - input_dimensions = MetalTensorDimensions(n: inputShape[0], channels: inputShape[1], width: inputShape[2], height: inputShape[3]) - weight_dimensions = MetalTensorDimensions(n: weight_shape[0], channels: weight_shape[1], width: weight_shape[2], height: weight_shape[3]) - col_dimensions = MetalTensorDimensions(n: inputShape[0], channels: inputShape[1] * weight_shape[2] * weight_shape[3], width: inputShape[2], height: inputShape[3]) - result_dimensions = MetalTensorDimensions(n: result_shape[0], channels: result_shape[1], width: result_shape[2], height: result_shape[3]) - tensor_dimensions = [input_dimensions, weight_dimensions, col_dimensions, result_dimensions] - - - col_output = createFloatNumbersArray(Int(col_dimensions.n * col_dimensions.channels * col_dimensions.height * col_dimensions.width)) - - - convolution_params = MetalConvolutionParameters(pad: pad, kernel_size: kernel_size, stride: stride) - - } - - - let resultBuffer = addConvolutionCommandToCommandBufferCached(metalCommandBuffer, inputBuffer: inputBuffer, im2ColCount: col_output.count, weights: weights, outputCount: outputCount, convolution_params: convolution_params, tensor_dimensions: tensor_dimensions, bias: bias_data, metalDefaultLibrary: metalDefaultLibrary, metalDevice:metalDevice, layer_data_caches: &layer_data_caches, layer_number: layer_number,layer_string: layer_string, caching_mode: caching_mode) - //metalCommandBuffer.commit() - - - - return (resultBuffer, metalCommandBuffer, result_shape) - -} - -func addConvolutionCommandToCommandBufferCached(commandBuffer: MTLCommandBuffer, - inputBuffer: MTLBuffer, - im2ColCount: Int, - weights: [Float], - outputCount: Int, - convolution_params: MetalConvolutionParameters, - tensor_dimensions: [MetalTensorDimensions], - bias: [Float], - metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout layer_data_caches: [Dictionary], - layer_number: Int, - layer_string: String, caching_mode:Bool) -> MTLBuffer { - - _ = NSDate() - - print("before output and col_output") - - var output:[Float] = [] - var col_output:[Float] = [] - - if(!caching_mode) { - output = createFloatNumbersArray(outputCount) - col_output = createFloatNumbersArray(im2ColCount) - } - - print("before setupshaderinpipeline") - - let (_, im2colComputePipelineState, _) = setupShaderInMetalPipeline("im2col", metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice) - - let resultMetalBuffer = createOrReuseFloatMetalBuffer("resultMetalBuffer", data: output, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - - print("after resultmetalbuffer") - - let weightMetalBuffer = createOrReuseFloatMetalBuffer("weightMetalBuffer", data: weights, cache: &layer_data_caches, layer_number:layer_number, metalDevice: metalDevice) - - - let convolutionParamsMetalBuffer = createOrReuseConvolutionParametersMetalBuffer("convolutionParamsMetalBuffer", data: convolution_params, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - let tensorDimensionsMetalBuffer = createOrReuseTensorDimensionsVectorMetalBuffer("tensorDimensionsMetalBuffer", data: tensor_dimensions, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - - let colOutputMetalBuffer = createOrReuseFloatMetalBuffer("colOutputMetalBuffer", data: col_output, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - let biasMetalBuffer = createOrReuseFloatMetalBuffer("bias", data: bias, cache: &layer_data_caches, layer_number:layer_number, metalDevice: metalDevice) - - - // Create Metal compute command encoder for im2col - var metalComputeCommandEncoder = commandBuffer.computeCommandEncoder() - metalComputeCommandEncoder.setBuffer(inputBuffer, offset: 0, atIndex: 0) - metalComputeCommandEncoder.setBuffer(tensorDimensionsMetalBuffer, offset: 0, atIndex: 1) - metalComputeCommandEncoder.setBuffer(convolutionParamsMetalBuffer, offset: 0, atIndex: 2) - metalComputeCommandEncoder.setBuffer(colOutputMetalBuffer, offset: 0, atIndex: 3) - //metalComputeCommandEncoder.setComputePipelineState(im2colComputePipelineState) - - - // Set the shader function that Metal will use - metalComputeCommandEncoder.setComputePipelineState(im2colComputePipelineState) - - // Set up thread groups on GPU - // TODO: check out http://metalbyexample.com/introduction-to-compute/ - var threadsPerGroup = MTLSize(width:im2colComputePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - print("before mtlsize 2") - var numThreadgroups = MTLSize(width:(col_output.count-1)/im2colComputePipelineState.threadExecutionWidth + 1, height:1, depth:1) - metalComputeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - print("after dispatch") - - // Finalize configuration - metalComputeCommandEncoder.endEncoding() - - - - - let (_, convolutionComputePipelineState, _) = setupShaderInMetalPipeline("convolution_layer", metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice) - metalComputeCommandEncoder = commandBuffer.computeCommandEncoder() - - // Create Metal Compute Command Encoder and add input and output buffers to it - metalComputeCommandEncoder.setBuffer(resultMetalBuffer, offset: 0, atIndex: 0) - metalComputeCommandEncoder.setBuffer(weightMetalBuffer, offset: 0, atIndex: 1) - metalComputeCommandEncoder.setBuffer(tensorDimensionsMetalBuffer, offset: 0, atIndex: 2) - metalComputeCommandEncoder.setBuffer(colOutputMetalBuffer, offset: 0, atIndex: 3) - metalComputeCommandEncoder.setBuffer(biasMetalBuffer, offset: 0, atIndex: 4) - - // Set the shader function that Metal will use - metalComputeCommandEncoder.setComputePipelineState(convolutionComputePipelineState) - - // Set up thread groups on GPU - // TODO: check out http://metalbyexample.com/introduction-to-compute/ - threadsPerGroup = MTLSize(width:convolutionComputePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - numThreadgroups = MTLSize(width:(outputCount-1)/convolutionComputePipelineState.threadExecutionWidth + 1, height:1, depth:1) - metalComputeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - // Finalize configuration - metalComputeCommandEncoder.endEncoding() - - - - - return resultMetalBuffer - -} - diff --git a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+Classify.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+Classify.swift deleted file mode 100644 index bb61c28..0000000 --- a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+Classify.swift +++ /dev/null @@ -1,62 +0,0 @@ -// -// DeepNetwork+Classify.swift -// MemkiteMetal -// -// Created by Amund Tveit on 25/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - -public extension DeepNetwork { - // e.g. 32x32x3 for CIFAR-10/100 - // as [1.0, 3.0, 32.0, 32.0] - public func classify(flattenedTensorWithImage: [Float]) -> Float { - let start = NSDate() - - // from 2.2 in http://memkite.com/blog/2014/12/30/example-of-sharing-memory-between-gpu-and-cpu-with-swift-and-metal-for-ios8/ - /*let xvectorVoidPtr = COpaquePointer(imageBuffer.contents()) - let xvectorFloatPtr = UnsafeMutablePointer(xvectorVoidPtr) - let xvectorFloatBufferPtr = UnsafeMutableBufferPointer(start:xvectorFloatPtr, count: flattenedTensorWithImage.count) - for index in xvectorFloatBufferPtr.startIndex.. NSDictionary? { - print(" ==> loadJSONFile(filename=\(filename)") - - do { - let bundle = NSBundle.mainBundle() - let path = bundle.pathForResource(filename, ofType: "json")! - let jsonData = NSData(contentsOfFile: path) - print(" <== loadJSONFile") - return try NSJSONSerialization.JSONObjectWithData(jsonData!, options: .AllowFragments) as? NSDictionary - } catch _ { - return nil - } -} -} \ No newline at end of file diff --git a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift deleted file mode 100644 index eefe185..0000000 --- a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift +++ /dev/null @@ -1,84 +0,0 @@ -// -// DeepNetwork+SetupNetworkFromDict.swift -// MemkiteMetal -// -// Created by Amund Tveit on 10/12/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - -public extension DeepNetwork { - - func setupNetworkFromDict(deepNetworkAsDict: NSDictionary, inputimage: MTLBuffer, inputshape: [Float], caching_mode:Bool) { - - let start = NSDate() - - print(" ==> setupNetworkFromDict()") - // Add input image - var layer_number = 0 - layer_data_caches.append(Dictionary()) // for input - pool_type_caches.append(Dictionary()) - blob_cache.append(Dictionary()) - namedDataLayers.append(("input", inputimage)) - layer_number += 1 - - - // Add remaining network - var previousBuffer:MTLBuffer = inputimage - var previousShape:[Float] = inputshape - - self.deepNetworkAsDict = deepNetworkAsDict - - // create new command buffer for next layer - var currentCommandBuffer: MTLCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() - - var t = NSDate() - for layer in deepNetworkAsDict["layer"] as! [NSDictionary] { - if let type = layer["type"] as? String { - let layer_string = layer["name"] as! String - - layer_data_caches.append(Dictionary()) - pool_type_caches.append(Dictionary()) - blob_cache.append(Dictionary()) - - - if type == "ReLU" { - self.gpuCommandLayers.append(currentCommandBuffer) - //(previousBuffer, currentCommandBuffer) = createRectifierLayer(previousBuffer) - (previousBuffer, currentCommandBuffer) = createRectifierLayer(previousBuffer, metalCommandQueue:metalCommandQueue, metalDefaultLibrary:metalDefaultLibrary, metalDevice:metalDevice) - self.namedDataLayers.append((layer["name"]! as! String, previousBuffer)) - } else if type == "Pooling" { - self.gpuCommandLayers.append(currentCommandBuffer) - // (previousBuffer, currentCommandBuffer, previousShape) = createPoolingLayer(layer, inputBuffer: previousBuffer, inputShape: previousShape) - (previousBuffer, currentCommandBuffer, previousShape) = createPoolingLayerCached(layer, inputBuffer: previousBuffer, inputShape: previousShape, metalCommandQueue: metalCommandQueue, metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice, pool_type_caches: &pool_type_caches, layer_data_caches: &layer_data_caches, layer_number: layer_number, layer_string: layer_string, caching_mode: caching_mode) - self.namedDataLayers.append((layer["name"]! as! String, previousBuffer)) - } else if type == "Convolution" { - self.gpuCommandLayers.append(currentCommandBuffer) - // (previousBuffer, currentCommandBuffer, previousShape) = createConvolutionLayer(layer, inputBuffer: previousBuffer, inputShape: previousShape) - (previousBuffer, currentCommandBuffer, previousShape) = createConvolutionLayerCached(layer, inputBuffer: previousBuffer, inputShape: previousShape, metalCommandQueue: metalCommandQueue, metalDefaultLibrary:metalDefaultLibrary, metalDevice:metalDevice, layer_data_caches: &layer_data_caches, blob_cache: &blob_cache, layer_number: layer_number, layer_string: layer_string, caching_mode: caching_mode) - - - self.namedDataLayers.append((layer["name"]! as! String, previousBuffer)) - } - let name = layer["name"] as! String - print("\(name): \(NSDate().timeIntervalSinceDate(t))") - t = NSDate() - layer_number += 1 - - } - } - - self.gpuCommandLayers.append(currentCommandBuffer) - - print("bar") - - print("AFTER LAYER DATA CHACES = \(layer_data_caches[0])") - - print("POOL TYPE CACHES = \(pool_type_caches)") - - print("Time to set up network: \(NSDate().timeIntervalSinceDate(start))") - - } -} diff --git a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork.swift deleted file mode 100644 index f4ddec4..0000000 --- a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/DeepNetwork.swift +++ /dev/null @@ -1,63 +0,0 @@ -// -// DeepNetwork.swift -// MemkiteMetal -// -// Created by Amund Tveit on 24/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - -public class DeepNetwork { - var gpuCommandLayers: [MTLCommandBuffer] = [] - var namedDataLayers: [(String, MTLBuffer)] = [] - var imageBuffer: MTLBuffer! - var metalDevice: MTLDevice! - var metalDefaultLibrary: MTLLibrary! - var metalCommandQueue: MTLCommandQueue! - var deepNetworkAsDict: NSDictionary! // for debugging perhaps - var layer_data_caches: [Dictionary] = [] - var pool_type_caches: [Dictionary] = [] - var dummy_image: [Float]! - var previous_shape: [Float]! - var blob_cache: [Dictionary] = [] - - public init() { - setupMetal() - deepNetworkAsDict = nil - } - - public func loadDeepNetworkFromJSON(networkName: String, inputImage: [Float], inputShape:[Float], caching_mode:Bool) { - print(" ==> loadDeepNetworkFromJSON(networkName=\(networkName)") - if deepNetworkAsDict == nil { - print("loading json file!") - deepNetworkAsDict = loadJSONFile(networkName)! - } - - - // IMAGE INPUT HANDLING START - TODO: hardcode input dimensions, - // and have random data, and then later overwrite the first buffer - //let imageLayer = loadJSONFile("conv1")! - //let imageData: [Float] = imageLayer["input"] as! [Float] - print(inputImage.count) - let imageTensor = createMetalBuffer(inputImage, metalDevice: metalDevice) - - // preLoadMetalShaders(metalDevice, metalDefaultLibrary:metalDefaultLibrary) - - setupNetworkFromDict(deepNetworkAsDict, inputimage: imageTensor, inputshape: inputShape, caching_mode:caching_mode ) - } - - - func setupMetal() { - // Get access to iPhone or iPad GPU - metalDevice = MTLCreateSystemDefaultDevice() - - // Queue to handle an ordered list of command buffers - metalCommandQueue = metalDevice.newCommandQueue() - print("metalCommandQueue = \(unsafeAddressOf(metalCommandQueue))") - - // Access to Metal functions that are stored in Shaders.metal file, e.g. sigmoid() - metalDefaultLibrary = metalDevice.newDefaultLibrary() - } -} diff --git a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/MetalDataStructures.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/MetalDataStructures.swift deleted file mode 100644 index ed34e8c..0000000 --- a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/MetalDataStructures.swift +++ /dev/null @@ -1,65 +0,0 @@ -// -// MetalDataStructures.swift -// MemkiteMetal -// -// Created by Amund Tveit on 24/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Foundation -import Metal -import UIKit -import QuartzCore - -////////////////////////////////////////// -// Metal Data Types - their SWIFT Counterparts -////////////////////////////////////////// -public struct MetalComplexNumberType { - var real: Float = 0.0 - var imag: Float = 0.0 -} - -public struct MetalShaderParameters { - let image_xdim: Float - let image_ydim: Float - let num_images: Float - let filter_xdim: Float - let filter_ydim: Float - let num_filters: Float - let conv_xdim: Float // image_xdim - filter_xdim + 1 without striding - let conv_ydim: Float // image_ydim - filter_ydim + 1 without striding - let pool_xdim: Float - let pool_ydim: Float - var b: Float -} - -public struct MetalMatrixVectorParameters { - let x_xdim: Float - let x_ydim: Float - let w_xdim: Float - let w_ydim: Float - let b_xdim: Float - let b_ydim: Float - let result_xdim: Float - let result_ydim: Float -} - -public struct MetalPoolingParameters { - let kernel_size: Float - let pool_stride: Float - let pad: Float -} - -public struct MetalTensorDimensions { - let n: Float - let channels: Float - let width: Float - let height: Float -} - -public struct MetalConvolutionParameters { - let pad: Float - let kernel_size: Float - let stride: Float -} diff --git a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/MetalUtilityFunctions.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/MetalUtilityFunctions.swift deleted file mode 100644 index 7779851..0000000 --- a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/MetalUtilityFunctions.swift +++ /dev/null @@ -1,182 +0,0 @@ -// -// MetalUtilFunctions.swift -// MemkiteMetal -// -// Created by Amund Tveit on 24/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - -func createComplexNumbersArray(count: Int) -> [MetalComplexNumberType] { - let zeroComplexNumber = MetalComplexNumberType() - return [MetalComplexNumberType](count: count, repeatedValue: zeroComplexNumber) -} - -func createFloatNumbersArray(count: Int) -> [Float] { - return [Float](count: count, repeatedValue: 0.0) -} - -func createFloatMetalBuffer(vector: [Float], let metalDevice:MTLDevice) -> MTLBuffer { - var vector = vector - let byteLength = vector.count*sizeof(Float) // future: MTLResourceStorageModePrivate - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -// TODO: could perhaps use generics to combine both functions below? -func createComplexMetalBuffer(vector:[MetalComplexNumberType], let metalDevice:MTLDevice) -> MTLBuffer { - var vector = vector - let byteLength = vector.count*sizeof(MetalComplexNumberType) // or size of and actual 1st element object? - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createShaderParametersMetalBuffer(shaderParameters:MetalShaderParameters, metalDevice:MTLDevice) -> MTLBuffer { - var shaderParameters = shaderParameters - let byteLength = sizeof(MetalShaderParameters) - return metalDevice.newBufferWithBytes(&shaderParameters, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createMatrixShaderParametersMetalBuffer(params: MetalMatrixVectorParameters, metalDevice: MTLDevice) -> MTLBuffer { - var params = params - let byteLength = sizeof(MetalMatrixVectorParameters) - return metalDevice.newBufferWithBytes(¶ms, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) - -} - -func createPoolingParametersMetalBuffer(params: MetalPoolingParameters, metalDevice: MTLDevice) -> MTLBuffer { - var params = params - let byteLength = sizeof(MetalPoolingParameters) - return metalDevice.newBufferWithBytes(¶ms, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createConvolutionParametersMetalBuffer(params: MetalConvolutionParameters, metalDevice: MTLDevice) -> MTLBuffer { - var params = params - let byteLength = sizeof(MetalConvolutionParameters) - return metalDevice.newBufferWithBytes(¶ms, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createTensorDimensionsVectorMetalBuffer(vector: [MetalTensorDimensions], metalDevice: MTLDevice) -> MTLBuffer { - var vector = vector - let byteLength = vector.count * sizeof(MetalTensorDimensions) - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func setupShaderInMetalPipeline(shaderName:String, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice) -> (shader:MTLFunction!, - computePipelineState:MTLComputePipelineState!, - computePipelineErrors:NSErrorPointer!) { - let shader = metalDefaultLibrary.newFunctionWithName(shaderName) - let computePipeLineDescriptor = MTLComputePipelineDescriptor() - computePipeLineDescriptor.computeFunction = shader - // var computePipelineErrors = NSErrorPointer() - // let computePipelineState:MTLComputePipelineState = metalDevice.newComputePipelineStateWithFunction(shader!, completionHandler: {(}) - let computePipelineErrors:NSErrorPointer = nil - var computePipelineState:MTLComputePipelineState? = nil - do { - computePipelineState = try metalDevice.newComputePipelineStateWithFunction(shader!) - } catch { - print("catching..") - } - return (shader, computePipelineState, computePipelineErrors) - -} - -func createMetalBuffer(vector:[Float], metalDevice:MTLDevice) -> MTLBuffer { - var vector = vector - let byteLength = vector.count*sizeof(Float) - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func preLoadMetalShaders(metalDevice: MTLDevice, metalDefaultLibrary: MTLLibrary) { - let shaders = ["avg_pool", "max_pool", "rectifier_linear", "convolution_layer", "im2col"] - for shader in shaders { - setupShaderInMetalPipeline(shader, metalDefaultLibrary: metalDefaultLibrary,metalDevice: metalDevice) // TODO: this returns stuff - } -} - -func createOrReuseFloatMetalBuffer(name:String, data: [Float], inout cache:[Dictionary], layer_number:Int, metalDevice:MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { - print("found key = \(name) in cache") - result = tmpval - } else { - print("didnt find key = \(name) in cache") - result = createFloatMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - // print("DEBUG: cache = \(cache)") - } - - return result -} - - -func createOrReuseConvolutionParametersMetalBuffer(name:String, - data: MetalConvolutionParameters, - inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { - print("found key = \(name) in cache") - result = tmpval - } else { - print("didnt find key = \(name) in cache") - result = createConvolutionParametersMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - -func createOrReuseTensorDimensionsVectorMetalBuffer(name:String, - data:[MetalTensorDimensions],inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { - print("found key = \(name) in cache") - result = tmpval - } else { - print("didnt find key = \(name) in cache") - result = createTensorDimensionsVectorMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - -// -//let sizeParamMetalBuffer = createShaderParametersMetalBuffer(size_params, metalDevice: metalDevice) -//let poolingParamMetalBuffer = createPoolingParametersMetalBuffer(pooling_params, metalDevice: metalDevice) - -func createOrReuseShaderParametersMetalBuffer(name:String, - data:MetalShaderParameters,inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { -// print("found key = \(name) in cache") - result = tmpval - } else { -// print("didnt find key = \(name) in cache") - result = createShaderParametersMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - -func createOrReusePoolingParametersMetalBuffer(name:String, - data:MetalPoolingParameters,inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { -// print("found key = \(name) in cache") - result = tmpval - } else { -// print("didnt find key = \(name) in cache") - result = createPoolingParametersMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - - diff --git a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/PoolingLayer.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/PoolingLayer.swift deleted file mode 100644 index d6d4310..0000000 --- a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/PoolingLayer.swift +++ /dev/null @@ -1,151 +0,0 @@ -// -// PoolingLayer.swift -// MemkiteMetal -// -// Created by Amund Tveit on 25/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - - -func createPoolingLayerCached(layer: NSDictionary, - inputBuffer: MTLBuffer, - inputShape: [Float], - metalCommandQueue: MTLCommandQueue, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout pool_type_caches: [Dictionary], - inout layer_data_caches: [Dictionary], - layer_number: Int, - layer_string: String, - caching_mode:Bool) -> (MTLBuffer, MTLCommandBuffer, [Float]) { - - print(" ==> createPoolingLayerCached") - let metalCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() -// let metalCommandBuffer = metalCommandQueue.commandBuffer() - - var params = NSDictionary() - var stride:Float = 1.0 - var kernel_size: Float = 1.0 - var pad: Float = 0.0 - var pooling_params = MetalPoolingParameters(kernel_size: kernel_size, pool_stride: stride, pad: pad) - var pool_type = 0 - var h:Float = 0.0 - var w:Float = 0.0 - var shape:[Float] = [] - var outputCount:Float = 0 - var pool_width = 0 - var pool_height = 0 - var size_params:MetalShaderParameters = MetalShaderParameters(image_xdim:0.0, image_ydim:0.0, num_images: 0.0, filter_xdim: 0.0, filter_ydim: 0.0, num_filters: 0.0, conv_xdim: 0.0, conv_ydim: 0.0, pool_xdim: 0.0, pool_ydim: 0.0, b:0.0) - var outputBuffer:MTLBuffer - - if(!caching_mode) { - - params = layer["pooling_param"] as! NSDictionary - stride = 1.0 - kernel_size = 1.0 - pad = 0.0 - if let val = params["stride"] { - stride = val as! Float - } - if let val = params["kernel_size"] { - kernel_size = val as! Float - if val as! NSNumber != 3 { - pad = 0 - } - } - pooling_params = MetalPoolingParameters(kernel_size: kernel_size, pool_stride: stride, pad: pad) - pool_type = params["pool"] as! Int - - // STORE pool type in cache! - pool_type_caches[layer_number]["pool_type"] = String(pool_type) - - //TODO: calculate outputCount - h = ceil((inputShape[2] + 2.0 * pad - kernel_size) / stride) + 1.0 - w = ceil((Float(inputShape[3]) + 2.0 * pad - kernel_size) / stride) + 1.0 - shape = [inputShape[0], inputShape[1], h, w] - outputCount = shape.reduce(1, combine: *) - pool_width = Int(shape[2]) - pool_height = Int(shape[3]) - size_params = MetalShaderParameters(image_xdim: Float(inputShape[2]), image_ydim: Float(inputShape[3]), - num_images: Float(inputShape[0]), - filter_xdim: 1.0, filter_ydim: 1.0, num_filters: Float(inputShape[1]), - conv_xdim:0.0, conv_ydim: 0.0, - pool_xdim: Float(pool_width), pool_ydim: Float(pool_height), b:0.0) - } else { - // need to fetch pool type from cache - print("FETCHING POOL TYPE FROM CACHE!!!!!") - pool_type = Int(pool_type_caches[layer_number]["pool_type"]!)! - } - - if pool_type == 1 { - outputBuffer = addPoolingCommandToCommandBufferCached(metalCommandBuffer, poolingMethod: "avg_pool", inputBuffer: inputBuffer, outputCount: Int(outputCount), size_params: size_params, pooling_params: pooling_params, metalDefaultLibrary: metalDefaultLibrary, metalDevice:metalDevice, - layer_data_caches: &layer_data_caches, layer_number: layer_number, layer_string: layer_string) - } else { - outputBuffer = addPoolingCommandToCommandBufferCached(metalCommandBuffer, poolingMethod: "max_pool", inputBuffer: inputBuffer, outputCount: Int(outputCount), size_params: size_params, pooling_params: pooling_params,metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice, - layer_data_caches: &layer_data_caches, layer_number: layer_number, layer_string: layer_string) - - } - //metalCommandBuffer.commit() - - print(" <== createPoolingLayerCached") - - - return (outputBuffer, metalCommandBuffer, shape) -} - - -func addPoolingCommandToCommandBufferCached(commandBuffer: MTLCommandBuffer, - poolingMethod: String, - inputBuffer: MTLBuffer, - outputCount: Int, - size_params: MetalShaderParameters, - pooling_params: MetalPoolingParameters, - metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout layer_data_caches: [Dictionary], - layer_number: Int, - layer_string: String) -> MTLBuffer { - - - print(" ==> addPoolingCommandtoCommandBufferCached") - - _ = layer_data_caches[layer_number] - - let output = createFloatNumbersArray(outputCount) - let (_, computePipelineState, _) = setupShaderInMetalPipeline(poolingMethod, metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice) - - let outputMetalBuffer = createOrReuseFloatMetalBuffer("outputMetalBuffer", data: output, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - // let outputMetalBuffer = createFloatMetalBuffer(output, metalDevice: metalDevice) - - let sizeParamMetalBuffer = createOrReuseShaderParametersMetalBuffer("sizeParamMetalBuffer", data: size_params, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - - // let sizeParamMetalBuffer = createShaderParametersMetalBuffer(size_params, metalDevice: metalDevice) - - - // let poolingParamMetalBuffer = createPoolingParametersMetalBuffer(pooling_params, metalDevice: metalDevice) - let poolingParamMetalBuffer = createOrReusePoolingParametersMetalBuffer("poolingParamMetalBuffer", data: pooling_params, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - // Create Metal Compute Command Encoder and add input and output buffers to it - let metalComputeCommandEncoder = commandBuffer.computeCommandEncoder() - metalComputeCommandEncoder.setBuffer(outputMetalBuffer, offset: 0, atIndex: 0) - metalComputeCommandEncoder.setBuffer(inputBuffer, offset: 0, atIndex: 1) - metalComputeCommandEncoder.setBuffer(sizeParamMetalBuffer, offset: 0, atIndex: 2) - metalComputeCommandEncoder.setBuffer(poolingParamMetalBuffer, offset: 0, atIndex: 3) - - // Set the shader function that Metal will use - metalComputeCommandEncoder.setComputePipelineState(computePipelineState) - - // Set up thread groups on GPU - // TODO: check out http://metalbyexample.com/introduction-to-compute/ - let threadsPerGroup = MTLSize(width:computePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - let numThreadgroups = MTLSize(width:(outputCount-1)/computePipelineState.threadExecutionWidth + 1, height:1, depth:1) - metalComputeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - // Finalize configuration - metalComputeCommandEncoder.endEncoding() - - print(" <== addPoolingCommandtoCommandBufferCached") - - - return outputMetalBuffer -} diff --git a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/RectifierLayer.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/RectifierLayer.swift deleted file mode 100644 index efc27ad..0000000 --- a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/RectifierLayer.swift +++ /dev/null @@ -1,54 +0,0 @@ -// -// RectifierLayer.swift -// MemkiteMetal -// -// Created by Amund Tveit on 25/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - -func createRectifierLayer(inputBuffer: MTLBuffer, metalCommandQueue: MTLCommandQueue, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice) -> (MTLBuffer,MTLCommandBuffer) { - print(" ==> createrectifierlayer") -// let metalCommandBuffer = metalCommandQueue.commandBuffer() - let metalCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() - - let result = addRectifierCommandToCommandBuffer(metalCommandBuffer, inputBuffer: inputBuffer, - metalDefaultLibrary: metalDefaultLibrary, metalDevice:metalDevice) - //metalCommandBuffer.commit() - - print(" <== createrectifierlayer") - return (result, metalCommandBuffer) -} - - -func addRectifierCommandToCommandBuffer(commandBuffer: MTLCommandBuffer, inputBuffer: MTLBuffer, - metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice) -> MTLBuffer { - - print("==> addRectifierToCommandBuffer") - - let count = inputBuffer.length / sizeof(Float) - let (_, computePipelineState, _) = setupShaderInMetalPipeline("rectifier_linear", metalDefaultLibrary: metalDefaultLibrary, - metalDevice: metalDevice) - - // Create Metal Compute Command Encoder and add input and output buffers to it - let computeCommandEncoder = commandBuffer.computeCommandEncoder() - computeCommandEncoder.setBuffer(inputBuffer, offset: 0, atIndex: 0) - // Set the shader function that Metal will use - computeCommandEncoder.setComputePipelineState(computePipelineState) - - // Set up thread groups on GPU - // TODO: check out http://metalbyexample.com/introduction-to-compute/ - let threadsPerGroup = MTLSize(width:computePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - let numThreadgroups = MTLSize(width:(count-1)/computePipelineState.threadExecutionWidth + 1, height:1, depth:1) - computeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - // Finalize configuration - computeCommandEncoder.endEncoding() - - print(" <== addRectifierToCommandBuffer") - - return inputBuffer -} diff --git a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Shaders.metal b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Shaders.metal deleted file mode 100644 index 37217fb..0000000 --- a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/Shaders.metal +++ /dev/null @@ -1,224 +0,0 @@ -// -// Shaders.metal -// memkite -// -// Created by Amund Tveit on 13/08/15. -// Copyright © 2015 Amund Tveit. All rights reserved. -// - -#include -#include -#include -#include -#include -#include -#include -#include // why? -using namespace metal; - -//////////////////////////////// -// DATA TYPES -//////////////////////////////// - -// TODO: perhaps add RGB support as part of this -struct MetalComplexNumberType { // needs to map to float2 in Metal - float real; - float imag; -}; - -// TODO: perhaps add B here? since it is only one value per convolution call (not entire vector) -struct MetalShaderParameters { - float image_xdim; - float image_ydim; - float num_images; - float filter_xdim; // e.g. 5 - float filter_ydim; // e.g. 5 - float num_filters; // e.g. 20 -> W = 20*1*5*5 - float conv_xdim; // image_xdim - filter_xdim + 1 without striding - float conv_ydim; // image_ydim - filter_ydim + 1 without striding - float pool_xdim; - float pool_ydim; - float b; // this should probably be an input array, but for now -}; - -struct MetalMatrixVectorParameters { - float x_xdim; - float x_ydim; - float w_xdim; - float w_ydim; - float b_xdim; - float b_ydim; - float result_xdim; - float result_ydim; -}; - -struct MetalPoolingParameters { - float kernel_size; - float pool_stride; - float pad; -}; - -struct MetalTensorDimensions { - float n; - float channels; - float width; - float height; -}; - -struct MetalConvolutionParameters { - float pad; - float kernel_size; - float stride; -}; - -//////////////////////////////// -// SHADER FUNCTIONS -//////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////// - - -// Returns max(0, X[id]) -kernel void rectifier_linear(device float* X [[ buffer(0)]], - uint id [[ thread_position_in_grid ]]) { - X[id] = fmax(0.0, X[id]); -} - -kernel void max_pool(device float* result [[ buffer(0) ]], - const device float* input [[ buffer(1) ]], - const device MetalShaderParameters* size_params [[ buffer(2) ]], - const device MetalPoolingParameters* pooling_params [[ buffer(3) ]], - uint id [[ thread_position_in_grid ]]) { - int channels = int(size_params[0].num_filters); - int in_width = int(size_params[0].image_xdim); - int in_height = int(size_params[0].image_ydim); - - float kernel_size = float(pooling_params[0].kernel_size); - int pool_stride = int(pooling_params[0].pool_stride); - int pad = int(pooling_params[0].pad); - - int out_width = int(size_params[0].pool_xdim); - int out_height = int(size_params[0].pool_ydim); - - int i = (id / out_height) % out_width; - int j = id % out_height; - int n = id / (channels * out_width * out_height); - int c = (id / (out_width * out_height)) % channels; - int wstart = i * pool_stride - pad; - int hstart = j * pool_stride - pad; - int wend = fmin(wstart + kernel_size, in_width + pad); - int hend = fmin(hstart + kernel_size, in_height + pad); - wstart = fmax(0.0, wstart); - hstart = fmax(0.0, hstart); - thread float pool = -100000.0; - for (int ii = wstart; ii < wend; ++ii) { - for (int jj = hstart; jj < hend; ++jj) { - pool = fmax(pool, input[(n * channels * in_height + c * in_height + ii) * in_width + jj]); - } - } - result[id] = pool; -} - -kernel void avg_pool(device float* result [[ buffer(0) ]], - const device float* input [[ buffer(1) ]], - const device MetalShaderParameters* size_params [[ buffer(2) ]], - const device MetalPoolingParameters* pooling_params [[ buffer(3) ]], - uint id [[ thread_position_in_grid ]]) { - int channels = int(size_params[0].num_filters); - int in_width = int(size_params[0].image_xdim); - int in_height = int(size_params[0].image_ydim); - - float kernel_size = float(pooling_params[0].kernel_size); - int pool_stride = int(pooling_params[0].pool_stride); - int pad = int(pooling_params[0].pad); - - int out_width = int(size_params[0].pool_xdim); - int out_height = int(size_params[0].pool_ydim); - - int i = (id / out_height) % out_width; - int j = id % out_height; - int n = id / (channels * out_width * out_height); - int c = (id / (out_width * out_height)) % channels; - int wstart = i * pool_stride - pad; - int hstart = j * pool_stride - pad; - int wend = fmin(wstart + kernel_size, in_width + pad); - int hend = fmin(hstart + kernel_size, in_height + pad); - float pool_size = (hend - hstart) * (wend - wstart); - wstart = fmax(0.0, wstart); - hstart = fmax(0.0, hstart); - thread float pool = 0.0; - for (int ii = wstart; ii < wend; ++ii) { - for (int jj = hstart; jj < hend; ++jj) { - pool += input[(n * channels * in_height + c * in_height + ii) * in_width + jj]/pool_size; - } - } - result[id] = pool; -} - -kernel void im2col(const device float* convolution_input [[ buffer(0)]], - const device MetalTensorDimensions* tensor_dimensions [[ buffer(1) ]], - const device MetalConvolutionParameters* convolution_params [[ buffer(2) ]], - device float* col_output [[ buffer(3) ]], - uint id [[ thread_position_in_grid ]]) { - //int num = int(tensor_dimensions[0].n); - int channels_in = int(tensor_dimensions[0].channels); - int in_width = int(tensor_dimensions[0].width); - int in_height = int(tensor_dimensions[0].height); - - int channels_col = int(tensor_dimensions[2].channels); - int width_col = int(tensor_dimensions[2].width); - int height_col = int(tensor_dimensions[2].height); - - - // 1. do an im2col transformation - int pad = int(convolution_params[0].pad); - int kernel_size = int(convolution_params[0].kernel_size); - - int n = id / (channels_col * height_col * width_col); - int c = (id / (width_col * height_col)) % channels_col; - int h = (id / width_col) % height_col; - int w = id % width_col; - int w_offset = c % kernel_size; - int h_offset = (c / kernel_size) % kernel_size; - int h_pad = h - pad + h_offset; - int w_pad = w - pad + w_offset; - int c_im = c / (kernel_size * kernel_size); - if (h_pad >= 0 && h_pad < in_height && w_pad >= 0 && w_pad < in_width) { - col_output[id] = convolution_input[(n * channels_in * in_height + c_im * in_height + h_pad) * in_width + w_pad]; - } -} - -// Tensor dimensions = { input_dimensions, weight_dimensions, col_dimensions, result_dimensions } -kernel void convolution_layer(device float* result [[ buffer(0) ]], - const device float* weights [[ buffer(1)]], - const device MetalTensorDimensions* tensor_dimensions [[ buffer(2) ]], - const device float* col_output [[ buffer(3) ]], - const device float* bias [[ buffer(4) ]], - uint id [[ thread_position_in_grid ]]) { - //int num = int(tensor_dimensions[2].n); - int channels_col = int(tensor_dimensions[2].channels); - int width_col = int(tensor_dimensions[2].width); - int height_col = int(tensor_dimensions[2].height); - - int channels_out = int(tensor_dimensions[3].channels); - int width_out = int(tensor_dimensions[3].width); - int height_out = int(tensor_dimensions[3].height); - - int n = id / (channels_out * height_out * width_out); - int a = (id / (height_out * width_out)) % channels_out; - int b = id % (height_out * width_out); - - thread float foo = bias[a]; - - for (int c = 0; c < channels_col; ++c) { -// result[id] += weights[a * channels_col + c] * col_output[(n * channels_col * width_col + c * width_col) * height_col + b]; - foo += weights[a * channels_col + c] * col_output[(n * channels_col * width_col + c * width_col) * height_col + b]; - } - -// result[id] += bias[a]; - - result[id] = foo; -} - - - diff --git a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ViewController.swift b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ViewController.swift index d9e1788..c835c0c 100644 --- a/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ViewController.swift +++ b/Examples/iOSDeepLearningKitApp/iOSDeepLearningKitApp/iOSDeepLearningKitApp/ViewController.swift @@ -7,6 +7,7 @@ // import UIKit +import DeepLearningKit class ViewController: UIViewController { @@ -29,7 +30,6 @@ class ViewController: UIViewController { // shows a tiny (32x32) CIFAR 10 image on screen showCIFARImage(image) - var randomimage = createFloatNumbersArray(image.count) for i in 0.. Date: Mon, 20 Jun 2016 19:41:18 +1200 Subject: [PATCH 09/10] chore (examples) setup OSX sample project with library --- .../project.pbxproj | 46 +--- .../ConvolutionLayer.swift | 223 ----------------- .../DeepNetwork+Classify.swift | 63 ----- .../DeepNetwork+JSON.swift | 26 -- .../DeepNetwork+SetupNetworkFromDict.swift | 84 ------- .../OSXDeepLearningKitApp/DeepNetwork.swift | 63 ----- .../MetalDataStructures.swift | 64 ----- .../MetalUtilityFunctions.swift | 182 -------------- .../OSXDeepLearningKitApp/PoolingLayer.swift | 151 ------------ .../RectifierLayer.swift | 54 ----- .../OSXDeepLearningKitApp/Shaders.metal | 224 ------------------ .../ViewController.swift | 16 +- 12 files changed, 11 insertions(+), 1185 deletions(-) delete mode 100644 Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/ConvolutionLayer.swift delete mode 100644 Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+Classify.swift delete mode 100644 Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+JSON.swift delete mode 100644 Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift delete mode 100644 Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork.swift delete mode 100644 Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/MetalDataStructures.swift delete mode 100644 Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/MetalUtilityFunctions.swift delete mode 100644 Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/PoolingLayer.swift delete mode 100644 Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/RectifierLayer.swift delete mode 100644 Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Shaders.metal diff --git a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.pbxproj b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.pbxproj index c34c14c..2b2dd06 100644 --- a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.pbxproj +++ b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.pbxproj @@ -7,27 +7,18 @@ objects = { /* Begin PBXBuildFile section */ + 53AC8ACB1D17D2E300778BB5 /* DeepLearningKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 53AC8ACA1D17D2E300778BB5 /* DeepLearningKit.framework */; }; 6B0A93641C724D9A00D73DEB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B0A93631C724D9A00D73DEB /* AppDelegate.swift */; }; 6B0A93661C724D9A00D73DEB /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B0A93651C724D9A00D73DEB /* ViewController.swift */; }; 6B0A93681C724D9A00D73DEB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6B0A93671C724D9A00D73DEB /* Assets.xcassets */; }; 6B0A936B1C724D9A00D73DEB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6B0A93691C724D9A00D73DEB /* Main.storyboard */; }; 6B0A93751C724DD200D73DEB /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B0A93731C724DD200D73DEB /* QuartzCore.framework */; }; - 6B0A93771C724DD800D73DEB /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B0A93761C724DD800D73DEB /* Metal.framework */; }; - 6B64DA231C724EE60048FD13 /* ConvolutionLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B64DA171C724EE60048FD13 /* ConvolutionLayer.swift */; }; - 6B64DA241C724EE60048FD13 /* DeepNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B64DA181C724EE60048FD13 /* DeepNetwork.swift */; }; - 6B64DA251C724EE60048FD13 /* DeepNetwork+Classify.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B64DA191C724EE60048FD13 /* DeepNetwork+Classify.swift */; }; - 6B64DA261C724EE60048FD13 /* DeepNetwork+JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B64DA1A1C724EE60048FD13 /* DeepNetwork+JSON.swift */; }; - 6B64DA271C724EE60048FD13 /* DeepNetwork+SetupNetworkFromDict.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B64DA1B1C724EE60048FD13 /* DeepNetwork+SetupNetworkFromDict.swift */; }; - 6B64DA281C724EE60048FD13 /* MetalDataStructures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B64DA1C1C724EE60048FD13 /* MetalDataStructures.swift */; }; - 6B64DA291C724EE60048FD13 /* MetalUtilityFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B64DA1D1C724EE60048FD13 /* MetalUtilityFunctions.swift */; }; 6B64DA2A1C724EE60048FD13 /* nin_cifar10_full.json in Resources */ = {isa = PBXBuildFile; fileRef = 6B64DA1E1C724EE60048FD13 /* nin_cifar10_full.json */; }; - 6B64DA2C1C724EE60048FD13 /* PoolingLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B64DA201C724EE60048FD13 /* PoolingLayer.swift */; }; - 6B64DA2D1C724EE60048FD13 /* RectifierLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B64DA211C724EE60048FD13 /* RectifierLayer.swift */; }; - 6B64DA2E1C724EE60048FD13 /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 6B64DA221C724EE60048FD13 /* Shaders.metal */; }; 6B64DA301C724F020048FD13 /* conv1.json in Resources */ = {isa = PBXBuildFile; fileRef = 6B64DA2F1C724F020048FD13 /* conv1.json */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 53AC8ACA1D17D2E300778BB5 /* DeepLearningKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DeepLearningKit.framework; path = "../../../../../../../Users/rafael/Library/Developer/Xcode/DerivedData/DeepLearningKit-csfprtnhalzpycftepmcgcebvxbt/Build/Products/Debug/DeepLearningKit.framework"; sourceTree = ""; }; 6B0A93601C724D9A00D73DEB /* OSXDeepLearningKitApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OSXDeepLearningKitApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 6B0A93631C724D9A00D73DEB /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 6B0A93651C724D9A00D73DEB /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; @@ -36,17 +27,7 @@ 6B0A936C1C724D9A00D73DEB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 6B0A93731C724DD200D73DEB /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 6B0A93761C724DD800D73DEB /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; }; - 6B64DA171C724EE60048FD13 /* ConvolutionLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConvolutionLayer.swift; sourceTree = ""; }; - 6B64DA181C724EE60048FD13 /* DeepNetwork.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeepNetwork.swift; sourceTree = ""; }; - 6B64DA191C724EE60048FD13 /* DeepNetwork+Classify.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DeepNetwork+Classify.swift"; sourceTree = ""; }; - 6B64DA1A1C724EE60048FD13 /* DeepNetwork+JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DeepNetwork+JSON.swift"; sourceTree = ""; }; - 6B64DA1B1C724EE60048FD13 /* DeepNetwork+SetupNetworkFromDict.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DeepNetwork+SetupNetworkFromDict.swift"; sourceTree = ""; }; - 6B64DA1C1C724EE60048FD13 /* MetalDataStructures.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalDataStructures.swift; sourceTree = ""; }; - 6B64DA1D1C724EE60048FD13 /* MetalUtilityFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalUtilityFunctions.swift; sourceTree = ""; }; 6B64DA1E1C724EE60048FD13 /* nin_cifar10_full.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = nin_cifar10_full.json; sourceTree = ""; }; - 6B64DA201C724EE60048FD13 /* PoolingLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PoolingLayer.swift; sourceTree = ""; }; - 6B64DA211C724EE60048FD13 /* RectifierLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RectifierLayer.swift; sourceTree = ""; }; - 6B64DA221C724EE60048FD13 /* Shaders.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Shaders.metal; sourceTree = ""; }; 6B64DA2F1C724F020048FD13 /* conv1.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = conv1.json; sourceTree = ""; }; /* End PBXFileReference section */ @@ -55,7 +36,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 6B0A93771C724DD800D73DEB /* Metal.framework in Frameworks */, + 53AC8ACB1D17D2E300778BB5 /* DeepLearningKit.framework in Frameworks */, 6B0A93751C724DD200D73DEB /* QuartzCore.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -66,6 +47,7 @@ 6B0A93571C724D9A00D73DEB = { isa = PBXGroup; children = ( + 53AC8ACA1D17D2E300778BB5 /* DeepLearningKit.framework */, 6B0A93761C724DD800D73DEB /* Metal.framework */, 6B0A93731C724DD200D73DEB /* QuartzCore.framework */, 6B0A93621C724D9A00D73DEB /* OSXDeepLearningKitApp */, @@ -89,18 +71,8 @@ 6B0A93671C724D9A00D73DEB /* Assets.xcassets */, 6B0A93691C724D9A00D73DEB /* Main.storyboard */, 6B0A936C1C724D9A00D73DEB /* Info.plist */, - 6B64DA171C724EE60048FD13 /* ConvolutionLayer.swift */, - 6B64DA181C724EE60048FD13 /* DeepNetwork.swift */, - 6B64DA191C724EE60048FD13 /* DeepNetwork+Classify.swift */, - 6B64DA1A1C724EE60048FD13 /* DeepNetwork+JSON.swift */, - 6B64DA1B1C724EE60048FD13 /* DeepNetwork+SetupNetworkFromDict.swift */, - 6B64DA1C1C724EE60048FD13 /* MetalDataStructures.swift */, - 6B64DA1D1C724EE60048FD13 /* MetalUtilityFunctions.swift */, 6B64DA2F1C724F020048FD13 /* conv1.json */, 6B64DA1E1C724EE60048FD13 /* nin_cifar10_full.json */, - 6B64DA201C724EE60048FD13 /* PoolingLayer.swift */, - 6B64DA211C724EE60048FD13 /* RectifierLayer.swift */, - 6B64DA221C724EE60048FD13 /* Shaders.metal */, ); path = OSXDeepLearningKitApp; sourceTree = ""; @@ -178,18 +150,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 6B64DA2E1C724EE60048FD13 /* Shaders.metal in Sources */, - 6B64DA271C724EE60048FD13 /* DeepNetwork+SetupNetworkFromDict.swift in Sources */, - 6B64DA251C724EE60048FD13 /* DeepNetwork+Classify.swift in Sources */, - 6B64DA241C724EE60048FD13 /* DeepNetwork.swift in Sources */, 6B0A93661C724D9A00D73DEB /* ViewController.swift in Sources */, - 6B64DA2D1C724EE60048FD13 /* RectifierLayer.swift in Sources */, 6B0A93641C724D9A00D73DEB /* AppDelegate.swift in Sources */, - 6B64DA281C724EE60048FD13 /* MetalDataStructures.swift in Sources */, - 6B64DA261C724EE60048FD13 /* DeepNetwork+JSON.swift in Sources */, - 6B64DA291C724EE60048FD13 /* MetalUtilityFunctions.swift in Sources */, - 6B64DA2C1C724EE60048FD13 /* PoolingLayer.swift in Sources */, - 6B64DA231C724EE60048FD13 /* ConvolutionLayer.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/ConvolutionLayer.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/ConvolutionLayer.swift deleted file mode 100644 index 474f100..0000000 --- a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/ConvolutionLayer.swift +++ /dev/null @@ -1,223 +0,0 @@ -// -// ConvolutionLayer.swift -// MemkiteMetal -// -// Created by Amund Tveit on 25/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - - - -func getDataFromBlob(blob: NSDictionary) -> ([Float], [Float]) { - - let shape = blob["shape"] as! NSDictionary - let data = blob["data"] as! [Float] - var FloatData = createFloatNumbersArray(data.count) - for i in 0 ..< data.count { - FloatData[i] = data[i] - } - return (shape["dim"] as! [Float], FloatData) -} - - - -func createConvolutionLayerCached(layer: NSDictionary, - inputBuffer: MTLBuffer, - inputShape: [Float], - metalCommandQueue: MTLCommandQueue, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout layer_data_caches: [Dictionary], - inout blob_cache: [Dictionary], - layer_number: Int, - layer_string: String, caching_mode:Bool) -> (MTLBuffer, MTLCommandBuffer, [Float]) { - - _ = NSDate() - - -// let metalCommandBuffer = metalCommandQueue.commandBuffer() - let metalCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() - - var convolution_params_dict:NSDictionary = NSDictionary() - var pad:Float = 0.0 - var kernel_size:Float = 1.0 - var stride:Float = 1.0 - var blobs:[NSDictionary] = [] - var weights:[Float] = [] - var weight_shape:[Float] = [] - var bias_data:[Float] = [] - var h:Float = 0.0 - var w:Float = 0.0 - var result_shape:[Float] = [] - var outputCount:Int = 0 - - var input_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var weight_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var result_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var tensor_dimensions:[MetalTensorDimensions] = [] - var col_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var col_output:[Float] = [] - var convolution_params:MetalConvolutionParameters = MetalConvolutionParameters(pad:0, kernel_size: 0, stride: 0) - - - if(!caching_mode) { - print("NOTCACHINGMODE") - convolution_params_dict = layer["convolution_param"] as! NSDictionary - pad = 0.0 - kernel_size = 1.0 - stride = 1.0 - if let val = convolution_params_dict["pad"] as? Float { - pad = val - } - if let val = convolution_params_dict["kernel_size"] as? Float { - kernel_size = val - } - - _ = NSDate() - - - if let tmpval = blob_cache[layer_number]["0"] { - (weight_shape, weights) = tmpval - } else { - blobs = layer["blobs"] as! [NSDictionary] - (weight_shape, weights) = getDataFromBlob(blobs[0]) - blob_cache[layer_number]["0"] = (weight_shape, weights) - } - - blobs = layer["blobs"] as! [NSDictionary] - (_, bias_data) = getDataFromBlob(blobs[1]) - - - - h = (inputShape[2] + 2 * pad - kernel_size) / stride + 1 - w = (inputShape[3] + 2 * pad - kernel_size) / stride + 1 - result_shape = [inputShape[0], weight_shape[0], h, w] - outputCount = Int(result_shape.reduce(1, combine: *)) - - // Create input and output vectors, and corresponding metal buffer - input_dimensions = MetalTensorDimensions(n: inputShape[0], channels: inputShape[1], width: inputShape[2], height: inputShape[3]) - weight_dimensions = MetalTensorDimensions(n: weight_shape[0], channels: weight_shape[1], width: weight_shape[2], height: weight_shape[3]) - col_dimensions = MetalTensorDimensions(n: inputShape[0], channels: inputShape[1] * weight_shape[2] * weight_shape[3], width: inputShape[2], height: inputShape[3]) - result_dimensions = MetalTensorDimensions(n: result_shape[0], channels: result_shape[1], width: result_shape[2], height: result_shape[3]) - tensor_dimensions = [input_dimensions, weight_dimensions, col_dimensions, result_dimensions] - - - col_output = createFloatNumbersArray(Int(col_dimensions.n * col_dimensions.channels * col_dimensions.height * col_dimensions.width)) - - - convolution_params = MetalConvolutionParameters(pad: pad, kernel_size: kernel_size, stride: stride) - - } - - - let resultBuffer = addConvolutionCommandToCommandBufferCached(metalCommandBuffer, inputBuffer: inputBuffer, im2ColCount: col_output.count, weights: weights, outputCount: outputCount, convolution_params: convolution_params, tensor_dimensions: tensor_dimensions, bias: bias_data, metalDefaultLibrary: metalDefaultLibrary, metalDevice:metalDevice, layer_data_caches: &layer_data_caches, layer_number: layer_number,layer_string: layer_string, caching_mode: caching_mode) - //metalCommandBuffer.commit() - - - - return (resultBuffer, metalCommandBuffer, result_shape) - -} - -func addConvolutionCommandToCommandBufferCached(commandBuffer: MTLCommandBuffer, - inputBuffer: MTLBuffer, - im2ColCount: Int, - weights: [Float], - outputCount: Int, - convolution_params: MetalConvolutionParameters, - tensor_dimensions: [MetalTensorDimensions], - bias: [Float], - metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout layer_data_caches: [Dictionary], - layer_number: Int, - layer_string: String, caching_mode:Bool) -> MTLBuffer { - - _ = NSDate() - - print("before output and col_output") - - var output:[Float] = [] - var col_output:[Float] = [] - - if(!caching_mode) { - output = createFloatNumbersArray(outputCount) - col_output = createFloatNumbersArray(im2ColCount) - } - - print("before setupshaderinpipeline") - - let (_, im2colComputePipelineState, _) = setupShaderInMetalPipeline("im2col", metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice) - - let resultMetalBuffer = createOrReuseFloatMetalBuffer("resultMetalBuffer", data: output, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - - print("after resultmetalbuffer") - - let weightMetalBuffer = createOrReuseFloatMetalBuffer("weightMetalBuffer", data: weights, cache: &layer_data_caches, layer_number:layer_number, metalDevice: metalDevice) - - - let convolutionParamsMetalBuffer = createOrReuseConvolutionParametersMetalBuffer("convolutionParamsMetalBuffer", data: convolution_params, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - let tensorDimensionsMetalBuffer = createOrReuseTensorDimensionsVectorMetalBuffer("tensorDimensionsMetalBuffer", data: tensor_dimensions, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - - let colOutputMetalBuffer = createOrReuseFloatMetalBuffer("colOutputMetalBuffer", data: col_output, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - let biasMetalBuffer = createOrReuseFloatMetalBuffer("bias", data: bias, cache: &layer_data_caches, layer_number:layer_number, metalDevice: metalDevice) - - - // Create Metal compute command encoder for im2col - var metalComputeCommandEncoder = commandBuffer.computeCommandEncoder() - metalComputeCommandEncoder.setBuffer(inputBuffer, offset: 0, atIndex: 0) - metalComputeCommandEncoder.setBuffer(tensorDimensionsMetalBuffer, offset: 0, atIndex: 1) - metalComputeCommandEncoder.setBuffer(convolutionParamsMetalBuffer, offset: 0, atIndex: 2) - metalComputeCommandEncoder.setBuffer(colOutputMetalBuffer, offset: 0, atIndex: 3) - //metalComputeCommandEncoder.setComputePipelineState(im2colComputePipelineState) - - - // Set the shader function that Metal will use - metalComputeCommandEncoder.setComputePipelineState(im2colComputePipelineState) - - // Set up thread groups on GPU - // TODO: check out http://metalbyexample.com/introduction-to-compute/ - var threadsPerGroup = MTLSize(width:im2colComputePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - print("before mtlsize 2") - var numThreadgroups = MTLSize(width:(col_output.count-1)/im2colComputePipelineState.threadExecutionWidth + 1, height:1, depth:1) - metalComputeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - print("after dispatch") - - // Finalize configuration - metalComputeCommandEncoder.endEncoding() - - - - - let (_, convolutionComputePipelineState, _) = setupShaderInMetalPipeline("convolution_layer", metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice) - metalComputeCommandEncoder = commandBuffer.computeCommandEncoder() - - // Create Metal Compute Command Encoder and add input and output buffers to it - metalComputeCommandEncoder.setBuffer(resultMetalBuffer, offset: 0, atIndex: 0) - metalComputeCommandEncoder.setBuffer(weightMetalBuffer, offset: 0, atIndex: 1) - metalComputeCommandEncoder.setBuffer(tensorDimensionsMetalBuffer, offset: 0, atIndex: 2) - metalComputeCommandEncoder.setBuffer(colOutputMetalBuffer, offset: 0, atIndex: 3) - metalComputeCommandEncoder.setBuffer(biasMetalBuffer, offset: 0, atIndex: 4) - - // Set the shader function that Metal will use - metalComputeCommandEncoder.setComputePipelineState(convolutionComputePipelineState) - - // Set up thread groups on GPU - // TODO: check out http://metalbyexample.com/introduction-to-compute/ - threadsPerGroup = MTLSize(width:convolutionComputePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - numThreadgroups = MTLSize(width:(outputCount-1)/convolutionComputePipelineState.threadExecutionWidth + 1, height:1, depth:1) - metalComputeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - // Finalize configuration - metalComputeCommandEncoder.endEncoding() - - - - - return resultMetalBuffer - -} - diff --git a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+Classify.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+Classify.swift deleted file mode 100644 index 5cbddf3..0000000 --- a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+Classify.swift +++ /dev/null @@ -1,63 +0,0 @@ -// -// DeepNetwork+Classify.swift -// MemkiteMetal -// -// Created by Amund Tveit on 25/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - -public extension DeepNetwork { - // e.g. 32x32x3 for CIFAR-10/100 - // as [1.0, 3.0, 32.0, 32.0] - public func classify(flattenedTensorWithImage: [Float]) -> Float { - //let flattenedTensorWithImage = flattenedTensorWithImage - let start = NSDate() - - // from 2.2 in http://memkite.com/blog/2014/12/30/example-of-sharing-memory-between-gpu-and-cpu-with-swift-and-metal-for-ios8/ - /*let xvectorVoidPtr = COpaquePointer(imageBuffer.contents()) - let xvectorFloatPtr = UnsafeMutablePointer(xvectorVoidPtr) - let xvectorFloatBufferPtr = UnsafeMutableBufferPointer(start:xvectorFloatPtr, count: flattenedTensorWithImage.count) - for index in xvectorFloatBufferPtr.startIndex.. NSDictionary? { - print(" ==> loadJSONFile(filename=\(filename)") - - do { - let bundle = NSBundle.mainBundle() - let path = bundle.pathForResource(filename, ofType: "json")! - let jsonData = NSData(contentsOfFile: path) - print(" <== loadJSONFile") - return try NSJSONSerialization.JSONObjectWithData(jsonData!, options: .AllowFragments) as? NSDictionary - } catch _ { - return nil - } -} -} \ No newline at end of file diff --git a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift deleted file mode 100644 index eefe185..0000000 --- a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift +++ /dev/null @@ -1,84 +0,0 @@ -// -// DeepNetwork+SetupNetworkFromDict.swift -// MemkiteMetal -// -// Created by Amund Tveit on 10/12/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - -public extension DeepNetwork { - - func setupNetworkFromDict(deepNetworkAsDict: NSDictionary, inputimage: MTLBuffer, inputshape: [Float], caching_mode:Bool) { - - let start = NSDate() - - print(" ==> setupNetworkFromDict()") - // Add input image - var layer_number = 0 - layer_data_caches.append(Dictionary()) // for input - pool_type_caches.append(Dictionary()) - blob_cache.append(Dictionary()) - namedDataLayers.append(("input", inputimage)) - layer_number += 1 - - - // Add remaining network - var previousBuffer:MTLBuffer = inputimage - var previousShape:[Float] = inputshape - - self.deepNetworkAsDict = deepNetworkAsDict - - // create new command buffer for next layer - var currentCommandBuffer: MTLCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() - - var t = NSDate() - for layer in deepNetworkAsDict["layer"] as! [NSDictionary] { - if let type = layer["type"] as? String { - let layer_string = layer["name"] as! String - - layer_data_caches.append(Dictionary()) - pool_type_caches.append(Dictionary()) - blob_cache.append(Dictionary()) - - - if type == "ReLU" { - self.gpuCommandLayers.append(currentCommandBuffer) - //(previousBuffer, currentCommandBuffer) = createRectifierLayer(previousBuffer) - (previousBuffer, currentCommandBuffer) = createRectifierLayer(previousBuffer, metalCommandQueue:metalCommandQueue, metalDefaultLibrary:metalDefaultLibrary, metalDevice:metalDevice) - self.namedDataLayers.append((layer["name"]! as! String, previousBuffer)) - } else if type == "Pooling" { - self.gpuCommandLayers.append(currentCommandBuffer) - // (previousBuffer, currentCommandBuffer, previousShape) = createPoolingLayer(layer, inputBuffer: previousBuffer, inputShape: previousShape) - (previousBuffer, currentCommandBuffer, previousShape) = createPoolingLayerCached(layer, inputBuffer: previousBuffer, inputShape: previousShape, metalCommandQueue: metalCommandQueue, metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice, pool_type_caches: &pool_type_caches, layer_data_caches: &layer_data_caches, layer_number: layer_number, layer_string: layer_string, caching_mode: caching_mode) - self.namedDataLayers.append((layer["name"]! as! String, previousBuffer)) - } else if type == "Convolution" { - self.gpuCommandLayers.append(currentCommandBuffer) - // (previousBuffer, currentCommandBuffer, previousShape) = createConvolutionLayer(layer, inputBuffer: previousBuffer, inputShape: previousShape) - (previousBuffer, currentCommandBuffer, previousShape) = createConvolutionLayerCached(layer, inputBuffer: previousBuffer, inputShape: previousShape, metalCommandQueue: metalCommandQueue, metalDefaultLibrary:metalDefaultLibrary, metalDevice:metalDevice, layer_data_caches: &layer_data_caches, blob_cache: &blob_cache, layer_number: layer_number, layer_string: layer_string, caching_mode: caching_mode) - - - self.namedDataLayers.append((layer["name"]! as! String, previousBuffer)) - } - let name = layer["name"] as! String - print("\(name): \(NSDate().timeIntervalSinceDate(t))") - t = NSDate() - layer_number += 1 - - } - } - - self.gpuCommandLayers.append(currentCommandBuffer) - - print("bar") - - print("AFTER LAYER DATA CHACES = \(layer_data_caches[0])") - - print("POOL TYPE CACHES = \(pool_type_caches)") - - print("Time to set up network: \(NSDate().timeIntervalSinceDate(start))") - - } -} diff --git a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork.swift deleted file mode 100644 index f4ddec4..0000000 --- a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/DeepNetwork.swift +++ /dev/null @@ -1,63 +0,0 @@ -// -// DeepNetwork.swift -// MemkiteMetal -// -// Created by Amund Tveit on 24/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - -public class DeepNetwork { - var gpuCommandLayers: [MTLCommandBuffer] = [] - var namedDataLayers: [(String, MTLBuffer)] = [] - var imageBuffer: MTLBuffer! - var metalDevice: MTLDevice! - var metalDefaultLibrary: MTLLibrary! - var metalCommandQueue: MTLCommandQueue! - var deepNetworkAsDict: NSDictionary! // for debugging perhaps - var layer_data_caches: [Dictionary] = [] - var pool_type_caches: [Dictionary] = [] - var dummy_image: [Float]! - var previous_shape: [Float]! - var blob_cache: [Dictionary] = [] - - public init() { - setupMetal() - deepNetworkAsDict = nil - } - - public func loadDeepNetworkFromJSON(networkName: String, inputImage: [Float], inputShape:[Float], caching_mode:Bool) { - print(" ==> loadDeepNetworkFromJSON(networkName=\(networkName)") - if deepNetworkAsDict == nil { - print("loading json file!") - deepNetworkAsDict = loadJSONFile(networkName)! - } - - - // IMAGE INPUT HANDLING START - TODO: hardcode input dimensions, - // and have random data, and then later overwrite the first buffer - //let imageLayer = loadJSONFile("conv1")! - //let imageData: [Float] = imageLayer["input"] as! [Float] - print(inputImage.count) - let imageTensor = createMetalBuffer(inputImage, metalDevice: metalDevice) - - // preLoadMetalShaders(metalDevice, metalDefaultLibrary:metalDefaultLibrary) - - setupNetworkFromDict(deepNetworkAsDict, inputimage: imageTensor, inputshape: inputShape, caching_mode:caching_mode ) - } - - - func setupMetal() { - // Get access to iPhone or iPad GPU - metalDevice = MTLCreateSystemDefaultDevice() - - // Queue to handle an ordered list of command buffers - metalCommandQueue = metalDevice.newCommandQueue() - print("metalCommandQueue = \(unsafeAddressOf(metalCommandQueue))") - - // Access to Metal functions that are stored in Shaders.metal file, e.g. sigmoid() - metalDefaultLibrary = metalDevice.newDefaultLibrary() - } -} diff --git a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/MetalDataStructures.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/MetalDataStructures.swift deleted file mode 100644 index 2cf6e7a..0000000 --- a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/MetalDataStructures.swift +++ /dev/null @@ -1,64 +0,0 @@ -// -// MetalDataStructures.swift -// MemkiteMetal -// -// Created by Amund Tveit on 24/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Foundation -import Metal -import QuartzCore - -////////////////////////////////////////// -// Metal Data Types - their SWIFT Counterparts -////////////////////////////////////////// -public struct MetalComplexNumberType { - var real: Float = 0.0 - var imag: Float = 0.0 -} - -public struct MetalShaderParameters { - let image_xdim: Float - let image_ydim: Float - let num_images: Float - let filter_xdim: Float - let filter_ydim: Float - let num_filters: Float - let conv_xdim: Float // image_xdim - filter_xdim + 1 without striding - let conv_ydim: Float // image_ydim - filter_ydim + 1 without striding - let pool_xdim: Float - let pool_ydim: Float - var b: Float -} - -public struct MetalMatrixVectorParameters { - let x_xdim: Float - let x_ydim: Float - let w_xdim: Float - let w_ydim: Float - let b_xdim: Float - let b_ydim: Float - let result_xdim: Float - let result_ydim: Float -} - -public struct MetalPoolingParameters { - let kernel_size: Float - let pool_stride: Float - let pad: Float -} - -public struct MetalTensorDimensions { - let n: Float - let channels: Float - let width: Float - let height: Float -} - -public struct MetalConvolutionParameters { - let pad: Float - let kernel_size: Float - let stride: Float -} diff --git a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/MetalUtilityFunctions.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/MetalUtilityFunctions.swift deleted file mode 100644 index 41dfb1a..0000000 --- a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/MetalUtilityFunctions.swift +++ /dev/null @@ -1,182 +0,0 @@ -// -// MetalUtilFunctions.swift -// MemkiteMetal -// -// Created by Amund Tveit on 24/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - -func createComplexNumbersArray(count: Int) -> [MetalComplexNumberType] { - let zeroComplexNumber = MetalComplexNumberType() - return [MetalComplexNumberType](count: count, repeatedValue: zeroComplexNumber) -} - -func createFloatNumbersArray(count: Int) -> [Float] { - return [Float](count: count, repeatedValue: 0.0) -} - -func createFloatMetalBuffer(vector: [Float], let metalDevice:MTLDevice) -> MTLBuffer { - var vector = vector - let byteLength = vector.count*sizeof(Float) // future: MTLResourceStorageModePrivate - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -// TODO: could perhaps use generics to combine both functions below? -func createComplexMetalBuffer(vector:[MetalComplexNumberType], let metalDevice:MTLDevice) -> MTLBuffer { - var vector = vector - let byteLength = vector.count*sizeof(MetalComplexNumberType) // or size of and actual 1st element object? - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createShaderParametersMetalBuffer(shaderParameters:MetalShaderParameters, metalDevice:MTLDevice) -> MTLBuffer { - var shaderParameters = shaderParameters - let byteLength = sizeof(MetalShaderParameters) - return metalDevice.newBufferWithBytes(&shaderParameters, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createMatrixShaderParametersMetalBuffer(params: MetalMatrixVectorParameters, metalDevice: MTLDevice) -> MTLBuffer { - var params = params - let byteLength = sizeof(MetalMatrixVectorParameters) - return metalDevice.newBufferWithBytes(¶ms, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) - -} - -func createPoolingParametersMetalBuffer(params: MetalPoolingParameters, metalDevice: MTLDevice) -> MTLBuffer { - var params = params - let byteLength = sizeof(MetalPoolingParameters) - return metalDevice.newBufferWithBytes(¶ms, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createConvolutionParametersMetalBuffer(params: MetalConvolutionParameters, metalDevice: MTLDevice) -> MTLBuffer { - var params = params - let byteLength = sizeof(MetalConvolutionParameters) - return metalDevice.newBufferWithBytes(¶ms, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createTensorDimensionsVectorMetalBuffer(vector: [MetalTensorDimensions], metalDevice: MTLDevice) -> MTLBuffer { - var vector = vector - let byteLength = vector.count * sizeof(MetalTensorDimensions) - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func setupShaderInMetalPipeline(shaderName:String, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice) -> (shader:MTLFunction!, - computePipelineState:MTLComputePipelineState!, - computePipelineErrors:NSErrorPointer!) { - let shader = metalDefaultLibrary.newFunctionWithName(shaderName) - let computePipeLineDescriptor = MTLComputePipelineDescriptor() - computePipeLineDescriptor.computeFunction = shader - // var computePipelineErrors = NSErrorPointer() - // let computePipelineState:MTLComputePipelineState = metalDevice.newComputePipelineStateWithFunction(shader!, completionHandler: {(}) - let computePipelineErrors:NSErrorPointer = nil // NSErrorPointer() - var computePipelineState:MTLComputePipelineState? = nil - do { - computePipelineState = try metalDevice.newComputePipelineStateWithFunction(shader!) - } catch { - print("catching..") - } - return (shader, computePipelineState, computePipelineErrors) - -} - -func createMetalBuffer(vector:[Float], metalDevice:MTLDevice) -> MTLBuffer { - var vector = vector - let byteLength = vector.count*sizeof(Float) - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func preLoadMetalShaders(metalDevice: MTLDevice, metalDefaultLibrary: MTLLibrary) { - let shaders = ["avg_pool", "max_pool", "rectifier_linear", "convolution_layer", "im2col"] - for shader in shaders { - setupShaderInMetalPipeline(shader, metalDefaultLibrary: metalDefaultLibrary,metalDevice: metalDevice) // TODO: this returns stuff - } -} - -func createOrReuseFloatMetalBuffer(name:String, data: [Float], inout cache:[Dictionary], layer_number:Int, metalDevice:MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { - print("found key = \(name) in cache") - result = tmpval - } else { - print("didnt find key = \(name) in cache") - result = createFloatMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - // print("DEBUG: cache = \(cache)") - } - - return result -} - - -func createOrReuseConvolutionParametersMetalBuffer(name:String, - data: MetalConvolutionParameters, - inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { - print("found key = \(name) in cache") - result = tmpval - } else { - print("didnt find key = \(name) in cache") - result = createConvolutionParametersMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - -func createOrReuseTensorDimensionsVectorMetalBuffer(name:String, - data:[MetalTensorDimensions],inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { - print("found key = \(name) in cache") - result = tmpval - } else { - print("didnt find key = \(name) in cache") - result = createTensorDimensionsVectorMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - -// -//let sizeParamMetalBuffer = createShaderParametersMetalBuffer(size_params, metalDevice: metalDevice) -//let poolingParamMetalBuffer = createPoolingParametersMetalBuffer(pooling_params, metalDevice: metalDevice) - -func createOrReuseShaderParametersMetalBuffer(name:String, - data:MetalShaderParameters,inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { -// print("found key = \(name) in cache") - result = tmpval - } else { -// print("didnt find key = \(name) in cache") - result = createShaderParametersMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - -func createOrReusePoolingParametersMetalBuffer(name:String, - data:MetalPoolingParameters,inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { -// print("found key = \(name) in cache") - result = tmpval - } else { -// print("didnt find key = \(name) in cache") - result = createPoolingParametersMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - - diff --git a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/PoolingLayer.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/PoolingLayer.swift deleted file mode 100644 index d6d4310..0000000 --- a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/PoolingLayer.swift +++ /dev/null @@ -1,151 +0,0 @@ -// -// PoolingLayer.swift -// MemkiteMetal -// -// Created by Amund Tveit on 25/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - - -func createPoolingLayerCached(layer: NSDictionary, - inputBuffer: MTLBuffer, - inputShape: [Float], - metalCommandQueue: MTLCommandQueue, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout pool_type_caches: [Dictionary], - inout layer_data_caches: [Dictionary], - layer_number: Int, - layer_string: String, - caching_mode:Bool) -> (MTLBuffer, MTLCommandBuffer, [Float]) { - - print(" ==> createPoolingLayerCached") - let metalCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() -// let metalCommandBuffer = metalCommandQueue.commandBuffer() - - var params = NSDictionary() - var stride:Float = 1.0 - var kernel_size: Float = 1.0 - var pad: Float = 0.0 - var pooling_params = MetalPoolingParameters(kernel_size: kernel_size, pool_stride: stride, pad: pad) - var pool_type = 0 - var h:Float = 0.0 - var w:Float = 0.0 - var shape:[Float] = [] - var outputCount:Float = 0 - var pool_width = 0 - var pool_height = 0 - var size_params:MetalShaderParameters = MetalShaderParameters(image_xdim:0.0, image_ydim:0.0, num_images: 0.0, filter_xdim: 0.0, filter_ydim: 0.0, num_filters: 0.0, conv_xdim: 0.0, conv_ydim: 0.0, pool_xdim: 0.0, pool_ydim: 0.0, b:0.0) - var outputBuffer:MTLBuffer - - if(!caching_mode) { - - params = layer["pooling_param"] as! NSDictionary - stride = 1.0 - kernel_size = 1.0 - pad = 0.0 - if let val = params["stride"] { - stride = val as! Float - } - if let val = params["kernel_size"] { - kernel_size = val as! Float - if val as! NSNumber != 3 { - pad = 0 - } - } - pooling_params = MetalPoolingParameters(kernel_size: kernel_size, pool_stride: stride, pad: pad) - pool_type = params["pool"] as! Int - - // STORE pool type in cache! - pool_type_caches[layer_number]["pool_type"] = String(pool_type) - - //TODO: calculate outputCount - h = ceil((inputShape[2] + 2.0 * pad - kernel_size) / stride) + 1.0 - w = ceil((Float(inputShape[3]) + 2.0 * pad - kernel_size) / stride) + 1.0 - shape = [inputShape[0], inputShape[1], h, w] - outputCount = shape.reduce(1, combine: *) - pool_width = Int(shape[2]) - pool_height = Int(shape[3]) - size_params = MetalShaderParameters(image_xdim: Float(inputShape[2]), image_ydim: Float(inputShape[3]), - num_images: Float(inputShape[0]), - filter_xdim: 1.0, filter_ydim: 1.0, num_filters: Float(inputShape[1]), - conv_xdim:0.0, conv_ydim: 0.0, - pool_xdim: Float(pool_width), pool_ydim: Float(pool_height), b:0.0) - } else { - // need to fetch pool type from cache - print("FETCHING POOL TYPE FROM CACHE!!!!!") - pool_type = Int(pool_type_caches[layer_number]["pool_type"]!)! - } - - if pool_type == 1 { - outputBuffer = addPoolingCommandToCommandBufferCached(metalCommandBuffer, poolingMethod: "avg_pool", inputBuffer: inputBuffer, outputCount: Int(outputCount), size_params: size_params, pooling_params: pooling_params, metalDefaultLibrary: metalDefaultLibrary, metalDevice:metalDevice, - layer_data_caches: &layer_data_caches, layer_number: layer_number, layer_string: layer_string) - } else { - outputBuffer = addPoolingCommandToCommandBufferCached(metalCommandBuffer, poolingMethod: "max_pool", inputBuffer: inputBuffer, outputCount: Int(outputCount), size_params: size_params, pooling_params: pooling_params,metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice, - layer_data_caches: &layer_data_caches, layer_number: layer_number, layer_string: layer_string) - - } - //metalCommandBuffer.commit() - - print(" <== createPoolingLayerCached") - - - return (outputBuffer, metalCommandBuffer, shape) -} - - -func addPoolingCommandToCommandBufferCached(commandBuffer: MTLCommandBuffer, - poolingMethod: String, - inputBuffer: MTLBuffer, - outputCount: Int, - size_params: MetalShaderParameters, - pooling_params: MetalPoolingParameters, - metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout layer_data_caches: [Dictionary], - layer_number: Int, - layer_string: String) -> MTLBuffer { - - - print(" ==> addPoolingCommandtoCommandBufferCached") - - _ = layer_data_caches[layer_number] - - let output = createFloatNumbersArray(outputCount) - let (_, computePipelineState, _) = setupShaderInMetalPipeline(poolingMethod, metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice) - - let outputMetalBuffer = createOrReuseFloatMetalBuffer("outputMetalBuffer", data: output, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - // let outputMetalBuffer = createFloatMetalBuffer(output, metalDevice: metalDevice) - - let sizeParamMetalBuffer = createOrReuseShaderParametersMetalBuffer("sizeParamMetalBuffer", data: size_params, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - - // let sizeParamMetalBuffer = createShaderParametersMetalBuffer(size_params, metalDevice: metalDevice) - - - // let poolingParamMetalBuffer = createPoolingParametersMetalBuffer(pooling_params, metalDevice: metalDevice) - let poolingParamMetalBuffer = createOrReusePoolingParametersMetalBuffer("poolingParamMetalBuffer", data: pooling_params, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - // Create Metal Compute Command Encoder and add input and output buffers to it - let metalComputeCommandEncoder = commandBuffer.computeCommandEncoder() - metalComputeCommandEncoder.setBuffer(outputMetalBuffer, offset: 0, atIndex: 0) - metalComputeCommandEncoder.setBuffer(inputBuffer, offset: 0, atIndex: 1) - metalComputeCommandEncoder.setBuffer(sizeParamMetalBuffer, offset: 0, atIndex: 2) - metalComputeCommandEncoder.setBuffer(poolingParamMetalBuffer, offset: 0, atIndex: 3) - - // Set the shader function that Metal will use - metalComputeCommandEncoder.setComputePipelineState(computePipelineState) - - // Set up thread groups on GPU - // TODO: check out http://metalbyexample.com/introduction-to-compute/ - let threadsPerGroup = MTLSize(width:computePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - let numThreadgroups = MTLSize(width:(outputCount-1)/computePipelineState.threadExecutionWidth + 1, height:1, depth:1) - metalComputeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - // Finalize configuration - metalComputeCommandEncoder.endEncoding() - - print(" <== addPoolingCommandtoCommandBufferCached") - - - return outputMetalBuffer -} diff --git a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/RectifierLayer.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/RectifierLayer.swift deleted file mode 100644 index efc27ad..0000000 --- a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/RectifierLayer.swift +++ /dev/null @@ -1,54 +0,0 @@ -// -// RectifierLayer.swift -// MemkiteMetal -// -// Created by Amund Tveit on 25/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - -func createRectifierLayer(inputBuffer: MTLBuffer, metalCommandQueue: MTLCommandQueue, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice) -> (MTLBuffer,MTLCommandBuffer) { - print(" ==> createrectifierlayer") -// let metalCommandBuffer = metalCommandQueue.commandBuffer() - let metalCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() - - let result = addRectifierCommandToCommandBuffer(metalCommandBuffer, inputBuffer: inputBuffer, - metalDefaultLibrary: metalDefaultLibrary, metalDevice:metalDevice) - //metalCommandBuffer.commit() - - print(" <== createrectifierlayer") - return (result, metalCommandBuffer) -} - - -func addRectifierCommandToCommandBuffer(commandBuffer: MTLCommandBuffer, inputBuffer: MTLBuffer, - metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice) -> MTLBuffer { - - print("==> addRectifierToCommandBuffer") - - let count = inputBuffer.length / sizeof(Float) - let (_, computePipelineState, _) = setupShaderInMetalPipeline("rectifier_linear", metalDefaultLibrary: metalDefaultLibrary, - metalDevice: metalDevice) - - // Create Metal Compute Command Encoder and add input and output buffers to it - let computeCommandEncoder = commandBuffer.computeCommandEncoder() - computeCommandEncoder.setBuffer(inputBuffer, offset: 0, atIndex: 0) - // Set the shader function that Metal will use - computeCommandEncoder.setComputePipelineState(computePipelineState) - - // Set up thread groups on GPU - // TODO: check out http://metalbyexample.com/introduction-to-compute/ - let threadsPerGroup = MTLSize(width:computePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - let numThreadgroups = MTLSize(width:(count-1)/computePipelineState.threadExecutionWidth + 1, height:1, depth:1) - computeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - // Finalize configuration - computeCommandEncoder.endEncoding() - - print(" <== addRectifierToCommandBuffer") - - return inputBuffer -} diff --git a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Shaders.metal b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Shaders.metal deleted file mode 100644 index 37217fb..0000000 --- a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/Shaders.metal +++ /dev/null @@ -1,224 +0,0 @@ -// -// Shaders.metal -// memkite -// -// Created by Amund Tveit on 13/08/15. -// Copyright © 2015 Amund Tveit. All rights reserved. -// - -#include -#include -#include -#include -#include -#include -#include -#include // why? -using namespace metal; - -//////////////////////////////// -// DATA TYPES -//////////////////////////////// - -// TODO: perhaps add RGB support as part of this -struct MetalComplexNumberType { // needs to map to float2 in Metal - float real; - float imag; -}; - -// TODO: perhaps add B here? since it is only one value per convolution call (not entire vector) -struct MetalShaderParameters { - float image_xdim; - float image_ydim; - float num_images; - float filter_xdim; // e.g. 5 - float filter_ydim; // e.g. 5 - float num_filters; // e.g. 20 -> W = 20*1*5*5 - float conv_xdim; // image_xdim - filter_xdim + 1 without striding - float conv_ydim; // image_ydim - filter_ydim + 1 without striding - float pool_xdim; - float pool_ydim; - float b; // this should probably be an input array, but for now -}; - -struct MetalMatrixVectorParameters { - float x_xdim; - float x_ydim; - float w_xdim; - float w_ydim; - float b_xdim; - float b_ydim; - float result_xdim; - float result_ydim; -}; - -struct MetalPoolingParameters { - float kernel_size; - float pool_stride; - float pad; -}; - -struct MetalTensorDimensions { - float n; - float channels; - float width; - float height; -}; - -struct MetalConvolutionParameters { - float pad; - float kernel_size; - float stride; -}; - -//////////////////////////////// -// SHADER FUNCTIONS -//////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////// - - -// Returns max(0, X[id]) -kernel void rectifier_linear(device float* X [[ buffer(0)]], - uint id [[ thread_position_in_grid ]]) { - X[id] = fmax(0.0, X[id]); -} - -kernel void max_pool(device float* result [[ buffer(0) ]], - const device float* input [[ buffer(1) ]], - const device MetalShaderParameters* size_params [[ buffer(2) ]], - const device MetalPoolingParameters* pooling_params [[ buffer(3) ]], - uint id [[ thread_position_in_grid ]]) { - int channels = int(size_params[0].num_filters); - int in_width = int(size_params[0].image_xdim); - int in_height = int(size_params[0].image_ydim); - - float kernel_size = float(pooling_params[0].kernel_size); - int pool_stride = int(pooling_params[0].pool_stride); - int pad = int(pooling_params[0].pad); - - int out_width = int(size_params[0].pool_xdim); - int out_height = int(size_params[0].pool_ydim); - - int i = (id / out_height) % out_width; - int j = id % out_height; - int n = id / (channels * out_width * out_height); - int c = (id / (out_width * out_height)) % channels; - int wstart = i * pool_stride - pad; - int hstart = j * pool_stride - pad; - int wend = fmin(wstart + kernel_size, in_width + pad); - int hend = fmin(hstart + kernel_size, in_height + pad); - wstart = fmax(0.0, wstart); - hstart = fmax(0.0, hstart); - thread float pool = -100000.0; - for (int ii = wstart; ii < wend; ++ii) { - for (int jj = hstart; jj < hend; ++jj) { - pool = fmax(pool, input[(n * channels * in_height + c * in_height + ii) * in_width + jj]); - } - } - result[id] = pool; -} - -kernel void avg_pool(device float* result [[ buffer(0) ]], - const device float* input [[ buffer(1) ]], - const device MetalShaderParameters* size_params [[ buffer(2) ]], - const device MetalPoolingParameters* pooling_params [[ buffer(3) ]], - uint id [[ thread_position_in_grid ]]) { - int channels = int(size_params[0].num_filters); - int in_width = int(size_params[0].image_xdim); - int in_height = int(size_params[0].image_ydim); - - float kernel_size = float(pooling_params[0].kernel_size); - int pool_stride = int(pooling_params[0].pool_stride); - int pad = int(pooling_params[0].pad); - - int out_width = int(size_params[0].pool_xdim); - int out_height = int(size_params[0].pool_ydim); - - int i = (id / out_height) % out_width; - int j = id % out_height; - int n = id / (channels * out_width * out_height); - int c = (id / (out_width * out_height)) % channels; - int wstart = i * pool_stride - pad; - int hstart = j * pool_stride - pad; - int wend = fmin(wstart + kernel_size, in_width + pad); - int hend = fmin(hstart + kernel_size, in_height + pad); - float pool_size = (hend - hstart) * (wend - wstart); - wstart = fmax(0.0, wstart); - hstart = fmax(0.0, hstart); - thread float pool = 0.0; - for (int ii = wstart; ii < wend; ++ii) { - for (int jj = hstart; jj < hend; ++jj) { - pool += input[(n * channels * in_height + c * in_height + ii) * in_width + jj]/pool_size; - } - } - result[id] = pool; -} - -kernel void im2col(const device float* convolution_input [[ buffer(0)]], - const device MetalTensorDimensions* tensor_dimensions [[ buffer(1) ]], - const device MetalConvolutionParameters* convolution_params [[ buffer(2) ]], - device float* col_output [[ buffer(3) ]], - uint id [[ thread_position_in_grid ]]) { - //int num = int(tensor_dimensions[0].n); - int channels_in = int(tensor_dimensions[0].channels); - int in_width = int(tensor_dimensions[0].width); - int in_height = int(tensor_dimensions[0].height); - - int channels_col = int(tensor_dimensions[2].channels); - int width_col = int(tensor_dimensions[2].width); - int height_col = int(tensor_dimensions[2].height); - - - // 1. do an im2col transformation - int pad = int(convolution_params[0].pad); - int kernel_size = int(convolution_params[0].kernel_size); - - int n = id / (channels_col * height_col * width_col); - int c = (id / (width_col * height_col)) % channels_col; - int h = (id / width_col) % height_col; - int w = id % width_col; - int w_offset = c % kernel_size; - int h_offset = (c / kernel_size) % kernel_size; - int h_pad = h - pad + h_offset; - int w_pad = w - pad + w_offset; - int c_im = c / (kernel_size * kernel_size); - if (h_pad >= 0 && h_pad < in_height && w_pad >= 0 && w_pad < in_width) { - col_output[id] = convolution_input[(n * channels_in * in_height + c_im * in_height + h_pad) * in_width + w_pad]; - } -} - -// Tensor dimensions = { input_dimensions, weight_dimensions, col_dimensions, result_dimensions } -kernel void convolution_layer(device float* result [[ buffer(0) ]], - const device float* weights [[ buffer(1)]], - const device MetalTensorDimensions* tensor_dimensions [[ buffer(2) ]], - const device float* col_output [[ buffer(3) ]], - const device float* bias [[ buffer(4) ]], - uint id [[ thread_position_in_grid ]]) { - //int num = int(tensor_dimensions[2].n); - int channels_col = int(tensor_dimensions[2].channels); - int width_col = int(tensor_dimensions[2].width); - int height_col = int(tensor_dimensions[2].height); - - int channels_out = int(tensor_dimensions[3].channels); - int width_out = int(tensor_dimensions[3].width); - int height_out = int(tensor_dimensions[3].height); - - int n = id / (channels_out * height_out * width_out); - int a = (id / (height_out * width_out)) % channels_out; - int b = id % (height_out * width_out); - - thread float foo = bias[a]; - - for (int c = 0; c < channels_col; ++c) { -// result[id] += weights[a * channels_col + c] * col_output[(n * channels_col * width_col + c * width_col) * height_col + b]; - foo += weights[a * channels_col + c] * col_output[(n * channels_col * width_col + c * width_col) * height_col + b]; - } - -// result[id] += bias[a]; - - result[id] = foo; -} - - - diff --git a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/ViewController.swift b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/ViewController.swift index 301e013..33b6638 100644 --- a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/ViewController.swift +++ b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp/ViewController.swift @@ -7,12 +7,12 @@ // import Cocoa +import DeepLearningKit class ViewController: NSViewController { var deepNetwork: DeepNetwork! - override func viewDidLoad() { super.viewDidLoad() } @@ -33,22 +33,20 @@ class ViewController: NSViewController { let imageShape:[Float] = [1.0, 3.0, 32.0, 32.0] - let caching_mode = false - // 0. load network in network model - deepNetwork.loadDeepNetworkFromJSON("nin_cifar10_full", inputImage: image, inputShape: imageShape, caching_mode:caching_mode) + deepNetwork.loadNetworkFromJson("nin_cifar10_full") // 1. classify image (of cat) - deepNetwork.classify(image) + deepNetwork.classify(image, shape:imageShape) // 2. reset deep network and classify random image - deepNetwork.loadDeepNetworkFromJSON("nin_cifar10_full", inputImage: randomimage, inputShape: imageShape,caching_mode:caching_mode) - deepNetwork.classify(randomimage) + deepNetwork.loadNetworkFromJson("nin_cifar10_full") + deepNetwork.classify(randomimage, shape:imageShape) // 3. reset deep network and classify cat image again - deepNetwork.loadDeepNetworkFromJSON("nin_cifar10_full", inputImage: image, inputShape: imageShape,caching_mode:caching_mode) - deepNetwork.classify(image) + deepNetwork.loadNetworkFromJson("nin_cifar10_full") + deepNetwork.classify(image, shape:imageShape) exit(0) } From 61bb982d2c090699fcafbedd80a805c3d120e99e Mon Sep 17 00:00:00 2001 From: Rafael Almeida Date: Mon, 20 Jun 2016 20:09:55 +1200 Subject: [PATCH 10/10] chore (examples) setup tvOS sample project with library --- .../contents.xcworkspacedata | 3 + .../project.pbxproj | 2 - .../project.pbxproj | 50 +--- .../ConvolutionLayer.swift | 223 ----------------- .../DeepNetwork+Classify.swift | 62 ----- .../DeepNetwork+JSON.swift | 26 -- .../DeepNetwork+SetupNetworkFromDict.swift | 84 ------- .../tvOSDeepLearningKitApp/DeepNetwork.swift | 63 ----- .../MetalDataStructures.swift | 64 ----- .../MetalUtilityFunctions.swift | 174 -------------- .../tvOSDeepLearningKitApp/PoolingLayer.swift | 151 ------------ .../RectifierLayer.swift | 54 ----- .../tvOSDeepLearningKitApp/Shaders.metal | 224 ------------------ .../ViewController.swift | 15 +- 14 files changed, 16 insertions(+), 1179 deletions(-) delete mode 100644 Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ConvolutionLayer.swift delete mode 100644 Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+Classify.swift delete mode 100644 Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+JSON.swift delete mode 100644 Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift delete mode 100644 Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork.swift delete mode 100644 Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/MetalDataStructures.swift delete mode 100644 Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/MetalUtilityFunctions.swift delete mode 100644 Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/PoolingLayer.swift delete mode 100644 Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/RectifierLayer.swift delete mode 100644 Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Shaders.metal diff --git a/DeepLearningKit.xcworkspace/contents.xcworkspacedata b/DeepLearningKit.xcworkspace/contents.xcworkspacedata index 884834c..93ad584 100644 --- a/DeepLearningKit.xcworkspace/contents.xcworkspacedata +++ b/DeepLearningKit.xcworkspace/contents.xcworkspacedata @@ -7,6 +7,9 @@ + + diff --git a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.pbxproj b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.pbxproj index 2b2dd06..c2671c8 100644 --- a/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.pbxproj +++ b/Examples/OSXDeepLearningKitApp/OSXDeepLearningKitApp/OSXDeepLearningKitApp.xcodeproj/project.pbxproj @@ -26,7 +26,6 @@ 6B0A936A1C724D9A00D73DEB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 6B0A936C1C724D9A00D73DEB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 6B0A93731C724DD200D73DEB /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; - 6B0A93761C724DD800D73DEB /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; }; 6B64DA1E1C724EE60048FD13 /* nin_cifar10_full.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = nin_cifar10_full.json; sourceTree = ""; }; 6B64DA2F1C724F020048FD13 /* conv1.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = conv1.json; sourceTree = ""; }; /* End PBXFileReference section */ @@ -48,7 +47,6 @@ isa = PBXGroup; children = ( 53AC8ACA1D17D2E300778BB5 /* DeepLearningKit.framework */, - 6B0A93761C724DD800D73DEB /* Metal.framework */, 6B0A93731C724DD200D73DEB /* QuartzCore.framework */, 6B0A93621C724D9A00D73DEB /* OSXDeepLearningKitApp */, 6B0A93611C724D9A00D73DEB /* Products */, diff --git a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp.xcodeproj/project.pbxproj b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp.xcodeproj/project.pbxproj index 9ad5497..8938f06 100644 --- a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp.xcodeproj/project.pbxproj +++ b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp.xcodeproj/project.pbxproj @@ -7,29 +7,20 @@ objects = { /* Begin PBXBuildFile section */ + 53AC8ACF1D17D9F600778BB5 /* DeepLearningKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 53AC8ACE1D17D9F600778BB5 /* DeepLearningKit.framework */; }; 6B2942D71C73CCF80002721C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B2942D61C73CCF80002721C /* AppDelegate.swift */; }; 6B2942D91C73CCF80002721C /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B2942D81C73CCF80002721C /* ViewController.swift */; }; 6B2942DC1C73CCF80002721C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6B2942DA1C73CCF80002721C /* Main.storyboard */; }; 6B2942DE1C73CCF80002721C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6B2942DD1C73CCF80002721C /* Assets.xcassets */; }; 6B2942E61C73CE3C0002721C /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B2942E51C73CE3B0002721C /* QuartzCore.framework */; }; - 6B2942E81C73CE410002721C /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B2942E71C73CE410002721C /* Metal.framework */; }; - 6B2942EF1C73CEB20002721C /* MetalDataStructures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B2942E91C73CEB20002721C /* MetalDataStructures.swift */; }; - 6B2942F01C73CEB20002721C /* MetalUtilityFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B2942EA1C73CEB20002721C /* MetalUtilityFunctions.swift */; }; 6B2942F11C73CEB20002721C /* nin_cifar10_full.json in Resources */ = {isa = PBXBuildFile; fileRef = 6B2942EB1C73CEB20002721C /* nin_cifar10_full.json */; }; - 6B2942F21C73CEB20002721C /* PoolingLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B2942EC1C73CEB20002721C /* PoolingLayer.swift */; }; - 6B2942F31C73CEB20002721C /* RectifierLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B2942ED1C73CEB20002721C /* RectifierLayer.swift */; }; - 6B2942F41C73CEB20002721C /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 6B2942EE1C73CEB20002721C /* Shaders.metal */; }; 6B2942FB1C73CEBB0002721C /* conv1.json in Resources */ = {isa = PBXBuildFile; fileRef = 6B2942F51C73CEBB0002721C /* conv1.json */; }; - 6B2942FC1C73CEBB0002721C /* ConvolutionLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B2942F61C73CEBB0002721C /* ConvolutionLayer.swift */; }; - 6B2942FD1C73CEBB0002721C /* DeepNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B2942F71C73CEBB0002721C /* DeepNetwork.swift */; }; - 6B2942FE1C73CEBB0002721C /* DeepNetwork+Classify.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B2942F81C73CEBB0002721C /* DeepNetwork+Classify.swift */; }; - 6B2942FF1C73CEBB0002721C /* DeepNetwork+JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B2942F91C73CEBB0002721C /* DeepNetwork+JSON.swift */; }; - 6B2943001C73CEBB0002721C /* DeepNetwork+SetupNetworkFromDict.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B2942FA1C73CEBB0002721C /* DeepNetwork+SetupNetworkFromDict.swift */; }; 6B57D6321C82E6610082387B /* UIImageExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B57D6311C82E6610082387B /* UIImageExtension.swift */; }; 6B57D63B1C8321980082387B /* ImageUtilityFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B57D63A1C8321980082387B /* ImageUtilityFunctions.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 53AC8ACE1D17D9F600778BB5 /* DeepLearningKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DeepLearningKit.framework; path = "../../../../../../../Users/rafael/Library/Developer/Xcode/DerivedData/DeepLearningKit-csfprtnhalzpycftepmcgcebvxbt/Build/Products/Debug-appletvsimulator/DeepLearningKit.framework"; sourceTree = ""; }; 6B2942D31C73CCF80002721C /* tvOSDeepLearningKitApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = tvOSDeepLearningKitApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 6B2942D61C73CCF80002721C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 6B2942D81C73CCF80002721C /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; @@ -37,19 +28,8 @@ 6B2942DD1C73CCF80002721C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 6B2942DF1C73CCF80002721C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 6B2942E51C73CE3B0002721C /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; - 6B2942E71C73CE410002721C /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; }; - 6B2942E91C73CEB20002721C /* MetalDataStructures.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalDataStructures.swift; sourceTree = ""; }; - 6B2942EA1C73CEB20002721C /* MetalUtilityFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalUtilityFunctions.swift; sourceTree = ""; }; 6B2942EB1C73CEB20002721C /* nin_cifar10_full.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = nin_cifar10_full.json; sourceTree = ""; }; - 6B2942EC1C73CEB20002721C /* PoolingLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PoolingLayer.swift; sourceTree = ""; }; - 6B2942ED1C73CEB20002721C /* RectifierLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RectifierLayer.swift; sourceTree = ""; }; - 6B2942EE1C73CEB20002721C /* Shaders.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Shaders.metal; sourceTree = ""; }; 6B2942F51C73CEBB0002721C /* conv1.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = conv1.json; sourceTree = ""; }; - 6B2942F61C73CEBB0002721C /* ConvolutionLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConvolutionLayer.swift; sourceTree = ""; }; - 6B2942F71C73CEBB0002721C /* DeepNetwork.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeepNetwork.swift; sourceTree = ""; }; - 6B2942F81C73CEBB0002721C /* DeepNetwork+Classify.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DeepNetwork+Classify.swift"; sourceTree = ""; }; - 6B2942F91C73CEBB0002721C /* DeepNetwork+JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DeepNetwork+JSON.swift"; sourceTree = ""; }; - 6B2942FA1C73CEBB0002721C /* DeepNetwork+SetupNetworkFromDict.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DeepNetwork+SetupNetworkFromDict.swift"; sourceTree = ""; }; 6B57D6311C82E6610082387B /* UIImageExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImageExtension.swift; sourceTree = ""; }; 6B57D63A1C8321980082387B /* ImageUtilityFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageUtilityFunctions.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -59,7 +39,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 6B2942E81C73CE410002721C /* Metal.framework in Frameworks */, + 53AC8ACF1D17D9F600778BB5 /* DeepLearningKit.framework in Frameworks */, 6B2942E61C73CE3C0002721C /* QuartzCore.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -70,7 +50,7 @@ 6B2942CA1C73CCF80002721C = { isa = PBXGroup; children = ( - 6B2942E71C73CE410002721C /* Metal.framework */, + 53AC8ACE1D17D9F600778BB5 /* DeepLearningKit.framework */, 6B2942E51C73CE3B0002721C /* QuartzCore.framework */, 6B2942D51C73CCF80002721C /* tvOSDeepLearningKitApp */, 6B2942D41C73CCF80002721C /* Products */, @@ -92,18 +72,8 @@ 6B2942D61C73CCF80002721C /* AppDelegate.swift */, 6B2942D81C73CCF80002721C /* ViewController.swift */, 6B2942F51C73CEBB0002721C /* conv1.json */, - 6B2942F61C73CEBB0002721C /* ConvolutionLayer.swift */, - 6B2942F71C73CEBB0002721C /* DeepNetwork.swift */, - 6B2942F81C73CEBB0002721C /* DeepNetwork+Classify.swift */, - 6B2942F91C73CEBB0002721C /* DeepNetwork+JSON.swift */, - 6B2942FA1C73CEBB0002721C /* DeepNetwork+SetupNetworkFromDict.swift */, 6B2942DA1C73CCF80002721C /* Main.storyboard */, - 6B2942E91C73CEB20002721C /* MetalDataStructures.swift */, - 6B2942EA1C73CEB20002721C /* MetalUtilityFunctions.swift */, 6B2942EB1C73CEB20002721C /* nin_cifar10_full.json */, - 6B2942EC1C73CEB20002721C /* PoolingLayer.swift */, - 6B2942ED1C73CEB20002721C /* RectifierLayer.swift */, - 6B2942EE1C73CEB20002721C /* Shaders.metal */, 6B2942DD1C73CCF80002721C /* Assets.xcassets */, 6B2942DF1C73CCF80002721C /* Info.plist */, 6B57D63A1C8321980082387B /* ImageUtilityFunctions.swift */, @@ -192,18 +162,8 @@ buildActionMask = 2147483647; files = ( 6B57D63B1C8321980082387B /* ImageUtilityFunctions.swift in Sources */, - 6B2942FE1C73CEBB0002721C /* DeepNetwork+Classify.swift in Sources */, - 6B2942EF1C73CEB20002721C /* MetalDataStructures.swift in Sources */, - 6B2942F41C73CEB20002721C /* Shaders.metal in Sources */, 6B2942D91C73CCF80002721C /* ViewController.swift in Sources */, - 6B2942F01C73CEB20002721C /* MetalUtilityFunctions.swift in Sources */, - 6B2942FF1C73CEBB0002721C /* DeepNetwork+JSON.swift in Sources */, - 6B2942F31C73CEB20002721C /* RectifierLayer.swift in Sources */, - 6B2943001C73CEBB0002721C /* DeepNetwork+SetupNetworkFromDict.swift in Sources */, - 6B2942FD1C73CEBB0002721C /* DeepNetwork.swift in Sources */, 6B57D6321C82E6610082387B /* UIImageExtension.swift in Sources */, - 6B2942F21C73CEB20002721C /* PoolingLayer.swift in Sources */, - 6B2942FC1C73CEBB0002721C /* ConvolutionLayer.swift in Sources */, 6B2942D71C73CCF80002721C /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -312,6 +272,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = org.deeplearningkit.tvOSDeepLearningKitApp; PRODUCT_NAME = "$(TARGET_NAME)"; + TVOS_DEPLOYMENT_TARGET = 9.2; }; name = Debug; }; @@ -324,6 +285,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = org.deeplearningkit.tvOSDeepLearningKitApp; PRODUCT_NAME = "$(TARGET_NAME)"; + TVOS_DEPLOYMENT_TARGET = 9.2; }; name = Release; }; diff --git a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ConvolutionLayer.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ConvolutionLayer.swift deleted file mode 100644 index 0cd8dae..0000000 --- a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ConvolutionLayer.swift +++ /dev/null @@ -1,223 +0,0 @@ -// -// ConvolutionLayer.swift -// MemkiteMetal -// -// Created by Amund Tveit on 25/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - - - -func getDataFromBlob(blob: NSDictionary) -> ([Float], [Float]) { - - let shape = blob["shape"] as! NSDictionary - let data = blob["data"] as! [Float] - var FloatData = createFloatNumbersArray(data.count) - for i in 0 ..< data.count { - FloatData[i] = data[i] - } - return (shape["dim"] as! [Float], FloatData) -} - - - -func createConvolutionLayerCached(layer: NSDictionary, - inputBuffer: MTLBuffer, - inputShape: [Float], - metalCommandQueue: MTLCommandQueue, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout layer_data_caches: [Dictionary], - inout blob_cache: [Dictionary], - layer_number: Int, - layer_string: String, caching_mode:Bool) -> (MTLBuffer, MTLCommandBuffer, [Float]) { - - let start = NSDate() - - -// let metalCommandBuffer = metalCommandQueue.commandBuffer() - let metalCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() - - var convolution_params_dict:NSDictionary = NSDictionary() - var pad:Float = 0.0 - var kernel_size:Float = 1.0 - var stride:Float = 1.0 - var blobs:[NSDictionary] = [] - var weights:[Float] = [] - var weight_shape:[Float] = [] - var bias_data:[Float] = [] - var h:Float = 0.0 - var w:Float = 0.0 - var result_shape:[Float] = [] - var outputCount:Int = 0 - - var input_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var weight_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var result_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var tensor_dimensions:[MetalTensorDimensions] = [] - var col_dimensions:MetalTensorDimensions = MetalTensorDimensions(n: 0, channels: 0, width: 0, height:0) - var col_output:[Float] = [] - var convolution_params:MetalConvolutionParameters = MetalConvolutionParameters(pad:0, kernel_size: 0, stride: 0) - - - if(!caching_mode) { - print("NOTCACHINGMODE") - convolution_params_dict = layer["convolution_param"] as! NSDictionary - pad = 0.0 - kernel_size = 1.0 - stride = 1.0 - if let val = convolution_params_dict["pad"] as? Float { - pad = val - } - if let val = convolution_params_dict["kernel_size"] as? Float { - kernel_size = val - } - - let startblob = NSDate() - - - if let tmpval = blob_cache[layer_number]["0"] { - (weight_shape, weights) = tmpval - } else { - blobs = layer["blobs"] as! [NSDictionary] - (weight_shape, weights) = getDataFromBlob(blobs[0]) - blob_cache[layer_number]["0"] = (weight_shape, weights) - } - - blobs = layer["blobs"] as! [NSDictionary] - (_, bias_data) = getDataFromBlob(blobs[1]) - - - - h = (inputShape[2] + 2 * pad - kernel_size) / stride + 1 - w = (inputShape[3] + 2 * pad - kernel_size) / stride + 1 - result_shape = [inputShape[0], weight_shape[0], h, w] - outputCount = Int(result_shape.reduce(1, combine: *)) - - // Create input and output vectors, and corresponding metal buffer - input_dimensions = MetalTensorDimensions(n: inputShape[0], channels: inputShape[1], width: inputShape[2], height: inputShape[3]) - weight_dimensions = MetalTensorDimensions(n: weight_shape[0], channels: weight_shape[1], width: weight_shape[2], height: weight_shape[3]) - col_dimensions = MetalTensorDimensions(n: inputShape[0], channels: inputShape[1] * weight_shape[2] * weight_shape[3], width: inputShape[2], height: inputShape[3]) - result_dimensions = MetalTensorDimensions(n: result_shape[0], channels: result_shape[1], width: result_shape[2], height: result_shape[3]) - tensor_dimensions = [input_dimensions, weight_dimensions, col_dimensions, result_dimensions] - - - col_output = createFloatNumbersArray(Int(col_dimensions.n * col_dimensions.channels * col_dimensions.height * col_dimensions.width)) - - - convolution_params = MetalConvolutionParameters(pad: pad, kernel_size: kernel_size, stride: stride) - - } - - - let resultBuffer = addConvolutionCommandToCommandBufferCached(metalCommandBuffer, inputBuffer: inputBuffer, im2ColCount: col_output.count, weights: weights, outputCount: outputCount, convolution_params: convolution_params, tensor_dimensions: tensor_dimensions, bias: bias_data, metalDefaultLibrary: metalDefaultLibrary, metalDevice:metalDevice, layer_data_caches: &layer_data_caches, layer_number: layer_number,layer_string: layer_string, caching_mode: caching_mode) - //metalCommandBuffer.commit() - - - - return (resultBuffer, metalCommandBuffer, result_shape) - -} - -func addConvolutionCommandToCommandBufferCached(commandBuffer: MTLCommandBuffer, - inputBuffer: MTLBuffer, - im2ColCount: Int, - weights: [Float], - outputCount: Int, - convolution_params: MetalConvolutionParameters, - tensor_dimensions: [MetalTensorDimensions], - bias: [Float], - metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout layer_data_caches: [Dictionary], - layer_number: Int, - layer_string: String, caching_mode:Bool) -> MTLBuffer { - - let start = NSDate() - - print("before output and col_output") - - var output:[Float] = [] - var col_output:[Float] = [] - - if(!caching_mode) { - output = createFloatNumbersArray(outputCount) - col_output = createFloatNumbersArray(im2ColCount) - } - - print("before setupshaderinpipeline") - - let (_, im2colComputePipelineState, _) = setupShaderInMetalPipeline("im2col", metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice) - - let resultMetalBuffer = createOrReuseFloatMetalBuffer("resultMetalBuffer", data: output, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - - print("after resultmetalbuffer") - - let weightMetalBuffer = createOrReuseFloatMetalBuffer("weightMetalBuffer", data: weights, cache: &layer_data_caches, layer_number:layer_number, metalDevice: metalDevice) - - - let convolutionParamsMetalBuffer = createOrReuseConvolutionParametersMetalBuffer("convolutionParamsMetalBuffer", data: convolution_params, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - let tensorDimensionsMetalBuffer = createOrReuseTensorDimensionsVectorMetalBuffer("tensorDimensionsMetalBuffer", data: tensor_dimensions, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - - let colOutputMetalBuffer = createOrReuseFloatMetalBuffer("colOutputMetalBuffer", data: col_output, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - let biasMetalBuffer = createOrReuseFloatMetalBuffer("bias", data: bias, cache: &layer_data_caches, layer_number:layer_number, metalDevice: metalDevice) - - - // Create Metal compute command encoder for im2col - var metalComputeCommandEncoder = commandBuffer.computeCommandEncoder() - metalComputeCommandEncoder.setBuffer(inputBuffer, offset: 0, atIndex: 0) - metalComputeCommandEncoder.setBuffer(tensorDimensionsMetalBuffer, offset: 0, atIndex: 1) - metalComputeCommandEncoder.setBuffer(convolutionParamsMetalBuffer, offset: 0, atIndex: 2) - metalComputeCommandEncoder.setBuffer(colOutputMetalBuffer, offset: 0, atIndex: 3) - //metalComputeCommandEncoder.setComputePipelineState(im2colComputePipelineState) - - - // Set the shader function that Metal will use - metalComputeCommandEncoder.setComputePipelineState(im2colComputePipelineState) - - // Set up thread groups on GPU - // TODO: check out http://metalbyexample.com/introduction-to-compute/ - var threadsPerGroup = MTLSize(width:im2colComputePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - print("before mtlsize 2") - var numThreadgroups = MTLSize(width:(col_output.count-1)/im2colComputePipelineState.threadExecutionWidth + 1, height:1, depth:1) - metalComputeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - print("after dispatch") - - // Finalize configuration - metalComputeCommandEncoder.endEncoding() - - - - - let (_, convolutionComputePipelineState, _) = setupShaderInMetalPipeline("convolution_layer", metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice) - metalComputeCommandEncoder = commandBuffer.computeCommandEncoder() - - // Create Metal Compute Command Encoder and add input and output buffers to it - metalComputeCommandEncoder.setBuffer(resultMetalBuffer, offset: 0, atIndex: 0) - metalComputeCommandEncoder.setBuffer(weightMetalBuffer, offset: 0, atIndex: 1) - metalComputeCommandEncoder.setBuffer(tensorDimensionsMetalBuffer, offset: 0, atIndex: 2) - metalComputeCommandEncoder.setBuffer(colOutputMetalBuffer, offset: 0, atIndex: 3) - metalComputeCommandEncoder.setBuffer(biasMetalBuffer, offset: 0, atIndex: 4) - - // Set the shader function that Metal will use - metalComputeCommandEncoder.setComputePipelineState(convolutionComputePipelineState) - - // Set up thread groups on GPU - // TODO: check out http://metalbyexample.com/introduction-to-compute/ - threadsPerGroup = MTLSize(width:convolutionComputePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - numThreadgroups = MTLSize(width:(outputCount-1)/convolutionComputePipelineState.threadExecutionWidth + 1, height:1, depth:1) - metalComputeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - // Finalize configuration - metalComputeCommandEncoder.endEncoding() - - - - - return resultMetalBuffer - -} - diff --git a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+Classify.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+Classify.swift deleted file mode 100644 index 59b07a2..0000000 --- a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+Classify.swift +++ /dev/null @@ -1,62 +0,0 @@ -// -// DeepNetwork+Classify.swift -// MemkiteMetal -// -// Created by Amund Tveit on 25/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - -public extension DeepNetwork { - // e.g. 32x32x3 for CIFAR-10/100 - // as [1.0, 3.0, 32.0, 32.0] - public func classify(var flattenedTensorWithImage: [Float]) -> Float { - let start = NSDate() - - // from 2.2 in http://memkite.com/blog/2014/12/30/example-of-sharing-memory-between-gpu-and-cpu-with-swift-and-metal-for-ios8/ - /*let xvectorVoidPtr = COpaquePointer(imageBuffer.contents()) - let xvectorFloatPtr = UnsafeMutablePointer(xvectorVoidPtr) - let xvectorFloatBufferPtr = UnsafeMutableBufferPointer(start:xvectorFloatPtr, count: flattenedTensorWithImage.count) - for index in xvectorFloatBufferPtr.startIndex.. NSDictionary? { - print(" ==> loadJSONFile(filename=\(filename)") - - do { - let bundle = NSBundle.mainBundle() - let path = bundle.pathForResource(filename, ofType: "json")! - let jsonData = NSData(contentsOfFile: path) - print(" <== loadJSONFile") - return try NSJSONSerialization.JSONObjectWithData(jsonData!, options: .AllowFragments) as? NSDictionary - } catch _ { - return nil - } -} -} \ No newline at end of file diff --git a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift deleted file mode 100644 index 5f830c0..0000000 --- a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork+SetupNetworkFromDict.swift +++ /dev/null @@ -1,84 +0,0 @@ -// -// DeepNetwork+SetupNetworkFromDict.swift -// MemkiteMetal -// -// Created by Amund Tveit on 10/12/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - -public extension DeepNetwork { - - func setupNetworkFromDict(deepNetworkAsDict: NSDictionary, inputimage: MTLBuffer, inputshape: [Float], caching_mode:Bool) { - - let start = NSDate() - - print(" ==> setupNetworkFromDict()") - // Add input image - var layer_number = 0 - layer_data_caches.append(Dictionary()) // for input - pool_type_caches.append(Dictionary()) - blob_cache.append(Dictionary()) - namedDataLayers.append(("input", inputimage)) - ++layer_number - - - // Add remaining network - var previousBuffer:MTLBuffer = inputimage - var previousShape:[Float] = inputshape - - self.deepNetworkAsDict = deepNetworkAsDict - - // create new command buffer for next layer - var currentCommandBuffer: MTLCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() - - var t = NSDate() - for layer in deepNetworkAsDict["layer"] as! [NSDictionary] { - if let type = layer["type"] as? String { - let layer_string = layer["name"] as! String - - layer_data_caches.append(Dictionary()) - pool_type_caches.append(Dictionary()) - blob_cache.append(Dictionary()) - - - if type == "ReLU" { - self.gpuCommandLayers.append(currentCommandBuffer) - //(previousBuffer, currentCommandBuffer) = createRectifierLayer(previousBuffer) - (previousBuffer, currentCommandBuffer) = createRectifierLayer(previousBuffer, metalCommandQueue:metalCommandQueue, metalDefaultLibrary:metalDefaultLibrary, metalDevice:metalDevice) - self.namedDataLayers.append((layer["name"]! as! String, previousBuffer)) - } else if type == "Pooling" { - self.gpuCommandLayers.append(currentCommandBuffer) - // (previousBuffer, currentCommandBuffer, previousShape) = createPoolingLayer(layer, inputBuffer: previousBuffer, inputShape: previousShape) - (previousBuffer, currentCommandBuffer, previousShape) = createPoolingLayerCached(layer, inputBuffer: previousBuffer, inputShape: previousShape, metalCommandQueue: metalCommandQueue, metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice, pool_type_caches: &pool_type_caches, layer_data_caches: &layer_data_caches, layer_number: layer_number, layer_string: layer_string, caching_mode: caching_mode) - self.namedDataLayers.append((layer["name"]! as! String, previousBuffer)) - } else if type == "Convolution" { - self.gpuCommandLayers.append(currentCommandBuffer) - // (previousBuffer, currentCommandBuffer, previousShape) = createConvolutionLayer(layer, inputBuffer: previousBuffer, inputShape: previousShape) - (previousBuffer, currentCommandBuffer, previousShape) = createConvolutionLayerCached(layer, inputBuffer: previousBuffer, inputShape: previousShape, metalCommandQueue: metalCommandQueue, metalDefaultLibrary:metalDefaultLibrary, metalDevice:metalDevice, layer_data_caches: &layer_data_caches, blob_cache: &blob_cache, layer_number: layer_number, layer_string: layer_string, caching_mode: caching_mode) - - - self.namedDataLayers.append((layer["name"]! as! String, previousBuffer)) - } - let name = layer["name"] as! String - print("\(name): \(NSDate().timeIntervalSinceDate(t))") - t = NSDate() - ++layer_number - - } - } - - self.gpuCommandLayers.append(currentCommandBuffer) - - print("bar") - - print("AFTER LAYER DATA CHACES = \(layer_data_caches[0])") - - print("POOL TYPE CACHES = \(pool_type_caches)") - - print("Time to set up network: \(NSDate().timeIntervalSinceDate(start))") - - } -} diff --git a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork.swift deleted file mode 100644 index f4ddec4..0000000 --- a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/DeepNetwork.swift +++ /dev/null @@ -1,63 +0,0 @@ -// -// DeepNetwork.swift -// MemkiteMetal -// -// Created by Amund Tveit on 24/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - -public class DeepNetwork { - var gpuCommandLayers: [MTLCommandBuffer] = [] - var namedDataLayers: [(String, MTLBuffer)] = [] - var imageBuffer: MTLBuffer! - var metalDevice: MTLDevice! - var metalDefaultLibrary: MTLLibrary! - var metalCommandQueue: MTLCommandQueue! - var deepNetworkAsDict: NSDictionary! // for debugging perhaps - var layer_data_caches: [Dictionary] = [] - var pool_type_caches: [Dictionary] = [] - var dummy_image: [Float]! - var previous_shape: [Float]! - var blob_cache: [Dictionary] = [] - - public init() { - setupMetal() - deepNetworkAsDict = nil - } - - public func loadDeepNetworkFromJSON(networkName: String, inputImage: [Float], inputShape:[Float], caching_mode:Bool) { - print(" ==> loadDeepNetworkFromJSON(networkName=\(networkName)") - if deepNetworkAsDict == nil { - print("loading json file!") - deepNetworkAsDict = loadJSONFile(networkName)! - } - - - // IMAGE INPUT HANDLING START - TODO: hardcode input dimensions, - // and have random data, and then later overwrite the first buffer - //let imageLayer = loadJSONFile("conv1")! - //let imageData: [Float] = imageLayer["input"] as! [Float] - print(inputImage.count) - let imageTensor = createMetalBuffer(inputImage, metalDevice: metalDevice) - - // preLoadMetalShaders(metalDevice, metalDefaultLibrary:metalDefaultLibrary) - - setupNetworkFromDict(deepNetworkAsDict, inputimage: imageTensor, inputshape: inputShape, caching_mode:caching_mode ) - } - - - func setupMetal() { - // Get access to iPhone or iPad GPU - metalDevice = MTLCreateSystemDefaultDevice() - - // Queue to handle an ordered list of command buffers - metalCommandQueue = metalDevice.newCommandQueue() - print("metalCommandQueue = \(unsafeAddressOf(metalCommandQueue))") - - // Access to Metal functions that are stored in Shaders.metal file, e.g. sigmoid() - metalDefaultLibrary = metalDevice.newDefaultLibrary() - } -} diff --git a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/MetalDataStructures.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/MetalDataStructures.swift deleted file mode 100644 index 2cf6e7a..0000000 --- a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/MetalDataStructures.swift +++ /dev/null @@ -1,64 +0,0 @@ -// -// MetalDataStructures.swift -// MemkiteMetal -// -// Created by Amund Tveit on 24/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Foundation -import Metal -import QuartzCore - -////////////////////////////////////////// -// Metal Data Types - their SWIFT Counterparts -////////////////////////////////////////// -public struct MetalComplexNumberType { - var real: Float = 0.0 - var imag: Float = 0.0 -} - -public struct MetalShaderParameters { - let image_xdim: Float - let image_ydim: Float - let num_images: Float - let filter_xdim: Float - let filter_ydim: Float - let num_filters: Float - let conv_xdim: Float // image_xdim - filter_xdim + 1 without striding - let conv_ydim: Float // image_ydim - filter_ydim + 1 without striding - let pool_xdim: Float - let pool_ydim: Float - var b: Float -} - -public struct MetalMatrixVectorParameters { - let x_xdim: Float - let x_ydim: Float - let w_xdim: Float - let w_ydim: Float - let b_xdim: Float - let b_ydim: Float - let result_xdim: Float - let result_ydim: Float -} - -public struct MetalPoolingParameters { - let kernel_size: Float - let pool_stride: Float - let pad: Float -} - -public struct MetalTensorDimensions { - let n: Float - let channels: Float - let width: Float - let height: Float -} - -public struct MetalConvolutionParameters { - let pad: Float - let kernel_size: Float - let stride: Float -} diff --git a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/MetalUtilityFunctions.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/MetalUtilityFunctions.swift deleted file mode 100644 index 7afbf55..0000000 --- a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/MetalUtilityFunctions.swift +++ /dev/null @@ -1,174 +0,0 @@ -// -// MetalUtilFunctions.swift -// MemkiteMetal -// -// Created by Amund Tveit on 24/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - -func createComplexNumbersArray(count: Int) -> [MetalComplexNumberType] { - let zeroComplexNumber = MetalComplexNumberType() - return [MetalComplexNumberType](count: count, repeatedValue: zeroComplexNumber) -} - -func createFloatNumbersArray(count: Int) -> [Float] { - return [Float](count: count, repeatedValue: 0.0) -} - -func createFloatMetalBuffer(var vector: [Float], let metalDevice:MTLDevice) -> MTLBuffer { - let byteLength = vector.count*sizeof(Float) // future: MTLResourceStorageModePrivate - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -// TODO: could perhaps use generics to combine both functions below? -func createComplexMetalBuffer(var vector:[MetalComplexNumberType], let metalDevice:MTLDevice) -> MTLBuffer { - let byteLength = vector.count*sizeof(MetalComplexNumberType) // or size of and actual 1st element object? - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createShaderParametersMetalBuffer(var shaderParameters:MetalShaderParameters, metalDevice:MTLDevice) -> MTLBuffer { - let byteLength = sizeof(MetalShaderParameters) - return metalDevice.newBufferWithBytes(&shaderParameters, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createMatrixShaderParametersMetalBuffer(var params: MetalMatrixVectorParameters, metalDevice: MTLDevice) -> MTLBuffer { - let byteLength = sizeof(MetalMatrixVectorParameters) - return metalDevice.newBufferWithBytes(¶ms, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) - -} - -func createPoolingParametersMetalBuffer(var params: MetalPoolingParameters, metalDevice: MTLDevice) -> MTLBuffer { - let byteLength = sizeof(MetalPoolingParameters) - return metalDevice.newBufferWithBytes(¶ms, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createConvolutionParametersMetalBuffer(var params: MetalConvolutionParameters, metalDevice: MTLDevice) -> MTLBuffer { - let byteLength = sizeof(MetalConvolutionParameters) - return metalDevice.newBufferWithBytes(¶ms, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func createTensorDimensionsVectorMetalBuffer(var vector: [MetalTensorDimensions], metalDevice: MTLDevice) -> MTLBuffer { - let byteLength = vector.count * sizeof(MetalTensorDimensions) - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func setupShaderInMetalPipeline(shaderName:String, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice) -> (shader:MTLFunction!, - computePipelineState:MTLComputePipelineState!, - computePipelineErrors:NSErrorPointer!) { - var shader = metalDefaultLibrary.newFunctionWithName(shaderName) - var computePipeLineDescriptor = MTLComputePipelineDescriptor() - computePipeLineDescriptor.computeFunction = shader - // var computePipelineErrors = NSErrorPointer() - // let computePipelineState:MTLComputePipelineState = metalDevice.newComputePipelineStateWithFunction(shader!, completionHandler: {(}) - var computePipelineErrors = NSErrorPointer() - var computePipelineState:MTLComputePipelineState? = nil - do { - computePipelineState = try metalDevice.newComputePipelineStateWithFunction(shader!) - } catch { - print("catching..") - } - return (shader, computePipelineState, computePipelineErrors) - -} - -func createMetalBuffer(var vector:[Float], metalDevice:MTLDevice) -> MTLBuffer { - let byteLength = vector.count*sizeof(Float) - return metalDevice.newBufferWithBytes(&vector, length: byteLength, options: MTLResourceOptions.CPUCacheModeDefaultCache) -} - -func preLoadMetalShaders(metalDevice: MTLDevice, metalDefaultLibrary: MTLLibrary) { - let shaders = ["avg_pool", "max_pool", "rectifier_linear", "convolution_layer", "im2col"] - for shader in shaders { - setupShaderInMetalPipeline(shader, metalDefaultLibrary: metalDefaultLibrary,metalDevice: metalDevice) // TODO: this returns stuff - } -} - -func createOrReuseFloatMetalBuffer(name:String, data: [Float], inout cache:[Dictionary], layer_number:Int, metalDevice:MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { - print("found key = \(name) in cache") - result = tmpval - } else { - print("didnt find key = \(name) in cache") - result = createFloatMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - // print("DEBUG: cache = \(cache)") - } - - return result -} - - -func createOrReuseConvolutionParametersMetalBuffer(name:String, - data: MetalConvolutionParameters, - inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { - print("found key = \(name) in cache") - result = tmpval - } else { - print("didnt find key = \(name) in cache") - result = createConvolutionParametersMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - -func createOrReuseTensorDimensionsVectorMetalBuffer(name:String, - data:[MetalTensorDimensions],inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { - print("found key = \(name) in cache") - result = tmpval - } else { - print("didnt find key = \(name) in cache") - result = createTensorDimensionsVectorMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - -// -//let sizeParamMetalBuffer = createShaderParametersMetalBuffer(size_params, metalDevice: metalDevice) -//let poolingParamMetalBuffer = createPoolingParametersMetalBuffer(pooling_params, metalDevice: metalDevice) - -func createOrReuseShaderParametersMetalBuffer(name:String, - data:MetalShaderParameters,inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { -// print("found key = \(name) in cache") - result = tmpval - } else { -// print("didnt find key = \(name) in cache") - result = createShaderParametersMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - -func createOrReusePoolingParametersMetalBuffer(name:String, - data:MetalPoolingParameters,inout cache:[Dictionary], layer_number: Int, metalDevice: MTLDevice) -> MTLBuffer { - var result:MTLBuffer - if let tmpval = cache[layer_number][name] { -// print("found key = \(name) in cache") - result = tmpval - } else { -// print("didnt find key = \(name) in cache") - result = createPoolingParametersMetalBuffer(data, metalDevice: metalDevice) - cache[layer_number][name] = result - //print("DEBUG: cache = \(cache)") - } - - return result -} - - diff --git a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/PoolingLayer.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/PoolingLayer.swift deleted file mode 100644 index 2ec59df..0000000 --- a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/PoolingLayer.swift +++ /dev/null @@ -1,151 +0,0 @@ -// -// PoolingLayer.swift -// MemkiteMetal -// -// Created by Amund Tveit on 25/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - - -func createPoolingLayerCached(layer: NSDictionary, - inputBuffer: MTLBuffer, - inputShape: [Float], - metalCommandQueue: MTLCommandQueue, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout pool_type_caches: [Dictionary], - inout layer_data_caches: [Dictionary], - layer_number: Int, - layer_string: String, - caching_mode:Bool) -> (MTLBuffer, MTLCommandBuffer, [Float]) { - - print(" ==> createPoolingLayerCached") - let metalCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() -// let metalCommandBuffer = metalCommandQueue.commandBuffer() - - var params = NSDictionary() - var stride:Float = 1.0 - var kernel_size: Float = 1.0 - var pad: Float = 0.0 - var pooling_params = MetalPoolingParameters(kernel_size: kernel_size, pool_stride: stride, pad: pad) - var pool_type = 0 - var h:Float = 0.0 - var w:Float = 0.0 - var shape:[Float] = [] - var outputCount:Float = 0 - var pool_width = 0 - var pool_height = 0 - var size_params:MetalShaderParameters = MetalShaderParameters(image_xdim:0.0, image_ydim:0.0, num_images: 0.0, filter_xdim: 0.0, filter_ydim: 0.0, num_filters: 0.0, conv_xdim: 0.0, conv_ydim: 0.0, pool_xdim: 0.0, pool_ydim: 0.0, b:0.0) - var outputBuffer:MTLBuffer - - if(!caching_mode) { - - params = layer["pooling_param"] as! NSDictionary - stride = 1.0 - kernel_size = 1.0 - pad = 0.0 - if let val = params["stride"] { - stride = val as! Float - } - if let val = params["kernel_size"] { - kernel_size = val as! Float - if val as! NSNumber != 3 { - pad = 0 - } - } - pooling_params = MetalPoolingParameters(kernel_size: kernel_size, pool_stride: stride, pad: pad) - pool_type = params["pool"] as! Int - - // STORE pool type in cache! - pool_type_caches[layer_number]["pool_type"] = String(pool_type) - - //TODO: calculate outputCount - h = ceil((inputShape[2] + 2.0 * pad - kernel_size) / stride) + 1.0 - w = ceil((Float(inputShape[3]) + 2.0 * pad - kernel_size) / stride) + 1.0 - shape = [inputShape[0], inputShape[1], h, w] - outputCount = shape.reduce(1, combine: *) - pool_width = Int(shape[2]) - pool_height = Int(shape[3]) - size_params = MetalShaderParameters(image_xdim: Float(inputShape[2]), image_ydim: Float(inputShape[3]), - num_images: Float(inputShape[0]), - filter_xdim: 1.0, filter_ydim: 1.0, num_filters: Float(inputShape[1]), - conv_xdim:0.0, conv_ydim: 0.0, - pool_xdim: Float(pool_width), pool_ydim: Float(pool_height), b:0.0) - } else { - // need to fetch pool type from cache - print("FETCHING POOL TYPE FROM CACHE!!!!!") - pool_type = Int(pool_type_caches[layer_number]["pool_type"]!)! - } - - if pool_type == 1 { - outputBuffer = addPoolingCommandToCommandBufferCached(metalCommandBuffer, poolingMethod: "avg_pool", inputBuffer: inputBuffer, outputCount: Int(outputCount), size_params: size_params, pooling_params: pooling_params, metalDefaultLibrary: metalDefaultLibrary, metalDevice:metalDevice, - layer_data_caches: &layer_data_caches, layer_number: layer_number, layer_string: layer_string) - } else { - outputBuffer = addPoolingCommandToCommandBufferCached(metalCommandBuffer, poolingMethod: "max_pool", inputBuffer: inputBuffer, outputCount: Int(outputCount), size_params: size_params, pooling_params: pooling_params,metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice, - layer_data_caches: &layer_data_caches, layer_number: layer_number, layer_string: layer_string) - - } - //metalCommandBuffer.commit() - - print(" <== createPoolingLayerCached") - - - return (outputBuffer, metalCommandBuffer, shape) -} - - -func addPoolingCommandToCommandBufferCached(commandBuffer: MTLCommandBuffer, - poolingMethod: String, - inputBuffer: MTLBuffer, - outputCount: Int, - size_params: MetalShaderParameters, - pooling_params: MetalPoolingParameters, - metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice, - inout layer_data_caches: [Dictionary], - layer_number: Int, - layer_string: String) -> MTLBuffer { - - - print(" ==> addPoolingCommandtoCommandBufferCached") - - var layer_data_cache = layer_data_caches[layer_number] - - let output = createFloatNumbersArray(outputCount) - let (_, computePipelineState, _) = setupShaderInMetalPipeline(poolingMethod, metalDefaultLibrary: metalDefaultLibrary, metalDevice: metalDevice) - - let outputMetalBuffer = createOrReuseFloatMetalBuffer("outputMetalBuffer", data: output, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - // let outputMetalBuffer = createFloatMetalBuffer(output, metalDevice: metalDevice) - - let sizeParamMetalBuffer = createOrReuseShaderParametersMetalBuffer("sizeParamMetalBuffer", data: size_params, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - - // let sizeParamMetalBuffer = createShaderParametersMetalBuffer(size_params, metalDevice: metalDevice) - - - // let poolingParamMetalBuffer = createPoolingParametersMetalBuffer(pooling_params, metalDevice: metalDevice) - let poolingParamMetalBuffer = createOrReusePoolingParametersMetalBuffer("poolingParamMetalBuffer", data: pooling_params, cache: &layer_data_caches, layer_number: layer_number, metalDevice: metalDevice) - // Create Metal Compute Command Encoder and add input and output buffers to it - let metalComputeCommandEncoder = commandBuffer.computeCommandEncoder() - metalComputeCommandEncoder.setBuffer(outputMetalBuffer, offset: 0, atIndex: 0) - metalComputeCommandEncoder.setBuffer(inputBuffer, offset: 0, atIndex: 1) - metalComputeCommandEncoder.setBuffer(sizeParamMetalBuffer, offset: 0, atIndex: 2) - metalComputeCommandEncoder.setBuffer(poolingParamMetalBuffer, offset: 0, atIndex: 3) - - // Set the shader function that Metal will use - metalComputeCommandEncoder.setComputePipelineState(computePipelineState) - - // Set up thread groups on GPU - // TODO: check out http://metalbyexample.com/introduction-to-compute/ - let threadsPerGroup = MTLSize(width:computePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - let numThreadgroups = MTLSize(width:(outputCount-1)/computePipelineState.threadExecutionWidth + 1, height:1, depth:1) - metalComputeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - // Finalize configuration - metalComputeCommandEncoder.endEncoding() - - print(" <== addPoolingCommandtoCommandBufferCached") - - - return outputMetalBuffer -} diff --git a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/RectifierLayer.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/RectifierLayer.swift deleted file mode 100644 index efc27ad..0000000 --- a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/RectifierLayer.swift +++ /dev/null @@ -1,54 +0,0 @@ -// -// RectifierLayer.swift -// MemkiteMetal -// -// Created by Amund Tveit on 25/11/15. -// Copyright © 2015 memkite. All rights reserved. -// - -import Foundation -import Metal - -func createRectifierLayer(inputBuffer: MTLBuffer, metalCommandQueue: MTLCommandQueue, metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice) -> (MTLBuffer,MTLCommandBuffer) { - print(" ==> createrectifierlayer") -// let metalCommandBuffer = metalCommandQueue.commandBuffer() - let metalCommandBuffer = metalCommandQueue.commandBufferWithUnretainedReferences() - - let result = addRectifierCommandToCommandBuffer(metalCommandBuffer, inputBuffer: inputBuffer, - metalDefaultLibrary: metalDefaultLibrary, metalDevice:metalDevice) - //metalCommandBuffer.commit() - - print(" <== createrectifierlayer") - return (result, metalCommandBuffer) -} - - -func addRectifierCommandToCommandBuffer(commandBuffer: MTLCommandBuffer, inputBuffer: MTLBuffer, - metalDefaultLibrary:MTLLibrary, metalDevice:MTLDevice) -> MTLBuffer { - - print("==> addRectifierToCommandBuffer") - - let count = inputBuffer.length / sizeof(Float) - let (_, computePipelineState, _) = setupShaderInMetalPipeline("rectifier_linear", metalDefaultLibrary: metalDefaultLibrary, - metalDevice: metalDevice) - - // Create Metal Compute Command Encoder and add input and output buffers to it - let computeCommandEncoder = commandBuffer.computeCommandEncoder() - computeCommandEncoder.setBuffer(inputBuffer, offset: 0, atIndex: 0) - // Set the shader function that Metal will use - computeCommandEncoder.setComputePipelineState(computePipelineState) - - // Set up thread groups on GPU - // TODO: check out http://metalbyexample.com/introduction-to-compute/ - let threadsPerGroup = MTLSize(width:computePipelineState.threadExecutionWidth,height:1,depth:1) - // ensure at least 1 threadgroup - let numThreadgroups = MTLSize(width:(count-1)/computePipelineState.threadExecutionWidth + 1, height:1, depth:1) - computeCommandEncoder.dispatchThreadgroups(numThreadgroups, threadsPerThreadgroup: threadsPerGroup) - - // Finalize configuration - computeCommandEncoder.endEncoding() - - print(" <== addRectifierToCommandBuffer") - - return inputBuffer -} diff --git a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Shaders.metal b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Shaders.metal deleted file mode 100644 index 0b496a9..0000000 --- a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/Shaders.metal +++ /dev/null @@ -1,224 +0,0 @@ -// -// Shaders.metal -// memkite -// -// Created by Amund Tveit on 13/08/15. -// Copyright © 2015 Amund Tveit. All rights reserved. -// - -#include -#include -#include -#include -#include -#include -#include -#include // why? -using namespace metal; - -//////////////////////////////// -// DATA TYPES -//////////////////////////////// - -// TODO: perhaps add RGB support as part of this -struct MetalComplexNumberType { // needs to map to float2 in Metal - float real; - float imag; -}; - -// TODO: perhaps add B here? since it is only one value per convolution call (not entire vector) -struct MetalShaderParameters { - float image_xdim; - float image_ydim; - float num_images; - float filter_xdim; // e.g. 5 - float filter_ydim; // e.g. 5 - float num_filters; // e.g. 20 -> W = 20*1*5*5 - float conv_xdim; // image_xdim - filter_xdim + 1 without striding - float conv_ydim; // image_ydim - filter_ydim + 1 without striding - float pool_xdim; - float pool_ydim; - float b; // this should probably be an input array, but for now -}; - -struct MetalMatrixVectorParameters { - float x_xdim; - float x_ydim; - float w_xdim; - float w_ydim; - float b_xdim; - float b_ydim; - float result_xdim; - float result_ydim; -}; - -struct MetalPoolingParameters { - float kernel_size; - float pool_stride; - float pad; -}; - -struct MetalTensorDimensions { - float n; - float channels; - float width; - float height; -}; - -struct MetalConvolutionParameters { - float pad; - float kernel_size; - float stride; -}; - -//////////////////////////////// -// SHADER FUNCTIONS -//////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////////// - - -// Returns max(0, X[id]) -kernel void rectifier_linear(device float* X [[ buffer(0)]], - uint id [[ thread_position_in_grid ]]) { - X[id] = fmax(0.0, X[id]); -} - -kernel void max_pool(device float* result [[ buffer(0) ]], - const device float* input [[ buffer(1) ]], - const device MetalShaderParameters* size_params [[ buffer(2) ]], - const device MetalPoolingParameters* pooling_params [[ buffer(3) ]], - uint id [[ thread_position_in_grid ]]) { - int channels = int(size_params[0].num_filters); - int in_width = int(size_params[0].image_xdim); - int in_height = int(size_params[0].image_ydim); - - float kernel_size = float(pooling_params[0].kernel_size); - int pool_stride = int(pooling_params[0].pool_stride); - int pad = int(pooling_params[0].pad); - - int out_width = int(size_params[0].pool_xdim); - int out_height = int(size_params[0].pool_ydim); - - int i = (id / out_height) % out_width; - int j = id % out_height; - int n = id / (channels * out_width * out_height); - int c = (id / (out_width * out_height)) % channels; - int wstart = i * pool_stride - pad; - int hstart = j * pool_stride - pad; - int wend = fmin(wstart + kernel_size, in_width + pad); - int hend = fmin(hstart + kernel_size, in_height + pad); - wstart = fmax(0.0, wstart); - hstart = fmax(0.0, hstart); - thread float pool = -100000.0; - for (int ii = wstart; ii < wend; ++ii) { - for (int jj = hstart; jj < hend; ++jj) { - pool = fmax(pool, input[(n * channels * in_height + c * in_height + ii) * in_width + jj]); - } - } - result[id] = pool; -} - -kernel void avg_pool(device float* result [[ buffer(0) ]], - const device float* input [[ buffer(1) ]], - const device MetalShaderParameters* size_params [[ buffer(2) ]], - const device MetalPoolingParameters* pooling_params [[ buffer(3) ]], - uint id [[ thread_position_in_grid ]]) { - int channels = int(size_params[0].num_filters); - int in_width = int(size_params[0].image_xdim); - int in_height = int(size_params[0].image_ydim); - - float kernel_size = float(pooling_params[0].kernel_size); - int pool_stride = int(pooling_params[0].pool_stride); - int pad = int(pooling_params[0].pad); - - int out_width = int(size_params[0].pool_xdim); - int out_height = int(size_params[0].pool_ydim); - - int i = (id / out_height) % out_width; - int j = id % out_height; - int n = id / (channels * out_width * out_height); - int c = (id / (out_width * out_height)) % channels; - int wstart = i * pool_stride - pad; - int hstart = j * pool_stride - pad; - int wend = fmin(wstart + kernel_size, in_width + pad); - int hend = fmin(hstart + kernel_size, in_height + pad); - float pool_size = (hend - hstart) * (wend - wstart); - wstart = fmax(0.0, wstart); - hstart = fmax(0.0, hstart); - thread float pool = 0.0; - for (int ii = wstart; ii < wend; ++ii) { - for (int jj = hstart; jj < hend; ++jj) { - pool += input[(n * channels * in_height + c * in_height + ii) * in_width + jj]/pool_size; - } - } - result[id] = pool; -} - -kernel void im2col(const device float* convolution_input [[ buffer(0)]], - const device MetalTensorDimensions* tensor_dimensions [[ buffer(1) ]], - const device MetalConvolutionParameters* convolution_params [[ buffer(2) ]], - device float* col_output [[ buffer(3) ]], - uint id [[ thread_position_in_grid ]]) { - int num = int(tensor_dimensions[0].n); - int channels_in = int(tensor_dimensions[0].channels); - int in_width = int(tensor_dimensions[0].width); - int in_height = int(tensor_dimensions[0].height); - - int channels_col = int(tensor_dimensions[2].channels); - int width_col = int(tensor_dimensions[2].width); - int height_col = int(tensor_dimensions[2].height); - - - // 1. do an im2col transformation - int pad = int(convolution_params[0].pad); - int kernel_size = int(convolution_params[0].kernel_size); - - int n = id / (channels_col * height_col * width_col); - int c = (id / (width_col * height_col)) % channels_col; - int h = (id / width_col) % height_col; - int w = id % width_col; - int w_offset = c % kernel_size; - int h_offset = (c / kernel_size) % kernel_size; - int h_pad = h - pad + h_offset; - int w_pad = w - pad + w_offset; - int c_im = c / (kernel_size * kernel_size); - if (h_pad >= 0 && h_pad < in_height && w_pad >= 0 && w_pad < in_width) { - col_output[id] = convolution_input[(n * channels_in * in_height + c_im * in_height + h_pad) * in_width + w_pad]; - } -} - -// Tensor dimensions = { input_dimensions, weight_dimensions, col_dimensions, result_dimensions } -kernel void convolution_layer(device float* result [[ buffer(0) ]], - const device float* weights [[ buffer(1)]], - const device MetalTensorDimensions* tensor_dimensions [[ buffer(2) ]], - const device float* col_output [[ buffer(3) ]], - const device float* bias [[ buffer(4) ]], - uint id [[ thread_position_in_grid ]]) { - //int num = int(tensor_dimensions[2].n); - int channels_col = int(tensor_dimensions[2].channels); - int width_col = int(tensor_dimensions[2].width); - int height_col = int(tensor_dimensions[2].height); - - int channels_out = int(tensor_dimensions[3].channels); - int width_out = int(tensor_dimensions[3].width); - int height_out = int(tensor_dimensions[3].height); - - int n = id / (channels_out * height_out * width_out); - int a = (id / (height_out * width_out)) % channels_out; - int b = id % (height_out * width_out); - - thread float foo = bias[a]; - - for (int c = 0; c < channels_col; ++c) { -// result[id] += weights[a * channels_col + c] * col_output[(n * channels_col * width_col + c * width_col) * height_col + b]; - foo += weights[a * channels_col + c] * col_output[(n * channels_col * width_col + c * width_col) * height_col + b]; - } - -// result[id] += bias[a]; - - result[id] = foo; -} - - - diff --git a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ViewController.swift b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ViewController.swift index de044f4..b0a512d 100644 --- a/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ViewController.swift +++ b/Examples/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/tvOSDeepLearningKitApp/ViewController.swift @@ -7,6 +7,7 @@ // import UIKit +import DeepLearningKit class ViewController: UIViewController { @@ -37,22 +38,20 @@ class ViewController: UIViewController { let imageShape:[Float] = [1.0, 3.0, 32.0, 32.0] - var caching_mode = false - // 0. load network in network model - deepNetwork.loadDeepNetworkFromJSON("nin_cifar10_full", inputImage: image, inputShape: imageShape, caching_mode:caching_mode) + deepNetwork.loadNetworkFromJson("nin_cifar10_full") // 1. classify image (of cat) - deepNetwork.classify(image) + deepNetwork.classify(image, shape:imageShape) // 2. reset deep network and classify random image - deepNetwork.loadDeepNetworkFromJSON("nin_cifar10_full", inputImage: randomimage, inputShape: imageShape,caching_mode:caching_mode) - deepNetwork.classify(randomimage) + deepNetwork.loadNetworkFromJson("nin_cifar10_full") + deepNetwork.classify(randomimage, shape:imageShape) // 3. reset deep network and classify cat image again - deepNetwork.loadDeepNetworkFromJSON("nin_cifar10_full", inputImage: image, inputShape: imageShape,caching_mode:caching_mode) - deepNetwork.classify(image) + deepNetwork.loadNetworkFromJson("nin_cifar10_full") + deepNetwork.classify(image, shape:imageShape) exit(0) }