1 #pragma once 2 #define HIP_TYPES 3 #ifdef __APPLE__ 4 5 #define LongUnsignedNewline "%llu\n" 6 #define Size_tNewline "%lu\n" 7 #define LongHexNewline "(0x%llx)\n" 8 #define alignedMalloc(size, alignment) memalign(alignment, size) 9 #define SNPRINTF snprintf 10 #else 11 12 #include <malloc.h> 13 14 #define LongHexNewline "(0x%lx)\n" 15 #define LongUnsignedNewline "%lu\n" 16 #define Size_tNewline "%lu\n" 17 #if defined (_WIN32) 18 #include "windows.h" 19 #define alignedMalloc(size, alignment) _aligned_malloc(size, alignment) 20 #define SNPRINTF _snprintf 21 #else 22 #define alignedMalloc(size, alignment) memalign(alignment, size) 23 #define SNPRINTF snprintf 24 #endif 25 #endif 26 27 #include <iostream> 28 #include <hip/hip_runtime.h> 29 30 #define HIP_TYPES 31 32 #include "shared.h" 33 34 #include <fstream> 35 36 #include<vector> 37 38 class HIPBackend : public Backend { 39 public: 40 class HIPConfig : public Backend::Config { 41 public: 42 boolean gpu; 43 }; 44 45 class HIPProgram : public Backend::Program { 46 class HIPKernel : public Backend::Program::Kernel { 47 class HIPBuffer : public Backend::Program::Kernel::Buffer { 48 public: 49 hipDeviceptr_t devicePtr; 50 51 HIPBuffer(Backend::Program::Kernel *kernel, Arg_s *arg); 52 53 void copyToDevice(); 54 55 void copyFromDevice(); 56 57 virtual ~HIPBuffer(); 58 }; 59 60 private: 61 hipFunction_t kernel; 62 hipStream_t hipStream; 63 public: 64 HIPKernel(Backend::Program *program, char* name, hipFunction_t kernel); 65 66 ~HIPKernel() override; 67 68 long ndrange( void *argArray); 69 }; 70 71 private: 72 hipModule_t module; 73 74 public: 75 HIPProgram(Backend *backend, BuildInfo *buildInfo, hipModule_t module); 76 77 ~HIPProgram(); 78 79 long getKernel(int nameLen, char *name); 80 81 bool programOK(); 82 }; 83 84 private: 85 hipDevice_t device; 86 hipCtx_t context; 87 public: 88 89 HIPBackend(HIPConfig *config, int configSchemaLen, char *configSchema); 90 91 HIPBackend(); 92 93 ~HIPBackend(); 94 95 int getMaxComputeUnits(); 96 97 void info(); 98 99 long compileProgram(int len, char *source); 100 101 }; 102