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 SpirvConfig : public Backend::Config { 30 public : 31 }; 32 33 class SpirvProgram : public Backend::Program { 34 class SpirvKernel : public Backend::Program::Kernel { 35 public: 36 SpirvKernel(Backend::Program *program, char *name) 37 : Backend::Program::Kernel(program, name) { 38 } 39 40 ~SpirvKernel() { 41 } 42 43 long ndrange(void *argArray) { 44 std::cout << "spirv ndrange() " << std::endl; 45 return 0; 46 } 47 }; 48 49 public: 50 SpirvProgram(Backend *backend, BuildInfo *buildInfo) 51 : Backend::Program(backend, buildInfo) { 52 } 53 54 ~SpirvProgram() { 55 } 56 57 long getKernel(int nameLen, char *name) { 58 return (long) new SpirvKernel(this, name); 59 } 60 61 bool programOK() { 62 return true; 63 } 64 }; 65 66 public: 67 68 SpirvBackend(SpirvConfig *spirvConfig, int spirvConfigSchemeLen, char *spirvBackendSchema) 69 : Backend(spirvConfig, spirvConfigSchemeLen, spirvBackendSchema) { 70 if (spirvConfig == nullptr) { 71 std::cout << "spirvConfig == null" << std::endl; 72 } else { 73 std::cout << "spirvConfig != null" << std::endl; 74 } 75 } 76 77 ~SpirvBackend() { 78 } 79 80 int getMaxComputeUnits() { 81 std::cout << "spirv getMaxComputeUnits()" << std::endl; 82 return 0; 83 } 84 85 void info() { 86 std::cout << "spirv info()" << std::endl; 87 } 88 89 long compileProgram(int len, char *source) { 90 std::cout << "spirv compileProgram()" << std::endl; 91 size_t srcLen = ::strlen(source); 92 char *src = new char[srcLen + 1]; 93 ::strncpy(src, source, srcLen); 94 src[srcLen] = '\0'; 95 std::cout << "native compiling " << src << std::endl; 96 return (long) new SpirvProgram(this, new BuildInfo(src, nullptr, false)); 97 } 98 }; 99 100 long getBackend(void *config, int configSchemaLen, char *configSchema) { 101 SpirvBackend::SpirvConfig *spirvConfig = (SpirvBackend::SpirvConfig *) config; 102 return (long) new SpirvBackend(spirvConfig, configSchemaLen, configSchema); 103 }