1 // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3 // 4 // SPDX-License-Identifier: BSD-2-Clause 5 // 6 // This file is part of CEED: http://github.com/ceed 7 8 #include <ceed.h> 9 #include <ceed/backend.h> 10 #include <stdlib.h> 11 #include <string.h> 12 13 #include "ceed-magma.h" 14 15 static int CeedInit_Magma_Det(const char *resource, Ceed ceed) { 16 const int nrc = 18; // number of characters in resource 17 CeedCheck(!strncmp(resource, "/gpu/cuda/magma/det", nrc) || !strncmp(resource, "/gpu/hip/magma/det", nrc), ceed, CEED_ERROR_BACKEND, 18 "Magma backend cannot use resource: %s", resource); 19 CeedCallBackend(CeedSetDeterministic(ceed, true)); 20 21 Ceed_Magma *data; 22 CeedCallBackend(CeedCalloc(1, &data)); 23 CeedCallBackend(CeedSetData(ceed, data)); 24 25 // Create reference Ceed that implementation will be dispatched through 26 Ceed ceed_ref; 27 #ifdef CEED_MAGMA_USE_HIP 28 CeedCallBackend(CeedInit("/gpu/hip/magma", &ceed_ref)); 29 #else 30 CeedCallBackend(CeedInit("/gpu/cuda/magma", &ceed_ref)); 31 #endif 32 CeedCallBackend(CeedSetDelegate(ceed, ceed_ref)); 33 34 return CEED_ERROR_SUCCESS; 35 } 36 37 CEED_INTERN int CeedRegister_Magma_Det(void) { 38 #ifdef CEED_MAGMA_USE_HIP 39 return CeedRegister("/gpu/hip/magma/det", CeedInit_Magma_Det, 125); 40 #else 41 return CeedRegister("/gpu/cuda/magma/det", CeedInit_Magma_Det, 125); 42 #endif 43 } 44