xref: /libCEED/backends/avx/ceed-avx-serial.c (revision caee03026e6576cbf7a399c2fc51bb918c77f451)
1 // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3 //
4 // SPDX-License-Identifier: BSD-2-Clause
5 //
6 // This file is part of CEED:  http://github.com/ceed
7 
8 #include <ceed/backend.h>
9 #include <ceed/ceed.h>
10 #include <stdbool.h>
11 #include <string.h>
12 
13 #include "ceed-avx.h"
14 
15 //------------------------------------------------------------------------------
16 // Backend Init
17 //------------------------------------------------------------------------------
18 static int CeedInit_Avx(const char *resource, Ceed ceed) {
19   if (strcmp(resource, "/cpu/self") && strcmp(resource, "/cpu/self/avx/serial")) {
20     // LCOV_EXCL_START
21     return CeedError(ceed, CEED_ERROR_BACKEND, "AVX backend cannot use resource: %s", resource);
22     // LCOV_EXCL_STOP
23   }
24   CeedCallBackend(CeedSetDeterministic(ceed, true));
25 
26   // Create reference CEED that implementation will be dispatched
27   //   through unless overridden
28   Ceed ceed_ref;
29   CeedCallBackend(CeedInit("/cpu/self/opt/serial", &ceed_ref));
30   CeedCallBackend(CeedSetDelegate(ceed, ceed_ref));
31 
32   if (CEED_SCALAR_TYPE == CEED_SCALAR_FP64) {
33     CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate", CeedTensorContractCreate_f64_Avx));
34   } else {
35     CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate", CeedTensorContractCreate_f32_Avx));
36   }
37 
38   return CEED_ERROR_SUCCESS;
39 }
40 
41 //------------------------------------------------------------------------------
42 // Backend Register
43 //------------------------------------------------------------------------------
44 CEED_INTERN int CeedRegister_Avx_Serial(void) { return CeedRegister("/cpu/self/avx/serial", CeedInit_Avx, 35); }
45 //------------------------------------------------------------------------------
46