xref: /libCEED/rust/libceed-sys/c-src/backends/avx/ceed-avx-serial.c (revision 3d8e882215d238700cdceb37404f76ca7fa24eaa)
1*3d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2*3d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
384a01de5SJeremy L Thompson //
4*3d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
584a01de5SJeremy L Thompson //
6*3d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
784a01de5SJeremy L Thompson 
8ec3da8bcSJed Brown #include <ceed/ceed.h>
9ec3da8bcSJed Brown #include <ceed/backend.h>
103d576824SJeremy L Thompson #include <stdbool.h>
113d576824SJeremy L Thompson #include <string.h>
1284a01de5SJeremy L Thompson #include "ceed-avx.h"
1384a01de5SJeremy L Thompson 
14f10650afSjeremylt //------------------------------------------------------------------------------
15f10650afSjeremylt // Backend Init
16f10650afSjeremylt //------------------------------------------------------------------------------
1784a01de5SJeremy L Thompson static int CeedInit_Avx(const char *resource, Ceed ceed) {
1884a01de5SJeremy L Thompson   int ierr;
1984a01de5SJeremy L Thompson   if (strcmp(resource, "/cpu/self")
2084a01de5SJeremy L Thompson       && strcmp(resource, "/cpu/self/avx/serial"))
21c042f62fSJeremy L Thompson     // LCOV_EXCL_START
22e15f9bd0SJeremy L Thompson     return CeedError(ceed, CEED_ERROR_BACKEND,
23e15f9bd0SJeremy L Thompson                      "AVX backend cannot use resource: %s", resource);
24c042f62fSJeremy L Thompson   // LCOV_EXCL_STOP
25e15f9bd0SJeremy L Thompson   ierr = CeedSetDeterministic(ceed, true); CeedChkBackend(ierr);
2684a01de5SJeremy L Thompson 
275f67fadeSJeremy L Thompson   // Create reference CEED that implementation will be dispatched
2884a01de5SJeremy L Thompson   //   through unless overridden
29d1d35e2fSjeremylt   Ceed ceed_ref;
30d1d35e2fSjeremylt   CeedInit("/cpu/self/opt/serial", &ceed_ref);
31d1d35e2fSjeremylt   ierr = CeedSetDelegate(ceed, ceed_ref); CeedChkBackend(ierr);
3284a01de5SJeremy L Thompson 
3380a9ef05SNatalie Beams   if (CEED_SCALAR_TYPE == CEED_SCALAR_FP64) {
342f86a920SJeremy L Thompson     ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate",
3580a9ef05SNatalie Beams                                   CeedTensorContractCreate_f64_Avx);
3680a9ef05SNatalie Beams     CeedChkBackend(ierr);
3780a9ef05SNatalie Beams   } else {
3880a9ef05SNatalie Beams     ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate",
3980a9ef05SNatalie Beams                                   CeedTensorContractCreate_f32_Avx);
4080a9ef05SNatalie Beams     CeedChkBackend(ierr);
4180a9ef05SNatalie Beams   }
4280a9ef05SNatalie Beams 
43e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
4484a01de5SJeremy L Thompson }
4584a01de5SJeremy L Thompson 
46f10650afSjeremylt //------------------------------------------------------------------------------
47f10650afSjeremylt // Backend Register
48f10650afSjeremylt //------------------------------------------------------------------------------
491d013790SJed Brown CEED_INTERN int CeedRegister_Avx_Serial(void) {
501d013790SJed Brown   return CeedRegister("/cpu/self/avx/serial", CeedInit_Avx, 35);
5184a01de5SJeremy L Thompson }
52f10650afSjeremylt //------------------------------------------------------------------------------
53