Path: blob/21.2-virgl/src/gallium/frontends/clover/core/module.hpp
4572 views
//1// Copyright 2012 Francisco Jerez2//3// Permission is hereby granted, free of charge, to any person obtaining a4// copy of this software and associated documentation files (the "Software"),5// to deal in the Software without restriction, including without limitation6// the rights to use, copy, modify, merge, publish, distribute, sublicense,7// and/or sell copies of the Software, and to permit persons to whom the8// Software is furnished to do so, subject to the following conditions:9//10// The above copyright notice and this permission notice shall be included in11// all copies or substantial portions of the Software.12//13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR17// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19// OTHER DEALINGS IN THE SOFTWARE.20//2122#ifndef CLOVER_CORE_MODULE_HPP23#define CLOVER_CORE_MODULE_HPP2425#include <vector>26#include <string>2728#include "CL/cl.h"2930namespace clover {31struct module {32typedef uint32_t resource_id;33typedef uint32_t size_t;3435struct section {36enum type {37text_intermediate,38text_library,39text_executable,40data_constant,41data_global,42data_local,43data_private44};4546section(resource_id id, enum type type, size_t size,47const std::vector<char> &data) :48id(id), type(type), size(size), data(data) { }49section() : id(0), type(text_intermediate), size(0), data() { }5051resource_id id;52type type;53size_t size;54std::vector<char> data;55};5657struct printf_info {58std::vector<uint32_t> arg_sizes;59std::vector<uint8_t> strings;60};6162struct arg_info {63arg_info(const std::string &arg_name, const std::string &type_name,64const cl_kernel_arg_type_qualifier type_qualifier,65const cl_kernel_arg_address_qualifier address_qualifier,66const cl_kernel_arg_access_qualifier access_qualifier) :67arg_name(arg_name), type_name(type_name),68type_qualifier(type_qualifier),69address_qualifier(address_qualifier),70access_qualifier(access_qualifier) { };71arg_info() : arg_name(""), type_name(""), type_qualifier(0),72address_qualifier(0), access_qualifier(0) { };7374std::string arg_name;75std::string type_name;76cl_kernel_arg_type_qualifier type_qualifier;77cl_kernel_arg_address_qualifier address_qualifier;78cl_kernel_arg_access_qualifier access_qualifier;79};8081struct argument {82enum type {83scalar,84constant,85global,86local,87image_rd,88image_wr,89sampler90};9192enum ext_type {93zero_ext,94sign_ext95};9697enum semantic {98general,99grid_dimension,100grid_offset,101image_size,102image_format,103constant_buffer,104printf_buffer105};106107argument(enum type type, size_t size,108size_t target_size, size_t target_align,109enum ext_type ext_type,110enum semantic semantic = general) :111type(type), size(size),112target_size(target_size), target_align(target_align),113ext_type(ext_type), semantic(semantic) { }114115argument(enum type type, size_t size) :116type(type), size(size),117target_size(size), target_align(1),118ext_type(zero_ext), semantic(general) { }119120argument() : type(scalar), size(0),121target_size(0), target_align(1),122ext_type(zero_ext), semantic(general) { }123124type type;125size_t size;126size_t target_size;127size_t target_align;128ext_type ext_type;129semantic semantic;130arg_info info;131};132133struct symbol {134symbol(const std::string &name, const std::string &attributes,135const std::vector<::size_t> &reqd_work_group_size,136resource_id section, size_t offset,137const std::vector<argument> &args) :138name(name), attributes(attributes),139reqd_work_group_size(reqd_work_group_size),140section(section),141offset(offset), args(args) { }142symbol() : name(), attributes(), reqd_work_group_size({0, 0, 0}),143section(0), offset(0), args() { }144145std::string name;146std::string attributes;147std::vector<::size_t> reqd_work_group_size;148resource_id section;149size_t offset;150std::vector<argument> args;151};152153module() : printf_strings_in_buffer(0) { }154void serialize(std::ostream &os) const;155static module deserialize(std::istream &is);156size_t size() const;157158std::vector<symbol> syms;159std::vector<section> secs;160std::vector<printf_info> printf_infos;161// printfs strings stored in output buffer162uint32_t printf_strings_in_buffer;163};164}165166#endif167168169