// Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. // // SPDX-License-Identifier: BSD-2-Clause // // This file is part of CEED: http://github.com/ceed #include "ceed-hip-ref.h" #include #include #include #include #include "../hip/ceed-hip-common.h" //------------------------------------------------------------------------------ // HIP preferred MemType //------------------------------------------------------------------------------ static int CeedGetPreferredMemType_Hip(CeedMemType *type) { *type = CEED_MEM_DEVICE; return CEED_ERROR_SUCCESS; } //------------------------------------------------------------------------------ // Get hipBLAS handle //------------------------------------------------------------------------------ int CeedGetHipblasHandle_Hip(Ceed ceed, hipblasHandle_t *handle) { Ceed_Hip *data; CeedCallBackend(CeedGetData(ceed, &data)); if (!data->hipblas_handle) CeedCallHipblas(ceed, hipblasCreate(&data->hipblas_handle)); *handle = data->hipblas_handle; return CEED_ERROR_SUCCESS; } //------------------------------------------------------------------------------ // Backend Init //------------------------------------------------------------------------------ static int CeedInit_Hip_ref(const char *resource, Ceed ceed) { Ceed_Hip *data; char *resource_root; CeedCallBackend(CeedGetResourceRoot(ceed, resource, ":", &resource_root)); CeedCheck(!strcmp(resource_root, "/gpu/hip/ref"), ceed, CEED_ERROR_BACKEND, "Hip backend cannot use resource: %s", resource); CeedCallBackend(CeedFree(&resource_root)); CeedCallBackend(CeedSetDeterministic(ceed, true)); CeedCallBackend(CeedCalloc(1, &data)); CeedCallBackend(CeedSetData(ceed, data)); CeedCallBackend(CeedInit_Hip(ceed, resource)); CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "GetPreferredMemType", CeedGetPreferredMemType_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "VectorCreate", CeedVectorCreate_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateTensorH1", CeedBasisCreateTensorH1_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "BasisCreateH1", CeedBasisCreateH1_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "ElemRestrictionCreate", CeedElemRestrictionCreate_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "QFunctionCreate", CeedQFunctionCreate_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "QFunctionContextCreate", CeedQFunctionContextCreate_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "OperatorCreate", CeedOperatorCreate_Hip)); CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy", CeedDestroy_Hip)); return CEED_ERROR_SUCCESS; } //------------------------------------------------------------------------------ // Backend Register //------------------------------------------------------------------------------ CEED_INTERN int CeedRegister_Hip(void) { return CeedRegister("/gpu/hip/ref", CeedInit_Hip_ref, 40); } //------------------------------------------------------------------------------