Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 40dffe83929973c8e205c395be5db23c360c2397
Author: Denny Sun <[email protected]>
Date:   Thu Mar 23 05:06:51 2023 +0000

    Merged PR 3176: [Accera] split_dim op supports dynamic dims with static split size

    With this fix the following test case which has dynamic dims with static split size can succeed.

    ```
            M, MN = create_dimensions()
            N = 16

            Input = Array(role=Role.INPUT, element_type=ScalarType.float32, shape=(MN,))
            Output = Array(role=Role.INPUT_OUTPUT, element_type=ScalarType.float32, shape=(M, N))

            nest = Nest(shape=(M, N))
            i, j = nest.get_indices()

            @nest.iteration_logic
            def _():
                split_input = Input._split_dimension(0, cast(16, ScalarType.index))
                Output[i, j] = split_input[i, j]
    ```

commit 451b67405d77ebbe1cf0722f9c7aeb191c3b4beb
Author: Mason Remy <[email protected]>
Date:   Thu Mar 23 01:19:37 2023 +0000

    Merged PR 3174: Ensure any dynamic allocations are heap allocs that get dealloced

    Ensure any dynamic allocations are heap allocs

commit 602b068f19cdf1ff9111aacbeb5d704974521ebd
Author: Kern Handa <[email protected]>
Date:   Wed Mar 22 20:59:43 2023 +0000

    Merged PR 3171: [test] Add some tests for Dimensions

commit ccd1f5c39964fbe96815672f137b5185ee2e9885
Author: Mason Remy <[email protected]>
Date:   Wed Mar 22 19:41:02 2023 +0000

    Merged PR 3175: Support reinterpret cast of same bitwidth without changing layout

    Support reinterpret cast of same bitwidth without changing layout

commit 270a3c8a9c1e1c06b0da3c9d61fa2f04438e3076
Author: Kern Handa <[email protected]>
Date:   Fri Mar 17 22:16:08 2023 +0000

    Merged PR 3167: Remove hack to treat INPUT_OUTPUT Arrays with shape (1,) as Elements

    I don't have complete context on this, so this might break something. If it does, that should be fixed separately rather than keep this hack around, which breaks semantics in non-obvious ways.

commit efcff61727c64e7f0a37f4f92c701bc47ea1c470
Author: Lisa Ong <[email protected]>
Date:   Fri Mar 17 08:09:07 2023 +0000

    Merged PR 3165: [build] Fix clang 14 release build warnings treated as errors on macOS/Apple

    Errors are showing up on release builds:

    ```
    cmake .. -DCMAKE_BUILD_TYPE=Release -G Ninja
    cmake --build . --config Release
    ```

    Clang version:
    ```
    Apple clang version 14.0.0 (clang-1400.0.29.202)
    Target: arm64-apple-darwin22.3.0
    Thread model: posix
    ```

commit 43f311aa706214243ce8d7acca7d29993bb7003b
Author: Lisa Ong <[email protected]>
Date:   Fri Mar 17 07:02:09 2023 +0000

    Merged PR 3162: Bump vcpkg to latest release

    Last release was Sept 2022. Update to the latest tag (2023.02.24)

    Preparation for LLVM 15 upgrade

commit 07098f502596d997bbe241e95f1130c11e318220
Author: Mason Remy <[email protected]>
Date:   Thu Mar 16 23:27:04 2023 +0000

    Merged PR 3161: Fix cache reduce scale constant hoisting

    Fix cache reduce scale constant hoisting

commit 696ef0df5947067f94b64255e00b7fffc4c04f9d
Author: Mason Remy <[email protected]>
Date:   Thu Mar 16 20:54:22 2023 +0000

    Merged PR 3163: Extend vector masked loads/stores to handle arbitrary bin ops and constant operands

    Extend vector masked loads/stores to handle arbitrary bin ops and
    constant operands
  • Loading branch information
Lisa Ong committed Mar 24, 2023
1 parent f55e4d8 commit 1127a60
Show file tree
Hide file tree
Showing 24 changed files with 852 additions and 245 deletions.
13 changes: 8 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ option(STRICT_MODE "Build with 'warnings as errors'" OFF)
option(USE_MKL "Build with Intel MKL" OFF)

option(USE_LIBCXX "Build with libc++ if using the Clang compiler" OFF)
if(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
if(CMAKE_CXX_COMPILER_ID STREQUAL Clang OR CMAKE_CXX_COMPILER_ID STREQUAL AppleClang)
if(USE_LIBCXX OR (CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin))
add_compile_options(-stdlib=libc++)
link_libraries(-lc++ -lc++abi)
endif(USE_LIBCXX OR (CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin))
endif(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
endif(CMAKE_CXX_COMPILER_ID STREQUAL Clang OR CMAKE_CXX_COMPILER_ID STREQUAL AppleClang)

# Try to create a compilation database, which is useful to have when working
# with clang tooling
Expand Down Expand Up @@ -161,10 +161,13 @@ else()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb3 -O0")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -ggdb3")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -ggdb3")
if(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)

if(CMAKE_CXX_COMPILER_ID STREQUAL Clang OR CMAKE_CXX_COMPILER_ID STREQUAL AppleClang)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
# Set options for Control Flow Integrity
add_compile_options(-fsanitize=cfi)
# Set options for Control Flow Integrity
if(NOT ${OSX_NATIVE_ARCH} STREQUAL "arm64")
add_compile_options(-fsanitize=cfi)
endif()
endif(CMAKE_BUILD_TYPE STREQUAL Debug)

add_compile_options(-Wno-backslash-newline-escape)
Expand Down
6 changes: 6 additions & 0 deletions accera/hat/include/HATEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ class Parameter : public TOMLSerializable
return SerializeCommonParameters();
}

virtual ~Parameter() = default;

protected:
Parameter(const LogicalParamType& logicalType, const std::string& name, const std::string& description, const UsageType usage, const std::string& declaredType, const std::string& elementType) :
_logicalType{ logicalType },
Expand Down Expand Up @@ -415,6 +417,8 @@ class Function : public TOMLSerializable
_description{ description },
_callingConvention{ callingConvention } {}

virtual ~Function() = default;

std::string Name() const { return _name; }

std::string Description() const { return _description; }
Expand Down Expand Up @@ -1021,6 +1025,8 @@ class ExternalLibraryReference : public TOMLSerializable
return table;
}

virtual ~ExternalLibraryReference() = default;

private:
std::string _name;
std::string _version;
Expand Down
10 changes: 7 additions & 3 deletions accera/ir/include/value/ValueOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,13 @@ def accv_CallOp : accv_Op<"call", [CallOpInterface]> {
$_state.addOperands(operands);
$_state.addAttribute("callee", callee);
$_state.addTypes(results);
}]>, OpBuilder<(ins "StringRef":$callee, "ArrayRef<Type>":$results, CArg<"ValueRange", "{}">:$operands), [{
build($_builder, $_state, StringAttr::get($_builder.getContext(), callee), results,
operands);

// BUGBUG: -Werror,-Winfinite-recursion, needed?
// }]>, OpBuilder<(ins "StringRef":$callee, "ArrayRef<Type>":$results, CArg<"ValueRange", "{}">:$operands), [{
// build($_builder, $_state, StringAttr::get($_builder.getContext(), callee), results,
// operands);
//

}]>];

let extraClassDeclaration = [{
Expand Down
2 changes: 1 addition & 1 deletion accera/ir/src/AffineConstraintsHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ namespace util
if (_cst.containsId(val))
{
unsigned id = 0;
bool found = _cst.findId(val, &id);
[[maybe_unused]] bool found = _cst.findId(val, &id);
assert(found);
return IdWrapper::FromFullId(id, _cst);
}
Expand Down
8 changes: 0 additions & 8 deletions accera/ir/src/TranslateToHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,14 +750,6 @@ namespace ir
}
std::vector<size_t> shapeVec;
std::transform(shape.begin(), shape.end(), std::back_inserter(shapeVec), [](int64_t val) { return static_cast<size_t>(val); });
if (usage != hat::UsageType::Input && shapeVec.size() == 1 && shapeVec[0] == 1)
{
// TODO: This is currently a hack since output Dimension does not work. So in the DSL we use Array
// instead and here we emulate an ElementParameter instead. Remove this when output Dimension are working.
assert(declaredType.back() == '*');
return std::make_unique<hat::ElementParameter>(name, description, usage, declaredType.substr(0, declaredType.length() - 1), elementType);
}

return std::make_unique<hat::AffineArrayParameter>(name, description, usage, declaredType, elementType, shapeVec, affineMap, affineOffset);
}

Expand Down
6 changes: 3 additions & 3 deletions accera/ir/src/value/ValueDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,9 @@ MemRefType ViewOp::computeMemRefType(Value source, ValueRange sizes, ValueRange
auto context = source.getContext();
auto sourceMemRefType = source.getType().cast<mlir::MemRefType>();
int64_t sourceRank = sourceMemRefType.getRank();
int64_t numOffsets = static_cast<int64_t>(offsets.size());
int64_t numSizes = static_cast<int64_t>(sizes.size());
int64_t numStrides = static_cast<int64_t>(strides.size());
[[maybe_unused]] int64_t numOffsets = static_cast<int64_t>(offsets.size());
[[maybe_unused]] int64_t numSizes = static_cast<int64_t>(sizes.size());
[[maybe_unused]] int64_t numStrides = static_cast<int64_t>(strides.size());
assert(sourceRank == numOffsets);
assert(sourceRank == numSizes);
assert(sourceRank == numStrides);
Expand Down
22 changes: 14 additions & 8 deletions accera/python/accera/lang/Array.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from operator import mul
from typing import *

from .._lang_python import ScalarType, _MemoryLayout, AllocateFlags, Role
from .._lang_python import ScalarType, _MemoryLayout, AllocateFlags, Role, type_size_bytes
from .._lang_python._lang import Array as NativeArray, Dimension
from .Layout import Layout, MemoryMapLayout
from ..Parameter import DelayedParameter
Expand Down Expand Up @@ -177,22 +177,28 @@ def _value(self):
return None

def _reinterpret_cast_internal(self, element_type):
if any(map(lambda d: isinstance(d, Dimension), self.shape)):
expected_layout = [-1]
src_element_size = type_size_bytes(self.element_type)
dst_element_size = type_size_bytes(element_type)
if src_element_size == dst_element_size:
expected_layout = self.shape
else:
src_element_size = np.dtype(SCALAR_TYPE_TO_DTYPE_STR[self.element_type]).itemsize
dst_element_size = np.dtype(SCALAR_TYPE_TO_DTYPE_STR[element_type]).itemsize
expected_layout = [int(self._num_elements * (src_element_size / dst_element_size))]
if any(map(lambda d: isinstance(d, Dimension), self.shape)):
expected_layout = [-1]
else:
expected_layout = [int(self._num_elements * (src_element_size / dst_element_size))]
reinterpreted = Array(role=self.role, element_type=element_type, shape=expected_layout)
return reinterpreted

def _get_memory_buffer(self):
return self._reinterpret_cast_internal(ScalarType.uint8)

def _reinterpret_cast(self, element_type):
if self.element_type != ScalarType.uint8 or len(self.shape) != 1:
src_bytewidth = type_size_bytes(self.element_type)
dst_bytewidth = type_size_bytes(element_type)
if src_bytewidth != dst_bytewidth and \
(self.element_type != ScalarType.uint8 or len(self.shape) != 1):
raise RuntimeError(
"Can only call reinterpret cast on flat uint8 memory buffers. Call _get_memory_buffer first?"
"Can only call reinterpret cast such that the bitwidth doesn't change, or on flat uint8 memory buffers. Call _get_memory_buffer first?"
)

return self._reinterpret_cast_internal(element_type)
Expand Down
49 changes: 43 additions & 6 deletions accera/python/accera/test/dsl_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,22 @@ def test_reinterpret_cast(self) -> None:
shape=(256, 256),
)

def reinterpret_arr_as_int16(array: Array):
# Assumes array is f32

num_elements = reduce(lambda x, y: x*y, array.shape, 1)
arr_mb = array._get_memory_buffer()
self.assertEqual(arr_mb.shape, [num_elements * 4])
self.assertEqual(arr_mb.element_type, ScalarType.uint8)
print(arr_mb.layout)

arr_as_int16 = arr_mb._reinterpret_cast(ScalarType.int16)
self.assertEqual(arr_as_int16.shape, [num_elements * 2])
self.assertEqual(arr_as_int16.element_type, ScalarType.int16)
print(arr_as_int16.layout)

return arr_as_int16

def reinterpret_arr_as_int32(array: Array):
# Assumes array is f32

Expand All @@ -656,9 +672,19 @@ def reinterpret_arr_as_int32(array: Array):

return arr_as_int32

def simple_reinterpret_arr_as_int32(array: Array):
# Assumes array is f32

num_elements = reduce(lambda x, y: x*y, array.shape, 1)
arr_as_int32 = array._reinterpret_cast(ScalarType.int32)
self.assertEqual(arr_as_int32.shape, array.shape)
self.assertEqual(arr_as_int32.element_type, ScalarType.int32)
print(arr_as_int32.layout)

return arr_as_int32

# add a function that utilizes a subarray layout
def make_reinterpreted_fn(array):
reinterpreted = reinterpret_arr_as_int32(array)
def make_reinterpreted_fn(array, reinterpreted):
nest = Nest(shape=reinterpreted.shape)
i = nest.get_indices()

Expand All @@ -668,12 +694,23 @@ def _():

return package.add(nest, args=(reinterpreted, ))

reinterpreted_fn = make_reinterpreted_fn(arr)
reinterpreted_i32 = reinterpret_arr_as_int32(arr)
reinterpreted_i32_fn = make_reinterpreted_fn(arr, reinterpreted_i32)

reinterpreted_i16 = reinterpret_arr_as_int16(arr)
reinterpreted_i16_fn = make_reinterpreted_fn(arr, reinterpreted_i16)

simple_reinterpreted_i32 = simple_reinterpret_arr_as_int32(arr)
simple_reinterpreted_i32_fn = make_reinterpreted_fn(arr, simple_reinterpreted_i32)

# add a function that instantiates a subarray of the input array and calls the function above
def main(array):
reinterpreted_array = reinterpret_arr_as_int32(array)
reinterpreted_fn(reinterpreted_array)
reinterpreted_array_i32 = reinterpret_arr_as_int32(array)
reinterpreted_array_i16 = reinterpret_arr_as_int16(array)
simple_reinterpreted_array_i32 = simple_reinterpret_arr_as_int32(array)
reinterpreted_i32_fn(reinterpreted_array_i32)
reinterpreted_i16_fn(reinterpreted_array_i16)
simple_reinterpreted_i32_fn(simple_reinterpreted_array_i32)

package.add(main, args=(arr, ))

Expand Down Expand Up @@ -1432,7 +1469,7 @@ def _():
}

# TODO: Disabling this verification for now, re-enable it when undoing this change.
# self._verify_helper(package, get_size_fn_name, get_size_fn.name, correctness_check_values)
self._verify_helper(package, get_size_fn_name, get_size_fn.name, correctness_check_values)

correctness_check_values = {
"pre": [size_test, x_ref, start_array_pre_test, delta_test],
Expand Down
Loading

0 comments on commit 1127a60

Please sign in to comment.