diff --git a/mlir/test/CMakeLists.txt b/mlir/test/CMakeLists.txt --- a/mlir/test/CMakeLists.txt +++ b/mlir/test/CMakeLists.txt @@ -38,8 +38,8 @@ mlir-sdbm-api-test mlir-tblgen mlir-translate - cblas - cblas_interface + mlir_test_cblas + mlir_test_cblas_interface mlir_runner_utils mlir_c_runner_utils ) diff --git a/mlir/test/mlir-cpu-runner/CMakeLists.txt b/mlir/test/mlir-cpu-runner/CMakeLists.txt --- a/mlir/test/mlir-cpu-runner/CMakeLists.txt +++ b/mlir/test/mlir-cpu-runner/CMakeLists.txt @@ -1,12 +1,12 @@ set(LLVM_OPTIONAL_SOURCES - cblas.cpp - cblas_interface.cpp + mlir_test_cblas.cpp + mlir_test_cblas_interface.cpp ) -add_llvm_library(cblas SHARED cblas.cpp) -target_compile_definitions(cblas PRIVATE cblas_EXPORTS) +add_llvm_library(mlir_test_cblas SHARED mlir_test_cblas.cpp) +target_compile_definitions(mlir_test_cblas PRIVATE mlir_test_cblas_EXPORTS) -add_llvm_library(cblas_interface SHARED cblas_interface.cpp) -target_link_libraries(cblas_interface PRIVATE cblas) -target_compile_definitions(cblas_interface PRIVATE cblas_interface_EXPORTS) +add_llvm_library(mlir_test_cblas_interface SHARED mlir_test_cblas_interface.cpp) +target_link_libraries(mlir_test_cblas_interface PRIVATE mlir_test_cblas) +target_compile_definitions(mlir_test_cblas_interface PRIVATE mlir_test_cblas_interface_EXPORTS) diff --git a/mlir/test/mlir-cpu-runner/include/cblas.h b/mlir/test/mlir-cpu-runner/include/cblas.h deleted file mode 100644 --- a/mlir/test/mlir-cpu-runner/include/cblas.h +++ /dev/null @@ -1,49 +0,0 @@ -//===- cblas.h - Simple Blas subset ---------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -#ifndef MLIR_CPU_RUNNER_CBLAS_H_ -#define MLIR_CPU_RUNNER_CBLAS_H_ - -#include "mlir/ExecutionEngine/RunnerUtils.h" - -#ifdef _WIN32 -#ifndef MLIR_CBLAS_EXPORT -#ifdef cblas_EXPORTS -/* We are building this library */ -#define MLIR_CBLAS_EXPORT __declspec(dllexport) -#else -/* We are using this library */ -#define MLIR_CBLAS_EXPORT __declspec(dllimport) -#endif // cblas_EXPORTS -#endif // MLIR_CBLAS_EXPORT -#else -#define MLIR_CBLAS_EXPORT -#endif // _WIN32 - -/// This reproduces a minimal subset of cblas to allow integration testing -/// without explicitly requiring a dependence on an external library. -/// Without loss of generality, various cblas implementations may be swapped in -/// by including the proper headers and linking with the proper library. -enum CBLAS_ORDER { CblasRowMajor = 101, CblasColMajor = 102 }; -enum CBLAS_TRANSPOSE { - CblasNoTrans = 111, - CblasTrans = 112, - CblasConjTrans = 113 -}; - -extern "C" MLIR_CBLAS_EXPORT float cblas_sdot(const int N, const float *X, - const int incX, const float *Y, - const int incY); - -extern "C" MLIR_CBLAS_EXPORT void -cblas_sgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, - const enum CBLAS_TRANSPOSE TransB, const int M, const int N, - const int K, const float alpha, const float *A, const int lda, - const float *B, const int ldb, const float beta, float *C, - const int ldc); - -#endif // MLIR_CPU_RUNNER_CBLAS_H_ diff --git a/mlir/test/mlir-cpu-runner/include/mlir_test_cblas.h b/mlir/test/mlir-cpu-runner/include/mlir_test_cblas.h new file mode 100644 --- /dev/null +++ b/mlir/test/mlir-cpu-runner/include/mlir_test_cblas.h @@ -0,0 +1,49 @@ +//===- mlir_test_cblas.h - Simple Blas subset -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef MLIR_CPU_RUNNER_MLIR_TEST_CBLAS_H_ +#define MLIR_CPU_RUNNER_MLIR_TEST_CBLAS_H_ + +#include "mlir/ExecutionEngine/RunnerUtils.h" + +#ifdef _WIN32 +#ifndef MLIR_TEST_CBLAS_EXPORT +#ifdef mlir_test_cblas_EXPORTS +/* We are building this library */ +#define MLIR_TEST_CBLAS_EXPORT __declspec(dllexport) +#else +/* We are using this library */ +#define MLIR_TEST_CBLAS_EXPORT __declspec(dllimport) +#endif // mlir_test_cblas_EXPORTS +#endif // MLIR_TEST_CBLAS_EXPORT +#else +#define MLIR_TEST_CBLAS_EXPORT +#endif // _WIN32 + +/// This reproduces a minimal subset of mlir_test_cblas to allow integration +/// testing without explicitly requiring a dependence on an external library. +/// Without loss of generality, various mlir_test_cblas implementations may be +/// swapped in by including the proper headers and linking with the proper +/// library. +enum CBLAS_ORDER { CblasRowMajor = 101, CblasColMajor = 102 }; +enum CBLAS_TRANSPOSE { + CblasNoTrans = 111, + CblasTrans = 112, + CblasConjTrans = 113 +}; + +extern "C" MLIR_TEST_CBLAS_EXPORT float +mlir_test_cblas_sdot(const int N, const float *X, const int incX, + const float *Y, const int incY); + +extern "C" MLIR_TEST_CBLAS_EXPORT void mlir_test_cblas_sgemm( + const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, + const float alpha, const float *A, const int lda, const float *B, + const int ldb, const float beta, float *C, const int ldc); + +#endif // MLIR_CPU_RUNNER_MLIR_TEST_CBLAS_H_ diff --git a/mlir/test/mlir-cpu-runner/include/cblas_interface.h b/mlir/test/mlir-cpu-runner/include/mlir_test_cblas_interface.h rename from mlir/test/mlir-cpu-runner/include/cblas_interface.h rename to mlir/test/mlir-cpu-runner/include/mlir_test_cblas_interface.h --- a/mlir/test/mlir-cpu-runner/include/cblas_interface.h +++ b/mlir/test/mlir-cpu-runner/include/mlir_test_cblas_interface.h @@ -1,59 +1,59 @@ -//===- cblas_interface.h - Simple Blas subset interface -------------------===// +//===- mlir_test_cblas_interface.h - Simple Blas subset interface ---------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// -#ifndef MLIR_CPU_RUNNER_CBLAS_INTERFACE_H_ -#define MLIR_CPU_RUNNER_CBLAS_INTERFACE_H_ +#ifndef MLIR_CPU_RUNNER_MLIR_TEST_CBLAS_INTERFACE_H_ +#define MLIR_CPU_RUNNER_MLIR_TEST_CBLAS_INTERFACE_H_ #include "mlir/ExecutionEngine/RunnerUtils.h" #ifdef _WIN32 -#ifndef MLIR_CBLAS_INTERFACE_EXPORT -#ifdef cblas_interface_EXPORTS +#ifndef MLIR_TEST_CBLAS_INTERFACE_EXPORT +#ifdef mlir_test_cblas_interface_EXPORTS /* We are building this library */ -#define MLIR_CBLAS_INTERFACE_EXPORT __declspec(dllexport) +#define MLIR_TEST_CBLAS_INTERFACE_EXPORT __declspec(dllexport) #else /* We are using this library */ -#define MLIR_CBLAS_INTERFACE_EXPORT __declspec(dllimport) -#endif // cblas_interface_EXPORTS -#endif // MLIR_CBLAS_INTERFACE_EXPORT +#define MLIR_TEST_CBLAS_INTERFACE_EXPORT __declspec(dllimport) +#endif // mlir_test_cblas_interface_EXPORTS +#endif // MLIR_TEST_CBLAS_INTERFACE_EXPORT #else -#define MLIR_CBLAS_INTERFACE_EXPORT +#define MLIR_TEST_CBLAS_INTERFACE_EXPORT #endif // _WIN32 -extern "C" MLIR_CBLAS_INTERFACE_EXPORT void +extern "C" MLIR_TEST_CBLAS_INTERFACE_EXPORT void _mlir_ciface_linalg_fill_viewf32_f32(StridedMemRefType *X, float f); -extern "C" MLIR_CBLAS_INTERFACE_EXPORT void +extern "C" MLIR_TEST_CBLAS_INTERFACE_EXPORT void _mlir_ciface_linalg_fill_viewsxf32_f32(StridedMemRefType *X, float f); -extern "C" MLIR_CBLAS_INTERFACE_EXPORT void +extern "C" MLIR_TEST_CBLAS_INTERFACE_EXPORT void _mlir_ciface_linalg_fill_viewsxsxf32_f32(StridedMemRefType *X, float f); -extern "C" MLIR_CBLAS_INTERFACE_EXPORT void +extern "C" MLIR_TEST_CBLAS_INTERFACE_EXPORT void _mlir_ciface_linalg_copy_viewf32_viewf32(StridedMemRefType *I, StridedMemRefType *O); -extern "C" MLIR_CBLAS_INTERFACE_EXPORT void +extern "C" MLIR_TEST_CBLAS_INTERFACE_EXPORT void _mlir_ciface_linalg_copy_viewsxf32_viewsxf32(StridedMemRefType *I, StridedMemRefType *O); -extern "C" MLIR_CBLAS_INTERFACE_EXPORT void +extern "C" MLIR_TEST_CBLAS_INTERFACE_EXPORT void _mlir_ciface_linalg_copy_viewsxsxf32_viewsxsxf32( StridedMemRefType *I, StridedMemRefType *O); -extern "C" MLIR_CBLAS_INTERFACE_EXPORT void +extern "C" MLIR_TEST_CBLAS_INTERFACE_EXPORT void _mlir_ciface_linalg_dot_viewsxf32_viewsxf32_viewf32( StridedMemRefType *X, StridedMemRefType *Y, StridedMemRefType *Z); -extern "C" MLIR_CBLAS_INTERFACE_EXPORT void +extern "C" MLIR_TEST_CBLAS_INTERFACE_EXPORT void _mlir_ciface_linalg_matmul_viewsxsxf32_viewsxsxf32_viewsxsxf32( StridedMemRefType *A, StridedMemRefType *B, StridedMemRefType *C); -#endif // MLIR_CPU_RUNNER_CBLAS_INTERFACE_H_ +#endif // MLIR_CPU_RUNNER_MLIR_TEST_CBLAS_INTERFACE_H_ diff --git a/mlir/test/mlir-cpu-runner/linalg_integration_test.mlir b/mlir/test/mlir-cpu-runner/linalg_integration_test.mlir --- a/mlir/test/mlir-cpu-runner/linalg_integration_test.mlir +++ b/mlir/test/mlir-cpu-runner/linalg_integration_test.mlir @@ -1,9 +1,9 @@ -// RUN: mlir-opt %s -convert-linalg-to-llvm | mlir-cpu-runner -e dot -entry-point-result=f32 -shared-libs=%linalg_test_lib_dir/libcblas%shlibext,%linalg_test_lib_dir/libcblas_interface%shlibext | FileCheck %s -// RUN: mlir-opt %s -convert-linalg-to-loops -convert-linalg-to-llvm | mlir-cpu-runner -e dot -entry-point-result=f32 -shared-libs=%linalg_test_lib_dir/libcblas%shlibext,%linalg_test_lib_dir/libcblas_interface%shlibext | FileCheck %s -// RUN: mlir-opt %s -convert-linalg-to-llvm | mlir-cpu-runner -e matmul -entry-point-result=f32 -shared-libs=%linalg_test_lib_dir/libcblas%shlibext,%linalg_test_lib_dir/libcblas_interface%shlibext | FileCheck %s -// RUN: mlir-opt %s -convert-linalg-to-loops -convert-linalg-to-llvm | mlir-cpu-runner -e matmul -entry-point-result=f32 -shared-libs=%linalg_test_lib_dir/libcblas%shlibext,%linalg_test_lib_dir/libcblas_interface%shlibext | FileCheck %s -// RUN: mlir-opt %s -linalg-tile -linalg-tile-sizes=2,3,4 -linalg-promote-subviews -convert-linalg-to-loops -convert-linalg-to-llvm | mlir-cpu-runner -e matmul -entry-point-result=f32 -shared-libs=%linalg_test_lib_dir/libcblas%shlibext,%linalg_test_lib_dir/libcblas_interface%shlibext | FileCheck %s -// RUN: mlir-opt %s -linalg-tile -linalg-tile-sizes=2,3,4 -linalg-promote-subviews -convert-linalg-to-llvm | mlir-cpu-runner -e matmul -entry-point-result=f32 -shared-libs=%linalg_test_lib_dir/libcblas%shlibext,%linalg_test_lib_dir/libcblas_interface%shlibext | FileCheck %s +// RUN: mlir-opt %s -convert-linalg-to-llvm | mlir-cpu-runner -e dot -entry-point-result=f32 -shared-libs=%linalg_test_lib_dir/libmlir_test_cblas%shlibext,%linalg_test_lib_dir/libmlir_test_cblas_interface%shlibext | FileCheck %s +// RUN: mlir-opt %s -convert-linalg-to-loops -convert-linalg-to-llvm | mlir-cpu-runner -e dot -entry-point-result=f32 -shared-libs=%linalg_test_lib_dir/libmlir_test_cblas%shlibext,%linalg_test_lib_dir/libmlir_test_cblas_interface%shlibext | FileCheck %s +// RUN: mlir-opt %s -convert-linalg-to-llvm | mlir-cpu-runner -e matmul -entry-point-result=f32 -shared-libs=%linalg_test_lib_dir/libmlir_test_cblas%shlibext,%linalg_test_lib_dir/libmlir_test_cblas_interface%shlibext | FileCheck %s +// RUN: mlir-opt %s -convert-linalg-to-loops -convert-linalg-to-llvm | mlir-cpu-runner -e matmul -entry-point-result=f32 -shared-libs=%linalg_test_lib_dir/libmlir_test_cblas%shlibext,%linalg_test_lib_dir/libmlir_test_cblas_interface%shlibext | FileCheck %s +// RUN: mlir-opt %s -linalg-tile -linalg-tile-sizes=2,3,4 -linalg-promote-subviews -convert-linalg-to-loops -convert-linalg-to-llvm | mlir-cpu-runner -e matmul -entry-point-result=f32 -shared-libs=%linalg_test_lib_dir/libmlir_test_cblas%shlibext,%linalg_test_lib_dir/libmlir_test_cblas_interface%shlibext | FileCheck %s +// RUN: mlir-opt %s -linalg-tile -linalg-tile-sizes=2,3,4 -linalg-promote-subviews -convert-linalg-to-llvm | mlir-cpu-runner -e matmul -entry-point-result=f32 -shared-libs=%linalg_test_lib_dir/libmlir_test_cblas%shlibext,%linalg_test_lib_dir/libmlir_test_cblas_interface%shlibext | FileCheck %s #strided1D = affine_map<(d0) -> (d0)> #strided2D = affine_map<(d0, d1)[s0] -> (d0 * s0 + d1)> diff --git a/mlir/test/mlir-cpu-runner/cblas.cpp b/mlir/test/mlir-cpu-runner/mlir_test_cblas.cpp rename from mlir/test/mlir-cpu-runner/cblas.cpp rename to mlir/test/mlir-cpu-runner/mlir_test_cblas.cpp --- a/mlir/test/mlir-cpu-runner/cblas.cpp +++ b/mlir/test/mlir-cpu-runner/mlir_test_cblas.cpp @@ -1,4 +1,4 @@ -//===- cblas.cpp - Simple Blas subset implementation ----------------------===// +//===- mlir_test_cblas.cpp - Simple Blas subset implementation ------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -10,24 +10,23 @@ // //===----------------------------------------------------------------------===// -#include "include/cblas.h" +#include "include/mlir_test_cblas.h" #include -extern "C" float cblas_sdot(const int N, const float *X, const int incX, - const float *Y, const int incY) { +extern "C" float mlir_test_cblas_sdot(const int N, const float *X, + const int incX, const float *Y, + const int incY) { float res = 0.0f; for (int i = 0; i < N; ++i) res += X[i * incX] * Y[i * incY]; return res; } -extern "C" void cblas_sgemm(const enum CBLAS_ORDER Order, - const enum CBLAS_TRANSPOSE TransA, - const enum CBLAS_TRANSPOSE TransB, const int M, - const int N, const int K, const float alpha, - const float *A, const int lda, const float *B, - const int ldb, const float beta, float *C, - const int ldc) { +extern "C" void mlir_test_cblas_sgemm( + const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, + const float alpha, const float *A, const int lda, const float *B, + const int ldb, const float beta, float *C, const int ldc) { assert(Order == CBLAS_ORDER::CblasRowMajor); assert(TransA == CBLAS_TRANSPOSE::CblasNoTrans); assert(TransB == CBLAS_TRANSPOSE::CblasNoTrans); diff --git a/mlir/test/mlir-cpu-runner/cblas_interface.cpp b/mlir/test/mlir-cpu-runner/mlir_test_cblas_interface.cpp rename from mlir/test/mlir-cpu-runner/cblas_interface.cpp rename to mlir/test/mlir-cpu-runner/mlir_test_cblas_interface.cpp --- a/mlir/test/mlir-cpu-runner/cblas_interface.cpp +++ b/mlir/test/mlir-cpu-runner/mlir_test_cblas_interface.cpp @@ -1,4 +1,4 @@ -//===- cblas_interface.cpp - Simple Blas subset interface -----------------===// +//===- mlir_test_cblas_interface.cpp - Simple Blas subset interface -------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -10,8 +10,8 @@ // //===----------------------------------------------------------------------===// -#include "include/cblas_interface.h" -#include "include/cblas.h" +#include "include/mlir_test_cblas_interface.h" +#include "include/mlir_test_cblas.h" #include #include @@ -82,8 +82,8 @@ return; } Z->data[Z->offset] += - cblas_sdot(X->sizes[0], X->data + X->offset, X->strides[0], - Y->data + Y->offset, Y->strides[0]); + mlir_test_cblas_sdot(X->sizes[0], X->data + X->offset, X->strides[0], + Y->data + Y->offset, Y->strides[0]); } extern "C" void _mlir_ciface_linalg_matmul_viewsxsxf32_viewsxsxf32_viewsxsxf32( @@ -99,9 +99,9 @@ printMemRefMetaData(std::cerr, *C); return; } - cblas_sgemm(CBLAS_ORDER::CblasRowMajor, CBLAS_TRANSPOSE::CblasNoTrans, - CBLAS_TRANSPOSE::CblasNoTrans, C->sizes[0], C->sizes[1], - A->sizes[1], 1.0f, A->data + A->offset, A->strides[0], - B->data + B->offset, B->strides[0], 1.0f, C->data + C->offset, - C->strides[0]); + mlir_test_cblas_sgemm( + CBLAS_ORDER::CblasRowMajor, CBLAS_TRANSPOSE::CblasNoTrans, + CBLAS_TRANSPOSE::CblasNoTrans, C->sizes[0], C->sizes[1], A->sizes[1], + 1.0f, A->data + A->offset, A->strides[0], B->data + B->offset, + B->strides[0], 1.0f, C->data + C->offset, C->strides[0]); } diff --git a/mlir/test/mlir-cpu-runner/unranked_memref.mlir b/mlir/test/mlir-cpu-runner/unranked_memref.mlir --- a/mlir/test/mlir-cpu-runner/unranked_memref.mlir +++ b/mlir/test/mlir-cpu-runner/unranked_memref.mlir @@ -1,4 +1,4 @@ -// RUN: mlir-opt %s -convert-linalg-to-loops -convert-linalg-to-llvm -convert-std-to-llvm | mlir-cpu-runner -e main -entry-point-result=void -shared-libs=%linalg_test_lib_dir/libmlir_runner_utils%shlibext,%linalg_test_lib_dir/libcblas%shlibext,%linalg_test_lib_dir/libcblas_interface%shlibext | FileCheck %s +// RUN: mlir-opt %s -convert-linalg-to-loops -convert-linalg-to-llvm -convert-std-to-llvm | mlir-cpu-runner -e main -entry-point-result=void -shared-libs=%linalg_test_lib_dir/libmlir_runner_utils%shlibext,%linalg_test_lib_dir/libmlir_test_cblas%shlibext,%linalg_test_lib_dir/libmlir_test_cblas_interface%shlibext | FileCheck %s // CHECK: rank = 2 // CHECK: rank = 2