Skip to content

Instantly share code, notes, and snippets.

--- before42031/VariableTypeEverything.cpp 2020-07-31 13:16:02.450902000 -0700
+++ after42031/VariableTypeEverything.cpp 2020-07-31 13:06:18.799446000 -0700
@@ -46,22 +46,6 @@
// Later when we merge the mobile op registration the anonymous namespace
// will be restored.
// namespace {
-Tensor __and___Scalar(const Tensor & self, Scalar other) {
- auto result = TypeDefault::__and___Scalar(self, other);
- return result;
-}
# No difference in VariableType
λ ~/pytorch033 cat diff_TypeDefault
--- TypeDefault_before 2020-08-03 16:23:14.155651681 -0700
+++ TypeDefault_after 2020-08-03 16:17:08.590947589 -0700
@@ -3904,6 +3904,8 @@
m.impl("conv_transpose3d.input",
torch::CppFunction::makeUnboxedOnly(&TypeDefault::conv_transpose3d_input));
m.def("copy_(Tensor(a!) self, Tensor src, bool non_blocking=False) -> Tensor(a!)");
+ m.impl("copy_",
@ailzhang
ailzhang / gist:1d6a0f0a9d4a6970722ab8f2068e4c2a
Created March 10, 2021 03:56
InplaceOrViewTypeEverything.cpp
#include "torch/csrc/autograd/VariableTypeUtils.h"
#include <torch/library.h>
#include "torch/csrc/autograd/function.h"
#include <ATen/RedispatchFunctions.h>
#include "ATen/quantized/Quantizer.h"
// @generated from tools/autograd/templates/InplaceOrViewType.cpp
diff --git a/fbcode/caffe2/aten/src/ATen/core/dispatch/DispatchKeyExtractor.h b/fbcode/caffe2/aten/src/ATen/core/dispatch/DispatchKeyExtractor.h
--- a/fbcode/caffe2/aten/src/ATen/core/dispatch/DispatchKeyExtractor.h
+++ b/fbcode/caffe2/aten/src/ATen/core/dispatch/DispatchKeyExtractor.h
@@ -49,7 +49,8 @@
// it's a bit troublesome, because fastpath TLS access requires the type of
// the TLS in question to be zero-initialized, so you don't actually win
// anyting in that case.
- return (((ks | local.included_ | always_included) - local.excluded_) & key_mask);
+ // For the addtional XOR op, see note [TLS Initialization]
+ return (((ks | (local.included_ ^ c10::InplaceOrView_keyset) | always_included) - local.excluded_) & key_mask);
diff --git a/fbcode/caffe2/c10/core/DispatchKeySet.h b/fbcode/caffe2/c10/core/DispatchKeySet.h
--- a/fbcode/caffe2/c10/core/DispatchKeySet.h
+++ b/fbcode/caffe2/c10/core/DispatchKeySet.h
@@ -82,6 +82,10 @@
DispatchKeySet operator-(DispatchKeySet other) const {
return DispatchKeySet(repr_ & ~other.repr_);
}
+ // Compute self ^ other
+ DispatchKeySet operator^(DispatchKeySet other) const {
+ return DispatchKeySet(repr_ ^ other.repr_);
diff --git a/fbcode/caffe2/c10/core/DispatchKeySet.h b/fbcode/caffe2/c10/core/DispatchKeySet.h
--- a/fbcode/caffe2/c10/core/DispatchKeySet.h
+++ b/fbcode/caffe2/c10/core/DispatchKeySet.h
@@ -82,6 +82,10 @@
DispatchKeySet operator-(DispatchKeySet other) const {
return DispatchKeySet(repr_ & ~other.repr_);
}
+ // Compute self ^ other
+ DispatchKeySet operator^(DispatchKeySet other) const {
+ return DispatchKeySet(repr_ ^ other.repr_);

Functionalization

Link to prototype branch: https://github.com/ailzhang/pytorch/commit/83f647e9f14a89e61378c8e834aec4dfbcb74a00

Quick summary:

This prototype only focus on getting rid of aliasing in view ops, after this Func2 you can safely assume that after Func2 kernel you won't see any view ops, but only view_op_copy ops that returns completely new storage.

You can build this branch and check some examples by running python test/base_to_view.py and python test/view_to_base.py. But this branch is only a proof of concept and comes with a lot of hacks, and requires some careful design work described in the section below.

# Authored by Tiantian Liu, Taichi Graphics.
import taichi as ti
import math
ti.init(arch=ti.cpu)
# global control
paused = ti.field(ti.i32, ())
# gravitational constant 6.67408e-11, using 1 for simplicity
# Authored by Yuanming Hu, Taichi Graphics.
import taichi as ti
ti.init(arch=ti.gpu)
max_num_particles = 1024
substeps = 10
spring_Y = 1000 # Young's modulus
drag_damping = 1
dashpot_damping = 100
  1. Install Vulkan SDK from https://vulkan.lunarg.com/sdk/home#mac
  2. Set the following env
VULKAN_SDK=~/VulkanSDK/1.2.189.0/macOS
export VULKAN_SDK
#PATH="$PATH:$VULKAN_SDK/bin"
PATH="$VULKAN_SDK/bin:$PATH"
export PATH