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-hip-common.h" 9 10 #include <ceed.h> 11 #include <ceed/backend.h> 12 #include <stdlib.h> 13 #include <string.h> 14 15 //------------------------------------------------------------------------------ 16 // Device information backend init 17 //------------------------------------------------------------------------------ 18 int CeedInit_Hip(Ceed ceed, const char *resource) { 19 const char *device_spec = strstr(resource, ":device_id="); 20 const int device_id = (device_spec) ? atoi(device_spec + 11) : -1; 21 22 int current_device_id; 23 CeedCallHip(ceed, hipGetDevice(¤t_device_id)); 24 if (device_id >= 0 && current_device_id != device_id) { 25 CeedCallHip(ceed, hipSetDevice(device_id)); 26 current_device_id = device_id; 27 } 28 29 struct hipDeviceProp_t device_prop; 30 CeedCallHip(ceed, hipGetDeviceProperties(&device_prop, current_device_id)); 31 32 Ceed_Hip *data; 33 CeedCallBackend(CeedGetData(ceed, &data)); 34 data->device_id = current_device_id; 35 data->opt_block_size = 256; 36 return CEED_ERROR_SUCCESS; 37 } 38 39 //------------------------------------------------------------------------------ 40 // Backend Destroy 41 //------------------------------------------------------------------------------ 42 int CeedDestroy_Hip(Ceed ceed) { 43 Ceed_Hip *data; 44 CeedCallBackend(CeedGetData(ceed, &data)); 45 if (data->hipblas_handle) { 46 CeedCallHipblas(ceed, hipblasDestroy(data->hipblas_handle)); 47 } 48 CeedCallBackend(CeedFree(&data)); 49 return CEED_ERROR_SUCCESS; 50 } 51 52 //------------------------------------------------------------------------------ 53