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. 3cb23e90cSJeremy L Thompson // 43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 5cb23e90cSJeremy L Thompson // 63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 7cb23e90cSJeremy L Thompson 849aac155SJeremy L Thompson #include <ceed.h> 9ec3da8bcSJed Brown #include <ceed/backend.h> 106dbfb411Snbeams #include <stdlib.h> 112b730f8bSJeremy L Thompson #include <string.h> 122b730f8bSJeremy L Thompson 13cb23e90cSJeremy L Thompson #include "ceed-magma.h" 14cb23e90cSJeremy L Thompson 156574a04fSJeremy L Thompson static int CeedInit_Magma_Det(const char *resource, Ceed ceed) { 166dbfb411Snbeams const int nrc = 18; // number of characters in resource 176574a04fSJeremy L Thompson CeedCheck(!strncmp(resource, "/gpu/cuda/magma/det", nrc) || !strncmp(resource, "/gpu/hip/magma/det", nrc), ceed, CEED_ERROR_BACKEND, 186574a04fSJeremy L Thompson "Magma backend cannot use resource: %s", resource); 192b730f8bSJeremy L Thompson CeedCallBackend(CeedSetDeterministic(ceed, true)); 20cb23e90cSJeremy L Thompson 216dbfb411Snbeams Ceed_Magma *data; 22*58549094SSebastian Grimberg CeedCallBackend(CeedCalloc(1, &data)); 232b730f8bSJeremy L Thompson CeedCallBackend(CeedSetData(ceed, data)); 246dbfb411Snbeams 25*58549094SSebastian Grimberg // Create reference Ceed that implementation will be dispatched through 26*58549094SSebastian Grimberg Ceed ceed_ref; 27e5f091ebSnbeams #ifdef CEED_MAGMA_USE_HIP 28*58549094SSebastian Grimberg CeedCallBackend(CeedInit("/gpu/hip/magma", &ceed_ref)); 29adb2481bSnbeams #else 30*58549094SSebastian Grimberg CeedCallBackend(CeedInit("/gpu/cuda/magma", &ceed_ref)); 31adb2481bSnbeams #endif 32*58549094SSebastian Grimberg CeedCallBackend(CeedSetDelegate(ceed, ceed_ref)); 33cb23e90cSJeremy L Thompson 34e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 35cb23e90cSJeremy L Thompson } 36cb23e90cSJeremy L Thompson 371d013790SJed Brown CEED_INTERN int CeedRegister_Magma_Det(void) { 38e5f091ebSnbeams #ifdef CEED_MAGMA_USE_HIP 391d013790SJed Brown return CeedRegister("/gpu/hip/magma/det", CeedInit_Magma_Det, 125); 40adb2481bSnbeams #else 411d013790SJed Brown return CeedRegister("/gpu/cuda/magma/det", CeedInit_Magma_Det, 125); 42adb2481bSnbeams #endif 43cb23e90cSJeremy L Thompson } 44