1 /* 2 * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 #include "shared.h" 26 27 class SpirvBackend : public Backend { 28 public: 29 class SpirvProgram : public Backend::Program { 30 class SpirvKernel : public Backend::Program::Kernel { 31 public: 32 SpirvKernel(Backend::Program *program, char *name) 33 : Backend::Program::Kernel(program, name) { 34 } 35 36 ~SpirvKernel() { 37 } 38 39 long ndrange(void *argArray) { 40 std::cout << "spirv ndrange() " << std::endl; 41 return 0; 42 } 43 }; 44 45 public: 46 SpirvProgram(Backend *backend, BuildInfo *buildInfo) 47 : Backend::Program(backend, buildInfo) { 48 } 49 50 ~SpirvProgram() { 51 } 52 53 long getKernel(int nameLen, char *name) { 54 return (long) new SpirvKernel(this, name); 55 } 56 57 bool programOK() { 58 return true; 59 } 60 }; 61 62 public: 63 SpirvBackend(int mode): Backend(mode) { 64 } 65 66 ~SpirvBackend() { 67 } 68 bool getBufferFromDeviceIfDirty(void *memorySegment, long memorySegmentLength) { 69 std::cout << "attempting to get buffer from SpirvBackend "<<std::endl; 70 return false; 71 } 72 int getMaxComputeUnits() { 73 std::cout << "spirv getMaxComputeUnits()" << std::endl; 74 return 0; 75 } 76 77 void info() { 78 std::cout << "spirv info()" << std::endl; 79 } 80 void computeStart(){ 81 std::cout << "spirv compute start()" << std::endl; 82 } 83 void computeEnd(){ 84 std::cout << "spirv compute start()" << std::endl; 85 } 86 87 long compileProgram(int len, char *source) { 88 std::cout << "spirv compileProgram()" << std::endl; 89 size_t srcLen = ::strlen(source); 90 char *src = new char[srcLen + 1]; 91 ::strncpy(src, source, srcLen); 92 src[srcLen] = '\0'; 93 std::cout << "native compiling " << src << std::endl; 94 return (long) new SpirvProgram(this, new BuildInfo(src, nullptr, false)); 95 } 96 }; 97 98 long getSpirvBackend(int mode) { 99 return (long) new SpirvBackend(mode); 100 }