1*9ba83ac0SJeremy L Thompson // Copyright (c) 2017-2026, 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.
382b77998SStan Tomov //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
582b77998SStan Tomov //
63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed
782b77998SStan Tomov
838612b08SStan Tomov #include "ceed-magma.h"
952d6035fSJeremy L Thompson
1049aac155SJeremy L Thompson #include <ceed.h>
112b730f8bSJeremy L Thompson #include <ceed/backend.h>
122b730f8bSJeremy L Thompson #include <stdlib.h>
132b730f8bSJeremy L Thompson #include <string.h>
142b730f8bSJeremy L Thompson
1500fb7a04SSebastian Grimberg #include "ceed-magma-common.h"
16e0582403Sabdelfattah83
1700fb7a04SSebastian Grimberg //------------------------------------------------------------------------------
1800fb7a04SSebastian Grimberg // Backend Init
1900fb7a04SSebastian Grimberg //------------------------------------------------------------------------------
CeedInit_Magma(const char * resource,Ceed ceed)2082b77998SStan Tomov static int CeedInit_Magma(const char *resource, Ceed ceed) {
2138293ee6SJeremy L Thompson Ceed ceed_ref;
2238293ee6SJeremy L Thompson Ceed_Magma *data;
236dbfb411Snbeams const int nrc = 14; // number of characters in resource
2438293ee6SJeremy L Thompson
256574a04fSJeremy L Thompson CeedCheck(!strncmp(resource, "/gpu/cuda/magma", nrc) || !strncmp(resource, "/gpu/hip/magma", nrc), ceed, CEED_ERROR_BACKEND,
266574a04fSJeremy L Thompson "Magma backend cannot use resource: %s", resource);
277f5b9731SStan Tomov
2858549094SSebastian Grimberg CeedCallBackend(CeedCalloc(1, &data));
292b730f8bSJeremy L Thompson CeedCallBackend(CeedSetData(ceed, data));
3000fb7a04SSebastian Grimberg CeedCallBackend(CeedInit_Magma_common(ceed, resource));
31e0582403Sabdelfattah83
3258549094SSebastian Grimberg // Create reference Ceed that implementation will be dispatched through unless overridden
33e5f091ebSnbeams #ifdef CEED_MAGMA_USE_HIP
3458549094SSebastian Grimberg CeedCallBackend(CeedInit("/gpu/hip/ref", &ceed_ref));
356dbfb411Snbeams #else
3658549094SSebastian Grimberg CeedCallBackend(CeedInit("/gpu/cuda/ref", &ceed_ref));
376dbfb411Snbeams #endif
3858549094SSebastian Grimberg CeedCallBackend(CeedSetDelegate(ceed, ceed_ref));
399bc66399SJeremy L Thompson CeedCallBackend(CeedDestroy(&ceed_ref));
406dbfb411Snbeams
412b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateTensorH1", CeedBasisCreateTensorH1_Magma));
422b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateH1", CeedBasisCreateH1_Magma));
439d15e85bSSebastian Grimberg CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateHdiv", CeedBasisCreateHdiv_Magma));
449d15e85bSSebastian Grimberg CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateHcurl", CeedBasisCreateHcurl_Magma));
452b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy", CeedDestroy_Magma));
46e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS;
4782b77998SStan Tomov }
4882b77998SStan Tomov
4900fb7a04SSebastian Grimberg //------------------------------------------------------------------------------
5000fb7a04SSebastian Grimberg // Backend Register
5100fb7a04SSebastian Grimberg //------------------------------------------------------------------------------
CeedRegister_Magma(void)521d013790SJed Brown CEED_INTERN int CeedRegister_Magma(void) {
53e5f091ebSnbeams #ifdef CEED_MAGMA_USE_HIP
541d013790SJed Brown return CeedRegister("/gpu/hip/magma", CeedInit_Magma, 120);
55adb2481bSnbeams #else
561d013790SJed Brown return CeedRegister("/gpu/cuda/magma", CeedInit_Magma, 120);
57adb2481bSnbeams #endif
5882b77998SStan Tomov }
5900fb7a04SSebastian Grimberg
6000fb7a04SSebastian Grimberg //------------------------------------------------------------------------------
61