Skip to content

Commit 296e827

Browse files
committed
Update
[ghstack-poisoned]
2 parents 173018e + 5ca60ad commit 296e827

File tree

4 files changed

+109
-2
lines changed

4 files changed

+109
-2
lines changed

backends/cadence/reference/operators/quantized_conv_out.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ __attribute__((noinline)) void conv2d_nchw_core_generic(
119119
if (((_h + d0 * _wh - p0) >= 0) &&
120120
((_h + d0 * _wh - p0) < h) &&
121121
((_w + d1 * _ww - p1) >= 0) &&
122-
((_w + d1 * _ww - p1 < w))) {
122+
((_w + d1 * _ww - p1) < w)) {
123123
int ioff =
124124
(_h + d0 * _wh - p0) * w + (_w + d1 * _ww - p1);
125125
int woff = _wh * ww + _ww;

backends/vulkan/runtime/graph/ops/glsl/conv2d_pw.glsl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ ${layout_declare_ubo(8, "float", "out_min", "float", "out_max")}
3333
layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in;
3434

3535
// shared memory to hold calculated positions, this would reduce register usage thus improving performance.
36-
shared ivec2 pos_shared[gl_WorkGroupSize.x * gl_WorkGroupSize.y * gl_WorkGroupSize.z * TILE_SIZE * TILE_SIZE];
36+
// 64 is the number of threads in the local wg
37+
$num_shared = 64 * TILE_SIZE * TILE_SIZE
38+
shared ivec2 pos_shared[${num_shared}];
3739

3840
/*
3941
* Computes a 2D pointwise convolution of an NxN output tile. Calculating an
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
2+
3+
# pyre-strict
4+
5+
import copy
6+
from typing import List, OrderedDict, Tuple
7+
8+
import torch
9+
from inputgen.argtuple.gen import ArgumentTupleGenerator
10+
from inputgen.specs.model import ConstraintProducer as cp
11+
from inputgen.utils.random_manager import random_manager
12+
from inputgen.variable.type import ScalarDtype
13+
from specdb.db import SpecDictDB
14+
15+
# seed to generate identical cases every run to reproduce from bisect
16+
random_manager.seed(1729)
17+
18+
19+
def apply_tensor_contraints(op_name: str, tensor_constraints: list[object]) -> None:
20+
match op_name:
21+
case (
22+
"sigmoid.default"
23+
| "_softmax.default"
24+
| "rsqrt.default"
25+
| "exp.default"
26+
| "mul.Tensor"
27+
| "div.Tensor"
28+
):
29+
tensor_constraints.append(
30+
cp.Dtype.In(lambda deps: [torch.float]),
31+
)
32+
case (
33+
"add.Tensor"
34+
| "sub.Tensor"
35+
| "add.Scalar"
36+
| "sub.Scalar"
37+
| "mul.Scalar"
38+
| "div.Scalar"
39+
):
40+
tensor_constraints.append(
41+
cp.Dtype.In(lambda deps: [torch.float, torch.int]),
42+
)
43+
case _:
44+
tensor_constraints.append(
45+
cp.Dtype.In(lambda deps: [torch.float, torch.int]),
46+
)
47+
tensor_constraints.extend(
48+
[
49+
cp.Value.Ge(lambda deps, dtype, struct: -(2**8)),
50+
cp.Value.Le(lambda deps, dtype, struct: 2**8),
51+
cp.Rank.Ge(lambda deps: 1),
52+
cp.Rank.Le(lambda deps: 2**2),
53+
cp.Size.Ge(lambda deps, r, d: 1),
54+
cp.Size.Le(lambda deps, r, d: 2**2),
55+
]
56+
)
57+
58+
59+
def facto_testcase_gen(op_name: str) -> List[Tuple[List[str], OrderedDict[str, str]]]:
60+
# minimal example to test add.Tensor using FACTO
61+
spec = SpecDictDB[op_name]
62+
63+
for index, in_spec in enumerate(copy.deepcopy(spec.inspec)):
64+
if in_spec.type.is_scalar():
65+
if in_spec.name != "alpha":
66+
spec.inspec[index].constraints.extend(
67+
[
68+
cp.Dtype.In(lambda deps: [ScalarDtype.float, ScalarDtype.int]),
69+
cp.Value.Ge(lambda deps, dtype: -(2**8)),
70+
cp.Value.Le(lambda deps, dtype: 2**2),
71+
cp.Size.Ge(lambda deps, r, d: 1),
72+
cp.Size.Le(lambda deps, r, d: 2**2),
73+
]
74+
)
75+
else:
76+
spec.inspec[index].constraints.extend(
77+
[
78+
cp.Value.Gt(lambda deps, dtype: 0),
79+
cp.Value.Le(lambda deps, dtype: 2),
80+
]
81+
)
82+
elif in_spec.type.is_tensor():
83+
tensor_constraints = []
84+
# common tensor constraints
85+
apply_tensor_contraints(op_name, tensor_constraints)
86+
spec.inspec[index].constraints.extend(tensor_constraints)
87+
88+
return [
89+
(posargs, inkwargs)
90+
for posargs, inkwargs, _ in ArgumentTupleGenerator(spec).gen()
91+
]

examples/cadence/operators/targets.bzl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# LICENSE file in the root directory of this source tree.
66

77
load("@fbcode_macros//build_defs:python_unittest.bzl", "python_unittest")
8+
load("@fbcode_macros//build_defs:python_library.bzl", "python_library")
89

910
TESTS_LIST = [
1011
"add_op",
@@ -16,6 +17,19 @@ def define_common_targets():
1617
for op in TESTS_LIST:
1718
_define_test_target(op)
1819

20+
python_library(
21+
name = "facto_util",
22+
srcs = [
23+
"facto_util.py",
24+
],
25+
typing = True,
26+
deps = [
27+
"fbcode//caffe2:torch",
28+
"fbcode//pytorch/facto:inputgen",
29+
"fbcode//pytorch/facto:specdb",
30+
],
31+
)
32+
1933

2034
def _define_test_target(test_name):
2135
file_name = "test_{}".format(test_name)

0 commit comments

Comments
 (0)