<commit_before>/*! \file BasicBlockInstrumentor.cpp
	\date Monday November 15, 2010
	\author <NAME> <<EMAIL>>
	\brief The source file for the BasicBlockInstrumentor class.
*/

#ifndef BASIC_BLOCK_INSTRUMENTOR_CPP_INCLUDED
#define BASIC_BLOCK_INSTRUMENTOR_CPP_INCLUDED

#include <ocelot/analysis/interface/BasicBlockInstrumentor.h>

#include <ocelot/cuda/interface/cuda_runtime.h>

#include <ocelot/transforms/interface/CToPTXInstrumentationPass.h>
#include <ocelot/transforms/interface/MemoryIntensityPass.h>
#include <ocelot/transforms/interface/DynamicInstructionCountPass.h>
#include <ocelot/transforms/interface/BasicBlockExecutionCountPass.h>
#include <ocelot/transforms/interface/BasicBlockInstrumentationPass.h>
#include <ocelot/ir/interface/Module.h>

#include <hydrazine/implementation/ArgumentParser.h>
#include <hydrazine/implementation/string.h>
#include <hydrazine/implementation/debug.h>
#include <hydrazine/implementation/Exception.h>

#include <fstream>

using namespace hydrazine;

namespace analysis
{

    void BasicBlockInstrumentor::checkConditions() {
        conditionsMet = true;
    }

    void BasicBlockInstrumentor::analyze(ir::Module &module) {
    
        basicBlocks = 0;
        if(!kernelName.empty()){
            basicBlocks = module.getKernel(kernelName)->cfg()->size() - 2;
        }
        else {
            for (ir::Module::KernelMap::const_iterator kernel = module.kernels().begin(); 
		        kernel != module.kernels().end(); ++kernel) {
                basicBlocks += (kernel->second)->cfg()->size();
            }
        }

        for( ir::ControlFlowGraph::const_iterator block = module.getKernel(kernelName)->cfg()->begin(); 
			block != module.getKernel(kernelName)->cfg()->end(); ++block ) {
            if(block->label == "entry" || block->label == "exit")
                continue;
            labels.push_back(block->label);
        }

        
    }

    void BasicBlockInstrumentor::initialize() {
        
        counter = 0;

        if(cudaMalloc((void **) &counter, entries * basicBlocks * threadBlocks * threads * sizeof(size_t)) != cudaSuccess){
            throw hydrazine::Exception( "Could not allocate sufficient memory on device (cudaMalloc failed)!" );
        }
        if(cudaMemset( counter, 0, entries * basicBlocks * threadBlocks * threads * sizeof( size_t )) != cudaSuccess){
            throw hydrazine::Exception( "cudaMemset failed!" );
        }
        
        if(cudaMemcpyToSymbol(symbol.c_str(), &counter, sizeof(size_t *), 0, cudaMemcpyHostToDevice) != cudaSuccess) {
            throw hydrazine::Exception( "cudaMemcpyToSymbol failed!");
        }
    }

    transforms::Pass *BasicBlockInstrumentor::createPass() {
        
        transforms::CToPTXInstrumentationPass *pass = new transforms::CToPTXInstrumentationPass("resources/dynamicInstructionCount.c");
        symbol = pass->baseAddress;
        entries = 1;
        return pass;
        
        /*
        
        transforms::BasicBlockInstrumentationPass *basicBlockPass;
        entries = 1;        

        switch(type) {
            case executionCount:
                basicBlockPass = new transforms::BasicBlockExecutionCountPass;
                break;
            case instructionCount:
                basicBlockPass = new transforms::DynamicInstructionCountPass;
                break;
            case memoryIntensity:
                basicBlockPass = new transforms::MemoryIntensityPass;
                entries = 2;
                break;
            default:
                throw hydrazine::Exception( "No basic block instrumentation pass specified!" );
        }
        

        basicBlockPass->entries = entries;
        return basicBlockPass;          
        */
    }
<commit_msg>ENH: Restored all other instrumentation passes.<commit_after>/*! \file BasicBlockInstrumentor.cpp
	\date Monday November 15, 2010
	\author <NAME> <<EMAIL>>
	\brief The source file for the BasicBlockInstrumentor class.
*/

#ifndef BASIC_BLOCK_INSTRUMENTOR_CPP_INCLUDED
#define BASIC_BLOCK_INSTRUMENTOR_CPP_INCLUDED

#include <ocelot/analysis/interface/BasicBlockInstrumentor.h>

#include <ocelot/cuda/interface/cuda_runtime.h>

#include <ocelot/transforms/interface/CToPTXInstrumentationPass.h>
#include <ocelot/transforms/interface/MemoryIntensityPass.h>
#include <ocelot/transforms/interface/DynamicInstructionCountPass.h>
#include <ocelot/transforms/interface/BasicBlockExecutionCountPass.h>
#include <ocelot/transforms/interface/BasicBlockInstrumentationPass.h>
#include <ocelot/ir/interface/Module.h>

#include <hydrazine/implementation/ArgumentParser.h>
#include <hydrazine/implementation/string.h>
#include <hydrazine/implementation/debug.h>
#include <hydrazine/implementation/Exception.h>

#include <fstream>

using namespace hydrazine;

namespace analysis
{

    void BasicBlockInstrumentor::checkConditions() {
        conditionsMet = true;
    }

    void BasicBlockInstrumentor::analyze(ir::Module &module) {
    
        basicBlocks = 0;
        if(!kernelName.empty()){
            basicBlocks = module.getKernel(kernelName)->cfg()->size() - 2;
        }
        else {
            for (ir::Module::KernelMap::const_iterator kernel = module.kernels().begin(); 
		        kernel != module.kernels().end(); ++kernel) {
                basicBlocks += (kernel->second)->cfg()->size();
            }
        }

        for( ir::ControlFlowGraph::const_iterator block = module.getKernel(kernelName)->cfg()->begin(); 
			block != module.getKernel(kernelName)->cfg()->end(); ++block ) {
            if(block->label == "entry" || block->label == "exit")
                continue;
            labels.push_back(block->label);
        }

        
    }

    void BasicBlockInstrumentor::initialize() {
        
        counter = 0;

        if(cudaMalloc((void **) &counter, entries * basicBlocks * threadBlocks * threads * sizeof(size_t)) != cudaSuccess){
            throw hydrazine::Exception( "Could not allocate sufficient memory on device (cudaMalloc failed)!" );
        }
        if(cudaMemset( counter, 0, entries * basicBlocks * threadBlocks * threads * sizeof( size_t )) != cudaSuccess){
            throw hydrazine::Exception( "cudaMemset failed!" );
        }
        
        if(cudaMemcpyToSymbol(symbol.c_str(), &counter, sizeof(size_t *), 0, cudaMemcpyHostToDevice) != cudaSuccess) {
            throw hydrazine::Exception( "cudaMemcpyToSymbol failed!");
        }
    }

    transforms::Pass *BasicBlockInstrumentor::createPass() {
        
        entries = 1;
        
        switch(type) {
            case executionCount:
            {
                transforms::BasicBlockInstrumentationPass *basicBlockPass = new transforms::BasicBlockExecutionCountPass;
                basicBlockPass->entries = entries;
                symbol = basicBlockPass->basicBlockCounterBase();
                return basicBlockPass;
            }
            case instructionCount:
            {
                transforms::CToPTXInstrumentationPass *pass = new transforms::CToPTXInstrumentationPass("resources/dynamicInstructionCount.c");
                symbol = pass->baseAddress;
                return pass;     
            }
            case memoryIntensity:
            {
                transforms::BasicBlockInstrumentationPass *basicBlockPass = new transforms::MemoryIntensityPass;
                basicBlockPass->entries = entries = 2;
                symbol = basicBlockPass->basicBlockCounterBase();
                return basicBlockPass;
            }
            default:
                throw hydrazine::Exception( "No basic block instrumentation pass specified!" );
        }
        
    }

{'fraction_non_alphanumeric': 0.11150234741784038, 'fraction_numerical': 0.0035211267605633804, 'mean_word_length': 2.7156007751937983, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4112294', 'n_tokens_mistral': 2190, 'n_tokens_neox': 2093, 'n_words': 378}