xref: /libCEED/rust/libceed-sys/c-src/backends/xsmm/ceed-xsmm-serial.c (revision 2b730f8b5a9c809740a0b3b302db43a719c636b1)
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.
38d713cf6Sjeremylt //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
58d713cf6Sjeremylt //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
78d713cf6Sjeremylt 
8ec3da8bcSJed Brown #include <ceed/backend.h>
9*2b730f8bSJeremy L Thompson #include <ceed/ceed.h>
103d576824SJeremy L Thompson #include <stdbool.h>
113d576824SJeremy L Thompson #include <string.h>
12*2b730f8bSJeremy L Thompson 
138d713cf6Sjeremylt #include "ceed-xsmm.h"
148d713cf6Sjeremylt 
15f10650afSjeremylt //------------------------------------------------------------------------------
16f10650afSjeremylt // Backend Init
17f10650afSjeremylt //------------------------------------------------------------------------------
188d713cf6Sjeremylt static int CeedInit_Xsmm_Serial(const char *resource, Ceed ceed) {
19*2b730f8bSJeremy L Thompson   if (strcmp(resource, "/cpu/self") && strcmp(resource, "/cpu/self/xsmm/serial")) {
20c042f62fSJeremy L Thompson     // LCOV_EXCL_START
21*2b730f8bSJeremy L Thompson     return CeedError(ceed, CEED_ERROR_BACKEND, "serial libXSMM backend cannot use resource: %s", resource);
22c042f62fSJeremy L Thompson     // LCOV_EXCL_STOP
23*2b730f8bSJeremy L Thompson   }
24*2b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetDeterministic(ceed, true));
258d713cf6Sjeremylt 
265f67fadeSJeremy L Thompson   // Create reference CEED that implementation will be dispatched
278d713cf6Sjeremylt   //   through unless overridden
28d1d35e2fSjeremylt   Ceed ceed_ref;
29*2b730f8bSJeremy L Thompson   CeedCallBackend(CeedInit("/cpu/self/opt/serial", &ceed_ref));
30*2b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetDelegate(ceed, ceed_ref));
318d713cf6Sjeremylt 
3280a9ef05SNatalie Beams   if (CEED_SCALAR_TYPE == CEED_SCALAR_FP64) {
33*2b730f8bSJeremy L Thompson     CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate", CeedTensorContractCreate_f64_Xsmm));
3480a9ef05SNatalie Beams   } else {
35*2b730f8bSJeremy L Thompson     CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate", CeedTensorContractCreate_f32_Xsmm));
3680a9ef05SNatalie Beams   }
378d713cf6Sjeremylt 
38e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
398d713cf6Sjeremylt }
408d713cf6Sjeremylt 
41f10650afSjeremylt //------------------------------------------------------------------------------
42f10650afSjeremylt // Backend Register
43f10650afSjeremylt //------------------------------------------------------------------------------
44*2b730f8bSJeremy L Thompson CEED_INTERN int CeedRegister_Xsmm_Serial(void) { return CeedRegister("/cpu/self/xsmm/serial", CeedInit_Xsmm_Serial, 25); }
45f10650afSjeremylt //------------------------------------------------------------------------------
46