Skip to content

Instantly share code, notes, and snippets.

View philipturner's full-sized avatar
🏠
Working from home

Philip Turner philipturner

🏠
Working from home
View GitHub Profile
import Foundation
import PythonKit
// Replace the path below with where your Python is located.
//PythonLibrary.useLibrary(at: "/Users/philipturner/miniforge3/bin/python")
let torch = Python.import("torch")
let nn = torch.nn
let DataLoader = torch.utils.data.DataLoader
let torchvision = Python.import("torchvision")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
////////// model_training_walkthrough.ipynb
// ========================================================
import TensorFlow
import PythonKit
import Foundation
import FoundationNetworking
func download(from sourceString: String, to destinationString: String) {
let source = URL(string: sourceString)!
let destination = URL(fileURLWithPath: destinationString)
tensorflow_version="2.9.1"
DESTDIR=${PWD}/Library/tensorflow-${tensorflow_version}
if [[ $(uname -s) == "Darwin" ]]; then
lib_end="dylib" # macOS
else
lib_end="so" # Linux
fi
# ===----------------------------------------------------------------------=== #
#if canImport(Darwin) // Apple platforms
import OpenCL
#else
// Don't know how to import OpenCL on Linux yet. It should be possible if I
// wrap it in a Clang module and link that to Swift.
#endif
/*
Sourced from this online tutorial:
https://www.eriksmistad.no/getting-started-with-opencl-and-gpu-computing/
////////////////////////////////////////////////////////////////////////////////
// Header file
////////////////////////////////////////////////////////////////////////////////
#include <metal_stdlib>
using namespace metal;
struct Double {
float lo;
float hi;
// I suspect that the crash is caused by a memory leak at runtime. It keeps
// crashing at random places. Once, it even crashed at the end of `llvm::orc::
// runAsMain`.
// I transformed it into a cast that I am 100% sure is allowed, and it still
// crashed, but less than 100% of the time. In the possibly illegal form, it
// crashed exactly 100% of the time.
// It seems like a valid cast in the code. It is a differentiable_function_expr
// but it is cached somewhere. I noticed that removing the previous declaration
import _Differentiation
func myFunc(x: Float, y: Float) -> Float { x + y }
let item: @differentiable(reverse) (Float, Float) -> Float = myFunc
class Box<T> {
var value: T
init(value: T) {
self.value = value
# Prepare for building S4TF
# Ensure this is your toolchain's bundle identifier. The one hard-coded is for
# May 4, 2022. That may not be your toolchain.
export TOOLCHAINS="org.swift.57202205041a"
# I plan to upgrade to v2.9.0-rc2 soon, so you may need to change this part of
# the script soon.
tensorflow_version="2.8.0"
# What ever directory this script is in, should contain the unzipped "Library"
# folder.
macOS 13, 10c CPU, 32c GPU, 1 TB SSD
| | | +-o AGXAcceleratorG13X <class AGXAcceleratorG13X, id 0x100000983, registered, matched, active, busy 0 (11866 ms), retain 77>
| | | | {
| | | | "SchedulerState" = {"Stamps"=(),"BusyWorkQueues"=()}
| | | | "IOMatchedAtBoot" = Yes
| | | | "vendor-id" = <6b100000>
| | | | "GPURawCounterBundleName" = "AGXGPURawCounterBundle"
| | | | "MetalStatisticsName" = "AGXMetalStatisticsExternalA14X"
| | | | "AGXParameterBufferMaxSizeEverMemless" = 1149763584