<commit_before>
/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2006 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/
//$Id$

#ifndef RASTER_COLORIZER_HPP
#define RASTER_COLORIZER_HPP

#include <mapnik/config.hpp>
#include <mapnik/config_error.hpp>
#include <mapnik/color.hpp>
#include <mapnik/feature.hpp>

#include <vector>

using mapnik::color;
using std::vector;

namespace mapnik
{
    struct MAPNIK_DECL color_band
    {
      float value_;
      color color_;
      unsigned midpoints_;
      bool is_interpolated_;
      color_band(float value, color c)
            : value_(value),
              color_(c),
              midpoints_(0),
              is_interpolated_(false) {}
      const bool is_interpolated() const
      {
         return is_interpolated_;
      }
      const unsigned get_midpoints() const
      {
         return midpoints_;
      }
      const float get_value() const
      {
         return value_;
      }
      const color& get_color() const
      {
         return color_;
      }
      bool operator==(color_band const& other) const
      {
          return value_ == other.value_ && color_ == other.color_;
      }
      std::string to_string() const
      {
          std::stringstream ss;
          ss << color_.to_string() << " " << value_;
          return ss.str();
      }
   };

    typedef vector<color_band> color_bands;

    struct MAPNIK_DECL raster_colorizer
    {
         explicit raster_colorizer()
            : colors_() {}

         raster_colorizer(const raster_colorizer &ps)
            : colors_(ps.colors_) {}

         raster_colorizer(color_bands &colors)
            : colors_(colors) {}

         const color_bands& get_color_bands() const
         {
            return colors_;
         }
         void append_band (color_band band)
         {
            if (colors_.size() > 0 && colors_.back().value_ > band.value_) {
#ifdef MAPNIK_DEBUG
               std::clog << "prev.v=" << colors_.back().value_ << ". band.v=" << band.value_ << "\n";
#endif
               throw config_error(
                  "Bands must be appended in ascending value order"
                  );
            }
            colors_.push_back(band);
         }
         void append_band (color_band band, unsigned midpoints)
         {
            band.midpoints_ = midpoints;
            if (colors_.size() > 0 && midpoints > 0) {
               color_band lo = colors_.back();
               color_band const &hi = band;
               int steps = midpoints+1;
               float dv = (hi.value_ - lo.value_)/steps;
               float da = (float(hi.color_.alpha()) - lo.color_.alpha())/steps;
               float dr = (float(hi.color_.red()) - lo.color_.red())/steps;
               float dg = (float(hi.color_.green()) - lo.color_.green())/steps;
               float db = (float(hi.color_.blue()) - lo.color_.blue())/steps;

#ifdef MAPNIK_DEBUG
               std::clog << "lo.v=" << lo.value_ << ", hi.v=" << hi.value_ << ", dv="<<dv<<"\n";
#endif
               // interpolate intermediate values and colors
               int j;
               for (j=1; j<steps; j++) {
                   color_band b(
                     lo.get_value() + dv*j,
                     color(int(float(lo.color_.red()) + dr*j),
                           int(float(lo.color_.green()) + dg*j),
                           int(float(lo.color_.blue()) + db*j),
                           int(float(lo.color_.alpha()) + da*j)
                           )
                     );
                     b.is_interpolated_ = true;
                     append_band(b);
               }
            }
            append_band(band);
         }

         void append_band (float value, color c)
         {
            append_band(color_band(value, c));
         }

         void append_band (float value, color c, unsigned midpoints)
         {
            append_band(color_band(value, c), midpoints);
         }

        /* rgba =
         *   if cs[pos].value <= value < cs[pos+1].value: cs[pos].color
         *   otherwise: transparent
         *     where 0 <= pos < length(bands)-1
         *   Last band is special, its value represents the upper bound and its
         *   color will only be used if the value matches its value exactly.
         */
         color get_color(float value) const {
            int pos=-1, last=(int)colors_.size()-1, lo=0, hi=last;
            while (lo<=hi) {
                pos = (lo+hi)/2;
                if (colors_[pos].value_<value) {
                    lo = pos+1;
                } else if (colors_[pos].value_>value) {
                    hi = pos-1;
                } else {
                    lo = pos+1;
                    break;
                }
            }
            lo--;
            if ((0 <= lo && lo < last) ||
                (lo==last && colors_[last].value_==value))
                return colors_[lo].color_;
            else
                return color(0,0,0,0);
         }

         void colorize(mapnik::raster_ptr const& raster) const {
            float *rasterData = (float*)raster->data_.getBytes();
            unsigned *imageData = raster->data_.getData();
            unsigned i;
            for (i=0; i<raster->data_.width()*raster->data_.height(); i++)
                imageData[i] = get_color(rasterData[i]).rgba();
         }

       private:
         color_bands colors_;
    };

    typedef boost::shared_ptr<mapnik::raster_colorizer> raster_colorizer_ptr;
}

#endif //RASTER_COLORIZER_HPP
<commit_msg>+ remove mapnik:: classification from inside namespace mapnik {} + use c++ style casts!<commit_after>
/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2006 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/
//$Id$

#ifndef RASTER_COLORIZER_HPP
#define RASTER_COLORIZER_HPP

#include <mapnik/config.hpp>
#include <mapnik/config_error.hpp>
#include <mapnik/color.hpp>
#include <mapnik/feature.hpp>

#include <vector>

namespace mapnik
{
struct MAPNIK_DECL color_band
{
    float value_;
    color color_;
    unsigned midpoints_;
    bool is_interpolated_;
    color_band(float value, color c)
	: value_(value),
	color_(c),
	midpoints_(0),
	is_interpolated_(false) {}
    const bool is_interpolated() const
    {
	return is_interpolated_;
    }
    const unsigned get_midpoints() const
    {
	return midpoints_;
    }
    const float get_value() const
    {
	return value_;
    }
    const color& get_color() const
    {
	return color_;
    }
    bool operator==(color_band const& other) const
    {
	return value_ == other.value_ && color_ == other.color_;
    }
    std::string to_string() const
    {
	std::stringstream ss;
	ss << color_.to_string() << " " << value_;
	return ss.str();
    }
};

typedef std::vector<color_band> color_bands;

struct MAPNIK_DECL raster_colorizer
{
    explicit raster_colorizer()
	: colors_() {}

    raster_colorizer(const raster_colorizer &ps)
	: colors_(ps.colors_) {}

    raster_colorizer(color_bands &colors)
	: colors_(colors) {}

    const color_bands& get_color_bands() const
    {
	return colors_;
    }
    void append_band (color_band band)
    {
	if (colors_.size() > 0 && colors_.back().value_ > band.value_) {
#ifdef MAPNIK_DEBUG
	    std::clog << "prev.v=" << colors_.back().value_ << ". band.v=" << band.value_ << "\n";
#endif
	    throw config_error(
		"Bands must be appended in ascending value order"
		);
	}
	colors_.push_back(band);
    }
    void append_band (color_band band, unsigned midpoints)
    {
	band.midpoints_ = midpoints;
	if (colors_.size() > 0 && midpoints > 0) {
	    color_band lo = colors_.back();
	    color_band const &hi = band;
	    int steps = midpoints+1;
	    float dv = (hi.value_ - lo.value_)/steps;
	    float da = (float(hi.color_.alpha()) - lo.color_.alpha())/steps;
	    float dr = (float(hi.color_.red()) - lo.color_.red())/steps;
	    float dg = (float(hi.color_.green()) - lo.color_.green())/steps;
	    float db = (float(hi.color_.blue()) - lo.color_.blue())/steps;

#ifdef MAPNIK_DEBUG
	    std::clog << "lo.v=" << lo.value_ << ", hi.v=" << hi.value_ << ", dv="<<dv<<"\n";
#endif
	    // interpolate intermediate values and colors
	    int j;
	    for (j=1; j<steps; j++) {
		color_band b(
		    lo.get_value() + dv*j,
		    color(int(float(lo.color_.red()) + dr*j),
			  int(float(lo.color_.green()) + dg*j),
			  int(float(lo.color_.blue()) + db*j),
			  int(float(lo.color_.alpha()) + da*j)
			)
		    );
		b.is_interpolated_ = true;
		append_band(b);
	    }
	}
	append_band(band);
    }

    void append_band (float value, color c)
    {
	append_band(color_band(value, c));
    }

    void append_band (float value, color c, unsigned midpoints)
    {
	append_band(color_band(value, c), midpoints);
    }

    /* rgba =
     *   if cs[pos].value <= value < cs[pos+1].value: cs[pos].color
     *   otherwise: transparent
     *     where 0 <= pos < length(bands)-1
     *   Last band is special, its value represents the upper bound and its
     *   color will only be used if the value matches its value exactly.
     */
    color get_color(float value) const {
	int pos=-1, last=(int)colors_.size()-1, lo=0, hi=last;
	while (lo<=hi) {
	    pos = (lo+hi)/2;
	    if (colors_[pos].value_<value) {
		lo = pos+1;
	    } else if (colors_[pos].value_>value) {
		hi = pos-1;
	    } else {
		lo = pos+1;
		break;
	    }
	}
	lo--;
	if ((0 <= lo && lo < last) ||
	    (lo==last && colors_[last].value_==value))
	    return colors_[lo].color_;
	else
	    return color(0,0,0,0);
    }

    void colorize(raster_ptr const& raster) const
    {
	float *rasterData = reinterpret_cast<float*>(raster->data_.getBytes());
	unsigned *imageData = raster->data_.getData();
	unsigned i;
	for (i=0; i<raster->data_.width()*raster->data_.height(); i++)
	{
	    imageData[i] = get_color(rasterData[i]).rgba();
	}
    }

private:
    color_bands colors_;
};

typedef boost::shared_ptr<raster_colorizer> raster_colorizer_ptr;

} // mapnik namespace

#endif //RASTER_COLORIZER_HPP
<|endoftext|>


<commit_before>#pragma once

#include <string>
#include <unordered_map>

#include <glm/glm.hpp>

#include "nova_renderer/rhi_enums.hpp"

#include "device_memory_resource.hpp"
#include "shaderpack_data.hpp"

namespace nova::renderer::rhi {

#pragma region Structs
    struct BufferCreateInfo {
        uint64_t size = 0;

        BufferUsage buffer_usage{};
    };

    struct DeviceMemory {};

    /*!
     * \brief A resource
     *
     * Resources may by dynamic of static. Dynamic resources are updated after they are created, possibly by a shader,
     * while static resources are loaded once and that's that
     */
    struct Resource {
        ResourceType type = {};
        bool is_dynamic = true;
    };

    struct Sampler {};

    struct Image : Resource {
        bool is_depth_tex = false;
    };

    struct Buffer : Resource {
        uint32_t size = 0;
    };

    struct Framebuffer {
        glm::uvec2 size;

        uint32_t num_attachments;
    };

    struct Renderpass {};

    struct ResourceBindingDescription {
        /*!
         * \brief Descriptor set that his binding belongs to
         */
        uint32_t set;

        /*!
         * \brief Binding of this resource binding
         */
        uint32_t binding;

        /*!
         * \brief Number of bindings. Useful if you have an array of descriptors
         *
         * If this is a unbounded array, this count is the upper limit on the size of the array
         */
        uint32_t count;

        /*!
         * \brief If true, this binding is an unbounded array
         *
         * Unbounded descriptors must be the final binding in their descriptor set
         */
        bool is_unbounded;

        /*!
         * \brief The type of object that will be bound
         */
        DescriptorType type;

        /*!
         * \brief The shader stages that need access to this binding
         */
        ShaderStageFlags stages;

        bool operator==(const ResourceBindingDescription& other);

        bool operator!=(const ResourceBindingDescription& other);
    };

    /*!
     * \brief The interface for a pipeline. Includes both inputs (descriptors) and outputs (framebuffers)
     */
    struct PipelineInterface {
        std::unordered_map<std::string, ResourceBindingDescription> bindings;
    };

    struct Pipeline {};

    struct Semaphore {};

    struct PresentSemaphore {};

    struct Fence {};

    struct DescriptorPool {};

    struct DescriptorSet {};

    // TODO: This struct actually maps pretty directly to a Vulkan barrier, so it doesn't map well to a D3D12 barrier. Figure out how to
    // make it D3D12-friendly
    struct ResourceBarrier {
        Resource* resource_to_barrier;

        /*!
         * \brief The resource access that much finish before this barrier executed
         */
        AccessFlags access_before_barrier;

        /*!
         * \brief The resource access that must wait for this battier to finish executing
         */
        AccessFlags access_after_barrier;

        /*!
         * \brief How you're going to access this resource just before this barrier
         *
         * Will a shader read from it before the barrier? Will the fragment depth by copied to a depth buffer before
         * this barrier? Will the resource be used as a indirect draw command buffer right before this barrier?
         */
        ResourceState old_state;

        /*!
         * \brief How you're going to access this resource after this barrier
         *
         * Will a shader read from it after the barrier? Will the fragment depth by copied to a depth buffer after
         * this barrier? Will the resource be used as a indirect draw command buffer right after this barrier?
         */
        ResourceState new_state;

        QueueType source_queue;
        QueueType destination_queue;

        union {
            struct {
                ImageAspectFlags aspect;
            } image_memory_barrier;

            struct {
                uint64_t offset;
                uint64_t size;
            } buffer_memory_barrier;
        };
    };

    struct DescriptorImageUpdate {
        const Image* image;
        shaderpack::TextureFormat format;
        Sampler* sampler;
    };

    struct DescriptorBufferWrite {
        const Buffer* buffer;
    };

    struct DescriptorSetWrite {
        /*!
         * \brief Pointer to the descriptor set to write to
         */
        DescriptorSet* set;

        /*!
         * \brief The specific binding in the set that you want to write to
         */
        uint32_t binding;

        /*!
         * \brief The type of descriptor you're writing to
         */
        DescriptorType type;

        union {
            /*!
             * \brief Information to update an image descriptor
             */
            DescriptorImageUpdate image_info;

            /*!
             * \brief Information to update a buffer descriptor
             */
            DescriptorBufferWrite buffer_info;
        };
    };
#pragma endregion

    ShaderStageFlags operator|=(ShaderStageFlags lhs, ShaderStageFlags rhs);
} // namespace nova::renderer::rhi
<commit_msg>[rhi] Support for updating descriptors as arrays of resources<commit_after>#pragma once

#include <string>
#include <unordered_map>

#include <glm/glm.hpp>

#include "nova_renderer/rhi_enums.hpp"

#include "device_memory_resource.hpp"
#include "shaderpack_data.hpp"

namespace nova::renderer::rhi {

#pragma region Structs
    struct BufferCreateInfo {
        uint64_t size = 0;

        BufferUsage buffer_usage{};
    };

    struct DeviceMemory {};

    /*!
     * \brief A resource
     *
     * Resources may by dynamic of static. Dynamic resources are updated after they are created, possibly by a shader,
     * while static resources are loaded once and that's that
     */
    struct Resource {
        ResourceType type = {};
        bool is_dynamic = true;
    };

    struct Sampler {};

    struct Image : Resource {
        bool is_depth_tex = false;
    };

    struct Buffer : Resource {
        uint32_t size = 0;
    };

    struct Framebuffer {
        glm::uvec2 size;

        uint32_t num_attachments;
    };

    struct Renderpass {};

    struct ResourceBindingDescription {
        /*!
         * \brief Descriptor set that his binding belongs to
         */
        uint32_t set;

        /*!
         * \brief Binding of this resource binding
         */
        uint32_t binding;

        /*!
         * \brief Number of bindings. Useful if you have an array of descriptors
         *
         * If this is a unbounded array, this count is the upper limit on the size of the array
         */
        uint32_t count;

        /*!
         * \brief If true, this binding is an unbounded array
         *
         * Unbounded descriptors must be the final binding in their descriptor set
         */
        bool is_unbounded;

        /*!
         * \brief The type of object that will be bound
         */
        DescriptorType type;

        /*!
         * \brief The shader stages that need access to this binding
         */
        ShaderStageFlags stages;

        bool operator==(const ResourceBindingDescription& other);

        bool operator!=(const ResourceBindingDescription& other);
    };

    /*!
     * \brief The interface for a pipeline. Includes both inputs (descriptors) and outputs (framebuffers)
     */
    struct PipelineInterface {
        std::unordered_map<std::string, ResourceBindingDescription> bindings;
    };

    struct Pipeline {};

    struct Semaphore {};

    struct PresentSemaphore {};

    struct Fence {};

    struct DescriptorPool {};

    struct DescriptorSet {};

    // TODO: This struct actually maps pretty directly to a Vulkan barrier, so it doesn't map well to a D3D12 barrier. Figure out how to
    // make it D3D12-friendly
    struct ResourceBarrier {
        Resource* resource_to_barrier;

        /*!
         * \brief The resource access that much finish before this barrier executed
         */
        AccessFlags access_before_barrier;

        /*!
         * \brief The resource access that must wait for this battier to finish executing
         */
        AccessFlags access_after_barrier;

        /*!
         * \brief How you're going to access this resource just before this barrier
         *
         * Will a shader read from it before the barrier? Will the fragment depth by copied to a depth buffer before
         * this barrier? Will the resource be used as a indirect draw command buffer right before this barrier?
         */
        ResourceState old_state;

        /*!
         * \brief How you're going to access this resource after this barrier
         *
         * Will a shader read from it after the barrier? Will the fragment depth by copied to a depth buffer after
         * this barrier? Will the resource be used as a indirect draw command buffer right after this barrier?
         */
        ResourceState new_state;

        QueueType source_queue;
        QueueType destination_queue;

        union {
            struct {
                ImageAspectFlags aspect;
            } image_memory_barrier;

            struct {
                uint64_t offset;
                uint64_t size;
            } buffer_memory_barrier;
        };
    };

    struct DescriptorImageInfo {
        const Image* image;
        shaderpack::TextureFormat format;
        Sampler* sampler;
    };

    struct DescriptorBufferInfo {
        const Buffer* buffer;
    };

	union DescriptorResourceInfo {
		/*!
		 * \brief Information to update an image descriptor
		 */
		DescriptorImageInfo image_info;

		/*!
		 * \brief Information to update a buffer descriptor
		 */
		DescriptorBufferInfo buffer_info;
	};

    struct DescriptorSetWrite {
        /*!
         * \brief Pointer to the descriptor set to write to
         */
        DescriptorSet* set;

        /*!
         * \brief The specific binding in the set that you want to write to
         */
        uint32_t first_binding;

        /*!
         * \brief The type of descriptor you're writing to
         */
        DescriptorType type;

        /*!
         * \brief Information about th
         */
        std::vector<DescriptorResourceInfo> bindings;
    };
#pragma endregion

    ShaderStageFlags operator|=(ShaderStageFlags lhs, ShaderStageFlags rhs);
} // namespace nova::renderer::rhi
<|endoftext|>


<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/io/p9_io_xbus_clear_firs.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
///
/// @file p9_io_xbus_clear_firs.C
/// @brief Clears I/O Firs
///-----------------------------------------------------------------------------
/// *HWP HWP Owner        : Chris Steffen <cwsteffen@us.ibm.com>
/// *HWP HWP Backup Owner : Gary Peterson <garyp@us.ibm.com>
/// *HWP FW Owner         : Jamie Knight <rjknight@us.ibm.com>
/// *HWP Team             : IO
/// *HWP Level            : 2
/// *HWP Consumed by      : FSP:HB
///-----------------------------------------------------------------------------
///
/// @verbatim
/// High-level procedure flow:
///
/// Clears I/O Xbus FIRs on the PHY Rx/Tx.
///
/// Clocks must be running.
///
/// @endverbatim
///----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//  Includes
//-----------------------------------------------------------------------------
#include <p9_io_xbus_clear_firs.H>
#include <p9_io_gcr.H>
#include <p9_io_regs.H>

//-----------------------------------------------------------------------------
//  Definitions
//-----------------------------------------------------------------------------
fapi2::ReturnCode io_rx_fir_reset(
    const fapi2::Target < fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t& i_clock_group);

fapi2::ReturnCode io_tx_fir_reset(
    const fapi2::Target < fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t& i_clock_group);

/**
 * @brief A HWP that runs on every instance of the XBUS(EDI+)
 * @param[in] i_target         FAPI2 Target
 * @param[in] i_clock_group    Clock Group
 * @retval ReturnCode
 */
fapi2::ReturnCode p9_io_xbus_clear_firs(
    const fapi2::Target < fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t& i_clock_group)
{
    FAPI_IMP("I/O Start Xbus Clear FIRs");

    FAPI_TRY(io_tx_fir_reset(i_target, i_clock_group), "Tx Reset Failed");

    FAPI_TRY(io_rx_fir_reset(i_target, i_clock_group), "Rx Reset Failed");

fapi_try_exit:
    FAPI_IMP("I/O End Xbus Clear FIRs");
    return fapi2::current_err;
}

/**
 * @brief This function resets the Rx Firs on a EDI+ Xbus
 * @param[in] i_target       FAPI2 Target
 * @param[in] i_clock_group  Clock Group
 * @retval ReturnCode
 */
fapi2::ReturnCode io_rx_fir_reset(
    const fapi2::Target < fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t& i_clock_group)
{
    Register < EDIP_RX_GLBSM_CNTLX1_EO_PG > rx_fir_reg;

    FAPI_TRY(rx_fir_reg.read(i_target, i_clock_group),
             "Reading Rx Fir Reg Failed");

    rx_fir_reg.set<EDIP_RX_FIR_RESET>(0);
    FAPI_TRY(rx_fir_reg.write(i_target, i_clock_group),
             "Writing Rx Fir Reg Failed");

    rx_fir_reg.set<EDIP_RX_FIR_RESET>(1);
    FAPI_TRY(rx_fir_reg.write(i_target, i_clock_group),
             "Writing rx Fir Reg Failed");

    rx_fir_reg.set<EDIP_RX_FIR_RESET>(0);
    FAPI_TRY(rx_fir_reg.write(i_target, i_clock_group),
             "Writing Rx Fir Reg Failed");

fapi_try_exit:
    return fapi2::current_err;
}

/**
 * @brief This function resets the Tx Firs on a EDI+ Xbus
 * @param[in] i_target       FAPI2 Target
 * @param[in] i_clock_group  Clock Group
 * @retval ReturnCode
 */
fapi2::ReturnCode io_tx_fir_reset(
    const fapi2::Target < fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t& i_clock_group)
{
    Register < EDIP_TX_FIR_RESET_PG  > tx_fir_reg;

    FAPI_TRY(tx_fir_reg.read(i_target, i_clock_group),
             "Reading Tx Fir Reg Failed");

    tx_fir_reg.set<EDIP_TX_FIR_RESET>(0);
    FAPI_TRY(tx_fir_reg.write(i_target, i_clock_group),
             "Writing Tx Fir Reg Failed");

    tx_fir_reg.set<EDIP_TX_FIR_RESET>(1);
    FAPI_TRY(tx_fir_reg.write(i_target, i_clock_group),
             "Writing Tx Fir Reg Failed");

    tx_fir_reg.set<EDIP_TX_FIR_RESET>(0);
    FAPI_TRY(tx_fir_reg.write(i_target, i_clock_group),
             "Writing Tx Fir Reg Failed");

fapi_try_exit:
    return fapi2::current_err;
}
<commit_msg>io scom access conversion<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/io/p9_io_xbus_clear_firs.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
///
/// @file p9_io_xbus_clear_firs.C
/// @brief Clears I/O Firs
///-----------------------------------------------------------------------------
/// *HWP HWP Owner        : Chris Steffen <cwsteffen@us.ibm.com>
/// *HWP HWP Backup Owner : Gary Peterson <garyp@us.ibm.com>
/// *HWP FW Owner         : Jamie Knight <rjknight@us.ibm.com>
/// *HWP Team             : IO
/// *HWP Level            : 2
/// *HWP Consumed by      : FSP:HB
///-----------------------------------------------------------------------------
///
/// @verbatim
/// High-level procedure flow:
///
/// Clears I/O Xbus FIRs on the PHY Rx/Tx.
///
/// Clocks must be running.
///
/// @endverbatim
///----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//  Includes
//-----------------------------------------------------------------------------
#include <p9_io_xbus_clear_firs.H>
#include <p9_io_scom.H>
#include <p9_io_regs.H>

//-----------------------------------------------------------------------------
//  Definitions
//-----------------------------------------------------------------------------
fapi2::ReturnCode io_rx_fir_reset(
    const fapi2::Target < fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t&                                   i_clock_group );

fapi2::ReturnCode io_tx_fir_reset(
    const fapi2::Target < fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t&                                   i_clock_group );

/**
 * @brief Clears PHY Rx/Tx FIRs on the XBUS(EDI+) specified target.  The FIRs
 *   are cleared by toggling a rx & tx fir reset bit.
 * @param[in] i_target         FAPI2 Target
 * @param[in] i_clock_group    Clock Group
 * @retval ReturnCode
 */
fapi2::ReturnCode p9_io_xbus_clear_firs(
    const fapi2::Target < fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t&                                   i_clock_group )
{
    FAPI_IMP( "I/O Start Xbus Clear FIRs" );

    FAPI_TRY( io_tx_fir_reset( i_target, i_clock_group ), "Tx Reset Failed" );

    FAPI_TRY( io_rx_fir_reset( i_target, i_clock_group ), "Rx Reset Failed" );

fapi_try_exit:
    FAPI_IMP( "I/O End Xbus Clear FIRs" );
    return fapi2::current_err;
}

/**
 * @brief This function resets the Rx Firs on a EDI+ Xbus
 * @param[in] i_target       FAPI2 Target
 * @param[in] i_clock_group  Clock Group
 * @retval ReturnCode
 */
fapi2::ReturnCode io_rx_fir_reset(
    const fapi2::Target < fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t& i_clock_group)
{
    const uint8_t LANE_00 = 0;
    uint64_t l_data = 0;

    FAPI_TRY( io::read( EDIP_RX_FIR_RESET, i_target, i_clock_group, LANE_00, l_data ),
              "Reading Rx Fir Reg Failed");

    io::set (EDIP_RX_FIR_RESET, 0, l_data);
    FAPI_TRY(io::write( EDIP_RX_FIR_RESET, i_target, i_clock_group, LANE_00, l_data ),
             "Writing Rx Fir Reg Failed");

    io::set (EDIP_RX_FIR_RESET, 1, l_data);
    FAPI_TRY(io::write( EDIP_RX_FIR_RESET, i_target, i_clock_group, LANE_00, l_data ),
             "Writing Rx Fir Reg Failed");

    io::set (EDIP_RX_FIR_RESET, 0, l_data);
    FAPI_TRY(io::write( EDIP_RX_FIR_RESET, i_target, i_clock_group, LANE_00, l_data ),
             "Writing Rx Fir Reg Failed");

fapi_try_exit:
    return fapi2::current_err;
}

/**
 * @brief This function resets the Tx Firs on a EDI+ Xbus
 * @param[in] i_target       FAPI2 Target
 * @param[in] i_clock_group  Clock Group
 * @retval ReturnCode
 */
fapi2::ReturnCode io_tx_fir_reset(
    const fapi2::Target < fapi2::TARGET_TYPE_XBUS >& i_target,
    const uint8_t& i_clock_group)
{
    const uint8_t LANE_00 = 0;
    uint64_t l_data = 0;

    FAPI_TRY( io::read( EDIP_TX_FIR_RESET, i_target, i_clock_group, LANE_00, l_data ),
              "Reading Tx Fir Reg Failed");

    io::set (EDIP_TX_FIR_RESET, 0, l_data);
    FAPI_TRY(io::write( EDIP_TX_FIR_RESET, i_target, i_clock_group, LANE_00, l_data ),
             "Writing Tx Fir Reg Failed");

    io::set (EDIP_TX_FIR_RESET, 1, l_data);
    FAPI_TRY(io::write( EDIP_TX_FIR_RESET, i_target, i_clock_group, LANE_00, l_data ),
             "Writing Tx Fir Reg Failed");

    io::set (EDIP_TX_FIR_RESET, 0, l_data);
    FAPI_TRY(io::write( EDIP_TX_FIR_RESET, i_target, i_clock_group, LANE_00, l_data ),
             "Writing Tx Fir Reg Failed");

fapi_try_exit:
    return fapi2::current_err;
}
<|endoftext|>


<commit_before>//
// Copyright (c) 2008 Advanced Micro Devices, Inc. All rights reserved.
//
#pragma once

#include "include/aclTypes.h"
#include "platform/context.hpp"
#include "platform/object.hpp"
#include "platform/memory.hpp"
#include "devwavelimiter.hpp"
#include "comgrctx.hpp"

#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
#ifndef USE_COMGR_LIBRARY
#include "driver/AmdCompiler.h"
#endif
//#include "llvm/Support/AMDGPUMetadata.h"

namespace llvm {
  namespace AMDGPU {
    namespace HSAMD {
      struct Metadata;
      namespace Kernel {
        struct Metadata;
}}}}

#define LC_METADATA 1
typedef llvm::AMDGPU::HSAMD::Metadata CodeObjectMD;
typedef llvm::AMDGPU::HSAMD::Kernel::Metadata KernelMD;
//typedef llvm::AMDGPU::HSAMD::Kernel::Arg::Metadata KernelArgMD;
#endif  // defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)

#ifndef LC_METADATA
typedef char CodeObjectMD;
#endif

namespace amd {
  namespace hsa {
    namespace loader {
      class Symbol;
    }  // loader
    namespace code {
      namespace Kernel {
        class Metadata;
      }  // Kernel
    }  // code
  }  // hsa
}  // amd

namespace amd {

class Device;
class Program;

namespace option {
  class Options;
}  // option
}

namespace device {
class ClBinary;
class Kernel;

//! A program object for a specific device.
class Program : public amd::HeapObject {
 public:
  typedef std::pair<const void*, size_t> binary_t;
  typedef std::unordered_map<std::string, Kernel*> kernels_t;
  // type of the program
  typedef enum {
    TYPE_NONE = 0,     // uncompiled
    TYPE_COMPILED,     // compiled
    TYPE_LIBRARY,      // linked library
    TYPE_EXECUTABLE,   // linked executable
    TYPE_INTERMEDIATE  // intermediate
  } type_t;

 private:
  //! The device target for this binary.
  amd::SharedReference<amd::Device> device_;

  kernels_t kernels_; //!< The kernel entry points this binary.
  type_t type_;       //!< type of this program

 protected:
   union {
     struct {
       uint32_t isNull_ : 1;          //!< Null program no memory allocations
       uint32_t internal_ : 1;        //!< Internal blit program
       uint32_t isLC_ : 1;            //!< LC was used for the program compilation
       uint32_t hasGlobalStores_ : 1; //!< Program has writable program scope variables
       uint32_t xnackEnabled_ : 1;    //!< Xnack was enabled during compilation
       uint32_t sramEccEnabled_ : 1;  //!< SRAM ECC was enabled during compilation
     };
     uint32_t flags_;  //!< Program flags
   };

  ClBinary* clBinary_;                          //!< The CL program binary file
  std::string llvmBinary_;                      //!< LLVM IR binary code
  amd::OclElf::oclElfSections elfSectionType_;  //!< LLVM IR binary code is in SPIR format
  std::string compileOptions_;                  //!< compile/build options.
  std::string linkOptions_;                     //!< link options.
                                                //!< the option arg passed in to clCompileProgram(), clLinkProgram(),
                                                //! or clBuildProgram(), whichever is called last
  aclBinaryOptions binOpts_;        //!< Binary options to create aclBinary
  aclBinary* binaryElf_;            //!< Binary for the new compiler library

  std::string lastBuildOptionsArg_;
  mutable std::string buildLog_;    //!< build log.
  cl_int buildStatus_;              //!< build status.
  cl_int buildError_;               //!< build error

  const char* machineTarget_;       //!< Machine target for this program
  aclTargetInfo info_;              //!< The info target for this binary.
  size_t globalVariableTotalSize_;
  amd::option::Options* programOptions_;

#if defined(USE_COMGR_LIBRARY)
  amd_comgr_metadata_node_t* metadata_;   //!< COMgr metadata
  std::map<std::string,amd_comgr_metadata_node_t> kernelMetadataMap_; //!< Map of kernel metadata
#else
  CodeObjectMD* metadata_;  //!< Runtime metadata
#endif

 public:
  //! Construct a section.
  Program(amd::Device& device);

  //! Destroy this binary image.
  virtual ~Program();

  //! Destroy all the kernels
  void clear();

  //! Return the compiler options passed to build this program
  amd::option::Options* getCompilerOptions() const { return programOptions_; }

  //! Compile the device program.
  cl_int compile(const std::string& sourceCode, const std::vector<const std::string*>& headers,
    const char** headerIncludeNames, const char* origOptions,
    amd::option::Options* options);

  //! Builds the device program.
  cl_int link(const std::vector<Program*>& inputPrograms, const char* origOptions,
    amd::option::Options* options);

  //! Builds the device program.
  cl_int build(const std::string& sourceCode, const char* origOptions,
    amd::option::Options* options);

  //! Returns the device object, associated with this program.
  const amd::Device& device() const { return device_(); }

  //! Return the compiler options used to build the program.
  const std::string& compileOptions() const { return compileOptions_; }

  //! Return the option arg passed in to clCompileProgram(), clLinkProgram(),
  //! or clBuildProgram(), whichever is called last
  const std::string lastBuildOptionsArg() const { return lastBuildOptionsArg_; }

  //! Return the build log.
  const std::string& buildLog() const { return buildLog_; }

  //! Return the build status.
  cl_build_status buildStatus() const { return buildStatus_; }

  //! Return the build error.
  cl_int buildError() const { return buildError_; }

  //! Return the symbols vector.
  const kernels_t& kernels() const { return kernels_; }
  kernels_t& kernels() { return kernels_; }

  //! Return the binary image.
  inline const binary_t binary() const;
  inline binary_t binary();

  //! Returns the CL program binary file
  ClBinary* clBinary() { return clBinary_; }
  const ClBinary* clBinary() const { return clBinary_; }

  bool setBinary(const char* binaryIn, size_t size);

  type_t type() const { return type_; }

  void setGlobalVariableTotalSize(size_t size) { globalVariableTotalSize_ = size; }

  size_t globalVariableTotalSize() const { return globalVariableTotalSize_; }

  //! Returns the aclBinary associated with the program
  aclBinary* binaryElf() const { return static_cast<aclBinary*>(binaryElf_); }

  //! Returns TRUE if the program just compiled
  bool isNull() const { return isNull_; }

  //! Returns TRUE if the program used internally by runtime
  bool isInternal() const { return internal_; }

  //! Returns TRUE if Lightning compiler was used for this program
  bool isLC() const { return isLC_; }

  //! Global variables are a part of the code segment
  bool hasGlobalStores() const { return hasGlobalStores_; }

#if defined(USE_COMGR_LIBRARY)
  const amd_comgr_metadata_node_t* metadata() const { return metadata_; }

  //! Get the kernel metadata
  const amd_comgr_metadata_node_t* getKernelMetadata(const std::string name) const {
    auto it = kernelMetadataMap_.find(name);
    return (it == kernelMetadataMap_.end()) ? nullptr : &(it->second);
  }
#else
  const CodeObjectMD* metadata() const { return metadata_; }
#endif

  //! Get the machine target for the program
  const char* machineTarget() const { return machineTarget_; }

  //! Check if xnack is enable
  const bool xnackEnable() const { return (xnackEnabled_ == 1); }

  //! Check if SRAM ECC is enable
  const bool sramEccEnable() const { return (sramEccEnabled_ == 1); }

  virtual bool findGlobalSymbols(void** dptr, size_t* bytes, const char* globalName) const {
    ShouldNotReachHere();
  }

 protected:
  //! pre-compile setup
  bool initBuild(amd::option::Options* options);

  //! post-compile cleanup
  bool finiBuild(bool isBuildGood);

  /*! \brief Compiles GPU CL program to LLVM binary (compiler frontend)
  *
  *  \return True if we successefully compiled a GPU program
  */
  virtual bool compileImpl(
    const std::string& sourceCode,  //!< the program's source code
    const std::vector<const std::string*>& headers,
    const char** headerIncludeNames,
    amd::option::Options* options   //!< compile options's object
  );

  //! Link the device program.
  virtual bool linkImpl(amd::option::Options* options);

  //! Link the device programs.
  virtual bool linkImpl(const std::vector<Program*>& inputPrograms, amd::option::Options* options,
    bool createLibrary);

  virtual bool createBinary(amd::option::Options* options) = 0;

  //! Initialize Binary (used only for clCreateProgramWithBinary()).
  bool initClBinary(const char* binaryIn, size_t size);

  //! Initialize Binary
  virtual bool initClBinary();

  virtual bool saveBinaryAndSetType(type_t type) = 0;

  //! Release the Binary
  void releaseClBinary();

  //! return target info
  virtual const aclTargetInfo& info(const char* str = "") = 0;

  virtual bool setKernels(
    amd::option::Options* options, void* binary, size_t binSize) { return true; }

  //! Returns all the options to be appended while passing to the compiler library
  std::string ProcessOptions(amd::option::Options* options);

  //! At linking time, get the set of compile options to be used from
  //! the set of input program, warn if they have inconsisten compile options.
  bool getCompileOptionsAtLinking(const std::vector<Program*>& inputPrograms,
    const amd::option::Options* linkOptions);

  void setType(type_t newType) { type_ = newType; }

#if defined(WITH_LIGHTNING_COMPILER) && !defined(USE_COMGR_LIBRARY)
  //! Return a new transient compiler instance.
  static std::unique_ptr<amd::opencl_driver::Compiler> newCompilerInstance();
#endif // defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)

  /* \brief Returns the next stage to compile from, based on sections in binary,
  *  also returns completeStages in a vector, which contains at least ACL_TYPE_DEFAULT,
  *  sets needOptionsCheck to true if options check is needed to decide whether or not to recompile
  */
  aclType getCompilationStagesFromBinary(
    std::vector<aclType>& completeStages,
    bool& needOptionsCheck);

  /* \brief Returns the next stage to compile from, based on sections and options in binary
  */
  aclType getNextCompilationStageFromBinary(amd::option::Options* options);

  //! Finds the total size of all global variables in the program
  bool FindGlobalVarSize(void* binary, size_t binSize);

  bool isElf(const char* bin) const { return amd::isElfMagic(bin); }

 private:
  //! Compile the device program with LC path
  bool compileImplLC(const std::string& sourceCode,
    const std::vector<const std::string*>& headers,
    const char** headerIncludeNames, amd::option::Options* options);

  //! Compile the device program with HSAIL path
  bool compileImplHSAIL(const std::string& sourceCode,
    const std::vector<const std::string*>& headers,
    const char** headerIncludeNames, amd::option::Options* options);

  //! Link the device programs with LC path
  bool linkImplLC(const std::vector<Program*>& inputPrograms,
    amd::option::Options* options, bool createLibrary);

  //! Link the device programs with HSAIL path
  bool linkImplHSAIL(const std::vector<Program*>& inputPrograms,
    amd::option::Options* options, bool createLibrary);

  //! Link the device program with LC path
  bool linkImplLC(amd::option::Options* options);

  //! Link the device program with HSAIL path
  bool linkImplHSAIL(amd::option::Options* options);

#if defined(USE_COMGR_LIBRARY)
  //! Dump the log data object to the build log, if both are present
  amd_comgr_status_t extractBuildLog(const char* buildLog,
                                     amd_comgr_data_set_t dataSet);
  //! Dump the code object data
  amd_comgr_status_t extractByteCodeBinary(const amd_comgr_data_set_t inDataSet,
    const amd_comgr_data_kind_t dataKind, const std::string& outFileName,
    char* outBinary[] = nullptr, size_t* outSize = nullptr);

  //! Set the OCL language and target triples with feature
  void setLangAndTargetStr(const char* clStd, amd_comgr_language_t* oclver,
                           std::string& targetIdent);

  //! Create code object and add it into the data set
  amd_comgr_status_t addCodeObjData(const char *source,
    const size_t size, const amd_comgr_data_kind_t type,
    const char* name, amd_comgr_data_set_t* dataSet);

  //! Create action for the specified language, target and options
  amd_comgr_status_t createAction(const amd_comgr_language_t oclvar,
    const std::string& targetIdent, const std::string& options,
    amd_comgr_action_info_t* action, bool* hasAction);

  //! Create the bitcode of the linked input dataset
  bool linkLLVMBitcode(const amd_comgr_data_set_t inputs,
    const std::string& options, const bool requiredDump,
    amd::option::Options* amdOptions, amd_comgr_data_set_t* output,
    char* binary[] = nullptr, size_t* binarySize = nullptr);

  //! Create the bitcode of the compiled input dataset
  bool compileToLLVMBitcode(const amd_comgr_data_set_t inputs,
    const std::string& options, amd::option::Options* amdOptions,
    char* binary[], size_t* binarySize);

  //! Compile and create the excutable of the input dataset
  bool compileAndLinkExecutable(const amd_comgr_data_set_t inputs,
    const std::string& options, amd::option::Options* amdOptions,
    char* executable[], size_t* executableSize);

  //! Create the map for the kernel name and its metadata for fast access
  bool createKernelMetadataMap();
#endif

  //! Disable default copy constructor
  Program(const Program&);

  //! Disable operator=
  Program& operator=(const Program&);
};

} // namespace device
<commit_msg>P4 to Git Change 1757956 by kjayapra@1_HIPWS_SL_IPC on 2019/03/18 18:47:13<commit_after>//
// Copyright (c) 2008 Advanced Micro Devices, Inc. All rights reserved.
//
#pragma once

#include "include/aclTypes.h"
#include "platform/context.hpp"
#include "platform/object.hpp"
#include "platform/memory.hpp"
#include "devwavelimiter.hpp"
#include "comgrctx.hpp"

#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
#ifndef USE_COMGR_LIBRARY
#include "driver/AmdCompiler.h"
#endif
//#include "llvm/Support/AMDGPUMetadata.h"

namespace llvm {
  namespace AMDGPU {
    namespace HSAMD {
      struct Metadata;
      namespace Kernel {
        struct Metadata;
}}}}

#define LC_METADATA 1
typedef llvm::AMDGPU::HSAMD::Metadata CodeObjectMD;
typedef llvm::AMDGPU::HSAMD::Kernel::Metadata KernelMD;
//typedef llvm::AMDGPU::HSAMD::Kernel::Arg::Metadata KernelArgMD;
#endif  // defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)

#ifndef LC_METADATA
typedef char CodeObjectMD;
#endif

namespace amd {
  namespace hsa {
    namespace loader {
      class Symbol;
    }  // loader
    namespace code {
      namespace Kernel {
        class Metadata;
      }  // Kernel
    }  // code
  }  // hsa
}  // amd

namespace amd {

class Device;
class Program;

namespace option {
  class Options;
}  // option
}

namespace device {
class ClBinary;
class Kernel;

//! A program object for a specific device.
class Program : public amd::HeapObject {
 public:
  typedef std::pair<const void*, size_t> binary_t;
  typedef std::unordered_map<std::string, Kernel*> kernels_t;
  // type of the program
  typedef enum {
    TYPE_NONE = 0,     // uncompiled
    TYPE_COMPILED,     // compiled
    TYPE_LIBRARY,      // linked library
    TYPE_EXECUTABLE,   // linked executable
    TYPE_INTERMEDIATE  // intermediate
  } type_t;

 private:
  //! The device target for this binary.
  amd::SharedReference<amd::Device> device_;

  kernels_t kernels_; //!< The kernel entry points this binary.
  type_t type_;       //!< type of this program

 protected:
   union {
     struct {
       uint32_t isNull_ : 1;          //!< Null program no memory allocations
       uint32_t internal_ : 1;        //!< Internal blit program
       uint32_t isLC_ : 1;            //!< LC was used for the program compilation
       uint32_t hasGlobalStores_ : 1; //!< Program has writable program scope variables
       uint32_t xnackEnabled_ : 1;    //!< Xnack was enabled during compilation
       uint32_t sramEccEnabled_ : 1;  //!< SRAM ECC was enabled during compilation
     };
     uint32_t flags_;  //!< Program flags
   };

  ClBinary* clBinary_;                          //!< The CL program binary file
  std::string llvmBinary_;                      //!< LLVM IR binary code
  amd::OclElf::oclElfSections elfSectionType_;  //!< LLVM IR binary code is in SPIR format
  std::string compileOptions_;                  //!< compile/build options.
  std::string linkOptions_;                     //!< link options.
                                                //!< the option arg passed in to clCompileProgram(), clLinkProgram(),
                                                //! or clBuildProgram(), whichever is called last
  aclBinaryOptions binOpts_;        //!< Binary options to create aclBinary
  aclBinary* binaryElf_;            //!< Binary for the new compiler library

  std::string lastBuildOptionsArg_;
  mutable std::string buildLog_;    //!< build log.
  cl_int buildStatus_;              //!< build status.
  cl_int buildError_;               //!< build error

  const char* machineTarget_;       //!< Machine target for this program
  aclTargetInfo info_;              //!< The info target for this binary.
  size_t globalVariableTotalSize_;
  amd::option::Options* programOptions_;

#if defined(USE_COMGR_LIBRARY)
  amd_comgr_metadata_node_t* metadata_;   //!< COMgr metadata
  std::map<std::string,amd_comgr_metadata_node_t> kernelMetadataMap_; //!< Map of kernel metadata
#else
  CodeObjectMD* metadata_;  //!< Runtime metadata
#endif

 public:
  //! Construct a section.
  Program(amd::Device& device);

  //! Destroy this binary image.
  virtual ~Program();

  //! Destroy all the kernels
  void clear();

  //! Return the compiler options passed to build this program
  amd::option::Options* getCompilerOptions() const { return programOptions_; }

  //! Compile the device program.
  cl_int compile(const std::string& sourceCode, const std::vector<const std::string*>& headers,
    const char** headerIncludeNames, const char* origOptions,
    amd::option::Options* options);

  //! Builds the device program.
  cl_int link(const std::vector<Program*>& inputPrograms, const char* origOptions,
    amd::option::Options* options);

  //! Builds the device program.
  cl_int build(const std::string& sourceCode, const char* origOptions,
    amd::option::Options* options);

  //! Returns the device object, associated with this program.
  const amd::Device& device() const { return device_(); }

  //! Return the compiler options used to build the program.
  const std::string& compileOptions() const { return compileOptions_; }

  //! Return the option arg passed in to clCompileProgram(), clLinkProgram(),
  //! or clBuildProgram(), whichever is called last
  const std::string lastBuildOptionsArg() const { return lastBuildOptionsArg_; }

  //! Return the build log.
  const std::string& buildLog() const { return buildLog_; }

  //! Return the build status.
  cl_build_status buildStatus() const { return buildStatus_; }

  //! Return the build error.
  cl_int buildError() const { return buildError_; }

  //! Return the symbols vector.
  const kernels_t& kernels() const { return kernels_; }
  kernels_t& kernels() { return kernels_; }

  //! Return the binary image.
  inline const binary_t binary() const;
  inline binary_t binary();

  //! Returns the CL program binary file
  ClBinary* clBinary() { return clBinary_; }
  const ClBinary* clBinary() const { return clBinary_; }

  bool setBinary(const char* binaryIn, size_t size);

  type_t type() const { return type_; }

  void setGlobalVariableTotalSize(size_t size) { globalVariableTotalSize_ = size; }

  size_t globalVariableTotalSize() const { return globalVariableTotalSize_; }

  //! Returns the aclBinary associated with the program
  aclBinary* binaryElf() const { return static_cast<aclBinary*>(binaryElf_); }

  //! Returns TRUE if the program just compiled
  bool isNull() const { return isNull_; }

  //! Returns TRUE if the program used internally by runtime
  bool isInternal() const { return internal_; }

  //! Returns TRUE if Lightning compiler was used for this program
  bool isLC() const { return isLC_; }

  //! Global variables are a part of the code segment
  bool hasGlobalStores() const { return hasGlobalStores_; }

#if defined(USE_COMGR_LIBRARY)
  const amd_comgr_metadata_node_t* metadata() const { return metadata_; }

  //! Get the kernel metadata
  const amd_comgr_metadata_node_t* getKernelMetadata(const std::string name) const {
    auto it = kernelMetadataMap_.find(name);
    return (it == kernelMetadataMap_.end()) ? nullptr : &(it->second);
  }
#else
  const CodeObjectMD* metadata() const { return metadata_; }
#endif

  //! Get the machine target for the program
  const char* machineTarget() const { return machineTarget_; }

  //! Check if xnack is enable
  const bool xnackEnable() const { return (xnackEnabled_ == 1); }

  //! Check if SRAM ECC is enable
  const bool sramEccEnable() const { return (sramEccEnabled_ == 1); }

  virtual bool findGlobalSymbols(void** dptr, size_t* bytes, const char* globalName) const {
    ShouldNotReachHere();
    return false;
  }

 protected:
  //! pre-compile setup
  bool initBuild(amd::option::Options* options);

  //! post-compile cleanup
  bool finiBuild(bool isBuildGood);

  /*! \brief Compiles GPU CL program to LLVM binary (compiler frontend)
  *
  *  \return True if we successefully compiled a GPU program
  */
  virtual bool compileImpl(
    const std::string& sourceCode,  //!< the program's source code
    const std::vector<const std::string*>& headers,
    const char** headerIncludeNames,
    amd::option::Options* options   //!< compile options's object
  );

  //! Link the device program.
  virtual bool linkImpl(amd::option::Options* options);

  //! Link the device programs.
  virtual bool linkImpl(const std::vector<Program*>& inputPrograms, amd::option::Options* options,
    bool createLibrary);

  virtual bool createBinary(amd::option::Options* options) = 0;

  //! Initialize Binary (used only for clCreateProgramWithBinary()).
  bool initClBinary(const char* binaryIn, size_t size);

  //! Initialize Binary
  virtual bool initClBinary();

  virtual bool saveBinaryAndSetType(type_t type) = 0;

  //! Release the Binary
  void releaseClBinary();

  //! return target info
  virtual const aclTargetInfo& info(const char* str = "") = 0;

  virtual bool setKernels(
    amd::option::Options* options, void* binary, size_t binSize) { return true; }

  //! Returns all the options to be appended while passing to the compiler library
  std::string ProcessOptions(amd::option::Options* options);

  //! At linking time, get the set of compile options to be used from
  //! the set of input program, warn if they have inconsisten compile options.
  bool getCompileOptionsAtLinking(const std::vector<Program*>& inputPrograms,
    const amd::option::Options* linkOptions);

  void setType(type_t newType) { type_ = newType; }

#if defined(WITH_LIGHTNING_COMPILER) && !defined(USE_COMGR_LIBRARY)
  //! Return a new transient compiler instance.
  static std::unique_ptr<amd::opencl_driver::Compiler> newCompilerInstance();
#endif // defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)

  /* \brief Returns the next stage to compile from, based on sections in binary,
  *  also returns completeStages in a vector, which contains at least ACL_TYPE_DEFAULT,
  *  sets needOptionsCheck to true if options check is needed to decide whether or not to recompile
  */
  aclType getCompilationStagesFromBinary(
    std::vector<aclType>& completeStages,
    bool& needOptionsCheck);

  /* \brief Returns the next stage to compile from, based on sections and options in binary
  */
  aclType getNextCompilationStageFromBinary(amd::option::Options* options);

  //! Finds the total size of all global variables in the program
  bool FindGlobalVarSize(void* binary, size_t binSize);

  bool isElf(const char* bin) const { return amd::isElfMagic(bin); }

 private:
  //! Compile the device program with LC path
  bool compileImplLC(const std::string& sourceCode,
    const std::vector<const std::string*>& headers,
    const char** headerIncludeNames, amd::option::Options* options);

  //! Compile the device program with HSAIL path
  bool compileImplHSAIL(const std::string& sourceCode,
    const std::vector<const std::string*>& headers,
    const char** headerIncludeNames, amd::option::Options* options);

  //! Link the device programs with LC path
  bool linkImplLC(const std::vector<Program*>& inputPrograms,
    amd::option::Options* options, bool createLibrary);

  //! Link the device programs with HSAIL path
  bool linkImplHSAIL(const std::vector<Program*>& inputPrograms,
    amd::option::Options* options, bool createLibrary);

  //! Link the device program with LC path
  bool linkImplLC(amd::option::Options* options);

  //! Link the device program with HSAIL path
  bool linkImplHSAIL(amd::option::Options* options);

#if defined(USE_COMGR_LIBRARY)
  //! Dump the log data object to the build log, if both are present
  amd_comgr_status_t extractBuildLog(const char* buildLog,
                                     amd_comgr_data_set_t dataSet);
  //! Dump the code object data
  amd_comgr_status_t extractByteCodeBinary(const amd_comgr_data_set_t inDataSet,
    const amd_comgr_data_kind_t dataKind, const std::string& outFileName,
    char* outBinary[] = nullptr, size_t* outSize = nullptr);

  //! Set the OCL language and target triples with feature
  void setLangAndTargetStr(const char* clStd, amd_comgr_language_t* oclver,
                           std::string& targetIdent);

  //! Create code object and add it into the data set
  amd_comgr_status_t addCodeObjData(const char *source,
    const size_t size, const amd_comgr_data_kind_t type,
    const char* name, amd_comgr_data_set_t* dataSet);

  //! Create action for the specified language, target and options
  amd_comgr_status_t createAction(const amd_comgr_language_t oclvar,
    const std::string& targetIdent, const std::string& options,
    amd_comgr_action_info_t* action, bool* hasAction);

  //! Create the bitcode of the linked input dataset
  bool linkLLVMBitcode(const amd_comgr_data_set_t inputs,
    const std::string& options, const bool requiredDump,
    amd::option::Options* amdOptions, amd_comgr_data_set_t* output,
    char* binary[] = nullptr, size_t* binarySize = nullptr);

  //! Create the bitcode of the compiled input dataset
  bool compileToLLVMBitcode(const amd_comgr_data_set_t inputs,
    const std::string& options, amd::option::Options* amdOptions,
    char* binary[], size_t* binarySize);

  //! Compile and create the excutable of the input dataset
  bool compileAndLinkExecutable(const amd_comgr_data_set_t inputs,
    const std::string& options, amd::option::Options* amdOptions,
    char* executable[], size_t* executableSize);

  //! Create the map for the kernel name and its metadata for fast access
  bool createKernelMetadataMap();
#endif

  //! Disable default copy constructor
  Program(const Program&);

  //! Disable operator=
  Program& operator=(const Program&);
};

} // namespace device
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: VKey.cxx,v $
 *
 *  $Revision: 1.13 $
 *
 *  last change: $Author: oj $ $Date: 2002-11-12 09:17:39 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _CONNECTIVITY_SDBCX_KEY_HXX_
#include "connectivity/sdbcx/VKey.hxx"
#endif
#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
#include <com/sun/star/lang/DisposedException.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_
#include <com/sun/star/sdbc/KeyRule.hpp>
#endif
#ifndef _COMPHELPER_SEQUENCE_HXX_
#include <comphelper/sequence.hxx>
#endif
#ifndef _CONNECTIVITY_SDBCX_COLUMN_HXX_
#include "connectivity/sdbcx/VColumn.hxx"
#endif
#ifndef _CONNECTIVITY_SDBCX_COLLECTION_HXX_
#include "connectivity/sdbcx/VCollection.hxx"
#endif
#ifndef CONNECTIVITY_CONNECTION_HXX
#include "TConnection.hxx"
#endif
// -------------------------------------------------------------------------
using namespace connectivity;
using namespace connectivity::sdbcx;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::lang;

// -----------------------------------------------------------------------------
::rtl::OUString SAL_CALL OKey::getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException)
{
    if(isNew())
        return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VKeyDescription");
    return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VKey");
}
// -----------------------------------------------------------------------------
::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OKey::getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException)
{
    ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1);
    if(isNew())
        aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.KeyDescription");
    else
        aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Key");

    return aSupported;
}
// -----------------------------------------------------------------------------
sal_Bool SAL_CALL OKey::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException)
{
    Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
    const ::rtl::OUString* pSupported = aSupported.getConstArray();
    const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
    for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
        ;

    return pSupported != pEnd;
}
// -------------------------------------------------------------------------
OKey::OKey(sal_Bool _bCase) :   ODescriptor_BASE(m_aMutex)
            ,   ODescriptor(ODescriptor_BASE::rBHelper,_bCase,sal_True)
            ,   m_pColumns(NULL)
{
}
// -------------------------------------------------------------------------
OKey::OKey( const ::rtl::OUString& _Name,
            const ::rtl::OUString& _ReferencedTable,
            sal_Int32       _Type,
            sal_Int32       _UpdateRule,
            sal_Int32       _DeleteRule,
            sal_Bool _bCase) :  ODescriptor_BASE(m_aMutex)
                        ,ODescriptor(ODescriptor_BASE::rBHelper,_bCase)
                        ,m_pColumns(NULL)
                        ,m_ReferencedTable(_ReferencedTable)
                        ,m_Type(_Type)
                        ,m_UpdateRule(_UpdateRule)
                        ,m_DeleteRule(_DeleteRule)
{
    m_Name = _Name;
}
// -------------------------------------------------------------------------
OKey::~OKey( )
{
    delete m_pColumns;
}
// -------------------------------------------------------------------------
Any SAL_CALL OKey::queryInterface( const Type & rType ) throw(RuntimeException)
{
    Any aRet = ODescriptor::queryInterface( rType);
    if(!aRet.hasValue())
    {
        if(!isNew())
            aRet = OKey_BASE::queryInterface(rType);
        if(!aRet.hasValue())
            aRet = ODescriptor_BASE::queryInterface( rType);
    }

    return aRet;
}
// -------------------------------------------------------------------------
Sequence< Type > SAL_CALL OKey::getTypes(  ) throw(RuntimeException)
{
    if(isNew())
        return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes());

    return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes(),OKey_BASE::getTypes());
}
// -------------------------------------------------------------------------
void OKey::construct()
{
    ODescriptor::construct();

    sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;

    registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REFERENCEDTABLE), PROPERTY_ID_REFERENCEDTABLE,    nAttrib,&m_ReferencedTable, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
    registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),                PROPERTY_ID_TYPE,               nAttrib,&m_Type,            ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
    registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_UPDATERULE),      PROPERTY_ID_UPDATERULE,         nAttrib,&m_UpdateRule,      ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
    registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DELETERULE),      PROPERTY_ID_DELETERULE,         nAttrib,&m_DeleteRule,      ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
}
// -------------------------------------------------------------------------
void SAL_CALL OKey::disposing()
{
    OPropertySetHelper::disposing();

    ::osl::MutexGuard aGuard(m_aMutex);

    if(m_pColumns)
        m_pColumns->disposing();

    ODescriptor_BASE::disposing();
}
// -------------------------------------------------------------------------
::cppu::IPropertyArrayHelper* OKey::createArrayHelper(sal_Int32 _nId ) const
{
    Sequence< Property > aProps;
    describeProperties(aProps);
    changePropertyAttributte(aProps);
    return new ::cppu::OPropertyArrayHelper(aProps);
}
// -------------------------------------------------------------------------
::cppu::IPropertyArrayHelper & OKey::getInfoHelper()
{
    return *const_cast<OKey*>(this)->getArrayHelper(isNew() ? 1 : 0);
}
// -------------------------------------------------------------------------
Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OKey::getColumns(  ) throw(RuntimeException)
{
    ::osl::MutexGuard aGuard(m_aMutex);
    checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);

    try
    {
        if ( !m_pColumns )
            refreshColumns();
    }
    catch( const RuntimeException& )
    {
        // allowed to leave this method
        throw;
    }
    catch( const Exception& )
    {
        // allowed
    }

    return const_cast<OKey*>(this)->m_pColumns;
}
// -------------------------------------------------------------------------
Reference< XPropertySet > SAL_CALL OKey::createDataDescriptor(  ) throw(RuntimeException)
{
    ::osl::MutexGuard aGuard(m_aMutex);
    checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);

    return this;
}
// -----------------------------------------------------------------------------
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OKey::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException)
{
    return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
}
// -----------------------------------------------------------------------------
::rtl::OUString SAL_CALL OKey::getName(  ) throw(::com::sun::star::uno::RuntimeException)
{
    return m_Name;
}
// -----------------------------------------------------------------------------
void SAL_CALL OKey::setName( const ::rtl::OUString& aName ) throw(::com::sun::star::uno::RuntimeException)
{
}
// -----------------------------------------------------------------------------
// XInterface
void SAL_CALL OKey::acquire() throw()
{
    ODescriptor_BASE::acquire();
}
// -----------------------------------------------------------------------------
void SAL_CALL OKey::release() throw()
{
    ODescriptor_BASE::release();
}
// -----------------------------------------------------------------------------

<commit_msg>INTEGRATION: CWS ooo19126 (1.13.320); FILE MERGED 2005/09/05 17:25:55 rt 1.13.320.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: VKey.cxx,v $
 *
 *  $Revision: 1.14 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 07:44:13 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _CONNECTIVITY_SDBCX_KEY_HXX_
#include "connectivity/sdbcx/VKey.hxx"
#endif
#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
#include <com/sun/star/lang/DisposedException.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_
#include <com/sun/star/sdbc/KeyRule.hpp>
#endif
#ifndef _COMPHELPER_SEQUENCE_HXX_
#include <comphelper/sequence.hxx>
#endif
#ifndef _CONNECTIVITY_SDBCX_COLUMN_HXX_
#include "connectivity/sdbcx/VColumn.hxx"
#endif
#ifndef _CONNECTIVITY_SDBCX_COLLECTION_HXX_
#include "connectivity/sdbcx/VCollection.hxx"
#endif
#ifndef CONNECTIVITY_CONNECTION_HXX
#include "TConnection.hxx"
#endif
// -------------------------------------------------------------------------
using namespace connectivity;
using namespace connectivity::sdbcx;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::lang;

// -----------------------------------------------------------------------------
::rtl::OUString SAL_CALL OKey::getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException)
{
    if(isNew())
        return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VKeyDescription");
    return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VKey");
}
// -----------------------------------------------------------------------------
::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OKey::getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException)
{
    ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1);
    if(isNew())
        aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.KeyDescription");
    else
        aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Key");

    return aSupported;
}
// -----------------------------------------------------------------------------
sal_Bool SAL_CALL OKey::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException)
{
    Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
    const ::rtl::OUString* pSupported = aSupported.getConstArray();
    const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
    for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
        ;

    return pSupported != pEnd;
}
// -------------------------------------------------------------------------
OKey::OKey(sal_Bool _bCase) :   ODescriptor_BASE(m_aMutex)
            ,   ODescriptor(ODescriptor_BASE::rBHelper,_bCase,sal_True)
            ,   m_pColumns(NULL)
{
}
// -------------------------------------------------------------------------
OKey::OKey( const ::rtl::OUString& _Name,
            const ::rtl::OUString& _ReferencedTable,
            sal_Int32       _Type,
            sal_Int32       _UpdateRule,
            sal_Int32       _DeleteRule,
            sal_Bool _bCase) :  ODescriptor_BASE(m_aMutex)
                        ,ODescriptor(ODescriptor_BASE::rBHelper,_bCase)
                        ,m_pColumns(NULL)
                        ,m_ReferencedTable(_ReferencedTable)
                        ,m_Type(_Type)
                        ,m_UpdateRule(_UpdateRule)
                        ,m_DeleteRule(_DeleteRule)
{
    m_Name = _Name;
}
// -------------------------------------------------------------------------
OKey::~OKey( )
{
    delete m_pColumns;
}
// -------------------------------------------------------------------------
Any SAL_CALL OKey::queryInterface( const Type & rType ) throw(RuntimeException)
{
    Any aRet = ODescriptor::queryInterface( rType);
    if(!aRet.hasValue())
    {
        if(!isNew())
            aRet = OKey_BASE::queryInterface(rType);
        if(!aRet.hasValue())
            aRet = ODescriptor_BASE::queryInterface( rType);
    }

    return aRet;
}
// -------------------------------------------------------------------------
Sequence< Type > SAL_CALL OKey::getTypes(  ) throw(RuntimeException)
{
    if(isNew())
        return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes());

    return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes(),OKey_BASE::getTypes());
}
// -------------------------------------------------------------------------
void OKey::construct()
{
    ODescriptor::construct();

    sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;

    registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REFERENCEDTABLE), PROPERTY_ID_REFERENCEDTABLE,    nAttrib,&m_ReferencedTable, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
    registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),                PROPERTY_ID_TYPE,               nAttrib,&m_Type,            ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
    registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_UPDATERULE),      PROPERTY_ID_UPDATERULE,         nAttrib,&m_UpdateRule,      ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
    registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DELETERULE),      PROPERTY_ID_DELETERULE,         nAttrib,&m_DeleteRule,      ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
}
// -------------------------------------------------------------------------
void SAL_CALL OKey::disposing()
{
    OPropertySetHelper::disposing();

    ::osl::MutexGuard aGuard(m_aMutex);

    if(m_pColumns)
        m_pColumns->disposing();

    ODescriptor_BASE::disposing();
}
// -------------------------------------------------------------------------
::cppu::IPropertyArrayHelper* OKey::createArrayHelper(sal_Int32 _nId ) const
{
    Sequence< Property > aProps;
    describeProperties(aProps);
    changePropertyAttributte(aProps);
    return new ::cppu::OPropertyArrayHelper(aProps);
}
// -------------------------------------------------------------------------
::cppu::IPropertyArrayHelper & OKey::getInfoHelper()
{
    return *const_cast<OKey*>(this)->getArrayHelper(isNew() ? 1 : 0);
}
// -------------------------------------------------------------------------
Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OKey::getColumns(  ) throw(RuntimeException)
{
    ::osl::MutexGuard aGuard(m_aMutex);
    checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);

    try
    {
        if ( !m_pColumns )
            refreshColumns();
    }
    catch( const RuntimeException& )
    {
        // allowed to leave this method
        throw;
    }
    catch( const Exception& )
    {
        // allowed
    }

    return const_cast<OKey*>(this)->m_pColumns;
}
// -------------------------------------------------------------------------
Reference< XPropertySet > SAL_CALL OKey::createDataDescriptor(  ) throw(RuntimeException)
{
    ::osl::MutexGuard aGuard(m_aMutex);
    checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);

    return this;
}
// -----------------------------------------------------------------------------
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OKey::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException)
{
    return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
}
// -----------------------------------------------------------------------------
::rtl::OUString SAL_CALL OKey::getName(  ) throw(::com::sun::star::uno::RuntimeException)
{
    return m_Name;
}
// -----------------------------------------------------------------------------
void SAL_CALL OKey::setName( const ::rtl::OUString& aName ) throw(::com::sun::star::uno::RuntimeException)
{
}
// -----------------------------------------------------------------------------
// XInterface
void SAL_CALL OKey::acquire() throw()
{
    ODescriptor_BASE::acquire();
}
// -----------------------------------------------------------------------------
void SAL_CALL OKey::release() throw()
{
    ODescriptor_BASE::release();
}
// -----------------------------------------------------------------------------

<|endoftext|>


<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/pm/p9_cpu_special_wakeup.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

/**
 * @file            :     p9_cpu_special_wakeup.C
 * @brief           :     HWP to perform special wakeup of core, EQ or EX.
 * @HWP HW Owner    :     Greg Still <stillgs@us.ibm.com>
 * @HWP FW Owner    :     Prem S Jha <premjha2@in.ibm.com>
 * @HWP Team        :     PM
 * @HWP Level       :     L1
 * @HWP Consumed by :     OCC, FSP, HOST
 */

// ---------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------
#include <p9_cpu_special_wakeup.H>

fapi2::ReturnCode
p9_cpu_special_wakeup(  CONST_FAPI2_WAKEUP_CHIPLET& i_chipletTarget,
                        PROC_SPCWKUP_OPS i_operation,
                        PROC_SPCWKUP_ENTITY i_entity )
{
    FAPI_IMP("Entering... ");

    FAPI_IMP("Exit..." );
    return fapi2::FAPI2_RC_SUCCESS;
}
<commit_msg>PM: Added make file for special wakeup HWP and fixed prolog.<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/pm/p9_cpu_special_wakeup.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

///
///  @file          :     p9_cpu_special_wakeup.C
///  @brief         :     HWP to perform special wakeup of core, EQ or EX.

// *HWP HW Owner    :    Greg Still <stillgs@us.ibm.com>
// *HWP FW Owner    :    Prem S Jha <premjha2@in.ibm.com>
// *HWP Team        :    PM
// *HWP Level       :    1
// *HWP Consumed by :    OCC:FSP:HOST

// ---------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------
#include <p9_cpu_special_wakeup.H>

using namespace p9specialWakeup;
enum
{
    NUM_SPCWKUP_ENTITIES = 4,
    NUM_SPCWKUP_OPS = 3,
};

fapi2::ReturnCode
p9_cpu_special_wakeup(  const FAPI2_WAKEUP_CHIPLET& i_chipletTarget,
                        const PROC_SPCWKUP_OPS i_operation,
                        const PROC_SPCWKUP_ENTITY i_entity )
{
    FAPI_DBG("Entering p9_cpu_special_wakeup");

    FAPI_DBG("Exit p9_cpu_special_wakeup" );
    return fapi2::FAPI2_RC_SUCCESS;
}
<|endoftext|>


<commit_before>#include "itkCommandLineArgumentParser.h"
#include "CommandLineArgumentHelper.h"

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"

#include "itkStatisticsImageFilter.h"
#include "itkInvertIntensityImageFilter.h"

/** This program inverts the intensity of an image:
 * new = max - old,
 * where max is the maximum of an image.
 */

//-------------------------------------------------------------------------------------

/** run: A macro to call a function. */
#define run( function, type, dim ) \
if ( ComponentTypeIn == #type && Dimension == dim ) \
{ \
  typedef itk::Image< type, dim > InputImageType; \
  function< InputImageType >( inputFileName, outputFileName ); \
  supported = true; \
}

//-------------------------------------------------------------------------------------

/** Declare InvertIntensity. */
template< class InputImageType >
void InvertIntensity(
  const std::string & inputFileName,
  const std::string & outputFileName );

/** Declare PrintHelp. */
void PrintHelp( void );

//-------------------------------------------------------------------------------------

int main( int argc, char ** argv )
{
  /** Check arguments for help. */
  if ( argc < 3 )
  {
    PrintHelp();
    return 1;
  }

  /** Create a command line argument parser. */
  itk::CommandLineArgumentParser::Pointer parser = itk::CommandLineArgumentParser::New();
  parser->SetCommandLineArguments( argc, argv );

  /** Get arguments. */
  std::string inputFileName = "";
  bool retin = parser->GetCommandLineArgument( "-in", inputFileName );
  if ( !retin )
  {
    std::cerr << "ERROR: You should specify \"-in\"." << std::endl;
    return 1;
  }

  std::string outputFileName = inputFileName.substr( 0, inputFileName.rfind( "." ) );
  outputFileName += "INVERTED.mhd";
  parser->GetCommandLineArgument( "-out", outputFileName );

  /** Determine image properties. */
  std::string ComponentTypeIn = "short";
  std::string PixelType; //we don't use this
  unsigned int Dimension = 2;
  unsigned int NumberOfComponents = 1;
  std::vector<unsigned int> imagesize( Dimension, 0 );
  int retgip = GetImageProperties(
    inputFileName,
    PixelType,
    ComponentTypeIn,
    Dimension,
    NumberOfComponents,
    imagesize );
  if ( retgip != 0 )
  {
    return 1;
  }

  /** Check for vector images. */
  if ( NumberOfComponents > 1 )
  {
    std::cerr << "ERROR: The NumberOfComponents is larger than 1!" << std::endl;
    std::cerr << "Vector images are not supported." << std::endl;
    return 1;
  }

  /** Get rid of the possible "_" in ComponentType. */
  ReplaceUnderscoreWithSpace( ComponentTypeIn );

  /** Run the program. */
  bool supported = false;
  try
  {
    /** 2D. */
    run( InvertIntensity, char, 2 );
    run( InvertIntensity, unsigned char, 2 );
    run( InvertIntensity, short, 2 );
    run( InvertIntensity, unsigned short, 2 );
    run( InvertIntensity, float, 2 );
    run( InvertIntensity, double, 2 );

    /** 3D. */
    run( InvertIntensity, char, 3 );
    run( InvertIntensity, unsigned char, 3 );
    run( InvertIntensity, short, 3 );
    run( InvertIntensity, unsigned short, 3 );
    run( InvertIntensity, float, 3 );
    run( InvertIntensity, double, 3 );

  } // end run
  catch ( itk::ExceptionObject &e )
  {
    std::cerr << "Caught ITK exception: " << e << std::endl;
    return 1;
  }
  if ( !supported )
  {
    std::cerr << "ERROR: this combination of pixeltype and dimension is not supported!" << std::endl;
    std::cerr
      << "pixel (component) type = " << ComponentTypeIn
      << " ; dimension = " << Dimension
      << std::endl;
    return 1;
  }

  /** End program. */
  return 0;

} // end main

  /**
   * ******************* InvertIntensity *******************
   *
   * The resize function templated over the input pixel type.
   */

template< class InputImageType >
void InvertIntensity( const std::string & inputFileName,
  const std::string & outputFileName )
{
  /** Some typedef's. */
  typedef typename InputImageType::PixelType                InputPixelType;
  typedef itk::ImageFileReader< InputImageType >            ReaderType;
  typedef itk::ImageFileWriter< InputImageType >            WriterType;
  typedef itk::StatisticsImageFilter< InputImageType >      StatisticsFilterType;
  typedef typename StatisticsFilterType::RealType           RealType;
  typedef itk::InvertIntensityImageFilter< InputImageType > InvertIntensityFilterType;

  /** Create reader. */
  typename ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName( inputFileName.c_str() );

  /** Create statistics filter. */
  typename StatisticsFilterType::Pointer statistics = StatisticsFilterType::New();
  statistics->SetInput( reader->GetOutput() );
  statistics->Update();

  /** Get all the output stuff. */
  InputPixelType max = statistics->GetMaximum();

  /** Create invert filter. */
  typename InvertIntensityFilterType::Pointer invertFilter = InvertIntensityFilterType::New();
  invertFilter->SetInput( reader->GetOutput() );
  invertFilter->SetMaximum( max );

  /** Create writer. */
  typename WriterType::Pointer writer = WriterType::New();
  writer->SetFileName( outputFileName.c_str() );
  writer->SetInput( invertFilter->GetOutput() );
  writer->Update();

} // end InvertIntensity()

/**
 * ******************* PrintHelp *******************
 */

void PrintHelp( void )
{
  std::cout << "This program inverts the intensities of an image." << std::endl;
  std::cout << "Usage:" << std::endl << "pxinvertintensityimagefilter" << std::endl;
  std::cout << "  -in      inputFilename" << std::endl;
  std::cout << "  [-out]   outputFilename; default: in + INVERTED.mhd" << std::endl;
  std::cout << "Supported: 2D, 3D, (unsigned) char, (unsigned) short, float, double." << std::endl;

} // end PrintHelp()

<commit_msg>New style arguments for invertintensityimagefilter<commit_after>#include "itkCommandLineArgumentParser.h"
#include "CommandLineArgumentHelper.h"

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"

#include "itkStatisticsImageFilter.h"
#include "itkInvertIntensityImageFilter.h"

/** This program inverts the intensity of an image:
 * new = max - old,
 * where max is the maximum of an image.
 */

//-------------------------------------------------------------------------------------

/** run: A macro to call a function. */
#define run( function, type, dim ) \
if ( ComponentTypeIn == #type && Dimension == dim ) \
{ \
  typedef itk::Image< type, dim > InputImageType; \
  function< InputImageType >( inputFileName, outputFileName ); \
  supported = true; \
}

//-------------------------------------------------------------------------------------

/** Declare InvertIntensity. */
template< class InputImageType >
void InvertIntensity(
  const std::string & inputFileName,
  const std::string & outputFileName );

/** Declare PrintHelp. */
std::string PrintHelp( void );

//-------------------------------------------------------------------------------------

int main( int argc, char ** argv )
{
  /** Create a command line argument parser. */
  itk::CommandLineArgumentParser::Pointer parser = itk::CommandLineArgumentParser::New();
  parser->SetCommandLineArguments( argc, argv );
  parser->SetProgramHelpText(PrintHelp());
  parser->MarkArgumentAsRequired( "-in", "The input filename." );
  bool validateArguments = parser->CheckForRequiredArguments();

  if(!validateArguments)
  {
    return EXIT_FAILURE;
  }

  /** Get arguments. */
  std::string inputFileName = "";
  parser->GetCommandLineArgument( "-in", inputFileName );

  std::string outputFileName = inputFileName.substr( 0, inputFileName.rfind( "." ) );
  outputFileName += "INVERTED.mhd";
  parser->GetCommandLineArgument( "-out", outputFileName );

  /** Determine image properties. */
  std::string ComponentTypeIn = "short";
  std::string PixelType; //we don't use this
  unsigned int Dimension = 2;
  unsigned int NumberOfComponents = 1;
  std::vector<unsigned int> imagesize( Dimension, 0 );
  int retgip = GetImageProperties(
    inputFileName,
    PixelType,
    ComponentTypeIn,
    Dimension,
    NumberOfComponents,
    imagesize );
  if ( retgip != 0 )
  {
    return 1;
  }

  /** Check for vector images. */
  if ( NumberOfComponents > 1 )
  {
    std::cerr << "ERROR: The NumberOfComponents is larger than 1!" << std::endl;
    std::cerr << "Vector images are not supported." << std::endl;
    return 1;
  }

  /** Get rid of the possible "_" in ComponentType. */
  ReplaceUnderscoreWithSpace( ComponentTypeIn );

  /** Run the program. */
  bool supported = false;
  try
  {
    /** 2D. */
    run( InvertIntensity, char, 2 );
    run( InvertIntensity, unsigned char, 2 );
    run( InvertIntensity, short, 2 );
    run( InvertIntensity, unsigned short, 2 );
    run( InvertIntensity, float, 2 );
    run( InvertIntensity, double, 2 );

    /** 3D. */
    run( InvertIntensity, char, 3 );
    run( InvertIntensity, unsigned char, 3 );
    run( InvertIntensity, short, 3 );
    run( InvertIntensity, unsigned short, 3 );
    run( InvertIntensity, float, 3 );
    run( InvertIntensity, double, 3 );

  } // end run
  catch ( itk::ExceptionObject &e )
  {
    std::cerr << "Caught ITK exception: " << e << std::endl;
    return 1;
  }
  if ( !supported )
  {
    std::cerr << "ERROR: this combination of pixeltype and dimension is not supported!" << std::endl;
    std::cerr
      << "pixel (component) type = " << ComponentTypeIn
      << " ; dimension = " << Dimension
      << std::endl;
    return 1;
  }

  /** End program. */
  return 0;

} // end main

  /**
   * ******************* InvertIntensity *******************
   *
   * The resize function templated over the input pixel type.
   */

template< class InputImageType >
void InvertIntensity( const std::string & inputFileName,
  const std::string & outputFileName )
{
  /** Some typedef's. */
  typedef typename InputImageType::PixelType                InputPixelType;
  typedef itk::ImageFileReader< InputImageType >            ReaderType;
  typedef itk::ImageFileWriter< InputImageType >            WriterType;
  typedef itk::StatisticsImageFilter< InputImageType >      StatisticsFilterType;
  typedef typename StatisticsFilterType::RealType           RealType;
  typedef itk::InvertIntensityImageFilter< InputImageType > InvertIntensityFilterType;

  /** Create reader. */
  typename ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName( inputFileName.c_str() );

  /** Create statistics filter. */
  typename StatisticsFilterType::Pointer statistics = StatisticsFilterType::New();
  statistics->SetInput( reader->GetOutput() );
  statistics->Update();

  /** Get all the output stuff. */
  InputPixelType max = statistics->GetMaximum();

  /** Create invert filter. */
  typename InvertIntensityFilterType::Pointer invertFilter = InvertIntensityFilterType::New();
  invertFilter->SetInput( reader->GetOutput() );
  invertFilter->SetMaximum( max );

  /** Create writer. */
  typename WriterType::Pointer writer = WriterType::New();
  writer->SetFileName( outputFileName.c_str() );
  writer->SetInput( invertFilter->GetOutput() );
  writer->Update();

} // end InvertIntensity()

/**
 * ******************* PrintHelp *******************
 */

std::string PrintHelp( void )
{
  std::string helpText = "This program inverts the intensities of an image. \
  Usage:\
  pxinvertintensityimagefilter \
    -in      inputFilename \
    [-out]   outputFilename; default: in + INVERTED.mhd \
  Supported: 2D, 3D, (unsigned) char, (unsigned) short, float, double.";

  return helpText;

} // end PrintHelp()

<|endoftext|>