1*5aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, 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 //------------------------------------------------------------------------------ 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)); 396dbfb411Snbeams 402b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateTensorH1", CeedBasisCreateTensorH1_Magma)); 412b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateH1", CeedBasisCreateH1_Magma)); 429d15e85bSSebastian Grimberg CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateHdiv", CeedBasisCreateHdiv_Magma)); 439d15e85bSSebastian Grimberg CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateHcurl", CeedBasisCreateHcurl_Magma)); 442b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy", CeedDestroy_Magma)); 45e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 4682b77998SStan Tomov } 4782b77998SStan Tomov 4800fb7a04SSebastian Grimberg //------------------------------------------------------------------------------ 4900fb7a04SSebastian Grimberg // Backend Register 5000fb7a04SSebastian Grimberg //------------------------------------------------------------------------------ 511d013790SJed Brown CEED_INTERN int CeedRegister_Magma(void) { 52e5f091ebSnbeams #ifdef CEED_MAGMA_USE_HIP 531d013790SJed Brown return CeedRegister("/gpu/hip/magma", CeedInit_Magma, 120); 54adb2481bSnbeams #else 551d013790SJed Brown return CeedRegister("/gpu/cuda/magma", CeedInit_Magma, 120); 56adb2481bSnbeams #endif 5782b77998SStan Tomov } 5800fb7a04SSebastian Grimberg 5900fb7a04SSebastian Grimberg //------------------------------------------------------------------------------ 60