Created
April 26, 2013 18:53
-
-
Save syst3mw0rm/5469526 to your computer and use it in GitHub Desktop.
puzzle1 viennaCL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include "viennacl/vector.hpp" | |
#include "benchmark-utils.hpp" | |
#define BENCHMARK_VECTOR_SIZE 1000 | |
#define BENCHMARK_RUNS 10 | |
int main() { | |
//Change this type definition to double if your gpu supports that | |
typedef float ScalarType; | |
int v_size = 1000; | |
Timer timer; | |
double e_time; | |
std::vector<ScalarType> stl_vec(v_size); | |
viennacl::vector<ScalarType> y1(v_size); | |
viennacl::vector<ScalarType> y2(v_size); | |
viennacl::vector<ScalarType> x1(v_size); | |
viennacl::vector<ScalarType> x2(v_size); | |
for(unsigned int i=0; i < v_size; i++) { | |
stl_vec[i] = i; | |
} | |
copy(stl_vec.begin(), stl_vec.end(), y1.begin()); | |
copy(stl_vec.begin(), stl_vec.end(), y2.begin()); | |
// COMMAND 1 | |
viennacl::backend::finish(); | |
timer.start(); | |
std::cout<<"Executing command 1 : x = y1 + y2"<<std::endl; | |
timer.start(); | |
for(int r=0;r<BENCHMARK_RUNS;r++) { | |
x1 = y1 + y2; | |
} | |
e_time = timer.get(); | |
std::cout << "GPU time: " << e_time << std::endl; | |
std::cout << "GPU "; printOps(2.0 * static_cast<double>(v_size), static_cast<double>(e_time) / static_cast<double>(BENCHMARK_RUNS)); | |
// COMMAND 2 | |
viennacl::backend::finish(); | |
timer.start(); | |
std::cout<<"Executing command 2 : x = y1 + y2 + y1 + y2"<<std::endl; | |
timer.start(); | |
for(int r=0;r<BENCHMARK_RUNS;r++) { | |
x2 = y1 + y2 + y1 + y2; | |
} | |
e_time = timer.get(); | |
std::cout << "GPU time: " << e_time << std::endl; | |
std::cout << "GPU "; printOps(2.0 * static_cast<double>(v_size), static_cast<double>(e_time) / static_cast<double>(BENCHMARK_RUNS)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment