xref: /libCEED/rust/libceed-sys/c-src/backends/avx/ceed-avx-serial.c (revision 2a86cc9d4dbfce2964c7e8927a1e6db8d19a41fc)
13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
384a01de5SJeremy L Thompson //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
584a01de5SJeremy L Thompson //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
784a01de5SJeremy L Thompson 
849aac155SJeremy L Thompson #include <ceed.h>
9ec3da8bcSJed Brown #include <ceed/backend.h>
103d576824SJeremy L Thompson #include <stdbool.h>
113d576824SJeremy L Thompson #include <string.h>
122b730f8bSJeremy L Thompson 
1384a01de5SJeremy L Thompson #include "ceed-avx.h"
1484a01de5SJeremy L Thompson 
15f10650afSjeremylt //------------------------------------------------------------------------------
16f10650afSjeremylt // Backend Init
17f10650afSjeremylt //------------------------------------------------------------------------------
1884a01de5SJeremy L Thompson static int CeedInit_Avx(const char *resource, Ceed ceed) {
192b730f8bSJeremy L Thompson   if (strcmp(resource, "/cpu/self") && strcmp(resource, "/cpu/self/avx/serial")) {
20c042f62fSJeremy L Thompson     // LCOV_EXCL_START
212b730f8bSJeremy L Thompson     return CeedError(ceed, CEED_ERROR_BACKEND, "AVX backend cannot use resource: %s", resource);
22c042f62fSJeremy L Thompson     // LCOV_EXCL_STOP
232b730f8bSJeremy L Thompson   }
242b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetDeterministic(ceed, true));
2584a01de5SJeremy L Thompson 
26ea61e9acSJeremy L Thompson   // Create reference Ceed that implementation will be dispatched through unless overridden
27d1d35e2fSjeremylt   Ceed ceed_ref;
282b730f8bSJeremy L Thompson   CeedCallBackend(CeedInit("/cpu/self/opt/serial", &ceed_ref));
292b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetDelegate(ceed, ceed_ref));
3084a01de5SJeremy L Thompson 
3180a9ef05SNatalie Beams   if (CEED_SCALAR_TYPE == CEED_SCALAR_FP64) {
322b730f8bSJeremy L Thompson     CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate", CeedTensorContractCreate_f64_Avx));
3380a9ef05SNatalie Beams   } else {
342b730f8bSJeremy L Thompson     CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate", CeedTensorContractCreate_f32_Avx));
3580a9ef05SNatalie Beams   }
3680a9ef05SNatalie Beams 
37e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
3884a01de5SJeremy L Thompson }
3984a01de5SJeremy L Thompson 
40f10650afSjeremylt //------------------------------------------------------------------------------
41f10650afSjeremylt // Backend Register
42f10650afSjeremylt //------------------------------------------------------------------------------
432b730f8bSJeremy L Thompson CEED_INTERN int CeedRegister_Avx_Serial(void) { return CeedRegister("/cpu/self/avx/serial", CeedInit_Avx, 35); }
44*2a86cc9dSSebastian Grimberg 
45f10650afSjeremylt //------------------------------------------------------------------------------
46