xref: /libCEED/rust/libceed-sys/c-src/backends/avx/ceed-avx-serial.c (revision 2a86cc9d4dbfce2964c7e8927a1e6db8d19a41fc)
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.h>
9 #include <ceed/backend.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 through unless overridden
27   Ceed ceed_ref;
28   CeedCallBackend(CeedInit("/cpu/self/opt/serial", &ceed_ref));
29   CeedCallBackend(CeedSetDelegate(ceed, ceed_ref));
30 
31   if (CEED_SCALAR_TYPE == CEED_SCALAR_FP64) {
32     CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate", CeedTensorContractCreate_f64_Avx));
33   } else {
34     CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate", CeedTensorContractCreate_f32_Avx));
35   }
36 
37   return CEED_ERROR_SUCCESS;
38 }
39 
40 //------------------------------------------------------------------------------
41 // Backend Register
42 //------------------------------------------------------------------------------
43 CEED_INTERN int CeedRegister_Avx_Serial(void) { return CeedRegister("/cpu/self/avx/serial", CeedInit_Avx, 35); }
44 
45 //------------------------------------------------------------------------------
46