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. 30d0321e0SJeremy L Thompson // 43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 50d0321e0SJeremy L Thompson // 63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 70d0321e0SJeremy L Thompson 80d0321e0SJeremy L Thompson #include "ceed-hip-ref.h" 90d0321e0SJeremy L Thompson 1049aac155SJeremy L Thompson #include <ceed.h> 112b730f8bSJeremy L Thompson #include <ceed/backend.h> 1249aac155SJeremy L Thompson #include <stdbool.h> 132b730f8bSJeremy L Thompson #include <string.h> 142b730f8bSJeremy L Thompson 1549aac155SJeremy L Thompson #include "../hip/ceed-hip-common.h" 1649aac155SJeremy L Thompson 170d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 180d0321e0SJeremy L Thompson // HIP preferred MemType 190d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 20d075f50bSSebastian Grimberg static int CeedGetPreferredMemType_Hip(CeedMemType *mem_type) { 21d075f50bSSebastian Grimberg *mem_type = CEED_MEM_DEVICE; 220d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 230d0321e0SJeremy L Thompson } 240d0321e0SJeremy L Thompson 250d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 260d0321e0SJeremy L Thompson // Get hipBLAS handle 270d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 28eb7e6cafSJeremy L Thompson int CeedGetHipblasHandle_Hip(Ceed ceed, hipblasHandle_t *handle) { 290d0321e0SJeremy L Thompson Ceed_Hip *data; 300d0321e0SJeremy L Thompson 31b7453713SJeremy L Thompson CeedCallBackend(CeedGetData(ceed, &data)); 320002d81dSZach Atkins if (!data->hipblas_handle) { 330002d81dSZach Atkins CeedCallHipblas(ceed, hipblasCreate(&data->hipblas_handle)); 340002d81dSZach Atkins CeedCallHipblas(ceed, hipblasSetPointerMode(data->hipblas_handle, HIPBLAS_POINTER_MODE_HOST)); 350002d81dSZach Atkins } 360d0321e0SJeremy L Thompson *handle = data->hipblas_handle; 370d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 380d0321e0SJeremy L Thompson } 390d0321e0SJeremy L Thompson 400d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 410d0321e0SJeremy L Thompson // Backend Init 420d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 43eb7e6cafSJeremy L Thompson static int CeedInit_Hip_ref(const char *resource, Ceed ceed) { 44b7453713SJeremy L Thompson Ceed_Hip *data; 45b11824b3SJeremy L Thompson char *resource_root; 46b7453713SJeremy L Thompson 47bc246734SJeremy L Thompson CeedCallBackend(CeedGetResourceRoot(ceed, resource, ":", &resource_root)); 486574a04fSJeremy L Thompson CeedCheck(!strcmp(resource_root, "/gpu/hip/ref"), ceed, CEED_ERROR_BACKEND, "Hip backend cannot use resource: %s", resource); 492b730f8bSJeremy L Thompson CeedCallBackend(CeedFree(&resource_root)); 502b730f8bSJeremy L Thompson CeedCallBackend(CeedSetDeterministic(ceed, true)); 510d0321e0SJeremy L Thompson 522b730f8bSJeremy L Thompson CeedCallBackend(CeedCalloc(1, &data)); 532b730f8bSJeremy L Thompson CeedCallBackend(CeedSetData(ceed, data)); 54eb7e6cafSJeremy L Thompson CeedCallBackend(CeedInit_Hip(ceed, resource)); 550d0321e0SJeremy L Thompson 562b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "GetPreferredMemType", CeedGetPreferredMemType_Hip)); 572b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "VectorCreate", CeedVectorCreate_Hip)); 582b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateTensorH1", CeedBasisCreateTensorH1_Hip)); 592b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateH1", CeedBasisCreateH1_Hip)); 60d075f50bSSebastian Grimberg CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateHdiv", CeedBasisCreateHdiv_Hip)); 61d075f50bSSebastian Grimberg CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateHcurl", CeedBasisCreateHcurl_Hip)); 622b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "ElemRestrictionCreate", CeedElemRestrictionCreate_Hip)); 63fe960054SJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "ElemRestrictionCreateAtPoints", CeedElemRestrictionCreate_Hip)); 642b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "QFunctionCreate", CeedQFunctionCreate_Hip)); 652b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "QFunctionContextCreate", CeedQFunctionContextCreate_Hip)); 662b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "OperatorCreate", CeedOperatorCreate_Hip)); 6767d9480aSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "OperatorCreateAtPoints", CeedOperatorCreateAtPoints_Hip)); 682b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy", CeedDestroy_Hip)); 690d0321e0SJeremy L Thompson return CEED_ERROR_SUCCESS; 700d0321e0SJeremy L Thompson } 710d0321e0SJeremy L Thompson 720d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 730d0321e0SJeremy L Thompson // Backend Register 740d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 75eb7e6cafSJeremy L Thompson CEED_INTERN int CeedRegister_Hip(void) { return CeedRegister("/gpu/hip/ref", CeedInit_Hip_ref, 40); } 762a86cc9dSSebastian Grimberg 770d0321e0SJeremy L Thompson //------------------------------------------------------------------------------ 78