-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pytorch] rewrite MemRef container in C++
Signed-off-by: Avimitin <[email protected]>
- Loading branch information
Showing
8 changed files
with
92 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
includes = [ | ||
../memref.h | ||
../memref.hpp | ||
]; | ||
|
||
buddyOptArgs = [ | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "memref.hpp" | ||
|
||
extern "C" void _mlir_ciface_forward(MemRef<float, 1> *output, | ||
MemRef<float, 1> *arg1, | ||
MemRef<float, 1> *arg2); | ||
|
||
// One-dimension, with length 512 | ||
static const int32_t sizes[1] = {512}; | ||
|
||
__attribute((section(".vdata"))) float input_float_1[512] = {1, 2, 3}; | ||
MemRef<float, 1> input1(input_float_1, sizes); | ||
|
||
__attribute((section(".vdata"))) float input_float_2[512] = {4, 5, 6}; | ||
MemRef<float, 1> input2(input_float_2, sizes); | ||
|
||
__attribute((section(".vdata"))) float output_float_1[512]; | ||
MemRef<float, 1> output(output_float_1, sizes); | ||
|
||
extern "C" int test() { | ||
_mlir_ciface_forward(&output, &input1, &input2); | ||
return 0; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#ifndef MEMREF_H | ||
#define MEMREF_H | ||
|
||
#include <cstddef> | ||
#include <cstdint> | ||
|
||
template <typename T, size_t N> class MemRef { | ||
public: | ||
constexpr MemRef(T *data, const int32_t sizes[N]); | ||
|
||
protected: | ||
inline void setStrides(); | ||
|
||
// https://github.com/llvm/llvm-project/blob/a50b9633357007ff886f3fd228ca4b8a9b9b9852/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp#L401 | ||
T *allocated = nullptr; | ||
T *aligned = nullptr; | ||
int32_t offset = 0; | ||
int32_t sizes[N]; | ||
int32_t strides[N]; | ||
}; | ||
|
||
template <typename T, std::size_t N> constexpr | ||
MemRef<T, N>::MemRef(T *data, const int32_t sizes[N]) { | ||
for (size_t i = 0; i < N; i++) { | ||
this->sizes[i] = sizes[i]; | ||
} | ||
|
||
setStrides(); | ||
|
||
allocated = data; | ||
aligned = data; | ||
} | ||
|
||
template <typename T, std::size_t N> inline void MemRef<T, N>::setStrides() { | ||
strides[N - 1] = 1; | ||
if (N < 2) | ||
return; | ||
|
||
for (std::size_t i = N - 1; i > 0; i--) { | ||
strides[i - 1] = strides[i] * sizes[i]; | ||
} | ||
} | ||
|
||
#endif |