From cfc5fedbb6df2471493b1ec162d0024485618211 Mon Sep 17 00:00:00 2001
From: AlexeyAB <alexeyab84@gmail.com>
Date: Tue, 10 Jul 2018 20:29:15 +0000
Subject: [PATCH] Just used spaces for indents instead of Tabs
---
src/gemm.c | 208 ++++++++++++++++++++++++++--------------------------
1 files changed, 104 insertions(+), 104 deletions(-)
diff --git a/src/gemm.c b/src/gemm.c
index 506687b..2b90b05 100644
--- a/src/gemm.c
+++ b/src/gemm.c
@@ -87,7 +87,7 @@
#include <immintrin.h>
#include <smmintrin.h>
-#else // Linux GCC/Clang
+#else // Linux GCC/Clang
#include <x86intrin.h>
#include <ammintrin.h>
#include <immintrin.h>
@@ -96,124 +96,124 @@
void asm_cpuid(uint32_t* abcd, uint32_t eax)
{
- uint32_t ebx = 0, edx = 0, ecx = 0;
+ uint32_t ebx = 0, edx = 0, ecx = 0;
- // EBX is saved to EDI and later restored
- __asm__("movl %%ebx, %%edi;"
- "cpuid;"
- "xchgl %%ebx, %%edi;"
- : "=D"(ebx),
- "+a"(eax), "+c"(ecx), "=d"(edx));
+ // EBX is saved to EDI and later restored
+ __asm__("movl %%ebx, %%edi;"
+ "cpuid;"
+ "xchgl %%ebx, %%edi;"
+ : "=D"(ebx),
+ "+a"(eax), "+c"(ecx), "=d"(edx));
- abcd[0] = eax;
- abcd[1] = ebx;
- abcd[2] = ecx;
- abcd[3] = edx;
+ abcd[0] = eax;
+ abcd[1] = ebx;
+ abcd[2] = ecx;
+ abcd[3] = edx;
}
#endif
int simd_detect_x86(unsigned int idFeature)
{
- uint32_t regs[4]; // EAX, EBX, ECX, EDX;
+ uint32_t regs[4]; // EAX, EBX, ECX, EDX;
#ifdef _WIN32
- __cpuid(regs, 0);
- if (regs[0] > 1U) __cpuid(regs, 1);
+ __cpuid(regs, 0);
+ if (regs[0] > 1U) __cpuid(regs, 1);
#else
- __get_cpuid(0, ®s[0], ®s[1], ®s[2], ®s[3]);
- if(regs[0] > 1U) __get_cpuid(1, ®s[0], ®s[1], ®s[2], ®s[3]);
+ __get_cpuid(0, ®s[0], ®s[1], ®s[2], ®s[3]);
+ if(regs[0] > 1U) __get_cpuid(1, ®s[0], ®s[1], ®s[2], ®s[3]);
#endif
- if ((regs[2] & idFeature) != idFeature)
- return 0;
- return 1;
+ if ((regs[2] & idFeature) != idFeature)
+ return 0;
+ return 1;
}
int is_fma_avx() {
- static int result = -1;
- if (result == -1) {
- result = simd_detect_x86(AVXFlag);
- if (result == 1) printf(" Used AVX \n");
- else printf(" Not used AVX \n");
- }
- return result;
+ static int result = -1;
+ if (result == -1) {
+ result = simd_detect_x86(AVXFlag);
+ if (result == 1) printf(" Used AVX \n");
+ else printf(" Not used AVX \n");
+ }
+ return result;
}
// https://software.intel.com/sites/landingpage/IntrinsicsGuide
void gemm_nn(int M, int N, int K, float ALPHA,
- float *A, int lda,
- float *B, int ldb,
- float *C, int ldc)
+ float *A, int lda,
+ float *B, int ldb,
+ float *C, int ldc)
{
- int i, j, k;
- if (is_fma_avx() == 1) { // AVX
- for (i = 0; i < M; ++i) {
- for (k = 0; k < K; ++k) {
- float A_PART = ALPHA*A[i*lda + k];
- __m256 a256, b256, c256, result256; // AVX
- a256 = _mm256_set1_ps(A_PART);
- for (j = 0; j < N - 8; j += 8) {
- b256 = _mm256_loadu_ps(&B[k*ldb + j]);
- c256 = _mm256_loadu_ps(&C[i*ldc + j]);
- // FMA - Intel Haswell (2013), AMD Piledriver (2012)
- //result256 = _mm256_fmadd_ps(a256, b256, c256);
- result256 = _mm256_mul_ps(a256, b256);
- result256 = _mm256_add_ps(result256, c256);
- _mm256_storeu_ps(&C[i*ldc + j], result256);
- }
+ int i, j, k;
+ if (is_fma_avx() == 1) { // AVX
+ for (i = 0; i < M; ++i) {
+ for (k = 0; k < K; ++k) {
+ float A_PART = ALPHA*A[i*lda + k];
+ __m256 a256, b256, c256, result256; // AVX
+ a256 = _mm256_set1_ps(A_PART);
+ for (j = 0; j < N - 8; j += 8) {
+ b256 = _mm256_loadu_ps(&B[k*ldb + j]);
+ c256 = _mm256_loadu_ps(&C[i*ldc + j]);
+ // FMA - Intel Haswell (2013), AMD Piledriver (2012)
+ //result256 = _mm256_fmadd_ps(a256, b256, c256);
+ result256 = _mm256_mul_ps(a256, b256);
+ result256 = _mm256_add_ps(result256, c256);
+ _mm256_storeu_ps(&C[i*ldc + j], result256);
+ }
- int prev_end = (N % 8 == 0) ? (N - 8) : (N / 8) * 8;
- for (j = prev_end; j < N; ++j)
- C[i*ldc + j] += A_PART*B[k*ldb + j];
- }
- }
- }
- else {
- for (i = 0; i < M; ++i) {
- for (k = 0; k < K; ++k) {
- register float A_PART = ALPHA*A[i*lda + k];
- for (j = 0; j < N; ++j) {
- C[i*ldc + j] += A_PART*B[k*ldb + j];
- }
- /* // SSE
- __m128 a128, b128, c128, result128; // SSE
- a128 = _mm_set1_ps(A_PART);
- for (j = 0; j < N - 4; j += 4) {
- b128 = _mm_loadu_ps(&B[k*ldb + j]);
- c128 = _mm_loadu_ps(&C[i*ldc + j]);
- //result128 = _mm_fmadd_ps(a128, b128, c128);
- result128 = _mm_mul_ps(a128, b128);
- result128 = _mm_add_ps(result128, c128);
- _mm_storeu_ps(&C[i*ldc + j], result128);
- }
+ int prev_end = (N % 8 == 0) ? (N - 8) : (N / 8) * 8;
+ for (j = prev_end; j < N; ++j)
+ C[i*ldc + j] += A_PART*B[k*ldb + j];
+ }
+ }
+ }
+ else {
+ for (i = 0; i < M; ++i) {
+ for (k = 0; k < K; ++k) {
+ register float A_PART = ALPHA*A[i*lda + k];
+ for (j = 0; j < N; ++j) {
+ C[i*ldc + j] += A_PART*B[k*ldb + j];
+ }
+ /* // SSE
+ __m128 a128, b128, c128, result128; // SSE
+ a128 = _mm_set1_ps(A_PART);
+ for (j = 0; j < N - 4; j += 4) {
+ b128 = _mm_loadu_ps(&B[k*ldb + j]);
+ c128 = _mm_loadu_ps(&C[i*ldc + j]);
+ //result128 = _mm_fmadd_ps(a128, b128, c128);
+ result128 = _mm_mul_ps(a128, b128);
+ result128 = _mm_add_ps(result128, c128);
+ _mm_storeu_ps(&C[i*ldc + j], result128);
+ }
- int prev_end = (N % 4 == 0) ? (N - 4) : (N / 4) * 4;
- for (j = prev_end; j < N; ++j){
- C[i*ldc + j] += A_PART*B[k*ldb + j];
- }
- */
- }
- }
- }
+ int prev_end = (N % 4 == 0) ? (N - 4) : (N / 4) * 4;
+ for (j = prev_end; j < N; ++j){
+ C[i*ldc + j] += A_PART*B[k*ldb + j];
+ }
+ */
+ }
+ }
+ }
}
#else
void gemm_nn(int M, int N, int K, float ALPHA,
- float *A, int lda,
- float *B, int ldb,
- float *C, int ldc)
+ float *A, int lda,
+ float *B, int ldb,
+ float *C, int ldc)
{
- int i, j, k;
- for (i = 0; i < M; ++i) {
- for (k = 0; k < K; ++k) {
- register float A_PART = ALPHA*A[i*lda + k];
- for (j = 0; j < N; ++j) {
- C[i*ldc + j] += A_PART*B[k*ldb + j];
- }
- }
- }
+ int i, j, k;
+ for (i = 0; i < M; ++i) {
+ for (k = 0; k < K; ++k) {
+ register float A_PART = ALPHA*A[i*lda + k];
+ for (j = 0; j < N; ++j) {
+ C[i*ldc + j] += A_PART*B[k*ldb + j];
+ }
+ }
+ }
}
-#endif // __x86_64
+#endif // __x86_64
void gemm_nt(int M, int N, int K, float ALPHA,
float *A, int lda,
@@ -282,18 +282,18 @@
}
}
- int t;
- #pragma omp parallel for
- for (t = 0; t < M; ++t) {
- if (!TA && !TB)
- gemm_nn(1, N, K, ALPHA, A + t*lda, lda, B, ldb, C + t*ldc, ldc);
- else if (TA && !TB)
- gemm_tn(1, N, K, ALPHA, A + t, lda, B, ldb, C + t*ldc, ldc);
- else if (!TA && TB)
- gemm_nt(1, N, K, ALPHA, A + t*lda, lda, B, ldb, C + t*ldc, ldc);
- else
- gemm_tt(1, N, K, ALPHA, A + t, lda, B, ldb, C + t*ldc, ldc);
- }
+ int t;
+ #pragma omp parallel for
+ for (t = 0; t < M; ++t) {
+ if (!TA && !TB)
+ gemm_nn(1, N, K, ALPHA, A + t*lda, lda, B, ldb, C + t*ldc, ldc);
+ else if (TA && !TB)
+ gemm_tn(1, N, K, ALPHA, A + t, lda, B, ldb, C + t*ldc, ldc);
+ else if (!TA && TB)
+ gemm_nt(1, N, K, ALPHA, A + t*lda, lda, B, ldb, C + t*ldc, ldc);
+ else
+ gemm_tt(1, N, K, ALPHA, A + t, lda, B, ldb, C + t*ldc, ldc);
+ }
}
#ifdef GPU
@@ -307,7 +307,7 @@
float *C_gpu, int ldc)
{
cublasHandle_t handle = blas_handle();
- cudaError_t stream_status = cublasSetStream(handle, get_cuda_stream());
+ cudaError_t stream_status = cublasSetStream(handle, get_cuda_stream());
cudaError_t status = cublasSgemm(handle, (TB ? CUBLAS_OP_T : CUBLAS_OP_N),
(TA ? CUBLAS_OP_T : CUBLAS_OP_N), N, M, K, &ALPHA, B_gpu, ldb, A_gpu, lda, &BETA, C_gpu, ldc);
check_error(status);
--
Gitblit v1.10.0