mat task adapts L4
This commit is contained in:
@@ -1,10 +1,19 @@
|
||||
StgSharp.Native layout
|
||||
# StgSharp.Native
|
||||
|
||||
## COMPILE
|
||||
|
||||
Though this project do has a .vcxproj file,
|
||||
you can only edit but not compile in visul studio.
|
||||
Currently you can only compile this lib via Clang and cmake.
|
||||
|
||||
## Code Layout
|
||||
|
||||
Conventions:
|
||||
|
||||
- src/ : project C sources and CMakeLists.txt calling add_library/add_executable
|
||||
- include/ : public headers (if used)
|
||||
- external/ : third-party libraries, each library lives in its own folder
|
||||
- <libname>/
|
||||
- libname/
|
||||
- head/ : header files for the library
|
||||
- lib/ : static or shared lib files (or CMake build for that lib)
|
||||
|
||||
|
||||
@@ -170,16 +170,32 @@ SN_MK_PROC_DECL_STD(double, 512, , fill);
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , quality);
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , fma_pack);
|
||||
SN_MK_PROC_DECL_STD(float, avx, , fma_pack);
|
||||
SN_MK_PROC_DECL_STD(float, 512, , fma_pack);
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , fma);
|
||||
SN_MK_PROC_DECL_STD(float, avx, , fma);
|
||||
SN_MK_PROC_DECL_STD(float, avx, _fma, fma);
|
||||
SN_MK_PROC_DECL_STD(float, 512, , fma);
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , fma_unpack);
|
||||
SN_MK_PROC_DECL_STD(float, avx, , fma_unpack);
|
||||
SN_MK_PROC_DECL_STD(float, 512, , fma_unpack);
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, sse, , fma_pack);
|
||||
SN_MK_PROC_DECL_STD(double, avx, , fma_pack);
|
||||
SN_MK_PROC_DECL_STD(double, 512, , fma_pack);
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, sse, , fma);
|
||||
SN_MK_PROC_DECL_STD(double, avx, , fma);
|
||||
SN_MK_PROC_DECL_STD(double, avx, _fma, fma);
|
||||
SN_MK_PROC_DECL_STD(double, 512, , fma);
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, sse, , fma_unpack);
|
||||
SN_MK_PROC_DECL_STD(double, avx, , fma_unpack);
|
||||
SN_MK_PROC_DECL_STD(double, 512, , fma_unpack);
|
||||
|
||||
SN_SK_PROC_DECL_STD(float, avx, , add);
|
||||
SN_SK_PROC_DECL_STD(float, 512, , add);
|
||||
|
||||
|
||||
@@ -46,9 +46,9 @@
|
||||
#define zero_vec
|
||||
#define zero_vec_256
|
||||
|
||||
#define ALIGN(simdVec)
|
||||
#define ALIGN256(simdVec)
|
||||
#define ALIGN512(simdVec)
|
||||
#define ALIGN(simdVec)
|
||||
#define ALIGN256(simdVec)
|
||||
#define ALIGN512(simdVec)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -79,6 +79,27 @@ typedef struct sn_L4_cache_head {
|
||||
uint64_t reverse_mask_2;
|
||||
} sn_L4_cache_head;
|
||||
|
||||
typedef struct sn_L4_handle {
|
||||
void *ptr;
|
||||
sn_L4_cache_head head;
|
||||
} sn_L4_handle;
|
||||
|
||||
typedef struct matrix_task_pack {
|
||||
sn_L4_handle buffer_0;
|
||||
sn_L4_handle buffer_1;
|
||||
sn_L4_handle buffer_2;
|
||||
sn_L4_handle buffer_3;
|
||||
uint64_t reverse_0;
|
||||
uint64_t reverse_1;
|
||||
uint64_t reverse_2;
|
||||
uint64_t reverse_3;
|
||||
uint64_t reverse_4;
|
||||
uint64_t reverse_5;
|
||||
uint64_t reverse_6;
|
||||
uint64_t reverse_7;
|
||||
|
||||
} matrix_task_pack;
|
||||
|
||||
typedef struct matrix_task {
|
||||
void *mat_0;
|
||||
void *mat_1;
|
||||
@@ -95,7 +116,7 @@ typedef struct matrix_task {
|
||||
scalar_pack padding;
|
||||
} matrix_task;
|
||||
|
||||
#define MAT_TASK(T) matrix_task
|
||||
#define MAT_TASK(T) matrix_task_pack
|
||||
|
||||
#if defined(__cplusplus)
|
||||
static_assert(sizeof(matrix_task) == 128, "matrix_parallel_task_package size mismatch");
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#define SN_STD_TARGET_ATTR(T_arch, T_feature) SN_STD_TARGET_ATTR_IMPL(T_arch, T_feature)
|
||||
|
||||
#pragma region mk_proc attributes
|
||||
#define MK_PROC_NAME_STD(T_type, T_arch, T_feature, T_op) \
|
||||
T_type##_multi_kernel_proc_##T_op##_##T_arch##_##T_feature
|
||||
#define GET_MK_PROC_STD(T_type, T_arch, T_feature, T_op) \
|
||||
@@ -18,6 +19,9 @@
|
||||
#define SN_MK_PROC_DECL_STD(T_type, T_arch, T_feature, T_op) \
|
||||
INTERNAL NOINLINE SN_STD_TARGET_ATTR(T_arch, T_feature) void SN_DECL MK_PROC_NAME_STD( \
|
||||
T_type, T_arch, T_feature, T_op)(MAT_TASK(T_type) const *task)
|
||||
#pragma endregion
|
||||
|
||||
#pragma region sk_proc attributes
|
||||
#define SK_PROC_NAME_STD(T_type, T_arch, T_feature, T_op) \
|
||||
T_type##_single_kernel_proc_##T_op##_##T_arch##_##T_feature
|
||||
#define GET_SK_PROC_STD(T_type, T_arch, T_feature, T_op) \
|
||||
@@ -27,6 +31,7 @@
|
||||
T_type, T_arch, T_feature, \
|
||||
T_op)(MAT_KERNEL(T_type) const *left, MAT_KERNEL(T_type) const *right, \
|
||||
MAT_KERNEL(T_type) *restrict ans, uint64_t scalar)
|
||||
#pragma endregion
|
||||
|
||||
#define _SN_STD__PROBE_0 0
|
||||
#define _SN_STD__PROBE_1 1
|
||||
@@ -42,27 +47,27 @@
|
||||
#define _SN_MATPROC_ANS_SCALAR 1
|
||||
|
||||
#define _SN_MK_EXPAND_RIGHT_ANS \
|
||||
SN_MAT_KERNEL_LOCAL const *right = (SN_MAT_KERNEL_LOCAL const *)task->mat_1; \
|
||||
SN_MAT_KERNEL_LOCAL *restrict ans = (SN_MAT_KERNEL_LOCAL *)task->mat_2;
|
||||
SN_MAT_KERNEL_LOCAL const *right = (SN_MAT_KERNEL_LOCAL const *)task->buffer_1.ptr; \
|
||||
SN_MAT_KERNEL_LOCAL *restrict ans = (SN_MAT_KERNEL_LOCAL *)task->buffer_2.ptr;
|
||||
|
||||
#define _SN_MK_EXPAND_LEFT_RIGHT_ANS \
|
||||
SN_MAT_KERNEL_LOCAL const *left = (SN_MAT_KERNEL_LOCAL const *)task->mat_0; \
|
||||
SN_MAT_KERNEL_LOCAL const *right = (SN_MAT_KERNEL_LOCAL const *)task->mat_1; \
|
||||
SN_MAT_KERNEL_LOCAL *restrict ans = (SN_MAT_KERNEL_LOCAL *)task->mat_2;
|
||||
SN_MAT_KERNEL_LOCAL const *left = (SN_MAT_KERNEL_LOCAL const *)task->buffer_0.ptr; \
|
||||
SN_MAT_KERNEL_LOCAL const *right = (SN_MAT_KERNEL_LOCAL const *)task->buffer_1.ptr; \
|
||||
SN_MAT_KERNEL_LOCAL *restrict ans = (SN_MAT_KERNEL_LOCAL *)task->buffer_2.ptr;
|
||||
|
||||
#define _SN_MK_EXPAND_RIGHT_ANS_SCALAR \
|
||||
SN_MAT_KERNEL_LOCAL const *right = (SN_MAT_KERNEL_LOCAL const *)task->mat_1; \
|
||||
SN_MAT_KERNEL_LOCAL *restrict ans = (SN_MAT_KERNEL_LOCAL *)task->mat_2; \
|
||||
SN_MAT_KERNEL_LOCAL const *right = (SN_MAT_KERNEL_LOCAL const *)task->buffer_1.ptr; \
|
||||
SN_MAT_KERNEL_LOCAL *restrict ans = (SN_MAT_KERNEL_LOCAL *)task->buffer_2.ptr; \
|
||||
scalar_pack *restrict scalar = (scalar_pack *restrict)task->scalar;
|
||||
|
||||
#define _SN_MK_EXPAND_LEFT_RIGHT_ANS_SCALAR \
|
||||
SN_MAT_KERNEL_LOCAL const *left = (SN_MAT_KERNEL_LOCAL const *)task->mat_0; \
|
||||
SN_MAT_KERNEL_LOCAL const *right = (SN_MAT_KERNEL_LOCAL const *)task->mat_1; \
|
||||
SN_MAT_KERNEL_LOCAL *restrict ans = (SN_MAT_KERNEL_LOCAL *)task->mat_2; \
|
||||
SN_MAT_KERNEL_LOCAL const *left = (SN_MAT_KERNEL_LOCAL const *)task->buffer_0.ptr; \
|
||||
SN_MAT_KERNEL_LOCAL const *right = (SN_MAT_KERNEL_LOCAL const *)task->buffer_1.ptr; \
|
||||
SN_MAT_KERNEL_LOCAL *restrict ans = (SN_MAT_KERNEL_LOCAL *)task->buffer_2.ptr; \
|
||||
scalar_pack *restrict scalar = (scalar_pack *restrict)task->scalar;
|
||||
|
||||
#define _SN_MK_EXPAND_ANS_SCALAR \
|
||||
SN_MAT_KERNEL_LOCAL *restrict ans = (SN_MAT_KERNEL_LOCAL *)task->mat_2; \
|
||||
SN_MAT_KERNEL_LOCAL *restrict ans = (SN_MAT_KERNEL_LOCAL *)task->buffer_2.ptr; \
|
||||
scalar_pack *restrict scalar = (scalar_pack *restrict)&(task->padding);
|
||||
|
||||
#define _SN_PARAM_STYLE(T) _SN_MATPROC_##T
|
||||
@@ -90,6 +95,7 @@
|
||||
size_t common_x = UNSAFE_AS(size_t, task->common_x); \
|
||||
size_t common_y = UNSAFE_AS(size_t, task->common_y); \
|
||||
size_t common_z = UNSAFE_AS(size_t, task->common_z);
|
||||
|
||||
#define _MK_MKPROC_EXPAND_INDEX_TILE \
|
||||
size_t x = UNSAFE_AS(size_t, task->x); \
|
||||
size_t y = UNSAFE_AS(size_t, task->y); \
|
||||
@@ -104,7 +110,7 @@
|
||||
|
||||
#define __mk_param_std(mem, param, T) \
|
||||
typedef MAT_KERNEL(T) SN_MAT_KERNEL_LOCAL; \
|
||||
matrix_task const *_ = (_SN_PARAM_STYLE(param), (_SN_MEM_LAYOUT(mem)), task); \
|
||||
matrix_task_pack const *_ = (_SN_PARAM_STYLE(param), (_SN_MEM_LAYOUT(mem)), task); \
|
||||
_SN_MK_EXPAND_PARAM(param); \
|
||||
_SN_MK_EXPAND_MEM(mem)
|
||||
|
||||
|
||||
@@ -7,12 +7,35 @@
|
||||
#include "sn_intrinsic.std.h"
|
||||
#include "sn_intrinsic.context.x86.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define _FMA_SELECT(i) _MM_SHUFFLE(i, i, i, i)
|
||||
|
||||
#define GET_INDEX(col_len, x, y) (col_len * x + y)
|
||||
|
||||
// float
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , fma_pack)
|
||||
{
|
||||
__mk_param_std(TILE, RIGHT_ANS, float);
|
||||
|
||||
memcpy(ans, right, sizeof(MAT_KERNEL(float)) * common_y * common_z);
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, avx, , fma_pack)
|
||||
{
|
||||
__mk_param_std(TILE, RIGHT_ANS, float);
|
||||
|
||||
memcpy(ans, right, sizeof(MAT_KERNEL(float)) * common_y * common_z);
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, 512, , fma_pack)
|
||||
{
|
||||
__mk_param_std(TILE, RIGHT_ANS, float);
|
||||
|
||||
memcpy(ans, right, sizeof(MAT_KERNEL(float)) * common_y * common_z);
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , fma)
|
||||
{
|
||||
__mk_param_std(TILE, LEFT_RIGHT_ANS, float);
|
||||
|
||||
Reference in New Issue
Block a user