mirror of
https://github.com/vortexgpgpu/vortex.git
synced 2025-04-23 21:39:10 -04:00
minor update
This commit is contained in:
parent
299657d693
commit
e4e0ee8fef
14 changed files with 154 additions and 109 deletions
|
@ -37,4 +37,4 @@ run-simx: $(PROJECT).bin
|
|||
$(CC) $(CFLAGS) -MM $^ > .depend;
|
||||
|
||||
clean:
|
||||
rm -rf *.elf *.bin *.dump .depend
|
||||
rm -rf *.elf *.bin *.dump *.log .depend
|
||||
|
|
|
@ -7,6 +7,6 @@ SRC_DIR := $(VORTEX_HOME)/tests/opencl/$(PROJECT)
|
|||
|
||||
SRCS := $(SRC_DIR)/main.cc
|
||||
|
||||
OPTS ?=
|
||||
OPTS ?= $(SRC_DIR)/graph4096.txt
|
||||
|
||||
include ../common.mk
|
||||
|
|
|
@ -182,14 +182,20 @@ void run_bfs_gpu(int no_of_nodes, Node *h_graph_nodes, int edge_list_size,
|
|||
int main(int argc, char *argv[]) {
|
||||
printf("enter demo main\n");
|
||||
|
||||
int errors = 0;
|
||||
int no_of_nodes;
|
||||
int edge_list_size;
|
||||
FILE *fp;
|
||||
Node *h_graph_nodes;
|
||||
char *h_graph_mask, *h_updating_graph_mask, *h_graph_visited;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("graph file missing!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
try {
|
||||
char *input_f = "graph4096.txt";
|
||||
char *input_f = argv[1];
|
||||
printf("Reading File\n");
|
||||
// Read in Graph from a file
|
||||
fp = fopen(input_f, "r");
|
||||
|
@ -277,7 +283,7 @@ int main(int argc, char *argv[]) {
|
|||
h_cost_ref);
|
||||
//---------------------------------------------------------
|
||||
//--result varification
|
||||
compare_results<int>(h_cost_ref, h_cost, no_of_nodes);
|
||||
errors = compare_results<int>(h_cost_ref, h_cost, no_of_nodes);
|
||||
// release host memory
|
||||
free(h_graph_nodes);
|
||||
free(h_graph_mask);
|
||||
|
@ -292,6 +298,12 @@ int main(int argc, char *argv[]) {
|
|||
free(h_updating_graph_mask);
|
||||
free(h_graph_visited);
|
||||
}
|
||||
|
||||
if (errors != 0) {
|
||||
printf("Failed!\n");
|
||||
return errors;
|
||||
}
|
||||
|
||||
printf("Passed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -50,22 +50,15 @@ void verify_array(const datatype *cpuResults, const datatype *gpuResults, const
|
|||
return ;
|
||||
}
|
||||
template<typename datatype>
|
||||
void compare_results(const datatype *cpu_results, const datatype *gpu_results, const int size){
|
||||
|
||||
char passed = true;
|
||||
int compare_results(const datatype *cpu_results, const datatype *gpu_results, const int size) {
|
||||
int errors = 0;
|
||||
//#pragma omp parallel for
|
||||
for (int i=0; i<size; i++){
|
||||
if (cpu_results[i]!=gpu_results[i]){
|
||||
passed = false;
|
||||
if (cpu_results[i] != gpu_results[i]){
|
||||
++errors;
|
||||
}
|
||||
}
|
||||
if (passed){
|
||||
std::cout << "--cambine: passed: -)" << endl;
|
||||
}
|
||||
else{
|
||||
std::cout << "--cambine: failed :-(" << endl;
|
||||
}
|
||||
return ;
|
||||
return errors;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -61,7 +61,7 @@ int main(int argc, char **argv)
|
|||
*h_X,
|
||||
*h_T;
|
||||
|
||||
const unsigned int optionCount = 64;
|
||||
const unsigned int optionCount = 64*64;
|
||||
const float R = 0.02f;
|
||||
const float V = 0.30f;
|
||||
|
||||
|
|
|
@ -71,11 +71,15 @@ main.cc.o: $(SRC_DIR)/main.cc
|
|||
main.cc.host.o: $(SRC_DIR)/main.cc
|
||||
$(CXX) $(CXXFLAGS) -DHOSTGPU -c $< -o $@
|
||||
|
||||
$(PROJECT): main.cc.o $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -L$(ROOT_DIR)/runtime/stub -lvortex -L$(POCL_RT_PATH)/lib -lOpenCL -o $@
|
||||
ifndef USE_SETUP
|
||||
setup:
|
||||
endif
|
||||
|
||||
$(PROJECT).host: main.cc.host.o $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -lOpenCL -o $@
|
||||
$(PROJECT): setup main.cc.o $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $(filter-out setup, $^) $(LDFLAGS) -L$(ROOT_DIR)/runtime/stub -lvortex -L$(POCL_RT_PATH)/lib -lOpenCL -o $@
|
||||
|
||||
$(PROJECT).host: setup main.cc.host.o $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $(filter-out setup, $^) $(LDFLAGS) -lOpenCL -o $@
|
||||
|
||||
run-gpu: $(PROJECT).host kernel.pocl
|
||||
./$(PROJECT).host $(OPTS)
|
||||
|
@ -100,7 +104,7 @@ endif
|
|||
$(CXX) $(CXXFLAGS) -MM $^ > .depend;
|
||||
|
||||
clean:
|
||||
rm -rf $(PROJECT) $(PROJECT).host *.o .depend
|
||||
rm -rf $(PROJECT) $(PROJECT).host *.o *.log .depend
|
||||
|
||||
clean-all: clean
|
||||
rm -rf *.dump *.pocl
|
||||
|
|
|
@ -7,6 +7,7 @@ SRC_DIR := $(VORTEX_HOME)/tests/opencl/$(PROJECT)
|
|||
|
||||
SRCS := $(SRC_DIR)/main.cc $(SRC_DIR)/clutils.cpp $(SRC_DIR)/utils.cpp
|
||||
|
||||
OPTS ?=
|
||||
# usage: [-f <input_file>] [-s <size>]
|
||||
OPTS ?= -q -s 32
|
||||
|
||||
include ../common.mk
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <algorithm>
|
||||
#include <algorithm>
|
||||
|
||||
#include "clutils.h"
|
||||
|
||||
|
@ -24,7 +24,7 @@ float *OpenClGaussianElimination(
|
|||
|
||||
void printUsage();
|
||||
int parseCommandline(int argc, char *argv[], char* filename,
|
||||
int *q, int *t, int *p, int *d);
|
||||
int *q, int *t, int *p, int *d, int* s);
|
||||
|
||||
void InitPerRun(int size,float *m);
|
||||
void ForwardSub(cl_context context, float *a, float *b, float *m, int size,int timing);
|
||||
|
|
|
@ -9,9 +9,9 @@ int main(int argc, char *argv[]) {
|
|||
printf("enter demo main\n");
|
||||
float *a = NULL, *b = NULL, *finalVec = NULL;
|
||||
float *m = NULL;
|
||||
int size;
|
||||
int size = 0;
|
||||
|
||||
FILE *fp;
|
||||
FILE *fp = NULL;
|
||||
|
||||
// args
|
||||
char filename[100];
|
||||
|
@ -19,26 +19,41 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
// parse command line
|
||||
if (parseCommandline(argc, argv, filename, &quiet, &timing, &platform,
|
||||
&device)) {
|
||||
&device, &size)) {
|
||||
printUsage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
context = cl_init_context(platform, device, quiet);
|
||||
|
||||
fp = fopen(filename, "r");
|
||||
fscanf(fp, "%d", &size);
|
||||
if (size == 0) {
|
||||
fp = fopen(filename, "r");
|
||||
fscanf(fp, "%d", &size);
|
||||
|
||||
a = (float *)malloc(size * size * sizeof(float));
|
||||
printf("using %dx%d input matrix\n", size, size);
|
||||
|
||||
InitMat(fp, size, a, size, size);
|
||||
// printf("The input matrix a is:\n");
|
||||
// PrintMat(a, size, size, size);
|
||||
b = (float *)malloc(size * sizeof(float));
|
||||
a = (float *)malloc(size * size * sizeof(float));
|
||||
|
||||
InitAry(fp, b, size);
|
||||
// printf("The input array b is:\n");
|
||||
// PrintAry(b, size);
|
||||
InitMat(fp, size, a, size, size);
|
||||
// printf("The input matrix a is:\n");
|
||||
// PrintMat(a, size, size, size);
|
||||
b = (float *)malloc(size * sizeof(float));
|
||||
|
||||
InitAry(fp, b, size);
|
||||
// printf("The input array b is:\n");
|
||||
// PrintAry(b, size);
|
||||
} else {
|
||||
// create the input matrix
|
||||
a = (float *)malloc(size * size * sizeof(float));
|
||||
b = (float *)malloc(size * sizeof(float));
|
||||
|
||||
for (int i = 0, n = size * size; i < n; ++i) {
|
||||
a[i] = static_cast<float>(std::rand()) / RAND_MAX;
|
||||
}
|
||||
for (int i = 0; i < size; ++i) {
|
||||
b[i] = static_cast<float>(std::rand()) / RAND_MAX;
|
||||
}
|
||||
}
|
||||
|
||||
// create the solution matrix
|
||||
m = (float *)malloc(size * size * sizeof(float));
|
||||
|
@ -68,7 +83,7 @@ int main(int argc, char *argv[]) {
|
|||
PrintAry(finalVec, size);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
if (fp) fclose(fp);
|
||||
free(m);
|
||||
free(a);
|
||||
free(b);
|
||||
|
@ -77,7 +92,6 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
cl_cleanup();
|
||||
|
||||
printf("Passed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -282,16 +296,20 @@ float eventTime(cl_event event, cl_command_queue command_queue) {
|
|||
}
|
||||
|
||||
int parseCommandline(int argc, char *argv[], char *filename, int *q, int *t,
|
||||
int *p, int *d) {
|
||||
int *p, int *d, int* s) {
|
||||
int i;
|
||||
// if (argc < 2) return 1; // error
|
||||
strncpy(filename, "matrix4.txt", 100);
|
||||
if (argc < 2) return 1; // error
|
||||
char flag;
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') { // flag
|
||||
flag = argv[i][1];
|
||||
switch (flag) {
|
||||
case 'f': // matrix file
|
||||
i++;
|
||||
strncpy(filename,argv[i],100);
|
||||
printf("Read file from %s \n", filename);
|
||||
break;
|
||||
case 'h': // help
|
||||
return 1;
|
||||
break;
|
||||
|
@ -309,6 +327,10 @@ int parseCommandline(int argc, char *argv[], char *filename, int *q, int *t,
|
|||
i++;
|
||||
*d = atoi(argv[i]);
|
||||
break;
|
||||
case 's': // size
|
||||
i++;
|
||||
*s = atoi(argv[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ SRC_DIR := $(VORTEX_HOME)/tests/opencl/$(PROJECT)
|
|||
|
||||
SRCS := $(SRC_DIR)/main.cc $(SRC_DIR)/read_input.c $(SRC_DIR)/rmse.c $(SRC_DIR)/kmeans_clustering.c $(SRC_DIR)/cluster.c $(SRC_DIR)/getopt.c
|
||||
|
||||
OPTS ?=
|
||||
# usage: -f<features> -p<points>
|
||||
OPTS ?= -f100 -p100
|
||||
|
||||
include ../common.mk
|
||||
|
|
|
@ -124,8 +124,8 @@ int setup(int argc, char **argv) {
|
|||
int max_nclusters = 5; /* default value */
|
||||
int min_nclusters = 5; /* default value */
|
||||
int best_nclusters = 0;
|
||||
int nfeatures = 0;
|
||||
int npoints = 0;
|
||||
int nfeatures = 100;
|
||||
int npoints = 100;
|
||||
float len;
|
||||
|
||||
float **features;
|
||||
|
@ -140,7 +140,7 @@ int setup(int argc, char **argv) {
|
|||
// float cluster_timing, io_timing;
|
||||
|
||||
/* obtain command line arguments and change appropriate options */
|
||||
while ((opt = getopt(argc, argv, "i:t:m:n:l:bro")) != EOF) {
|
||||
while ((opt = getopt(argc, argv, "p:f:i:t:m:n:l:bro")) != EOF) {
|
||||
switch (opt) {
|
||||
case 'i':
|
||||
filename = optarg;
|
||||
|
@ -157,6 +157,12 @@ int setup(int argc, char **argv) {
|
|||
case 'n':
|
||||
min_nclusters = atoi(optarg);
|
||||
break;
|
||||
case 'f':
|
||||
nfeatures = atoi(optarg);
|
||||
break;
|
||||
case 'p':
|
||||
npoints = atoi(optarg);
|
||||
break;
|
||||
case 'r':
|
||||
isRMSE = 1;
|
||||
break;
|
||||
|
@ -179,73 +185,73 @@ int setup(int argc, char **argv) {
|
|||
/* get nfeatures and npoints */
|
||||
// io_timing = omp_get_wtime();
|
||||
|
||||
/*if (isBinaryFile) { // Binary file input
|
||||
FILE *infile;
|
||||
if ((infile = fopen("100", "r")) == NULL) {
|
||||
fprintf(stderr, "Error: no such file (%s)\n", filename);
|
||||
exit(1);
|
||||
}
|
||||
fread(&npoints, 1, sizeof(int), infile);
|
||||
fread(&nfeatures, 1, sizeof(int), infile);
|
||||
if (filename) {
|
||||
if (isBinaryFile) { // Binary file input
|
||||
FILE *infile;
|
||||
if ((infile = fopen("100", "r")) == NULL) {
|
||||
fprintf(stderr, "Error: no such file (%s)\n", filename);
|
||||
exit(1);
|
||||
}
|
||||
fread(&npoints, 1, sizeof(int), infile);
|
||||
fread(&nfeatures, 1, sizeof(int), infile);
|
||||
|
||||
// allocate space for features[][] and read attributes of all objects
|
||||
// allocate space for features[][] and read attributes of all objects
|
||||
buf = (float *)malloc(npoints * nfeatures * sizeof(float));
|
||||
features = (float **)malloc(npoints * sizeof(float *));
|
||||
features[0] = (float *)malloc(npoints * nfeatures * sizeof(float));
|
||||
for (i = 1; i < npoints; i++) {
|
||||
features[i] = features[i - 1] + nfeatures;
|
||||
}
|
||||
fread(buf, 1, npoints * nfeatures * sizeof(float), infile);
|
||||
fclose(infile);
|
||||
} else {
|
||||
FILE *infile;
|
||||
if ((infile = fopen("100", "r")) == NULL) {
|
||||
fprintf(stderr, "Error: no such file (%s)\n", filename);
|
||||
exit(1);
|
||||
}
|
||||
while (fgets(line, 1024, infile) != NULL)
|
||||
if (strtok(line, " \t\n") != 0) {
|
||||
npoints++;
|
||||
}
|
||||
rewind(infile);
|
||||
while (fgets(line, 1024, infile) != NULL) {
|
||||
if (strtok(line, " \t\n") != 0) {
|
||||
// ignore the id (first attribute): nfeatures = 1;
|
||||
while (strtok(NULL, " ,\t\n") != NULL)
|
||||
nfeatures++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// allocate space for features[] and read attributes of all objects
|
||||
buf = (float *)malloc(npoints * nfeatures * sizeof(float));
|
||||
features = (float **)malloc(npoints * sizeof(float *));
|
||||
features[0] = (float *)malloc(npoints * nfeatures * sizeof(float));
|
||||
for (i = 1; i < npoints; i++)
|
||||
features[i] = features[i - 1] + nfeatures;
|
||||
rewind(infile);
|
||||
i = 0;
|
||||
while (fgets(line, 1024, infile) != NULL) {
|
||||
if (strtok(line, " \t\n") == NULL)
|
||||
continue;
|
||||
for (j = 0; j < nfeatures; j++) {
|
||||
buf[i] = atof(strtok(NULL, " ,\t\n"));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
fclose(infile);
|
||||
}
|
||||
} else {
|
||||
buf = (float *)malloc(npoints * nfeatures * sizeof(float));
|
||||
features = (float **)malloc(npoints * sizeof(float *));
|
||||
features[0] = (float *)malloc(npoints * nfeatures * sizeof(float));
|
||||
for (i = 1; i < npoints; i++) {
|
||||
features[i] = features[i - 1] + nfeatures;
|
||||
}
|
||||
fread(buf, 1, npoints * nfeatures * sizeof(float), infile);
|
||||
fclose(infile);
|
||||
} else {
|
||||
FILE *infile;
|
||||
if ((infile = fopen("100", "r")) == NULL) {
|
||||
fprintf(stderr, "Error: no such file (%s)\n", filename);
|
||||
exit(1);
|
||||
for (i = 0; i < npoints * nfeatures; ++i) {
|
||||
buf[i] = (i % 64);
|
||||
}
|
||||
while (fgets(line, 1024, infile) != NULL)
|
||||
if (strtok(line, " \t\n") != 0) {
|
||||
npoints++;
|
||||
}
|
||||
rewind(infile);
|
||||
while (fgets(line, 1024, infile) != NULL) {
|
||||
if (strtok(line, " \t\n") != 0) {
|
||||
// ignore the id (first attribute): nfeatures = 1;
|
||||
while (strtok(NULL, " ,\t\n") != NULL)
|
||||
nfeatures++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// allocate space for features[] and read attributes of all objects
|
||||
buf = (float *)malloc(npoints * nfeatures * sizeof(float));
|
||||
features = (float **)malloc(npoints * sizeof(float *));
|
||||
features[0] = (float *)malloc(npoints * nfeatures * sizeof(float));
|
||||
for (i = 1; i < npoints; i++)
|
||||
features[i] = features[i - 1] + nfeatures;
|
||||
rewind(infile);
|
||||
i = 0;
|
||||
while (fgets(line, 1024, infile) != NULL) {
|
||||
if (strtok(line, " \t\n") == NULL)
|
||||
continue;
|
||||
for (j = 0; j < nfeatures; j++) {
|
||||
buf[i] = atof(strtok(NULL, " ,\t\n"));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
fclose(infile);
|
||||
}*/
|
||||
|
||||
npoints = 100;
|
||||
nfeatures = 100;
|
||||
buf = (float *)malloc(npoints * nfeatures * sizeof(float));
|
||||
features = (float **)malloc(npoints * sizeof(float *));
|
||||
features[0] = (float *)malloc(npoints * nfeatures * sizeof(float));
|
||||
for (i = 1; i < npoints; i++) {
|
||||
features[i] = features[i - 1] + nfeatures;
|
||||
}
|
||||
for (i = 0; i < npoints * nfeatures; ++i) {
|
||||
buf[i] = (i % 64);
|
||||
}
|
||||
|
||||
// io_timing = omp_get_wtime() - io_timing;
|
||||
|
|
|
@ -7,6 +7,12 @@ SRC_DIR := $(VORTEX_HOME)/tests/opencl/$(PROJECT)
|
|||
|
||||
SRCS := $(SRC_DIR)/main.cc $(SRC_DIR)/clutils.cpp $(SRC_DIR)/utils.cpp
|
||||
|
||||
OPTS ?= $(SRC_DIR)/filelist.txt
|
||||
OPTS ?= filelist.log
|
||||
|
||||
filelist.log:
|
||||
echo "$(SRC_DIR)/cane4_0.db\n$(SRC_DIR)/cane4_1.db" > filelist.log
|
||||
|
||||
setup: filelist.log
|
||||
USE_SETUP := yes
|
||||
|
||||
include ../common.mk
|
||||
|
|
|
@ -98,7 +98,7 @@ endif
|
|||
$(CXX) $(CXXFLAGS) -MM $^ > .depend;
|
||||
|
||||
clean:
|
||||
rm -rf $(PROJECT) *.o .depend
|
||||
rm -rf $(PROJECT) *.o *.log .depend
|
||||
|
||||
clean-all: clean
|
||||
rm -rf *.elf *.bin *.dump
|
||||
|
|
|
@ -18,7 +18,7 @@ run:
|
|||
./$(PROJECT)
|
||||
|
||||
clean:
|
||||
rm -rf $(PROJECT) *.o .depend
|
||||
rm -rf $(PROJECT) *.o *.log .depend
|
||||
|
||||
clean-all: clean
|
||||
rm -rf *.elf *.bin *.dump
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue