text:
#include "../include/ConfigModel.h"

#include <boost/version.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/foreach.hpp>
using boost::property_tree::ptree;

ConfigModel::ConfigModel()
{
}

ConfigModel::ConfigModel( bool                              isExist,
                          const list< SignificantRegion* >& significant_regions,
                          vector< string >&                 sig_region_names,
                          const PhaseRegion*                phase,
                          double                            weight,
                          double                            time_variation,
                          double                            compute_intensity_variation,
                          double                            granularity_sig_region,
                          vector< string >&                 t_variation_reg,
                          vector< string >&                 com_intensity_variation_reg )
{
    ptree significant_region;
    ptree intra_phase;
    if ( significant_regions.empty() )
    {
        for ( const auto& region : sig_region_names )
        {
            significant_region.put( "name", region );
            significant_region.put( "granularity", 1 );
            significant_region.put( "weight", 1 );
            significant_region.put( "time_variation_reg", 1 );
            significant_region.put( "time_variation_phase", 1 );
            significant_region.put( "compute_intensity", 1);
            intra_phase.push_back( make_pair( "significantRegion", significant_region ) );
        }
    } else {
        for ( const auto& region : significant_regions )
        {
            significant_region.put( "name", region->name );
            significant_region.put( "granularity", region->granularity );
            significant_region.put( "weight", region->dynamism_metrics[ 0 ].dyn_perc_phase );
            significant_region.put( "time_variation_reg", region->dynamism_metrics[ 0 ].dev_perc_reg );
            significant_region.put( "time_variation_phase", region->dynamism_metrics[ 0 ].dev_perc_phase );
            significant_region.put( "compute_intensity", region->dynamism_metrics[ 1 ].dyn_perc_phase );
            intra_phase.push_back( make_pair( "significantRegion", significant_region ) );
        }
    }

    ptree tuning_potential;
    tuning_potential.add_child( "Intra-phase", intra_phase );
    if( phase != NULL )
    {
        ptree inter_phase;
        inter_phase.put( "name", phase->name );
        inter_phase.put( "variation", phase->dev_perc );
        tuning_potential.add_child( "Inter-phase", inter_phase  );
    }

    ptree thresholds;
    thresholds.put( "weight", weight );
    thresholds.put( "time_variation", time_variation );
    thresholds.put( "compute_intensity_variation", compute_intensity_variation );
    thresholds.put( "granularity_significant_region", granularity_sig_region );
    tuning_potential.add_child( "Thresholds", thresholds );

    ptree dyn_t_variation;
    for ( const auto& t_reg : t_variation_reg )
    {
        dyn_t_variation.add( "name", t_reg );
    }

    ptree dynamism;
    dynamism.add_child( "dyn_time_variation", dyn_t_variation );

    ptree dyn_comIn_variation;
    for ( const auto& com_reg : com_intensity_variation_reg )
    {
        dyn_comIn_variation.add( "name", com_reg );
    }

    dynamism.add_child( "dyn_comIn_variation", dyn_comIn_variation );
    tuning_potential.add_child( "dynamism", dynamism );

    if( isExist )
        internalData = tuning_potential;
    else
        internalData.add_child( "Configuration.readex-dyn-detect", tuning_potential );
}

void
ConfigModel::updateTree( ptree& configTree )
{
    //XMLConfigTree = configTree.get_child( "Configuration.readex-dyn-detect" );
    try
    {
        configTree.put_child( "Configuration.readex-dyn-detect", internalData );
        XMLConfigTree = configTree;
    } catch ( exception &e )
    {
        remove( "readex_config.xml" );
        createTemplate();
    }
}

void
ConfigModel::createTemplate()
{
    ptree tuning_parameter;
    XMLConfigTree = internalData;

    //Add cpu freq
    ptree cpu_freq;
    cpu_freq.put( "min_freq",  string() );
    cpu_freq.put( "max_freq",  string() );
    cpu_freq.put( "freq_step", string() );
    cpu_freq.put( "default", string() );
    tuning_parameter.add_child( "frequency", cpu_freq );

    //Add uncore freq
    ptree uncore_freq;
    uncore_freq.put( "min_freq",  string() );
    uncore_freq.put( "max_freq",  string() );
    uncore_freq.put( "freq_step", string() );
    uncore_freq.put( "default", string() );
    tuning_parameter.add_child( "uncore", uncore_freq );

    //Add OpenMPThread
    ptree openMPThreads;
    openMPThreads.put( "lower_value", string() );
    openMPThreads.put( "step", string() );
    tuning_parameter.add_child( "openMPThreads", openMPThreads );
    XMLConfigTree.add_child( "Configuration.tuningParameter", tuning_parameter );

    //Add Objectives
    ptree objectives;
    objectives.add( "objective", "Energy" );
    //objectives.add( "objective", "NormalizedEnergy" );
    objectives.add( "objective", "Time" );
    //objectives.add( "objective", "NormalizedTime" );
    objectives.add( "objective", "EDP" );
    //objectives.add( "objective", "NormalizedEDP" );
    objectives.add( "objective", "ED2P" );
    //objectives.add( "objective", "NormalizedED2P" );
    objectives.add( "objective", "CPUEnergy" );
    //objectives.add( "objective", "NormalizedCPUEnergy" );
    objectives.add( "objective", "TCO" );
    //objectives.add( "objective", "NormalizedTCO" );
    XMLConfigTree.add_child( "Configuration.objectives", objectives );

    //TCO
    ptree CostPerJoule;
    CostPerJoule.put( "", 0.00000008 );
    XMLConfigTree.add_child( "Configuration.CostPerJoule", CostPerJoule );

    ptree CostPerCoreHour;
    CostPerCoreHour.put( "", 1.0 );
    XMLConfigTree.add_child( "Configuration.CostPerCoreHour", CostPerCoreHour );

    //Add Metric Plugin
    ptree metric_plugin;
    metric_plugin.put( "name", "hdeem_sync_plugin" );
    metric_plugin.put( "name", "x86_energy_sync_plugin" );
    XMLConfigTree.add_child( "Configuration.periscope.metricPlugin", metric_plugin );

    //Add Metrics
    ptree metric_energy;
    metric_energy.put( "node_energy", "hdeem/BLADE/E" );
    metric_energy.put( "cpu0_energy", "hdeem/CPU0/E" );
    metric_energy.put( "cpu1_energy", "hdeem/CPU1/E" );
    metric_energy.put( "node_energy", "x86_energy/BLADE/E" );
    XMLConfigTree.add_child( "Configuration.periscope.metrics", metric_energy );

    //Add searchAlogirthm
    ptree search_alg;
    search_alg.put( "name", "exhaustive" );
    XMLConfigTree.add_child( "Configuration.periscope.searchAlgorithm", search_alg );

    //Add searchAlogirthm for ATP
    ptree atp_search_alg;
    atp_search_alg.put( "name", "exhaustive_atp" );
    XMLConfigTree.add_child( "Configuration.periscope.atp.searchAlgorithm", atp_search_alg );

    //Add tuning_model file path
    ptree tuning_model;
    tuning_model.put( "file_path", string() );
    XMLConfigTree.add_child( "Configuration.periscope.tuningModel", tuning_model );

    //Add tuning_model file path
    ptree scorep;
    scorep.put( "tuningSubstrate", string() );
    XMLConfigTree.add_child( "Configuration.scorep", scorep );
}

void
ConfigModel::toXML( const string& filename )
{
#if BOOST_VERSION >= 105600
    write_xml( filename, XMLConfigTree, locale(), xml_writer_settings< ptree::key_type >( ' ', 4 ) );
#else
    write_xml( filename, XMLConfigTree, locale(), xml_writer_settings< char >( ' ', 4 ) );
#endif
}

max_stars_repo_name: readex-eu/readex-ptf

max_issues_repo_name: readex-eu/readex-ptf

max_forks_repo_name: readex-eu/readex-ptf


text:
//---------------------------------------------------------------------------//
// Copyright (c) 2013-2014 Mageswaran.D <mageswaran1989@gmail.com>
//
// Book Refered: OpenCL Programming Guide
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//

//---------------------------------------------------------------------------//
// About Sobel Filter:
// * Edge Filter - distinguishes the differrent color region
// * Finds the gradient in x and y-axes
// * Three step process
//   -> Find x-axis gradient with kernel/matrix
//           Gx = [-1 0 +1]
//                [-2 0 +2]
//                [-1 0 +1]
//   -> Find y-axis gradient with kernel/matrix
//           Gy = [-1 -2 -1]
//                [ 0  0  0]
//                [+1 +2 +1]
// * Gradient magnitude G = sqrt(Gx^2 + Gy^2)
//---------------------------------------------------------------------------//

#include <iostream>
#include <string>

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <boost/compute/system.hpp>
#include <boost/compute/interop/opencv/core.hpp>
#include <boost/compute/interop/opencv/highgui.hpp>
#include <boost/compute/utility/source.hpp>

#include <boost/program_options.hpp>

namespace compute = boost::compute;
namespace po = boost::program_options;

// Create sobel filter program
const char source[] = BOOST_COMPUTE_STRINGIZE_SOURCE (
    //For out of boundary pixels, edge pixel
    // value is returned
    const sampler_t sampler = CLK_ADDRESS_CLAMP_TO_EDGE |
                              CLK_FILTER_NEAREST;
    kernel void sobel_rgb(read_only image2d_t src, write_only image2d_t dst)
    {
        int x = (int)get_global_id(0);
        int y = (int)get_global_id(1);

        if (x >= get_image_width(src) || y >= get_image_height(src))
                return;

        //  [(x-1, y+1), (x, y+1), (x+1, y+1)]
        //  [(x-1, y  ), (x, y  ), (x+1, y  )]
        //  [(x-1, y-1), (x, y-1), (x+1, y-1)]

        //  [p02, p12,   p22]
        //  [p01, pixel, p21]
        //  [p00, p10,   p20]

        //Basically finding influence of neighbour pixels on current pixel
        float4 p00 = read_imagef(src, sampler, (int2)(x - 1, y - 1));
        float4 p10 = read_imagef(src, sampler, (int2)(x,     y - 1));
        float4 p20 = read_imagef(src, sampler, (int2)(x + 1, y - 1));

        float4 p01 = read_imagef(src, sampler, (int2)(x - 1, y));
        //pixel that we are working on
        float4 p21 = read_imagef(src, sampler, (int2)(x + 1, y));

        float4 p02 = read_imagef(src, sampler, (int2)(x - 1, y + 1));
        float4 p12 = read_imagef(src, sampler, (int2)(x,     y + 1));
        float4 p22 = read_imagef(src, sampler, (int2)(x + 1, y + 1));

        //Find Gx = kernel + 3x3 around current pixel
        //           Gx = [-1 0 +1]     [p02, p12,   p22]
        //                [-2 0 +2]  +  [p01, pixel, p21]
        //                [-1 0 +1]     [p00, p10,   p20]
        float3 gx = -p00.xyz + p20.xyz +
                    2.0f * (p21.xyz - p01.xyz)
                    -p02.xyz + p22.xyz;

        //Find Gy = kernel + 3x3 around current pixel
        //           Gy = [-1 -2 -1]     [p02, p12,   p22]
        //                [ 0  0  0]  +  [p01, pixel, p21]
        //                [+1 +2 +1]     [p00, p10,   p20]
        float3 gy = p00.xyz + p20.xyz +
                    2.0f * (- p12.xyz + p10.xyz) -
                    p02.xyz - p22.xyz;
        //Find G
        float3 g = native_sqrt(gx * gx + gy * gy);

        // we could also approximate this as g = fabs(gx) + fabs(gy)
        write_imagef(dst, (int2)(x, y), (float4)(g.x, g.y, g.z, 1.0f));
    }
);

// This example shows how to apply sobel filter on images or on camera frames
// with OpenCV, transfer the frames to the GPU, and apply a sobel filter
// written in OpenCL
int main(int argc, char *argv[])
{
    ///////////////////////////////////////////////////////////////////////////

    // setup the command line arguments
    po::options_description desc;
    desc.add_options()
            ("help",  "show available options")
            ("camera", po::value<int>()->default_value(-1),
                                 "if not default camera, specify a camera id")
            ("image", po::value<std::string>(), "path to image file");

    // Parse the command lines
    po::variables_map vm;
    po::store(po::parse_command_line(argc, argv, desc), vm);
    po::notify(vm);

    //check the command line arguments
    if(vm.count("help"))
    {
        std::cout << desc << std::endl;
        return 0;
    }

    ///////////////////////////////////////////////////////////////////////////

    //OpenCV variables
    cv::Mat cv_mat;
    cv::VideoCapture cap; //OpenCV camera handle.

    //OpenCL variables
    // Get default device and setup context
    compute::device gpu = compute::system::default_device();
    compute::context context(gpu);
    compute::command_queue queue(context, gpu);
    compute::program filter_program =
            compute::program::create_with_source(source, context);

    try
    {
        filter_program.build();
    }
    catch(compute::opencl_error e)
    {
        std::cout<<"Build Error: "<<std::endl
                 <<filter_program.build_log();
    }

    // create fliter kernel and set arguments
    compute::kernel filter_kernel(filter_program, "sobel_rgb");

    ///////////////////////////////////////////////////////////////////////////

    //check for image paths
    if(vm.count("image"))
    {
        // Read image with OpenCV
        cv_mat = cv::imread(vm["image"].as<std::string>(),
                                       CV_LOAD_IMAGE_COLOR);
        if(!cv_mat.data){
            std::cerr << "Failed to load image" << std::endl;
            return -1;
        }
    }
    else //by default use camera
    {
        //open camera
        cap.open(vm["camera"].as<int>());
        // read first frame
        cap >> cv_mat;
        if(!cv_mat.data){
            std::cerr << "failed to capture frame" << std::endl;
            return -1;
        }
    }

    // Convert image to BGRA (OpenCL requires 16-byte aligned data)
    cv::cvtColor(cv_mat, cv_mat, CV_BGR2BGRA);

    // Transfer image/frame data to gpu
    compute::image2d dev_input_image =
            compute::opencv_create_image2d_with_mat(
                cv_mat, compute::image2d::read_write, queue
                );

    // Create output image
    // Be sure what will be your ouput image/frame size
    compute::image2d dev_output_image(
                context,
                dev_input_image.width(),
                dev_input_image.height(),
                dev_input_image.format(),
                compute::image2d::write_only
                );

    filter_kernel.set_arg(0, dev_input_image);
    filter_kernel.set_arg(1, dev_output_image);

    // run flip kernel
    size_t origin[2] = { 0, 0 };
    size_t region[2] = { dev_input_image.width(),
                         dev_input_image.height() };

    ///////////////////////////////////////////////////////////////////////////

    queue.enqueue_nd_range_kernel(filter_kernel, 2, origin, region, 0);

    //check for image paths
    if(vm.count("image"))
    {
        // show host image
        cv::imshow("Original Image", cv_mat);

        // show gpu image
        compute::opencv_imshow("Filtered Image", dev_output_image, queue);

        // wait and return
        cv::waitKey(0);
    }
    else
    {
        char key = '\0';
        while(key != 27) //check for escape key
        {
            cap >> cv_mat;

            // Convert image to BGRA (OpenCL requires 16-byte aligned data)
            cv::cvtColor(cv_mat, cv_mat, CV_BGR2BGRA);

            // Update the device image memory with current frame data
            compute::opencv_copy_mat_to_image(cv_mat,
                                              dev_input_image,queue);

            // Run the kernel on the device
            queue.enqueue_nd_range_kernel(filter_kernel, 2, origin, region, 0);

            // Show host image
            cv::imshow("Camera Frame", cv_mat);

            // Show GPU image
            compute::opencv_imshow("Filtered RGB Frame", dev_output_image, queue);

            // wait
            key = cv::waitKey(10);
        }
    }
    return 0;
}

ext: cpp


text:
#ifndef SUPPORT_FOR_MODEL_GENERATION
#   define SUPPORT_FOR_MODEL_GENERATION
#endif  // SUPPORT_FOR_MODEL_GENERATION
#include "libs/transform_action/mapvalues_task.h"
#include "libs/transform_action/map_values_conf.h"
#include "libs/sources_handling/row_data_input.h"
#include "utils/dc_lookup_table.h"
#include "logging.h"
#include <boost/range/algorithm/transform.hpp>

namespace lookup
{
namespace
{

tablegen_function::result_type
    default_case(const tablegen_function::arg_type& )
{
    return
        make_trasform_func(dont_trasform_op);
}

table make_lookup_table(const mlmodels::class_data& from)
{
    return map(std::begin(from), std::end(from));
}

table make_table(const /*lookup::func::*/tablegen_function::arg_type& from,
        const column_data::id_type& id)
{
    auto lbl_col = classifier::labels_data(from, id, classifier::rows(from));
    return make_lookup_table(lbl_col);
}

transform_action::result_type
    convert(transform_action::arg_type from, const table& transfomer)
{
    using target_type = transform_action::arg_type::value_type;
    if (!from.empty()) {

        boost::transform(from, from.begin(), [&transfomer](auto val) {
                    return static_cast<target_type>(mapped(transfomer, val));
                }
        );
    }
    return from;
}

}   // end of local namespace

transform_action::result_type
    preform_action(const lookup::table& table, const transform_action::arg_type& column)
{
    return convert(column, table);
}

tablegen_function::result_type preform_action(
        const map_values_conf& action, const tablegen_function::arg_type& arg)
{
    LOG_INFO<<"creating lookup table from input data of size "<<classifier::rows(arg)<<" for column "<<action.column;

    if (classifier::empty(arg)) {
        LOG_INFO<<"failed to create values to integers mapping - data is empty";
        return default_case(arg);
    } else if (action.classifier()) {
        LOG_DEBUG<<"creating lookup table for classifier model type";
        return  make_trasform_func(make_table(arg, action.column));
    } else {
        LOG_DEBUG<<"no need for table lookup - we are running in regression mode";
        return default_case(arg);
    }
}

uniqued_function::result_type
    preform_action(uniqued_function::result_type val, const uniqued_function::arg_type&)
{
    return val;
}

} // end of namespace lookup


text:
#include <rw/common/ThreadPool.hpp>
#include <rw/loaders/ImageLoader.hpp>

#include <boost/bind.hpp>
#include <boost/function.hpp>

using namespace rw::common;
using namespace rw::core;
using rw::loaders::ImageLoader;
using rw::sensor::Image;

static boost::mutex outMutex;
static boost::mutex imageMutex;
static std::vector<Image::Ptr> images;

void loadFile(ThreadPool* pool, const std::string &file) {
	{
		boost::mutex::scoped_lock lock(outMutex);
		std::cout << "Loading " << file << std::endl;
	}
	Image::Ptr image;
	try {
		image = ImageLoader::Factory::load(file);
	} catch (Exception&) {
		image = NULL;
	}
	if (pool->isStopping())
		return;
	{
		boost::mutex::scoped_lock lock(imageMutex);
		images.push_back(image);
	}
}

int main(int argc, const char* argv[]) {
	ThreadPool::Ptr pool = ownedPtr(new ThreadPool(std::atoi(argv[1])));
	for (int i = 2; i < argc; i++) {
		ThreadPool::WorkFunction work = boost::bind(&loadFile,boost::arg<1>(),argv[i]);
		pool->addWork(work);
	}
	pool->waitForEmptyQueue();
	return 0;
}


text:
#pragma once

#ifdef new
#undef new
#endif

#include <boost/shared_array.hpp>
using boost::shared_array;

#ifdef DEBUG_NEW
#define new DEBUG_NEW
#endif

ext: hpp

max_stars_repo_name: bowlofstew/omim

max_issues_repo_name: bowlofstew/omim

max_forks_repo_name: bowlofstew/omim