matrix fixed
This commit is contained in:
34
perflab/matrix/Makefile
Normal file
34
perflab/matrix/Makefile
Normal file
@ -0,0 +1,34 @@
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -O1 -g
|
||||
#LDFLAGS = -lm -lcudart -lcuda
|
||||
|
||||
# Source files
|
||||
SRCS = rowcol_test.c clock.c cpe.c fcyc.c lsquare.c rowcol_202302723005.c
|
||||
#CUDA_SRCS = rowcol.cu
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
#rowcol.o
|
||||
|
||||
# Target executable
|
||||
TARGET = matrix_test
|
||||
|
||||
# Default target
|
||||
all: $(TARGET)
|
||||
|
||||
# Rule to build the executable
|
||||
$(TARGET): $(OBJS)
|
||||
$(CC) $(OBJS) -o $(TARGET) $(LDFLAGS)
|
||||
|
||||
# Rule to build object files
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
# Rule to build CUDA object files
|
||||
#rowcol.o: rowcol.cu
|
||||
# $(NVCC) $(CUDA_FLAGS) -c $< -o $@
|
||||
|
||||
# Clean rule
|
||||
clean:
|
||||
rm -f $(OBJS) $(TARGET)
|
||||
|
||||
# Phony targets
|
||||
.PHONY: all clean
|
||||
@ -1,229 +1,196 @@
|
||||
/* clock.c
|
||||
* Retrofitted to use thread-specific timers
|
||||
* and to get clock information from /proc/cpuinfo
|
||||
* (C) R. E. Bryant, 2010
|
||||
*
|
||||
*/
|
||||
|
||||
/* When this constant is not defined, uses time stamp counter */
|
||||
#define USE_POSIX 0
|
||||
|
||||
/* Choice to use cpu_gettime call or Intel time stamp counter directly */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <intrin.h>
|
||||
//#include <intrinsics.h>
|
||||
#include <windows.h>
|
||||
#include <time.h>
|
||||
#include "clock.h"
|
||||
|
||||
/* Use x86 cycle counter */
|
||||
|
||||
/* Initialize the cycle counter */
|
||||
static unsigned cyc_hi = 0;
|
||||
static unsigned cyc_lo = 0;
|
||||
|
||||
/* Set *hi and *lo to the high and low order bits of the cycle counter.
|
||||
Implementation requires assembly code to use the rdtsc instruction. */
|
||||
void access_counter(unsigned *hi, unsigned *lo)
|
||||
{
|
||||
|
||||
long long counter;
|
||||
|
||||
counter = __rdtsc();
|
||||
(*hi) = (unsigned int)(counter >> 32);
|
||||
(*lo) = (unsigned int)counter;
|
||||
/*
|
||||
|
||||
LARGE_INTEGER lPerformanceCount;
|
||||
|
||||
QueryPerformanceCounter(&lPerformanceCount);
|
||||
(*hi) = (unsigned int)lPerformanceCount.HighPart;
|
||||
(*lo) = (unsigned int)lPerformanceCount.LowPart;
|
||||
// printf("%08X %08X\n",(*hi),(*lo));
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/* Record the current value of the cycle counter. */
|
||||
void start_counter()
|
||||
{
|
||||
access_counter(&cyc_hi, &cyc_lo);
|
||||
}
|
||||
|
||||
/* Return the number of cycles since the last call to start_counter. */
|
||||
double get_counter()
|
||||
{
|
||||
unsigned ncyc_hi, ncyc_lo;
|
||||
unsigned hi, lo, borrow;
|
||||
double result;
|
||||
|
||||
/* Get cycle counter */
|
||||
access_counter(&ncyc_hi, &ncyc_lo);
|
||||
|
||||
/* Do double precision subtraction */
|
||||
lo = ncyc_lo - cyc_lo;
|
||||
borrow = cyc_lo > ncyc_lo;
|
||||
hi = ncyc_hi - cyc_hi - borrow;
|
||||
result = (double) hi * (1 << 30) * 4 + lo;
|
||||
return result;
|
||||
}
|
||||
void make_CPU_busy(void)
|
||||
{
|
||||
volatile double old_tick,new_tick;
|
||||
start_counter();
|
||||
old_tick = get_counter();
|
||||
new_tick = get_counter();
|
||||
while (new_tick - old_tick < 1000000000)
|
||||
new_tick = get_counter();
|
||||
}
|
||||
|
||||
//CPU<50><55>Ƶ<EFBFBD><C6B5>
|
||||
double mhz(int verbose)
|
||||
{
|
||||
LARGE_INTEGER lFrequency;
|
||||
LARGE_INTEGER lPerformanceCount_Start;
|
||||
LARGE_INTEGER lPerformanceCount_End;
|
||||
double mhz;
|
||||
double fTime;
|
||||
__int64 _i64StartCpuCounter;
|
||||
__int64 _i64EndCpuCounter;
|
||||
//On a multiprocessor machine, it should not matter which processor is called.
|
||||
//However, you can get different results on different processors due to bugs in
|
||||
//the BIOS or the HAL. To specify processor affinity for a thread, use the SetThreadAffinityMask function.
|
||||
HANDLE hThread=GetCurrentThread();
|
||||
SetThreadAffinityMask(hThread,0x1);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ϸ߾<CFB8><DFBE>ȶ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ľ<EFBFBD><C4BE><EFBFBD>Ƶ<EFBFBD><C6B5>
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ӧ<EFBFBD>þ<EFBFBD><C3BE><EFBFBD>һƬ8253<35><33><EFBFBD><EFBFBD>8254
|
||||
//<2F><>intel ich7<68>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD>8254
|
||||
QueryPerformanceFrequency(&lFrequency);
|
||||
// if (verbose>0)
|
||||
// printf("<22>߾<EFBFBD><DFBE>ȶ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ľ<EFBFBD><C4BE><EFBFBD>Ƶ<EFBFBD>ʣ<EFBFBD>%1.0fHz.\n",(double)lFrequency.QuadPart);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+1
|
||||
QueryPerformanceCounter(&lPerformanceCount_Start);
|
||||
|
||||
//RDTSCָ<43><D6B8>:<3A><>ȡCPU<50><55><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
_i64StartCpuCounter=__rdtsc();
|
||||
|
||||
//<2F><>ʱ<EFBFBD><CAB1>һ<EFBFBD><D2BB>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сһ<D0A1><D2BB>
|
||||
//int nTemp=100000;
|
||||
//while (--nTemp);
|
||||
Sleep(200);
|
||||
|
||||
QueryPerformanceCounter(&lPerformanceCount_End);
|
||||
|
||||
_i64EndCpuCounter=__rdtsc();
|
||||
|
||||
//f=1/T => f=<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*T)
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ġ<EFBFBD><C4A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*T<><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||||
fTime=((double)lPerformanceCount_End.QuadPart-(double)lPerformanceCount_Start.QuadPart)
|
||||
/(double)lFrequency.QuadPart;
|
||||
|
||||
mhz = (_i64EndCpuCounter-_i64StartCpuCounter)/(fTime*1000000.0);
|
||||
if (verbose>0)
|
||||
printf("CPUƵ<EFBFBD><EFBFBD>Ϊ:%1.6fMHz.\n",mhz);
|
||||
return mhz;
|
||||
}
|
||||
|
||||
double CPU_Factor1(void)
|
||||
{
|
||||
double result;
|
||||
int i,j,k,ii,jj,kk;
|
||||
LARGE_INTEGER lStart,lEnd;
|
||||
LARGE_INTEGER lFrequency;
|
||||
HANDLE hThread;
|
||||
double fTime;
|
||||
|
||||
QueryPerformanceFrequency(&lFrequency);
|
||||
|
||||
ii = 43273;
|
||||
kk = 1238;
|
||||
result = 1;
|
||||
jj = 1244;
|
||||
|
||||
hThread=GetCurrentThread();
|
||||
SetThreadAffinityMask(hThread,0x1);
|
||||
QueryPerformanceCounter(&lStart);
|
||||
//_asm("cpuid");
|
||||
start_counter();
|
||||
for (i=0;i<100;i++)
|
||||
for (j=0;j<1000;j++)
|
||||
for (k=0;k<1000;k++)
|
||||
kk += kk*ii+jj;
|
||||
|
||||
result = get_counter();
|
||||
QueryPerformanceCounter(&lEnd);
|
||||
fTime=((double)lEnd.QuadPart-(double)lStart.QuadPart);
|
||||
printf("CPU<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>Ϊ%f",result);
|
||||
printf("\t %f\n",fTime);
|
||||
return result;
|
||||
}
|
||||
|
||||
double CPU_Factor(void)
|
||||
{
|
||||
double frequency;
|
||||
double multiplier = 1000 * 1000 * 1000;//nano
|
||||
LARGE_INTEGER lFrequency;
|
||||
LARGE_INTEGER start,stop;
|
||||
HANDLE hThread;
|
||||
int i;
|
||||
const int gigahertz= 1000*1000*1000;
|
||||
const int known_instructions_per_loop = 27317;
|
||||
|
||||
int iterations = 100000000;
|
||||
int g = 0;
|
||||
double normal_ticks_per_second;
|
||||
double ticks;
|
||||
double time;
|
||||
double loops_per_sec;
|
||||
double instructions_per_loop;
|
||||
double ratio;
|
||||
double actual_freq;
|
||||
|
||||
QueryPerformanceFrequency(&lFrequency);
|
||||
frequency = (double)lFrequency.QuadPart;
|
||||
|
||||
hThread=GetCurrentThread();
|
||||
SetThreadAffinityMask(hThread,0x1);
|
||||
QueryPerformanceCounter(&start);
|
||||
for( i = 0; i < iterations; i++)
|
||||
{
|
||||
g++;
|
||||
g++;
|
||||
g++;
|
||||
g++;
|
||||
}
|
||||
QueryPerformanceCounter(&stop);
|
||||
|
||||
//normal ticks differs from the WMI data, i.e 3125, when WMI 3201, and CPUZ 3199
|
||||
normal_ticks_per_second = frequency * 1000;
|
||||
ticks = (double)((double)stop.QuadPart - (double)start.QuadPart);
|
||||
time = (ticks * multiplier) /frequency;
|
||||
loops_per_sec = iterations / (time/multiplier);
|
||||
instructions_per_loop = normal_ticks_per_second / loops_per_sec;
|
||||
|
||||
ratio = (instructions_per_loop / known_instructions_per_loop);
|
||||
actual_freq = normal_ticks_per_second / ratio;
|
||||
/*
|
||||
actual_freq = normal_ticks_per_second / ratio;
|
||||
actual_freq = known_instructions_per_loop*iterations*multiplier/time;
|
||||
|
||||
2293 = x/time;
|
||||
|
||||
2292.599713*1191533038.809362=known_instructions_per_loop*100000000*1000
|
||||
loops_per_sec = iterations*frequency / ticks
|
||||
|
||||
instructions_per_loop = / loops_per_sec;
|
||||
*/
|
||||
printf("Perf counter freq: %f\n", normal_ticks_per_second);
|
||||
printf("Loops per sec: %f\n", loops_per_sec);
|
||||
printf("Perf counter freq div loops per sec: %f\n", instructions_per_loop);
|
||||
printf("Presumed freq: %f\n", actual_freq);
|
||||
printf("ratio: %f\n", ratio);
|
||||
printf("time=%f\n",time);
|
||||
return ratio;
|
||||
}
|
||||
/* clock.c
|
||||
* Retrofitted to use thread-specific timers
|
||||
* and to get clock information from /proc/cpuinfo
|
||||
* (C) R. E. Bryant, 2010
|
||||
* Modified for cross-platform compatibility
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE // For sched_setaffinity on Linux
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <intrin.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sched.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <x86intrin.h>
|
||||
typedef struct {
|
||||
uint64_t QuadPart;
|
||||
} LARGE_INTEGER;
|
||||
typedef void *HANDLE;
|
||||
#define __int64 long long
|
||||
#define Sleep(ms) usleep((ms) * 1000)
|
||||
#endif
|
||||
|
||||
#include "clock.h"
|
||||
|
||||
/* Use x86 cycle counter */
|
||||
static unsigned cyc_hi = 0;
|
||||
static unsigned cyc_lo = 0;
|
||||
|
||||
void access_counter(unsigned *hi, unsigned *lo) {
|
||||
uint64_t counter = __rdtsc();
|
||||
*hi = (unsigned)(counter >> 32);
|
||||
*lo = (unsigned)counter;
|
||||
}
|
||||
|
||||
void start_counter() { access_counter(&cyc_hi, &cyc_lo); }
|
||||
|
||||
double get_counter() {
|
||||
unsigned ncyc_hi, ncyc_lo;
|
||||
access_counter(&ncyc_hi, &ncyc_lo);
|
||||
uint64_t start = ((uint64_t)cyc_hi << 32) | cyc_lo;
|
||||
uint64_t end = ((uint64_t)ncyc_hi << 32) | ncyc_lo;
|
||||
return (double)(end - start);
|
||||
}
|
||||
|
||||
void make_CPU_busy(void) {
|
||||
volatile double old_tick = get_counter();
|
||||
volatile double new_tick;
|
||||
while ((new_tick - old_tick) < 1000000000) {
|
||||
new_tick = get_counter();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#define GET_TIME(dest) QueryPerformanceCounter(dest)
|
||||
#else
|
||||
static inline void GET_TIME(LARGE_INTEGER *dest) {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
dest->QuadPart = (uint64_t)ts.tv_sec * 1000000000 + ts.tv_nsec;
|
||||
}
|
||||
#define QueryPerformanceFrequency(freq) ((freq)->QuadPart = 1000000000)
|
||||
#endif
|
||||
|
||||
double mhz(int verbose) {
|
||||
LARGE_INTEGER lFrequency;
|
||||
LARGE_INTEGER lPerformanceCount_Start;
|
||||
LARGE_INTEGER lPerformanceCount_End;
|
||||
double mhz;
|
||||
double fTime;
|
||||
__int64 _i64StartCpuCounter;
|
||||
__int64 _i64EndCpuCounter;
|
||||
|
||||
#ifdef _WIN32
|
||||
HANDLE hThread = GetCurrentThread();
|
||||
SetThreadAffinityMask(hThread, 0x1);
|
||||
#else
|
||||
cpu_set_t cpuset;
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(0, &cpuset);
|
||||
sched_setaffinity(0, sizeof(cpuset), &cpuset);
|
||||
#endif
|
||||
|
||||
QueryPerformanceFrequency(&lFrequency);
|
||||
GET_TIME(&lPerformanceCount_Start);
|
||||
_i64StartCpuCounter = __rdtsc();
|
||||
Sleep(200);
|
||||
GET_TIME(&lPerformanceCount_End);
|
||||
_i64EndCpuCounter = __rdtsc();
|
||||
|
||||
fTime = (lPerformanceCount_End.QuadPart - lPerformanceCount_Start.QuadPart) /
|
||||
(double)lFrequency.QuadPart;
|
||||
mhz = (_i64EndCpuCounter - _i64StartCpuCounter) / (fTime * 1000000.0);
|
||||
|
||||
if (verbose > 0) {
|
||||
printf("CPU频率为: %.6fMHz.\n", mhz);
|
||||
}
|
||||
return mhz;
|
||||
}
|
||||
|
||||
double CPU_Factor1(void) {
|
||||
double result;
|
||||
int i, j, k;
|
||||
LARGE_INTEGER lStart, lEnd;
|
||||
LARGE_INTEGER lFrequency;
|
||||
double fTime;
|
||||
|
||||
#ifdef _WIN32
|
||||
HANDLE hThread = GetCurrentThread();
|
||||
SetThreadAffinityMask(hThread, 0x1);
|
||||
#else
|
||||
cpu_set_t cpuset;
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(0, &cpuset);
|
||||
sched_setaffinity(0, sizeof(cpuset), &cpuset);
|
||||
#endif
|
||||
|
||||
QueryPerformanceFrequency(&lFrequency);
|
||||
GET_TIME(&lStart);
|
||||
start_counter();
|
||||
|
||||
for (i = 0; i < 100; i++)
|
||||
for (j = 0; j < 1000; j++)
|
||||
for (k = 0; k < 1000; k++)
|
||||
;
|
||||
|
||||
result = get_counter();
|
||||
GET_TIME(&lEnd);
|
||||
|
||||
fTime = (lEnd.QuadPart - lStart.QuadPart) / (double)lFrequency.QuadPart;
|
||||
printf("CPU计算时长为: %f", result);
|
||||
printf("\t %f\n", fTime);
|
||||
return result;
|
||||
}
|
||||
|
||||
double CPU_Factor(void) {
|
||||
double frequency;
|
||||
double multiplier = 1000 * 1000 * 1000; // nano
|
||||
LARGE_INTEGER lFrequency;
|
||||
LARGE_INTEGER start, stop;
|
||||
int i;
|
||||
const int known_instructions_per_loop = 27317;
|
||||
int iterations = 100000000;
|
||||
int g = 0;
|
||||
double normal_ticks_per_second;
|
||||
double ticks;
|
||||
double time;
|
||||
double loops_per_sec;
|
||||
double instructions_per_loop;
|
||||
double ratio;
|
||||
double actual_freq;
|
||||
|
||||
#ifdef _WIN32
|
||||
HANDLE hThread = GetCurrentThread();
|
||||
SetThreadAffinityMask(hThread, 0x1);
|
||||
#else
|
||||
cpu_set_t cpuset;
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(0, &cpuset);
|
||||
sched_setaffinity(0, sizeof(cpuset), &cpuset);
|
||||
#endif
|
||||
|
||||
QueryPerformanceFrequency(&lFrequency);
|
||||
frequency = (double)lFrequency.QuadPart;
|
||||
GET_TIME(&start);
|
||||
|
||||
for (i = 0; i < iterations; i++) {
|
||||
g++;
|
||||
g++;
|
||||
g++;
|
||||
g++;
|
||||
}
|
||||
|
||||
GET_TIME(&stop);
|
||||
normal_ticks_per_second = frequency * 1000;
|
||||
ticks = (double)(stop.QuadPart - start.QuadPart);
|
||||
time = (ticks * multiplier) / frequency;
|
||||
loops_per_sec = iterations / (time / multiplier);
|
||||
instructions_per_loop = normal_ticks_per_second / loops_per_sec;
|
||||
ratio = instructions_per_loop / known_instructions_per_loop;
|
||||
actual_freq = normal_ticks_per_second / ratio;
|
||||
|
||||
printf("Perf counter freq: %f\n", normal_ticks_per_second);
|
||||
printf("Loops per sec: %f\n", loops_per_sec);
|
||||
printf("Perf counter freq div loops per sec: %f\n", instructions_per_loop);
|
||||
printf("Presumed freq: %f\n", actual_freq);
|
||||
printf("ratio: %f\n", ratio);
|
||||
printf("time=%f\n", time);
|
||||
return ratio;
|
||||
}
|
||||
|
||||
229
perflab/matrix/clock.c.bak
Normal file
229
perflab/matrix/clock.c.bak
Normal file
@ -0,0 +1,229 @@
|
||||
/* clock.c
|
||||
* Retrofitted to use thread-specific timers
|
||||
* and to get clock information from /proc/cpuinfo
|
||||
* (C) R. E. Bryant, 2010
|
||||
*
|
||||
*/
|
||||
|
||||
/* When this constant is not defined, uses time stamp counter */
|
||||
#define USE_POSIX 0
|
||||
|
||||
/* Choice to use cpu_gettime call or Intel time stamp counter directly */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <x86intrin.h>
|
||||
//#include <intrinsics.h>
|
||||
//#include <windows.h>
|
||||
#include <time.h>
|
||||
#include "clock.h"
|
||||
|
||||
/* Use x86 cycle counter */
|
||||
|
||||
/* Initialize the cycle counter */
|
||||
static unsigned cyc_hi = 0;
|
||||
static unsigned cyc_lo = 0;
|
||||
|
||||
/* Set *hi and *lo to the high and low order bits of the cycle counter.
|
||||
Implementation requires assembly code to use the rdtsc instruction. */
|
||||
void access_counter(unsigned *hi, unsigned *lo)
|
||||
{
|
||||
|
||||
long long counter;
|
||||
|
||||
counter = __rdtsc();
|
||||
(*hi) = (unsigned int)(counter >> 32);
|
||||
(*lo) = (unsigned int)counter;
|
||||
/*
|
||||
|
||||
LARGE_INTEGER lPerformanceCount;
|
||||
|
||||
QueryPerformanceCounter(&lPerformanceCount);
|
||||
(*hi) = (unsigned int)lPerformanceCount.HighPart;
|
||||
(*lo) = (unsigned int)lPerformanceCount.LowPart;
|
||||
// printf("%08X %08X\n",(*hi),(*lo));
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/* Record the current value of the cycle counter. */
|
||||
void start_counter()
|
||||
{
|
||||
access_counter(&cyc_hi, &cyc_lo);
|
||||
}
|
||||
|
||||
/* Return the number of cycles since the last call to start_counter. */
|
||||
double get_counter()
|
||||
{
|
||||
unsigned ncyc_hi, ncyc_lo;
|
||||
unsigned hi, lo, borrow;
|
||||
double result;
|
||||
|
||||
/* Get cycle counter */
|
||||
access_counter(&ncyc_hi, &ncyc_lo);
|
||||
|
||||
/* Do double precision subtraction */
|
||||
lo = ncyc_lo - cyc_lo;
|
||||
borrow = cyc_lo > ncyc_lo;
|
||||
hi = ncyc_hi - cyc_hi - borrow;
|
||||
result = (double) hi * (1 << 30) * 4 + lo;
|
||||
return result;
|
||||
}
|
||||
void make_CPU_busy(void)
|
||||
{
|
||||
volatile double old_tick,new_tick;
|
||||
start_counter();
|
||||
old_tick = get_counter();
|
||||
new_tick = get_counter();
|
||||
while (new_tick - old_tick < 1000000000)
|
||||
new_tick = get_counter();
|
||||
}
|
||||
|
||||
//CPU<50><55>Ƶ<EFBFBD><C6B5>
|
||||
double mhz(int verbose)
|
||||
{
|
||||
LARGE_INTEGER lFrequency;
|
||||
LARGE_INTEGER lPerformanceCount_Start;
|
||||
LARGE_INTEGER lPerformanceCount_End;
|
||||
double mhz;
|
||||
double fTime;
|
||||
__int64 _i64StartCpuCounter;
|
||||
__int64 _i64EndCpuCounter;
|
||||
//On a multiprocessor machine, it should not matter which processor is called.
|
||||
//However, you can get different results on different processors due to bugs in
|
||||
//the BIOS or the HAL. To specify processor affinity for a thread, use the SetThreadAffinityMask function.
|
||||
HANDLE hThread=GetCurrentThread();
|
||||
SetThreadAffinityMask(hThread,0x1);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ϸ߾<CFB8><DFBE>ȶ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ľ<EFBFBD><C4BE><EFBFBD>Ƶ<EFBFBD><C6B5>
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ӧ<EFBFBD>þ<EFBFBD><C3BE><EFBFBD>һƬ8253<35><33><EFBFBD><EFBFBD>8254
|
||||
//<2F><>intel ich7<68>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD>8254
|
||||
QueryPerformanceFrequency(&lFrequency);
|
||||
// if (verbose>0)
|
||||
// printf("<22>߾<EFBFBD><DFBE>ȶ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ľ<EFBFBD><C4BE><EFBFBD>Ƶ<EFBFBD>ʣ<EFBFBD>%1.0fHz.\n",(double)lFrequency.QuadPart);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+1
|
||||
QueryPerformanceCounter(&lPerformanceCount_Start);
|
||||
|
||||
//RDTSCָ<43><D6B8>:<3A><>ȡCPU<50><55><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
_i64StartCpuCounter=__rdtsc();
|
||||
|
||||
//<2F><>ʱ<EFBFBD><CAB1>һ<EFBFBD><D2BB>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сһ<D0A1><D2BB>
|
||||
//int nTemp=100000;
|
||||
//while (--nTemp);
|
||||
Sleep(200);
|
||||
|
||||
QueryPerformanceCounter(&lPerformanceCount_End);
|
||||
|
||||
_i64EndCpuCounter=__rdtsc();
|
||||
|
||||
//f=1/T => f=<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*T)
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ġ<EFBFBD><C4A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*T<><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||||
fTime=((double)lPerformanceCount_End.QuadPart-(double)lPerformanceCount_Start.QuadPart)
|
||||
/(double)lFrequency.QuadPart;
|
||||
|
||||
mhz = (_i64EndCpuCounter-_i64StartCpuCounter)/(fTime*1000000.0);
|
||||
if (verbose>0)
|
||||
printf("CPUƵ<EFBFBD><EFBFBD>Ϊ:%1.6fMHz.\n",mhz);
|
||||
return mhz;
|
||||
}
|
||||
|
||||
double CPU_Factor1(void)
|
||||
{
|
||||
double result;
|
||||
int i,j,k,ii,jj,kk;
|
||||
LARGE_INTEGER lStart,lEnd;
|
||||
LARGE_INTEGER lFrequency;
|
||||
HANDLE hThread;
|
||||
double fTime;
|
||||
|
||||
QueryPerformanceFrequency(&lFrequency);
|
||||
|
||||
ii = 43273;
|
||||
kk = 1238;
|
||||
result = 1;
|
||||
jj = 1244;
|
||||
|
||||
hThread=GetCurrentThread();
|
||||
SetThreadAffinityMask(hThread,0x1);
|
||||
QueryPerformanceCounter(&lStart);
|
||||
//_asm("cpuid");
|
||||
start_counter();
|
||||
for (i=0;i<100;i++)
|
||||
for (j=0;j<1000;j++)
|
||||
for (k=0;k<1000;k++)
|
||||
kk += kk*ii+jj;
|
||||
|
||||
result = get_counter();
|
||||
QueryPerformanceCounter(&lEnd);
|
||||
fTime=((double)lEnd.QuadPart-(double)lStart.QuadPart);
|
||||
printf("CPU<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>Ϊ%f",result);
|
||||
printf("\t %f\n",fTime);
|
||||
return result;
|
||||
}
|
||||
|
||||
double CPU_Factor(void)
|
||||
{
|
||||
double frequency;
|
||||
double multiplier = 1000 * 1000 * 1000;//nano
|
||||
LARGE_INTEGER lFrequency;
|
||||
LARGE_INTEGER start,stop;
|
||||
HANDLE hThread;
|
||||
int i;
|
||||
const int gigahertz= 1000*1000*1000;
|
||||
const int known_instructions_per_loop = 27317;
|
||||
|
||||
int iterations = 100000000;
|
||||
int g = 0;
|
||||
double normal_ticks_per_second;
|
||||
double ticks;
|
||||
double time;
|
||||
double loops_per_sec;
|
||||
double instructions_per_loop;
|
||||
double ratio;
|
||||
double actual_freq;
|
||||
|
||||
QueryPerformanceFrequency(&lFrequency);
|
||||
frequency = (double)lFrequency.QuadPart;
|
||||
|
||||
hThread=GetCurrentThread();
|
||||
SetThreadAffinityMask(hThread,0x1);
|
||||
QueryPerformanceCounter(&start);
|
||||
for( i = 0; i < iterations; i++)
|
||||
{
|
||||
g++;
|
||||
g++;
|
||||
g++;
|
||||
g++;
|
||||
}
|
||||
QueryPerformanceCounter(&stop);
|
||||
|
||||
//normal ticks differs from the WMI data, i.e 3125, when WMI 3201, and CPUZ 3199
|
||||
normal_ticks_per_second = frequency * 1000;
|
||||
ticks = (double)((double)stop.QuadPart - (double)start.QuadPart);
|
||||
time = (ticks * multiplier) /frequency;
|
||||
loops_per_sec = iterations / (time/multiplier);
|
||||
instructions_per_loop = normal_ticks_per_second / loops_per_sec;
|
||||
|
||||
ratio = (instructions_per_loop / known_instructions_per_loop);
|
||||
actual_freq = normal_ticks_per_second / ratio;
|
||||
/*
|
||||
actual_freq = normal_ticks_per_second / ratio;
|
||||
actual_freq = known_instructions_per_loop*iterations*multiplier/time;
|
||||
|
||||
2293 = x/time;
|
||||
|
||||
2292.599713*1191533038.809362=known_instructions_per_loop*100000000*1000
|
||||
loops_per_sec = iterations*frequency / ticks
|
||||
|
||||
instructions_per_loop = / loops_per_sec;
|
||||
*/
|
||||
printf("Perf counter freq: %f\n", normal_ticks_per_second);
|
||||
printf("Loops per sec: %f\n", loops_per_sec);
|
||||
printf("Perf counter freq div loops per sec: %f\n", instructions_per_loop);
|
||||
printf("Presumed freq: %f\n", actual_freq);
|
||||
printf("ratio: %f\n", ratio);
|
||||
printf("time=%f\n",time);
|
||||
return ratio;
|
||||
}
|
||||
BIN
perflab/matrix/clock.o
Normal file
BIN
perflab/matrix/clock.o
Normal file
Binary file not shown.
BIN
perflab/matrix/cpe.o
Normal file
BIN
perflab/matrix/cpe.o
Normal file
Binary file not shown.
@ -119,7 +119,7 @@ double fcyc(test_funct f, int *params)
|
||||
if (clear_cache)
|
||||
clear();
|
||||
start_counter();
|
||||
f(params);
|
||||
f((long*)params);
|
||||
cyc = get_counter();
|
||||
if (cyc > 0.0)
|
||||
add_sample(cyc);
|
||||
@ -131,7 +131,7 @@ double fcyc(test_funct f, int *params)
|
||||
clear();
|
||||
start_counter();
|
||||
for (i=0;i<MAX_ITER_TIMES;i++)
|
||||
f(params);
|
||||
f((long*)params);
|
||||
cyc = get_counter()/MAX_ITER_TIMES;
|
||||
if (cyc > 0.0)
|
||||
add_sample(cyc);
|
||||
|
||||
BIN
perflab/matrix/fcyc.o
Normal file
BIN
perflab/matrix/fcyc.o
Normal file
Binary file not shown.
BIN
perflab/matrix/lsquare.o
Normal file
BIN
perflab/matrix/lsquare.o
Normal file
Binary file not shown.
BIN
perflab/matrix/matrix_test
Normal file
BIN
perflab/matrix/matrix_test
Normal file
Binary file not shown.
@ -1,77 +1,69 @@
|
||||
/**************************************************************************
|
||||
<09><>/<2F><><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>༭<EFBFBD><E0BCAD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
1. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>š<EFBFBD><C5A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD>͵ķ<CDB5>ʽд<CABD><D0B4><EFBFBD><EFBFBD><EFBFBD>棻
|
||||
2. ʵ<>ֲ<EFBFBD>ͬ<EFBFBD>汾<EFBFBD><E6B1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD><EFBFBD><EFBFBD>
|
||||
3. <EFBFBD>༭rc_fun_rec rc_fun_tab<EFBFBD><EFBFBD><EFBFBD>飬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õĴ<EFBFBD><EFBFBD><EFBFBD>
|
||||
<09><><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD><CDA1><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
||||
??/???????????????????????????????
|
||||
1. ???????????????????????????????
|
||||
2. ??????????????????????
|
||||
3. ??rc_fun_rec rc_fun_tab??????????????????
|
||||
???????????????????????????????????????????
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
ѧ<>ţ<EFBFBD>201209054233
|
||||
<09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҹ<EFBFBD><D2B9><EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD>
|
||||
????201209054233
|
||||
??????????????
|
||||
*/
|
||||
|
||||
#include "rowcol.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "rowcol.h"
|
||||
#include <math.h>
|
||||
|
||||
/* <20>ο<EFBFBD><CEBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD>ʵ<EFBFBD><CAB5> */
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ÿһ<C3BF>еĺ͡<C4BA><CDA1><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>
|
||||
һ<><D2BB><EFBFBD>ģ<EFBFBD>ֻ<EFBFBD>ǵ<EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
/* ????????????????? */
|
||||
/* ???????????????????????????????????????????????
|
||||
??????????2?????????????????
|
||||
*/
|
||||
|
||||
void c_sum(matrix_t M, vector_t rowsum, vector_t colsum)
|
||||
{
|
||||
int i,j;
|
||||
void c_sum(matrix_t M, vector_t rowsum, vector_t colsum) {
|
||||
int i, j;
|
||||
for (j = 0; j < N; j++) {
|
||||
colsum[j] = 0;
|
||||
for (i = 0; i < N; i++)
|
||||
colsum[j] += M[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
/* ???????????????????? */
|
||||
/* ??????????????????????? */
|
||||
|
||||
void rc_sum(matrix_t M, vector_t rowsum, vector_t colsum) {
|
||||
int i, j;
|
||||
for (i = 0; i < N; i++) {
|
||||
rowsum[i] = colsum[i] = 0;
|
||||
for (j = 0; j < N; j++) {
|
||||
colsum[j] = 0;
|
||||
for (i = 0; i < N; i++)
|
||||
colsum[j] += M[i][j];
|
||||
rowsum[i] += M[i][j];
|
||||
colsum[i] += M[j][i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* <20>ο<EFBFBD><CEBF><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD>ʵ<EFBFBD><CAB5> */
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ÿһ<C3BF>С<EFBFBD>ÿһ<C3BF>еĺ͡<C4BA> */
|
||||
|
||||
void rc_sum(matrix_t M, vector_t rowsum, vector_t colsum)
|
||||
{
|
||||
int i,j;
|
||||
for (i = 0; i < N; i++) {
|
||||
rowsum[i] = colsum[i] = 0;
|
||||
for (j = 0; j < N; j++) {
|
||||
rowsum[i] += M[i][j];
|
||||
colsum[i] += M[j][i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
<09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD>أ<EFBFBD>ÿһ<C3BF><D2BB>Ԫ<EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, COL/ROWCOL, "<22><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>"<22><>
|
||||
COL<4F><4C>ʾ<EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿһ<C3BF>еĺ<D0B5>
|
||||
ROWCOL<4F><4C>ʾ<EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿһ<C3BF>С<EFBFBD>ÿһ<C3BF>еĺ<D0B5>
|
||||
<09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>档
|
||||
<09><><EFBFBD>磺
|
||||
{my_c_sum1, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>"},
|
||||
{my_rc_sum2, "<22><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>"},
|
||||
/*
|
||||
????????????????????????????????????????, COL/ROWCOL, "?????????"??
|
||||
COL??????????????????????
|
||||
ROWCOL???????????????????????
|
||||
?????????????????????????????
|
||||
????
|
||||
{my_c_sum1, "?????????????????"},
|
||||
{my_rc_sum2, "??????????????????"},
|
||||
*/
|
||||
|
||||
rc_fun_rec rc_fun_tab[] =
|
||||
{
|
||||
rc_fun_rec rc_fun_tab[] = {
|
||||
|
||||
/* <EFBFBD><EFBFBD>һ<EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵ĺ<EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD> */
|
||||
/* ???????????????????????????????? */
|
||||
{c_sum, COL, "Best column sum"},
|
||||
/* <EFBFBD>ڶ<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵ĺ<EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD> */
|
||||
/* ?????????????????????????????????? */
|
||||
{rc_sum, ROWCOL, "Best row and column sum"},
|
||||
|
||||
{c_sum, COL, "Column sum, reference implementation"},
|
||||
|
||||
{rc_sum, ROWCOL, "Row and column sum, reference implementation"},
|
||||
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD>벻<EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
{NULL,ROWCOL,NULL}
|
||||
};
|
||||
/* ??????????????????????????????????????? */
|
||||
{NULL, ROWCOL, NULL}};
|
||||
162
perflab/matrix/rowcol.c~
Normal file
162
perflab/matrix/rowcol.c~
Normal file
@ -0,0 +1,162 @@
|
||||
/**************************************************************************
|
||||
<09><>/<2F><><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>༭<EFBFBD><E0BCAD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
1. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>š<EFBFBD><C5A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD>͵ķ<CDB5>ʽд<CABD><D0B4><EFBFBD><EFBFBD><EFBFBD>棻
|
||||
2. ʵ<>ֲ<EFBFBD>ͬ<EFBFBD>汾<EFBFBD><E6B1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD><EFBFBD><EFBFBD>
|
||||
3. <20>༭rc_fun_rec rc_fun_tab<61><62><EFBFBD>飬<EFBFBD><E9A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õĴ<C3B5><C4B4><EFBFBD>
|
||||
<09><><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD><CDA1><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
ѧ<>ţ<EFBFBD>202302723005
|
||||
<09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̾<EFBFBD><CCBE><EFBFBD>
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "rowcol.h"
|
||||
#include <math.h>
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
/* <20>ο<EFBFBD><CEBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD>ʵ<EFBFBD><CAB5> */
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ÿһ<C3BF>еĺ͡<C4BA><CDA1><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>
|
||||
һ<><D2BB><EFBFBD>ģ<EFBFBD>ֻ<EFBFBD>ǵ<EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
|
||||
void c_sum(matrix_t M, vector_t rowsum, vector_t colsum)
|
||||
{
|
||||
int i,j;
|
||||
for (j = 0; j < N; j++) {
|
||||
colsum[j] = 0;
|
||||
for (i = 0; i < N; i++)
|
||||
colsum[j] += M[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* <20>ο<EFBFBD><CEBF><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD>ʵ<EFBFBD><CAB5> */
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ÿһ<C3BF>С<EFBFBD>ÿһ<C3BF>еĺ͡<C4BA> */
|
||||
|
||||
void rc_sum(matrix_t M, vector_t rowsum, vector_t colsum)
|
||||
{
|
||||
int i,j;
|
||||
for (i = 0; i < N; i++) {
|
||||
rowsum[i] = colsum[i] = 0;
|
||||
for (j = 0; j < N; j++) {
|
||||
rowsum[i] += M[i][j];
|
||||
colsum[i] += M[j][i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* CUDA<44>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD> */
|
||||
void cuda_c_sum(matrix_t M, vector_t rowsum, vector_t colsum)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD>ڴ<EFBFBD>
|
||||
int *d_M, *d_colsum;
|
||||
cudaMalloc(&d_M, N * N * sizeof(int));
|
||||
cudaMalloc(&d_colsum, N * sizeof(int));
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>豸
|
||||
cudaMemcpy(d_M, M, N * N * sizeof(int), cudaMemcpyHostToDevice);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>CUDA<44>˺<EFBFBD><CBBA><EFBFBD>
|
||||
dim3 blockDim(256);
|
||||
dim3 gridDim((N + blockDim.x - 1) / blockDim.x);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD><CBBA><EFBFBD>
|
||||
cudaColumnSum<<<gridDim, blockDim>>>(d_M, d_colsum);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD>ƻ<EFBFBD><C6BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
cudaMemcpy(colsum, d_colsum, N * sizeof(int), cudaMemcpyDeviceToHost);
|
||||
|
||||
// <20>ͷ<EFBFBD><CDB7>豸<EFBFBD>ڴ<EFBFBD>
|
||||
cudaFree(d_M);
|
||||
cudaFree(d_colsum);
|
||||
}
|
||||
|
||||
/* CUDA<44>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD> */
|
||||
void cuda_rc_sum(matrix_t M, vector_t rowsum, vector_t colsum)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD>ڴ<EFBFBD>
|
||||
int *d_M, *d_rowsum, *d_colsum;
|
||||
cudaMalloc(&d_M, N * N * sizeof(int));
|
||||
cudaMalloc(&d_rowsum, N * sizeof(int));
|
||||
cudaMalloc(&d_colsum, N * sizeof(int));
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>豸
|
||||
cudaMemcpy(d_M, M, N * N * sizeof(int), cudaMemcpyHostToDevice);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>CUDA<44>˺<EFBFBD><CBBA><EFBFBD>
|
||||
dim3 blockDim(256);
|
||||
dim3 gridDim((N + blockDim.x - 1) / blockDim.x);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD><CBBA><EFBFBD>
|
||||
cudaRowColSum<<<gridDim, blockDim>>>(d_M, d_rowsum, d_colsum);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD>ƻ<EFBFBD><C6BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
cudaMemcpy(rowsum, d_rowsum, N * sizeof(int), cudaMemcpyDeviceToHost);
|
||||
cudaMemcpy(colsum, d_colsum, N * sizeof(int), cudaMemcpyDeviceToHost);
|
||||
|
||||
// <20>ͷ<EFBFBD><CDB7>豸<EFBFBD>ڴ<EFBFBD>
|
||||
cudaFree(d_M);
|
||||
cudaFree(d_rowsum);
|
||||
cudaFree(d_colsum);
|
||||
}
|
||||
|
||||
/* CUDA<44>˺<EFBFBD><CBBA><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
__global__ void cudaColumnSum(int *M, int *colsum)
|
||||
{
|
||||
int col = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
if (col < N) {
|
||||
colsum[col] = 0;
|
||||
for (int row = 0; row < N; row++) {
|
||||
colsum[col] += M[row * N + col];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* CUDA<44>˺<EFBFBD><CBBA><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
__global__ void cudaRowColSum(int *M, int *rowsum, int *colsum)
|
||||
{
|
||||
int idx = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
if (idx < N) {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>
|
||||
rowsum[idx] = 0;
|
||||
for (int j = 0; j < N; j++) {
|
||||
rowsum[idx] += M[idx * N + j];
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>
|
||||
colsum[idx] = 0;
|
||||
for (int i = 0; i < N; i++) {
|
||||
colsum[idx] += M[i * N + idx];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
<09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD>أ<EFBFBD>ÿһ<C3BF><D2BB>Ԫ<EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, COL/ROWCOL, "<22><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>"<22><>
|
||||
COL<4F><4C>ʾ<EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿһ<C3BF>еĺ<D0B5>
|
||||
ROWCOL<4F><4C>ʾ<EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿһ<C3BF>С<EFBFBD>ÿһ<C3BF>еĺ<D0B5>
|
||||
<09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>档
|
||||
<09><><EFBFBD>磺
|
||||
{my_c_sum1, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>"},
|
||||
{my_rc_sum2, "<22><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>"},
|
||||
*/
|
||||
|
||||
rc_fun_rec rc_fun_tab[] =
|
||||
{
|
||||
|
||||
/* <20><>һ<EFBFBD>Ӧ<EEA3AC><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵ĺ<CDB5><C4BA><EFBFBD>ʵ<EFBFBD><CAB5> */
|
||||
{cuda_c_sum, COL, "CUDA optimized column sum"},
|
||||
/* <20>ڶ<EFBFBD><DAB6>Ӧ<EEA3AC><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵ĺ<CDB5><C4BA><EFBFBD>ʵ<EFBFBD><CAB5> */
|
||||
{cuda_rc_sum, ROWCOL, "CUDA optimized row and column sum"},
|
||||
|
||||
{c_sum, COL, "Column sum, reference implementation"},
|
||||
|
||||
{rc_sum, ROWCOL, "Row and column sum, reference implementation"},
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4>벻<EFBFBD><EBB2BB><EFBFBD>Ļ<DEB8><C4BB><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD> */
|
||||
{NULL,ROWCOL,NULL}
|
||||
};
|
||||
BIN
perflab/matrix/rowcol.o
Normal file
BIN
perflab/matrix/rowcol.o
Normal file
Binary file not shown.
240
perflab/matrix/rowcol.y~
Normal file
240
perflab/matrix/rowcol.y~
Normal file
@ -0,0 +1,240 @@
|
||||
/**************************************************************************
|
||||
<20><>/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
1. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
2. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
3. <20><>rc_fun_rec rc_fun_tab<61><62><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
<20><><EFBFBD><EFBFBD>201209054233
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "rowcol.h"
|
||||
#include <math.h>
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F2BFBFBF>
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
|
||||
void c_sum(matrix_t M, vector_t rowsum, vector_t colsum)
|
||||
{
|
||||
int i,j;
|
||||
for (j = 0; j < N; j++) {
|
||||
colsum[j] = 0;
|
||||
for (i = 0; i < N; i++)
|
||||
colsum[j] += M[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
|
||||
void rc_sum(matrix_t M, vector_t rowsum, vector_t colsum)
|
||||
{
|
||||
int i,j;
|
||||
for (i = 0; i < N; i++) {
|
||||
rowsum[i] = colsum[i] = 0;
|
||||
for (j = 0; j < N; j++) {
|
||||
rowsum[i] += M[i][j];
|
||||
colsum[i] += M[j][i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, COL/ROWCOL, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"<22><>
|
||||
COL<4F><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
ROWCOL<4F><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD>
|
||||
{my_c_sum1, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"},
|
||||
{my_rc_sum2, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"},
|
||||
*/
|
||||
|
||||
rc_fun_rec rc_fun_tab[] =
|
||||
{
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
{c_sum, COL, "Best column sum"},
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
{rc_sum, ROWCOL, "Best row and column sum"},
|
||||
|
||||
{c_sum, COL, "Column sum, reference implementation"},
|
||||
|
||||
{rc_sum, ROWCOL, "Row and column sum, reference implementation"},
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
{NULL,ROWCOL,NULL}
|
||||
};
|
||||
|
||||
// /**************************************************************************
|
||||
// <09><>/<2F><><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>༭<EFBFBD><E0BCAD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
// 1. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>š<EFBFBD><C5A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD>͵ķ<CDB5>ʽд<CABD><D0B4><EFBFBD><EFBFBD><EFBFBD>棻
|
||||
// 2. ʵ<>ֲ<EFBFBD>ͬ<EFBFBD>汾<EFBFBD><E6B1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD><EFBFBD><EFBFBD>
|
||||
// 3. <20>༭rc_fun_rec rc_fun_tab<61><62><EFBFBD>飬<EFBFBD><E9A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õĴ<C3B5><C4B4><EFBFBD>
|
||||
// <09><><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD><CDA1><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
||||
// ***************************************************************************/
|
||||
//
|
||||
// /*
|
||||
// ѧ<>ţ<EFBFBD>202302723005
|
||||
// <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̾<EFBFBD><CCBE><EFBFBD>
|
||||
// */
|
||||
//
|
||||
//
|
||||
// #include <stdio.h>
|
||||
// #include <stdlib.h>
|
||||
// #include "rowcol.h"
|
||||
// #include <math.h>
|
||||
// #include <cuda_runtime.h>
|
||||
//
|
||||
// /* <20>ο<EFBFBD><CEBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD>ʵ<EFBFBD><CAB5> */
|
||||
// /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ÿһ<C3BF>еĺ͡<C4BA><CDA1><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>
|
||||
// һ<><D2BB><EFBFBD>ģ<EFBFBD>ֻ<EFBFBD>ǵ<EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
// */
|
||||
//
|
||||
// void c_sum(matrix_t M, vector_t rowsum, vector_t colsum)
|
||||
// {
|
||||
// int i,j;
|
||||
// for (j = 0; j < N; j++) {
|
||||
// colsum[j] = 0;
|
||||
// for (i = 0; i < N; i++)
|
||||
// colsum[j] += M[i][j];
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /* <20>ο<EFBFBD><CEBF><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD>ʵ<EFBFBD><CAB5> */
|
||||
// /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ÿһ<C3BF>С<EFBFBD>ÿһ<C3BF>еĺ͡<C4BA> */
|
||||
//
|
||||
// void rc_sum(matrix_t M, vector_t rowsum, vector_t colsum)
|
||||
// {
|
||||
// int i,j;
|
||||
// for (i = 0; i < N; i++) {
|
||||
// rowsum[i] = colsum[i] = 0;
|
||||
// for (j = 0; j < N; j++) {
|
||||
// rowsum[i] += M[i][j];
|
||||
// colsum[i] += M[j][i];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /* CUDA<44>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD> */
|
||||
// void cuda_c_sum(matrix_t M, vector_t rowsum, vector_t colsum)
|
||||
// {
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD>ڴ<EFBFBD>
|
||||
// int *d_M, *d_colsum;
|
||||
// cudaMalloc(&d_M, N * N * sizeof(int));
|
||||
// cudaMalloc(&d_colsum, N * sizeof(int));
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>豸
|
||||
// cudaMemcpy(d_M, M, N * N * sizeof(int), cudaMemcpyHostToDevice);
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD>CUDA<44>˺<EFBFBD><CBBA><EFBFBD>
|
||||
// dim3 blockDim(256);
|
||||
// dim3 gridDim((N + blockDim.x - 1) / blockDim.x);
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD><CBBA><EFBFBD>
|
||||
// cudaColumnSum<<<gridDim, blockDim>>>(d_M, d_colsum);
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD>ƻ<EFBFBD><C6BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
// cudaMemcpy(colsum, d_colsum, N * sizeof(int), cudaMemcpyDeviceToHost);
|
||||
//
|
||||
// // <20>ͷ<EFBFBD><CDB7>豸<EFBFBD>ڴ<EFBFBD>
|
||||
// cudaFree(d_M);
|
||||
// cudaFree(d_colsum);
|
||||
// }
|
||||
//
|
||||
// /* CUDA<44>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD> */
|
||||
// void cuda_rc_sum(matrix_t M, vector_t rowsum, vector_t colsum)
|
||||
// {
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD>ڴ<EFBFBD>
|
||||
// int *d_M, *d_rowsum, *d_colsum;
|
||||
// cudaMalloc(&d_M, N * N * sizeof(int));
|
||||
// cudaMalloc(&d_rowsum, N * sizeof(int));
|
||||
// cudaMalloc(&d_colsum, N * sizeof(int));
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>豸
|
||||
// cudaMemcpy(d_M, M, N * N * sizeof(int), cudaMemcpyHostToDevice);
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD>CUDA<44>˺<EFBFBD><CBBA><EFBFBD>
|
||||
// dim3 blockDim(256);
|
||||
// dim3 gridDim((N + blockDim.x - 1) / blockDim.x);
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD><CBBA><EFBFBD>
|
||||
// cudaRowColSum<<<gridDim, blockDim>>>(d_M, d_rowsum, d_colsum);
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD>ƻ<EFBFBD><C6BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
// cudaMemcpy(rowsum, d_rowsum, N * sizeof(int), cudaMemcpyDeviceToHost);
|
||||
// cudaMemcpy(colsum, d_colsum, N * sizeof(int), cudaMemcpyDeviceToHost);
|
||||
//
|
||||
// // <20>ͷ<EFBFBD><CDB7>豸<EFBFBD>ڴ<EFBFBD>
|
||||
// cudaFree(d_M);
|
||||
// cudaFree(d_rowsum);
|
||||
// cudaFree(d_colsum);
|
||||
// }
|
||||
//
|
||||
// /* CUDA<44>˺<EFBFBD><CBBA><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
// __global__ void cudaColumnSum(int *M, int *colsum)
|
||||
// {
|
||||
// int col = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
// if (col < N) {
|
||||
// colsum[col] = 0;
|
||||
// for (int row = 0; row < N; row++) {
|
||||
// colsum[col] += M[row * N + col];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /* CUDA<44>˺<EFBFBD><CBBA><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
// __global__ void cudaRowColSum(int *M, int *rowsum, int *colsum)
|
||||
// {
|
||||
// int idx = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
// if (idx < N) {
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>
|
||||
// rowsum[idx] = 0;
|
||||
// for (int j = 0; j < N; j++) {
|
||||
// rowsum[idx] += M[idx * N + j];
|
||||
// }
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>
|
||||
// colsum[idx] = 0;
|
||||
// for (int i = 0; i < N; i++) {
|
||||
// colsum[idx] += M[i * N + idx];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD>أ<EFBFBD>ÿһ<C3BF><D2BB>Ԫ<EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, COL/ROWCOL, "<22><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>"<22><>
|
||||
// COL<4F><4C>ʾ<EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿһ<C3BF>еĺ<D0B5>
|
||||
// ROWCOL<4F><4C>ʾ<EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿһ<C3BF>С<EFBFBD>ÿһ<C3BF>еĺ<D0B5>
|
||||
// <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>档
|
||||
// <09><><EFBFBD>磺
|
||||
// {my_c_sum1, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>"},
|
||||
// {my_rc_sum2, "<22><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>"},
|
||||
// */
|
||||
//
|
||||
// rc_fun_rec rc_fun_tab[] =
|
||||
// {
|
||||
//
|
||||
// /* <20><>һ<EFBFBD>Ӧ<EEA3AC><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵ĺ<CDB5><C4BA><EFBFBD>ʵ<EFBFBD><CAB5> */
|
||||
// {cuda_c_sum, COL, "CUDA optimized column sum"},
|
||||
// /* <20>ڶ<EFBFBD><DAB6>Ӧ<EEA3AC><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵ĺ<CDB5><C4BA><EFBFBD>ʵ<EFBFBD><CAB5> */
|
||||
// {cuda_rc_sum, ROWCOL, "CUDA optimized row and column sum"},
|
||||
//
|
||||
// {c_sum, COL, "Column sum, reference implementation"},
|
||||
//
|
||||
// {rc_sum, ROWCOL, "Row and column sum, reference implementation"},
|
||||
//
|
||||
// /* <20><><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4>벻<EFBFBD><EBB2BB><EFBFBD>Ļ<DEB8><C4BB><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD> */
|
||||
// {NULL,ROWCOL,NULL}
|
||||
// };
|
||||
240
perflab/matrix/rowcol.z~
Normal file
240
perflab/matrix/rowcol.z~
Normal file
@ -0,0 +1,240 @@
|
||||
/**************************************************************************
|
||||
<20><>/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
1. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
2. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
3. <20><>rc_fun_rec rc_fun_tab<61><62><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
<20><><EFBFBD><EFBFBD>201209054233
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "rowcol.h"
|
||||
#include <math.h>
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F2BFBFBF>
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
|
||||
void c_sum(matrix_t M, vector_t rowsum, vector_t colsum)
|
||||
{
|
||||
int i,j;
|
||||
for (j = 0; j < N; j++) {
|
||||
colsum[j] = 0;
|
||||
for (i = 0; i < N; i++)
|
||||
colsum[j] += M[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
|
||||
void rc_sum(matrix_t M, vector_t rowsum, vector_t colsum)
|
||||
{
|
||||
int i,j;
|
||||
for (i = 0; i < N; i++) {
|
||||
rowsum[i] = colsum[i] = 0;
|
||||
for (j = 0; j < N; j++) {
|
||||
rowsum[i] += M[i][j];
|
||||
colsum[i] += M[j][i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, COL/ROWCOL, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"<22><>
|
||||
COL<4F><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
ROWCOL<4F><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD>
|
||||
{my_c_sum1, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"},
|
||||
{my_rc_sum2, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"},
|
||||
*/
|
||||
|
||||
rc_fun_rec rc_fun_tab[] =
|
||||
{
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
{c_sum, COL, "Best column sum"},
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
{rc_sum, ROWCOL, "Best row and column sum"},
|
||||
|
||||
{c_sum, COL, "Column sum, reference implementation"},
|
||||
|
||||
{rc_sum, ROWCOL, "Row and column sum, reference implementation"},
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
{NULL,ROWCOL,NULL}
|
||||
};
|
||||
|
||||
// /**************************************************************************
|
||||
// <09><>/<2F><><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>༭<EFBFBD><E0BCAD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
// 1. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>š<EFBFBD><C5A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD>͵ķ<CDB5>ʽд<CABD><D0B4><EFBFBD><EFBFBD><EFBFBD>棻
|
||||
// 2. ʵ<>ֲ<EFBFBD>ͬ<EFBFBD>汾<EFBFBD><E6B1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD><EFBFBD><EFBFBD>
|
||||
// 3. <20>༭rc_fun_rec rc_fun_tab<61><62><EFBFBD>飬<EFBFBD><E9A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õĴ<C3B5><C4B4><EFBFBD>
|
||||
// <09><><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD><CDA1><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
||||
// ***************************************************************************/
|
||||
//
|
||||
// /*
|
||||
// ѧ<>ţ<EFBFBD>202302723005
|
||||
// <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̾<EFBFBD><CCBE><EFBFBD>
|
||||
// */
|
||||
//
|
||||
//
|
||||
// #include <stdio.h>
|
||||
// #include <stdlib.h>
|
||||
// #include "rowcol.h"
|
||||
// #include <math.h>
|
||||
// #include <cuda_runtime.h>
|
||||
//
|
||||
// /* <20>ο<EFBFBD><CEBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD>ʵ<EFBFBD><CAB5> */
|
||||
// /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ÿһ<C3BF>еĺ͡<C4BA><CDA1><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>
|
||||
// һ<><D2BB><EFBFBD>ģ<EFBFBD>ֻ<EFBFBD>ǵ<EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
// */
|
||||
//
|
||||
// void c_sum(matrix_t M, vector_t rowsum, vector_t colsum)
|
||||
// {
|
||||
// int i,j;
|
||||
// for (j = 0; j < N; j++) {
|
||||
// colsum[j] = 0;
|
||||
// for (i = 0; i < N; i++)
|
||||
// colsum[j] += M[i][j];
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /* <20>ο<EFBFBD><CEBF><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD>ʵ<EFBFBD><CAB5> */
|
||||
// /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ÿһ<C3BF>С<EFBFBD>ÿһ<C3BF>еĺ͡<C4BA> */
|
||||
//
|
||||
// void rc_sum(matrix_t M, vector_t rowsum, vector_t colsum)
|
||||
// {
|
||||
// int i,j;
|
||||
// for (i = 0; i < N; i++) {
|
||||
// rowsum[i] = colsum[i] = 0;
|
||||
// for (j = 0; j < N; j++) {
|
||||
// rowsum[i] += M[i][j];
|
||||
// colsum[i] += M[j][i];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /* CUDA<44>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD> */
|
||||
// void cuda_c_sum(matrix_t M, vector_t rowsum, vector_t colsum)
|
||||
// {
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD>ڴ<EFBFBD>
|
||||
// int *d_M, *d_colsum;
|
||||
// cudaMalloc(&d_M, N * N * sizeof(int));
|
||||
// cudaMalloc(&d_colsum, N * sizeof(int));
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>豸
|
||||
// cudaMemcpy(d_M, M, N * N * sizeof(int), cudaMemcpyHostToDevice);
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD>CUDA<44>˺<EFBFBD><CBBA><EFBFBD>
|
||||
// dim3 blockDim(256);
|
||||
// dim3 gridDim((N + blockDim.x - 1) / blockDim.x);
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD><CBBA><EFBFBD>
|
||||
// cudaColumnSum<<<gridDim, blockDim>>>(d_M, d_colsum);
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD>ƻ<EFBFBD><C6BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
// cudaMemcpy(colsum, d_colsum, N * sizeof(int), cudaMemcpyDeviceToHost);
|
||||
//
|
||||
// // <20>ͷ<EFBFBD><CDB7>豸<EFBFBD>ڴ<EFBFBD>
|
||||
// cudaFree(d_M);
|
||||
// cudaFree(d_colsum);
|
||||
// }
|
||||
//
|
||||
// /* CUDA<44>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD> */
|
||||
// void cuda_rc_sum(matrix_t M, vector_t rowsum, vector_t colsum)
|
||||
// {
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD>ڴ<EFBFBD>
|
||||
// int *d_M, *d_rowsum, *d_colsum;
|
||||
// cudaMalloc(&d_M, N * N * sizeof(int));
|
||||
// cudaMalloc(&d_rowsum, N * sizeof(int));
|
||||
// cudaMalloc(&d_colsum, N * sizeof(int));
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>豸
|
||||
// cudaMemcpy(d_M, M, N * N * sizeof(int), cudaMemcpyHostToDevice);
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD>CUDA<44>˺<EFBFBD><CBBA><EFBFBD>
|
||||
// dim3 blockDim(256);
|
||||
// dim3 gridDim((N + blockDim.x - 1) / blockDim.x);
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD><CBBA><EFBFBD>
|
||||
// cudaRowColSum<<<gridDim, blockDim>>>(d_M, d_rowsum, d_colsum);
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD>ƻ<EFBFBD><C6BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
// cudaMemcpy(rowsum, d_rowsum, N * sizeof(int), cudaMemcpyDeviceToHost);
|
||||
// cudaMemcpy(colsum, d_colsum, N * sizeof(int), cudaMemcpyDeviceToHost);
|
||||
//
|
||||
// // <20>ͷ<EFBFBD><CDB7>豸<EFBFBD>ڴ<EFBFBD>
|
||||
// cudaFree(d_M);
|
||||
// cudaFree(d_rowsum);
|
||||
// cudaFree(d_colsum);
|
||||
// }
|
||||
//
|
||||
// /* CUDA<44>˺<EFBFBD><CBBA><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
// __global__ void cudaColumnSum(int *M, int *colsum)
|
||||
// {
|
||||
// int col = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
// if (col < N) {
|
||||
// colsum[col] = 0;
|
||||
// for (int row = 0; row < N; row++) {
|
||||
// colsum[col] += M[row * N + col];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /* CUDA<44>˺<EFBFBD><CBBA><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
// __global__ void cudaRowColSum(int *M, int *rowsum, int *colsum)
|
||||
// {
|
||||
// int idx = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
// if (idx < N) {
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>
|
||||
// rowsum[idx] = 0;
|
||||
// for (int j = 0; j < N; j++) {
|
||||
// rowsum[idx] += M[idx * N + j];
|
||||
// }
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>
|
||||
// colsum[idx] = 0;
|
||||
// for (int i = 0; i < N; i++) {
|
||||
// colsum[idx] += M[i * N + idx];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD>أ<EFBFBD>ÿһ<C3BF><D2BB>Ԫ<EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, COL/ROWCOL, "<22><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>"<22><>
|
||||
// COL<4F><4C>ʾ<EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿһ<C3BF>еĺ<D0B5>
|
||||
// ROWCOL<4F><4C>ʾ<EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿһ<C3BF>С<EFBFBD>ÿһ<C3BF>еĺ<D0B5>
|
||||
// <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>档
|
||||
// <09><><EFBFBD>磺
|
||||
// {my_c_sum1, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>"},
|
||||
// {my_rc_sum2, "<22><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>"},
|
||||
// */
|
||||
//
|
||||
// rc_fun_rec rc_fun_tab[] =
|
||||
// {
|
||||
//
|
||||
// /* <20><>һ<EFBFBD>Ӧ<EEA3AC><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵ĺ<CDB5><C4BA><EFBFBD>ʵ<EFBFBD><CAB5> */
|
||||
// {cuda_c_sum, COL, "CUDA optimized column sum"},
|
||||
// /* <20>ڶ<EFBFBD><DAB6>Ӧ<EEA3AC><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵ĺ<CDB5><C4BA><EFBFBD>ʵ<EFBFBD><CAB5> */
|
||||
// {cuda_rc_sum, ROWCOL, "CUDA optimized row and column sum"},
|
||||
//
|
||||
// {c_sum, COL, "Column sum, reference implementation"},
|
||||
//
|
||||
// {rc_sum, ROWCOL, "Row and column sum, reference implementation"},
|
||||
//
|
||||
// /* <20><><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4>벻<EFBFBD><EBB2BB><EFBFBD>Ļ<DEB8><C4BB><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD> */
|
||||
// {NULL,ROWCOL,NULL}
|
||||
// };
|
||||
69
perflab/matrix/rowcol_202302723005.c
Normal file
69
perflab/matrix/rowcol_202302723005.c
Normal file
@ -0,0 +1,69 @@
|
||||
/**************************************************************************
|
||||
??/???????????????????????????????
|
||||
1. ???????????????????????????????
|
||||
2. ??????????????????????
|
||||
3. ??rc_fun_rec rc_fun_tab??????????????????
|
||||
???????????????????????????????????????????
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
????201209054233
|
||||
??????????????
|
||||
*/
|
||||
|
||||
#include "rowcol.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* ????????????????? */
|
||||
/* ???????????????????????????????????????????????
|
||||
??????????2?????????????????
|
||||
*/
|
||||
|
||||
void c_sum(matrix_t M, vector_t rowsum, vector_t colsum) {
|
||||
int i, j;
|
||||
for (j = 0; j < N; j++) {
|
||||
colsum[j] = 0;
|
||||
for (i = 0; i < N; i++)
|
||||
colsum[j] += M[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
/* ???????????????????? */
|
||||
/* ??????????????????????? */
|
||||
|
||||
void rc_sum(matrix_t M, vector_t rowsum, vector_t colsum) {
|
||||
int i, j;
|
||||
for (i = 0; i < N; i++) {
|
||||
rowsum[i] = colsum[i] = 0;
|
||||
for (j = 0; j < N; j++) {
|
||||
rowsum[i] += M[i][j];
|
||||
colsum[i] += M[j][i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
????????????????????????????????????????, COL/ROWCOL, "?????????"??
|
||||
COL??????????????????????
|
||||
ROWCOL???????????????????????
|
||||
?????????????????????????????
|
||||
????
|
||||
{my_c_sum1, "?????????????????"},
|
||||
{my_rc_sum2, "??????????????????"},
|
||||
*/
|
||||
|
||||
rc_fun_rec rc_fun_tab[] = {
|
||||
|
||||
/* ???????????????????????????????? */
|
||||
{c_sum, COL, "Best column sum"},
|
||||
/* ?????????????????????????????????? */
|
||||
{rc_sum, ROWCOL, "Best row and column sum"},
|
||||
|
||||
{c_sum, COL, "Column sum, reference implementation"},
|
||||
|
||||
{rc_sum, ROWCOL, "Row and column sum, reference implementation"},
|
||||
|
||||
/* ??????????????????????????????????????? */
|
||||
{NULL, ROWCOL, NULL}};
|
||||
BIN
perflab/matrix/rowcol_202302723005.o
Normal file
BIN
perflab/matrix/rowcol_202302723005.o
Normal file
Binary file not shown.
@ -1,9 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
//#include <random.h>
|
||||
#include "rowcol.h"
|
||||
#include "fcyc.h"
|
||||
// #include <random.h>
|
||||
#include "clock.h"
|
||||
#include "fcyc.h"
|
||||
#include "rowcol.h"
|
||||
|
||||
#define MAX_ITER_COUNT 100
|
||||
|
||||
@ -11,9 +11,9 @@
|
||||
static struct {
|
||||
double cref; /* Cycles taken by reference solution */
|
||||
double cbest; /* Cycles taken by our best implementation */
|
||||
} cstandard[2] =
|
||||
{{7.7, 6.40}, /* Column Sum */
|
||||
{9.75, 6.60} /* Row & Column Sum */
|
||||
} cstandard[2] = {
|
||||
{7.7, 6.40}, /* Column Sum */
|
||||
{9.75, 6.60} /* Row & Column Sum */
|
||||
};
|
||||
|
||||
/* Put in code to align matrix so that it starts on a cache block boundary.
|
||||
@ -26,7 +26,7 @@ static struct {
|
||||
#define WPB 16
|
||||
|
||||
int verbose = 1;
|
||||
int data[N*N+WPB];
|
||||
int data[N * N + WPB];
|
||||
int *mstart;
|
||||
|
||||
typedef vector_t *row_t;
|
||||
@ -37,137 +37,122 @@ vector_t rsref, csref, rcomp, ccomp;
|
||||
static void init_tests(void);
|
||||
extern void make_CPU_busy(void);
|
||||
|
||||
static void init_tests(void)
|
||||
{
|
||||
int i, j;
|
||||
size_t bytes_per_block = sizeof(int) * WPB;
|
||||
/* round mstart up to nearest block boundary */
|
||||
mstart = (int *)
|
||||
(((size_t) data + bytes_per_block-1) / bytes_per_block * bytes_per_block);
|
||||
for (i = 0; i < N; i++) {
|
||||
rsref[i] = csref[i] = 0;
|
||||
}
|
||||
for (i = 0; i < N; i++) {
|
||||
for (j = 0; j < N; j++) {
|
||||
int val = rand();
|
||||
mstart[i*N+j] = val;
|
||||
rsref[i] += val;
|
||||
csref[j] += val;
|
||||
}
|
||||
static void init_tests(void) {
|
||||
int i, j;
|
||||
size_t bytes_per_block = sizeof(int) * WPB;
|
||||
/* round mstart up to nearest block boundary */
|
||||
mstart = (int *)(((size_t)data + bytes_per_block - 1) / bytes_per_block *
|
||||
bytes_per_block);
|
||||
for (i = 0; i < N; i++) {
|
||||
rsref[i] = csref[i] = 0;
|
||||
}
|
||||
for (i = 0; i < N; i++) {
|
||||
for (j = 0; j < N; j++) {
|
||||
int val = rand();
|
||||
mstart[i * N + j] = val;
|
||||
rsref[i] += val;
|
||||
csref[j] += val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Test function on all values */
|
||||
int test_rc(rc_fun f, FILE *rpt, rc_comp_t rc_type) {
|
||||
int i;
|
||||
int ok = 1;
|
||||
int i;
|
||||
int ok = 1;
|
||||
|
||||
for (i = 0; i < N; i++)
|
||||
rcomp[i] = ccomp[i] = 0xDEADBEEF;
|
||||
f((row_t)mstart, rcomp, ccomp);
|
||||
|
||||
for (i = 0; ok && i < N; i++) {
|
||||
if (rc_type == ROWCOL
|
||||
&& rsref[i] != rcomp[i]) {
|
||||
ok = 0;
|
||||
if (rpt)
|
||||
fprintf(rpt,
|
||||
"<EFBFBD>Ե<EFBFBD>%d<>еļ<D0B5><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%d<><64><EFBFBD><EFBFBD><EFBFBD>Ǽ<EFBFBD><C7BC><EFBFBD><EFBFBD>õ<EFBFBD>%d\n",
|
||||
i, rsref[i], rcomp[i]);
|
||||
}
|
||||
if ((rc_type == ROWCOL || rc_type == COL)
|
||||
&& csref[i] != ccomp[i]) {
|
||||
ok = 0;
|
||||
if (rpt)
|
||||
fprintf(rpt,
|
||||
"<EFBFBD>Ե<EFBFBD>%d<>еļ<D0B5><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%d<><64><EFBFBD><EFBFBD><EFBFBD>Ǽ<EFBFBD><C7BC><EFBFBD><EFBFBD>õ<EFBFBD>%d\n",
|
||||
i, csref[i], ccomp[i]);
|
||||
}
|
||||
for (i = 0; i < N; i++)
|
||||
rcomp[i] = ccomp[i] = 0xDEADBEEF;
|
||||
f((row_t)mstart, rcomp, ccomp);
|
||||
|
||||
for (i = 0; ok && i < N; i++) {
|
||||
if (rc_type == ROWCOL && rsref[i] != rcomp[i]) {
|
||||
ok = 0;
|
||||
if (rpt)
|
||||
fprintf(rpt, "对第%d行的计算出错!正确结果是%d,但是计算得到%d\n", i,
|
||||
rsref[i], rcomp[i]);
|
||||
}
|
||||
return ok;
|
||||
if ((rc_type == ROWCOL || rc_type == COL) && csref[i] != ccomp[i]) {
|
||||
ok = 0;
|
||||
if (rpt)
|
||||
fprintf(rpt, "对第%d列的计算出错!正确结果是%d,但是计算得到%d\n", i,
|
||||
csref[i], ccomp[i]);
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* Kludgy way to interface to cycle measuring code */
|
||||
void do_test(int *intf)
|
||||
{
|
||||
rc_fun f = (rc_fun) intf;
|
||||
void do_test(int *intf) {
|
||||
rc_fun f = (rc_fun)intf;
|
||||
f((row_t)mstart, rcomp, ccomp);
|
||||
}
|
||||
|
||||
void time_rc(rc_fun f, rc_comp_t rc_type, char *descr, double *cycp)
|
||||
{
|
||||
int i;
|
||||
int *intf = (int *) f;
|
||||
void time_rc(rc_fun f, rc_comp_t rc_type, char *descr, double *cycp) {
|
||||
int i;
|
||||
int *intf = (int *)f;
|
||||
double t, cme;
|
||||
t = 0;
|
||||
if (verbose) printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%s\n", descr);
|
||||
if (verbose)
|
||||
printf("函数:%s\n", descr);
|
||||
if (test_rc(f, stdout, rc_type)) {
|
||||
make_CPU_busy();
|
||||
for (i=0;i<MAX_ITER_COUNT;i++)
|
||||
t += fcyc(do_test, intf);
|
||||
t = t/MAX_ITER_COUNT;
|
||||
cme = t/(N*N);
|
||||
if (verbose) printf(" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> = %.2f, ƽ<><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/Ԫ<><D4AA> = %.2f\n",
|
||||
t, cme);
|
||||
make_CPU_busy();
|
||||
for (i = 0; i < MAX_ITER_COUNT; i++)
|
||||
t += fcyc((void (*)(long *))do_test, intf);
|
||||
t = t / MAX_ITER_COUNT;
|
||||
cme = t / (N * N);
|
||||
if (verbose)
|
||||
printf(" 总周期数 = %.2f, 平均周期/元素 = %.2f\n", t, cme);
|
||||
if (cycp)
|
||||
*cycp = cme;
|
||||
}
|
||||
}
|
||||
|
||||
/* Compute the grade achieved by function */
|
||||
static double compute_score(double cmeas, double cref, double cbest)
|
||||
{
|
||||
double sbest = cref/cbest;
|
||||
double smeas = cref/cmeas;
|
||||
if (smeas < 0.1*(sbest-1)+1)
|
||||
static double compute_score(double cmeas, double cref, double cbest) {
|
||||
double sbest = cref / cbest;
|
||||
double smeas = cref / cmeas;
|
||||
if (smeas < 0.1 * (sbest - 1) + 1)
|
||||
return 0;
|
||||
if (smeas > 1.1*(sbest-1)+1)
|
||||
if (smeas > 1.1 * (sbest - 1) + 1)
|
||||
return 120;
|
||||
return 100*((smeas-1.0)/(sbest-1.0) + 0.1);
|
||||
return 100 * ((smeas - 1.0) / (sbest - 1.0) + 0.1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
int i;
|
||||
double cme;
|
||||
double cme_c,cme_rc;
|
||||
int EnableScore=0;
|
||||
|
||||
if (argc == 3)
|
||||
{
|
||||
EnableScore = 1;
|
||||
verbose = 0;
|
||||
double cme_c, cme_rc;
|
||||
int EnableScore = 0;
|
||||
|
||||
if (argc == 3) {
|
||||
EnableScore = 1;
|
||||
verbose = 0;
|
||||
}
|
||||
init_tests();
|
||||
set_fcyc_clear_cache(1); /* Set so that clears cache between runs */
|
||||
set_fcyc_clear_cache(1); /* Set so that clears cache between runs */
|
||||
for (i = 0; rc_fun_tab[i].f != NULL; i++) {
|
||||
cme = 100.0;
|
||||
time_rc(rc_fun_tab[i].f,
|
||||
rc_fun_tab[i].rc_type, rc_fun_tab[i].descr, &cme);
|
||||
if (i == 0)
|
||||
{
|
||||
cme_c = cme;
|
||||
if (EnableScore==0)
|
||||
{
|
||||
printf(" <20><><EFBFBD><EFBFBD>\"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\"<EFBFBD>÷<EFBFBD> ======================== %.0f\n",
|
||||
compute_score(cme, cstandard[0].cref, cstandard[0].cbest));
|
||||
}
|
||||
}
|
||||
if (i == 1)
|
||||
{
|
||||
cme_rc = cme;
|
||||
if (EnableScore==0)
|
||||
{
|
||||
printf(" <20><><EFBFBD><EFBFBD>\"<EFBFBD>к<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\"<EFBFBD>÷<EFBFBD> ====================== %.0f\n",
|
||||
compute_score(cme, cstandard[1].cref, cstandard[1].cbest));
|
||||
}
|
||||
}
|
||||
cme = 100.0;
|
||||
time_rc(rc_fun_tab[i].f, rc_fun_tab[i].rc_type, rc_fun_tab[i].descr, &cme);
|
||||
if (i == 0) {
|
||||
cme_c = cme;
|
||||
if (EnableScore == 0) {
|
||||
printf(" 最高\"列求和\"得分 ======================== %.0f\n",
|
||||
compute_score(cme, cstandard[0].cref, cstandard[0].cbest));
|
||||
}
|
||||
}
|
||||
if (i == 1) {
|
||||
cme_rc = cme;
|
||||
if (EnableScore == 0) {
|
||||
printf(" 最高\"行和列求和\"得分 ====================== %.0f\n",
|
||||
compute_score(cme, cstandard[1].cref, cstandard[1].cbest));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (EnableScore)
|
||||
printf("%.2f\t %.0f\t %.2f\t %.0f\t 0\t 0\n",cme_c,compute_score(cme_c, cstandard[0].cref, cstandard[0].cbest),
|
||||
cme_rc,compute_score(cme_rc, cstandard[1].cref, cstandard[1].cbest));
|
||||
printf("%.2f\t %.0f\t %.2f\t %.0f\t 0\t 0\n", cme_c,
|
||||
compute_score(cme_c, cstandard[0].cref, cstandard[0].cbest), cme_rc,
|
||||
compute_score(cme_rc, cstandard[1].cref, cstandard[1].cbest));
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
perflab/matrix/rowcol_test.o
Normal file
BIN
perflab/matrix/rowcol_test.o
Normal file
Binary file not shown.
35
perflab/poly/Makefile
Normal file
35
perflab/poly/Makefile
Normal file
@ -0,0 +1,35 @@
|
||||
CC = gcc
|
||||
NVCC = nvcc
|
||||
CFLAGS = -Wall -O2 -g
|
||||
CUDA_FLAGS = -O2 -g
|
||||
LDFLAGS = -lm -lcudart
|
||||
|
||||
# Source files
|
||||
SRCS = poly_test.c clock.c cpe.c fcyc.c lsquare.c
|
||||
CUDA_SRCS = poly.cu
|
||||
OBJS = $(SRCS:.c=.o) poly.o
|
||||
|
||||
# Target executable
|
||||
TARGET = poly_test
|
||||
|
||||
# Default target
|
||||
all: $(TARGET)
|
||||
|
||||
# Rule to build the executable
|
||||
$(TARGET): $(OBJS)
|
||||
$(CC) $(OBJS) -o $(TARGET) $(LDFLAGS)
|
||||
|
||||
# Rule to build object files
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
# Rule to build CUDA object files
|
||||
poly.o: poly.cu
|
||||
$(NVCC) $(CUDA_FLAGS) -c $< -o $@
|
||||
|
||||
# Clean rule
|
||||
clean:
|
||||
rm -f $(OBJS) $(TARGET)
|
||||
|
||||
# Phony targets
|
||||
.PHONY: all clean
|
||||
@ -13,11 +13,11 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <intrin.h>
|
||||
//#include <intrinsics.h>
|
||||
#include <windows.h>
|
||||
#include <time.h>
|
||||
#include <x86intrin.h>
|
||||
// #include <intrinsics.h>
|
||||
#include "clock.h"
|
||||
#include <time.h>
|
||||
#include <windows.h>
|
||||
|
||||
/* Use x86 cycle counter */
|
||||
|
||||
@ -27,203 +27,195 @@ static unsigned cyc_lo = 0;
|
||||
|
||||
/* Set *hi and *lo to the high and low order bits of the cycle counter.
|
||||
Implementation requires assembly code to use the rdtsc instruction. */
|
||||
void access_counter(unsigned *hi, unsigned *lo)
|
||||
{
|
||||
void access_counter(unsigned *hi, unsigned *lo) {
|
||||
|
||||
long long counter;
|
||||
long long counter;
|
||||
|
||||
counter = __rdtsc();
|
||||
(*hi) = (unsigned int)(counter >> 32);
|
||||
(*lo) = (unsigned int)counter;
|
||||
/*
|
||||
counter = __rdtsc();
|
||||
(*hi) = (unsigned int)(counter >> 32);
|
||||
(*lo) = (unsigned int)counter;
|
||||
/*
|
||||
|
||||
LARGE_INTEGER lPerformanceCount;
|
||||
LARGE_INTEGER lPerformanceCount;
|
||||
|
||||
QueryPerformanceCounter(&lPerformanceCount);
|
||||
(*hi) = (unsigned int)lPerformanceCount.HighPart;
|
||||
(*lo) = (unsigned int)lPerformanceCount.LowPart;
|
||||
// printf("%08X %08X\n",(*hi),(*lo));
|
||||
*/
|
||||
QueryPerformanceCounter(&lPerformanceCount);
|
||||
(*hi) = (unsigned int)lPerformanceCount.HighPart;
|
||||
(*lo) = (unsigned int)lPerformanceCount.LowPart;
|
||||
// printf("%08X %08X\n",(*hi),(*lo));
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/* Record the current value of the cycle counter. */
|
||||
void start_counter()
|
||||
{
|
||||
access_counter(&cyc_hi, &cyc_lo);
|
||||
}
|
||||
void start_counter() { access_counter(&cyc_hi, &cyc_lo); }
|
||||
|
||||
/* Return the number of cycles since the last call to start_counter. */
|
||||
double get_counter()
|
||||
{
|
||||
unsigned ncyc_hi, ncyc_lo;
|
||||
unsigned hi, lo, borrow;
|
||||
double result;
|
||||
double get_counter() {
|
||||
unsigned ncyc_hi, ncyc_lo;
|
||||
unsigned hi, lo, borrow;
|
||||
double result;
|
||||
|
||||
/* Get cycle counter */
|
||||
access_counter(&ncyc_hi, &ncyc_lo);
|
||||
/* Get cycle counter */
|
||||
access_counter(&ncyc_hi, &ncyc_lo);
|
||||
|
||||
/* Do double precision subtraction */
|
||||
lo = ncyc_lo - cyc_lo;
|
||||
borrow = cyc_lo > ncyc_lo;
|
||||
hi = ncyc_hi - cyc_hi - borrow;
|
||||
result = (double) hi * (1 << 30) * 4 + lo;
|
||||
return result;
|
||||
/* Do double precision subtraction */
|
||||
lo = ncyc_lo - cyc_lo;
|
||||
borrow = cyc_lo > ncyc_lo;
|
||||
hi = ncyc_hi - cyc_hi - borrow;
|
||||
result = (double)hi * (1 << 30) * 4 + lo;
|
||||
return result;
|
||||
}
|
||||
void make_CPU_busy(void)
|
||||
{
|
||||
volatile double old_tick,new_tick;
|
||||
start_counter();
|
||||
old_tick = get_counter();
|
||||
new_tick = get_counter();
|
||||
while (new_tick - old_tick < 1000000000)
|
||||
new_tick = get_counter();
|
||||
void make_CPU_busy(void) {
|
||||
volatile double old_tick, new_tick;
|
||||
start_counter();
|
||||
old_tick = get_counter();
|
||||
new_tick = get_counter();
|
||||
while (new_tick - old_tick < 1000000000)
|
||||
new_tick = get_counter();
|
||||
}
|
||||
|
||||
//CPU<50><55>Ƶ<EFBFBD><C6B5>
|
||||
double mhz(int verbose)
|
||||
{
|
||||
LARGE_INTEGER lFrequency;
|
||||
LARGE_INTEGER lPerformanceCount_Start;
|
||||
LARGE_INTEGER lPerformanceCount_End;
|
||||
double mhz;
|
||||
double fTime;
|
||||
__int64 _i64StartCpuCounter;
|
||||
__int64 _i64EndCpuCounter;
|
||||
//On a multiprocessor machine, it should not matter which processor is called.
|
||||
//However, you can get different results on different processors due to bugs in
|
||||
//the BIOS or the HAL. To specify processor affinity for a thread, use the SetThreadAffinityMask function.
|
||||
HANDLE hThread=GetCurrentThread();
|
||||
SetThreadAffinityMask(hThread,0x1);
|
||||
// CPU<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>
|
||||
double mhz(int verbose) {
|
||||
LARGE_INTEGER lFrequency;
|
||||
LARGE_INTEGER lPerformanceCount_Start;
|
||||
LARGE_INTEGER lPerformanceCount_End;
|
||||
double mhz;
|
||||
double fTime;
|
||||
__int64 _i64StartCpuCounter;
|
||||
__int64 _i64EndCpuCounter;
|
||||
// On a multiprocessor machine, it should not matter which processor is
|
||||
// called. However, you can get different results on different processors due
|
||||
// to bugs in the BIOS or the HAL. To specify processor affinity for a thread,
|
||||
// use the SetThreadAffinityMask function.
|
||||
HANDLE hThread = GetCurrentThread();
|
||||
SetThreadAffinityMask(hThread, 0x1);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ϸ߾<CFB8><DFBE>ȶ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ľ<EFBFBD><C4BE><EFBFBD>Ƶ<EFBFBD><C6B5>
|
||||
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>Ӧ<EFBFBD>þ<EFBFBD><EFBFBD><EFBFBD>һƬ8253<EFBFBD><EFBFBD><EFBFBD><EFBFBD>8254
|
||||
//<2F><>intel ich7<68>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD>8254
|
||||
QueryPerformanceFrequency(&lFrequency);
|
||||
// if (verbose>0)
|
||||
// printf("<22>߾<EFBFBD><DFBE>ȶ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ľ<EFBFBD><C4BE><EFBFBD>Ƶ<EFBFBD>ʣ<EFBFBD>%1.0fHz.\n",(double)lFrequency.QuadPart);
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ߾<EFBFBD><EFBFBD>ȶ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>Ӧ<EFBFBD>þ<EFBFBD><EFBFBD><EFBFBD>һƄ1<EFBFBD>78253<EFBFBD><EFBFBD><EFBFBD><EFBFBD>8254
|
||||
// <EFBFBD><EFBFBD>intel ich7<68>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD>8254
|
||||
QueryPerformanceFrequency(&lFrequency);
|
||||
// if (verbose>0)
|
||||
// printf("<22>߾<EFBFBD><DFBE>ȶ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ľ<EFBFBD><C4BE><EFBFBD>Ƶ<EFBFBD>ʣ<EFBFBD>%1.0fHz.\n",(double)lFrequency.QuadPart);
|
||||
|
||||
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+1
|
||||
QueryPerformanceCounter(&lPerformanceCount_Start);
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+1
|
||||
QueryPerformanceCounter(&lPerformanceCount_Start);
|
||||
|
||||
//RDTSCָ<43><D6B8>:<3A><>ȡCPU<50><55><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
_i64StartCpuCounter=__rdtsc();
|
||||
// RDTSCָ<EFBFBD><EFBFBD>:<3A><>ȡCPU<50><55><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
_i64StartCpuCounter = __rdtsc();
|
||||
|
||||
//<2F><>ʱ<EFBFBD><CAB1>һ<EFBFBD><D2BB>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сһ<EFBFBD><EFBFBD>
|
||||
//int nTemp=100000;
|
||||
//while (--nTemp);
|
||||
Sleep(200);
|
||||
// <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>Сһ<D0A1><D2BB>
|
||||
// int nTemp=100000;
|
||||
// while (--nTemp);
|
||||
Sleep(200);
|
||||
|
||||
QueryPerformanceCounter(&lPerformanceCount_End);
|
||||
QueryPerformanceCounter(&lPerformanceCount_End);
|
||||
|
||||
_i64EndCpuCounter=__rdtsc();
|
||||
_i64EndCpuCounter = __rdtsc();
|
||||
|
||||
//f=1/T => f=<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*T)
|
||||
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ġ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*T<><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||||
fTime=((double)lPerformanceCount_End.QuadPart-(double)lPerformanceCount_Start.QuadPart)
|
||||
/(double)lFrequency.QuadPart;
|
||||
// f=1/T => f=<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*T)
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ġ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ᅣ1<EFBFBD>7*T<><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ᅣ1<EFBFBD>7
|
||||
fTime = ((double)lPerformanceCount_End.QuadPart -
|
||||
(double)lPerformanceCount_Start.QuadPart) /
|
||||
(double)lFrequency.QuadPart;
|
||||
|
||||
mhz = (_i64EndCpuCounter-_i64StartCpuCounter)/(fTime*1000000.0);
|
||||
if (verbose>0)
|
||||
printf("CPUƵ<EFBFBD><EFBFBD>Ϊ:%1.6fMHz.\n",mhz);
|
||||
return mhz;
|
||||
mhz = (_i64EndCpuCounter - _i64StartCpuCounter) / (fTime * 1000000.0);
|
||||
if (verbose > 0)
|
||||
printf("CPUƵ<EFBFBD><EFBFBD>Ϊ:%1.6fMHz.\n", mhz);
|
||||
return mhz;
|
||||
}
|
||||
|
||||
double CPU_Factor1(void)
|
||||
{
|
||||
double result;
|
||||
int i,j,k,ii,jj,kk;
|
||||
LARGE_INTEGER lStart,lEnd;
|
||||
double CPU_Factor1(void) {
|
||||
double result;
|
||||
int i, j, k, ii, jj, kk;
|
||||
LARGE_INTEGER lStart, lEnd;
|
||||
LARGE_INTEGER lFrequency;
|
||||
HANDLE hThread;
|
||||
double fTime;
|
||||
|
||||
QueryPerformanceFrequency(&lFrequency);
|
||||
|
||||
ii = 43273;
|
||||
kk = 1238;
|
||||
result = 1;
|
||||
jj = 1244;
|
||||
ii = 43273;
|
||||
kk = 1238;
|
||||
result = 1;
|
||||
jj = 1244;
|
||||
|
||||
hThread=GetCurrentThread();
|
||||
SetThreadAffinityMask(hThread,0x1);
|
||||
hThread = GetCurrentThread();
|
||||
SetThreadAffinityMask(hThread, 0x1);
|
||||
QueryPerformanceCounter(&lStart);
|
||||
//_asm("cpuid");
|
||||
start_counter();
|
||||
for (i=0;i<100;i++)
|
||||
for (j=0;j<1000;j++)
|
||||
for (k=0;k<1000;k++)
|
||||
kk += kk*ii+jj;
|
||||
start_counter();
|
||||
for (i = 0; i < 100; i++)
|
||||
for (j = 0; j < 1000; j++)
|
||||
for (k = 0; k < 1000; k++)
|
||||
kk += kk * ii + jj;
|
||||
|
||||
result = get_counter();
|
||||
QueryPerformanceCounter(&lEnd);
|
||||
fTime=((double)lEnd.QuadPart-(double)lStart.QuadPart);
|
||||
printf("CPU<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>Ϊ%f",result);
|
||||
printf("\t %f\n",fTime);
|
||||
return result;
|
||||
result = get_counter();
|
||||
QueryPerformanceCounter(&lEnd);
|
||||
fTime = ((double)lEnd.QuadPart - (double)lStart.QuadPart);
|
||||
printf("CPU<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>Ϊ%f", result);
|
||||
printf("\t %f\n", fTime);
|
||||
return result;
|
||||
}
|
||||
|
||||
double CPU_Factor(void)
|
||||
{
|
||||
double frequency;
|
||||
double multiplier = 1000 * 1000 * 1000;//nano
|
||||
LARGE_INTEGER lFrequency;
|
||||
LARGE_INTEGER start,stop;
|
||||
HANDLE hThread;
|
||||
int i;
|
||||
const int gigahertz= 1000*1000*1000;
|
||||
const int known_instructions_per_loop = 27317;
|
||||
double CPU_Factor(void) {
|
||||
double frequency;
|
||||
double multiplier = 1000 * 1000 * 1000; // nano
|
||||
LARGE_INTEGER lFrequency;
|
||||
LARGE_INTEGER start, stop;
|
||||
HANDLE hThread;
|
||||
int i;
|
||||
const int gigahertz = 1000 * 1000 * 1000;
|
||||
const int known_instructions_per_loop = 27317;
|
||||
|
||||
int iterations = 100000000;
|
||||
int g = 0;
|
||||
double normal_ticks_per_second;
|
||||
double ticks;
|
||||
double time;
|
||||
double loops_per_sec;
|
||||
double instructions_per_loop;
|
||||
double ratio;
|
||||
double actual_freq;
|
||||
int iterations = 100000000;
|
||||
int g = 0;
|
||||
double normal_ticks_per_second;
|
||||
double ticks;
|
||||
double time;
|
||||
double loops_per_sec;
|
||||
double instructions_per_loop;
|
||||
double ratio;
|
||||
double actual_freq;
|
||||
|
||||
QueryPerformanceFrequency(&lFrequency);
|
||||
frequency = (double)lFrequency.QuadPart;
|
||||
QueryPerformanceFrequency(&lFrequency);
|
||||
frequency = (double)lFrequency.QuadPart;
|
||||
|
||||
hThread=GetCurrentThread();
|
||||
SetThreadAffinityMask(hThread,0x1);
|
||||
QueryPerformanceCounter(&start);
|
||||
for( i = 0; i < iterations; i++)
|
||||
{
|
||||
g++;
|
||||
g++;
|
||||
g++;
|
||||
g++;
|
||||
}
|
||||
QueryPerformanceCounter(&stop);
|
||||
hThread = GetCurrentThread();
|
||||
SetThreadAffinityMask(hThread, 0x1);
|
||||
QueryPerformanceCounter(&start);
|
||||
for (i = 0; i < iterations; i++) {
|
||||
g++;
|
||||
g++;
|
||||
g++;
|
||||
g++;
|
||||
}
|
||||
QueryPerformanceCounter(&stop);
|
||||
|
||||
//normal ticks differs from the WMI data, i.e 3125, when WMI 3201, and CPUZ 3199
|
||||
normal_ticks_per_second = frequency * 1000;
|
||||
ticks = (double)((double)stop.QuadPart - (double)start.QuadPart);
|
||||
time = (ticks * multiplier) /frequency;
|
||||
loops_per_sec = iterations / (time/multiplier);
|
||||
instructions_per_loop = normal_ticks_per_second / loops_per_sec;
|
||||
// normal ticks differs from the WMI data, i.e 3125, when WMI 3201, and CPUZ
|
||||
// 3199
|
||||
normal_ticks_per_second = frequency * 1000;
|
||||
ticks = (double)((double)stop.QuadPart - (double)start.QuadPart);
|
||||
time = (ticks * multiplier) / frequency;
|
||||
loops_per_sec = iterations / (time / multiplier);
|
||||
instructions_per_loop = normal_ticks_per_second / loops_per_sec;
|
||||
|
||||
ratio = (instructions_per_loop / known_instructions_per_loop);
|
||||
actual_freq = normal_ticks_per_second / ratio;
|
||||
/*
|
||||
actual_freq = normal_ticks_per_second / ratio;
|
||||
actual_freq = known_instructions_per_loop*iterations*multiplier/time;
|
||||
ratio = (instructions_per_loop / known_instructions_per_loop);
|
||||
actual_freq = normal_ticks_per_second / ratio;
|
||||
/*
|
||||
actual_freq = normal_ticks_per_second / ratio;
|
||||
actual_freq = known_instructions_per_loop*iterations*multiplier/time;
|
||||
|
||||
2293 = x/time;
|
||||
|
||||
2292.599713*1191533038.809362=known_instructions_per_loop*100000000*1000
|
||||
loops_per_sec = iterations*frequency / ticks
|
||||
|
||||
instructions_per_loop = / loops_per_sec;
|
||||
*/
|
||||
printf("Perf counter freq: %f\n", normal_ticks_per_second);
|
||||
printf("Loops per sec: %f\n", loops_per_sec);
|
||||
printf("Perf counter freq div loops per sec: %f\n", instructions_per_loop);
|
||||
printf("Presumed freq: %f\n", actual_freq);
|
||||
printf("ratio: %f\n", ratio);
|
||||
printf("time=%f\n",time);
|
||||
return ratio;
|
||||
2293 = x/time;
|
||||
|
||||
2292.599713*1191533038.809362=known_instructions_per_loop*100000000*1000
|
||||
loops_per_sec = iterations*frequency / ticks
|
||||
|
||||
instructions_per_loop = / loops_per_sec;
|
||||
*/
|
||||
printf("Perf counter freq: %f\n", normal_ticks_per_second);
|
||||
printf("Loops per sec: %f\n", loops_per_sec);
|
||||
printf("Perf counter freq div loops per sec: %f\n", instructions_per_loop);
|
||||
printf("Presumed freq: %f\n", actual_freq);
|
||||
printf("ratio: %f\n", ratio);
|
||||
printf("time=%f\n", time);
|
||||
return ratio;
|
||||
}
|
||||
|
||||
325
perflab/poly/poly.cu
Normal file
325
perflab/poly/poly.cu
Normal file
@ -0,0 +1,325 @@
|
||||
/**************************************************************************
|
||||
多项式计算函数。按下面的要求编辑此文件:
|
||||
1. 将你的学号、姓名,以注释的方式写到下面;
|
||||
2. 实现不同版本的多项式计算函数;
|
||||
3. 编辑peval_fun_rec peval_fun_tab数组,将你的最好的答案
|
||||
(最小CPE、最小C10)作为数组的前两项
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
学号:201209054233
|
||||
姓名:夜半加班狂
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <cuda_runtime.h>
|
||||
typedef int (*peval_fun)(int*, int, int);
|
||||
|
||||
typedef struct {
|
||||
peval_fun f;
|
||||
char *descr;
|
||||
} peval_fun_rec, *peval_fun_ptr;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
Edit this comment to indicate your name and Andrew ID
|
||||
#ifdef ASSIGN
|
||||
Submission by Harry Q. Bovik, bovik@andrew.cmu.edu
|
||||
#else
|
||||
Instructor's version.
|
||||
Created by Randal E. Bryant, Randy.Bryant@cs.cmu.edu, 10/07/02
|
||||
#endif
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
实现一个指定的常系数多项式计算
|
||||
第一次,请直接运行程序,以便获知你需要实现的常系数是啥
|
||||
*/
|
||||
int const_poly_eval(int *not_use, int not_use2, int x)
|
||||
{
|
||||
int result = 0;
|
||||
/* int i;
|
||||
int xpwr = 1; // x的幂次
|
||||
int a[4] = {21,90,42,88};
|
||||
for (i = 0; i <= 3; i++) {
|
||||
result += a[i]*xpwr;
|
||||
xpwr *= x;
|
||||
}
|
||||
*/
|
||||
// 90 = 64 + 32 - 4 - 2
|
||||
// 42 = 32 + 8 + 2
|
||||
// 88 = 64 + 16 + 8
|
||||
int x64,x32,x16,x8,x4,x2;
|
||||
|
||||
x64 = x << 6;
|
||||
x32 = x << 5;
|
||||
x16 = x << 4;
|
||||
x8 = x << 3;
|
||||
x4 = x << 2;
|
||||
x2 = x << 1;
|
||||
result = 21 + x64+x32-x4-x2 + ((x32+x8+x2) + (x64+x16+x8)*x)*x;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* 多项式计算函数。注意:这个只是一个参考实现,你需要实现自己的版本 */
|
||||
|
||||
/*
|
||||
友情提示:lcc支持ATT格式的嵌入式汇编,例如
|
||||
|
||||
_asm("movl %eax,%ebx");
|
||||
_asm("pushl %edx");
|
||||
|
||||
可以在lcc中project->configuration->Compiler->Code Generation->Generate .asm,
|
||||
将其选中后,可以在lcc目录下面生成对应程序的汇编代码实现。通过查看汇编文件,
|
||||
你可以了解编译器是如何实现你的代码的。有些实现可能非常低效。
|
||||
你可以在适当的地方加入嵌入式汇编,来大幅度提高计算性能。
|
||||
*/
|
||||
|
||||
int poly_eval(int *a, int degree, int x)
|
||||
{
|
||||
int result = 0;
|
||||
int i;
|
||||
int xpwr = 1; /* x的幂次 */
|
||||
// printf("阶=%d\n",degree);
|
||||
for (i = 0; i <= degree; i++) {
|
||||
result += a[i]*xpwr;
|
||||
xpwr *= x;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* CUDA优化的多项式计算函数 - 低CPE版本 */
|
||||
int cuda_poly_eval_low_cpe(int *a, int degree, int x)
|
||||
{
|
||||
// 对于低CPE版本,我们使用CUDA并行计算多项式的各个项
|
||||
// 然后将结果传回主机进行求和
|
||||
|
||||
// 分配设备内存
|
||||
int *d_a, *d_results;
|
||||
cudaError_t err;
|
||||
|
||||
// 分配内存
|
||||
err = cudaMalloc(&d_a, (degree + 1) * sizeof(int));
|
||||
if (err != cudaSuccess) {
|
||||
printf("CUDA Error: %s\n", cudaGetErrorString(err));
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = cudaMalloc(&d_results, (degree + 1) * sizeof(int));
|
||||
if (err != cudaSuccess) {
|
||||
printf("CUDA Error: %s\n", cudaGetErrorString(err));
|
||||
cudaFree(d_a);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 将系数从主机复制到设备
|
||||
err = cudaMemcpy(d_a, a, (degree + 1) * sizeof(int), cudaMemcpyHostToDevice);
|
||||
if (err != cudaSuccess) {
|
||||
printf("CUDA Error: %s\n", cudaGetErrorString(err));
|
||||
cudaFree(d_a);
|
||||
cudaFree(d_results);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 定义CUDA核函数
|
||||
dim3 blockDim(256);
|
||||
dim3 gridDim((degree + 1 + blockDim.x - 1) / blockDim.x);
|
||||
|
||||
// 启动核函数
|
||||
cudaPolyEvalLowCPE<<<gridDim, blockDim>>>(d_a, degree, x, d_results);
|
||||
|
||||
// 检查核函数执行错误
|
||||
err = cudaGetLastError();
|
||||
if (err != cudaSuccess) {
|
||||
printf("CUDA Error: %s\n", cudaGetErrorString(err));
|
||||
cudaFree(d_a);
|
||||
cudaFree(d_results);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 分配主机内存用于结果
|
||||
int *h_results = (int *)malloc((degree + 1) * sizeof(int));
|
||||
if (h_results == NULL) {
|
||||
printf("Memory allocation error\n");
|
||||
cudaFree(d_a);
|
||||
cudaFree(d_results);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 将结果从设备复制回主机
|
||||
err = cudaMemcpy(h_results, d_results, (degree + 1) * sizeof(int), cudaMemcpyDeviceToHost);
|
||||
if (err != cudaSuccess) {
|
||||
printf("CUDA Error: %s\n", cudaGetErrorString(err));
|
||||
free(h_results);
|
||||
cudaFree(d_a);
|
||||
cudaFree(d_results);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 在主机上求和
|
||||
int result = 0;
|
||||
for (int i = 0; i <= degree; i++) {
|
||||
result += h_results[i];
|
||||
}
|
||||
|
||||
// 释放内存
|
||||
free(h_results);
|
||||
cudaFree(d_a);
|
||||
cudaFree(d_results);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* CUDA优化的多项式计算函数 - 10阶优化版本 */
|
||||
int cuda_poly_eval_degree10(int *a, int degree, int x)
|
||||
{
|
||||
// 对于10阶多项式,我们可以使用更优化的方法
|
||||
// 使用CUDA并行计算,但针对10阶多项式进行特殊优化
|
||||
|
||||
// 分配设备内存
|
||||
int *d_a, *d_result;
|
||||
cudaError_t err;
|
||||
|
||||
// 分配内存
|
||||
err = cudaMalloc(&d_a, (degree + 1) * sizeof(int));
|
||||
if (err != cudaSuccess) {
|
||||
printf("CUDA Error: %s\n", cudaGetErrorString(err));
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = cudaMalloc(&d_result, sizeof(int));
|
||||
if (err != cudaSuccess) {
|
||||
printf("CUDA Error: %s\n", cudaGetErrorString(err));
|
||||
cudaFree(d_a);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 将系数从主机复制到设备
|
||||
err = cudaMemcpy(d_a, a, (degree + 1) * sizeof(int), cudaMemcpyHostToDevice);
|
||||
if (err != cudaSuccess) {
|
||||
printf("CUDA Error: %s\n", cudaGetErrorString(err));
|
||||
cudaFree(d_a);
|
||||
cudaFree(d_result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 定义CUDA核函数
|
||||
dim3 blockDim(256);
|
||||
dim3 gridDim(1); // 只需要一个块,因为我们只需要一个结果
|
||||
|
||||
// 启动核函数
|
||||
cudaPolyEvalDegree10<<<gridDim, blockDim>>>(d_a, degree, x, d_result);
|
||||
|
||||
// 检查核函数执行错误
|
||||
err = cudaGetLastError();
|
||||
if (err != cudaSuccess) {
|
||||
printf("CUDA Error: %s\n", cudaGetErrorString(err));
|
||||
cudaFree(d_a);
|
||||
cudaFree(d_result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 获取结果
|
||||
int result;
|
||||
err = cudaMemcpy(&result, d_result, sizeof(int), cudaMemcpyDeviceToHost);
|
||||
if (err != cudaSuccess) {
|
||||
printf("CUDA Error: %s\n", cudaGetErrorString(err));
|
||||
cudaFree(d_a);
|
||||
cudaFree(d_result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 释放内存
|
||||
cudaFree(d_a);
|
||||
cudaFree(d_result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* CUDA核函数 - 低CPE版本 */
|
||||
__global__ void cudaPolyEvalLowCPE(int *a, int degree, int x, int *results)
|
||||
{
|
||||
int idx = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
if (idx <= degree) {
|
||||
// 计算x的幂
|
||||
int xpwr = 1;
|
||||
for (int i = 0; i < idx; i++) {
|
||||
xpwr *= x;
|
||||
}
|
||||
|
||||
// 计算这一项的结果
|
||||
results[idx] = a[idx] * xpwr;
|
||||
}
|
||||
}
|
||||
|
||||
/* CUDA核函数 - 10阶优化版本 */
|
||||
__global__ void cudaPolyEvalDegree10(int *a, int degree, int x, int *result)
|
||||
{
|
||||
// 使用共享内存来存储中间结果
|
||||
__shared__ int shared_result;
|
||||
|
||||
// 只有第一个线程初始化共享结果
|
||||
if (threadIdx.x == 0) {
|
||||
shared_result = 0;
|
||||
}
|
||||
__syncthreads();
|
||||
|
||||
// 每个线程计算一部分项
|
||||
int local_result = 0;
|
||||
int xpwr = 1;
|
||||
|
||||
// 计算x的幂
|
||||
for (int i = 0; i < threadIdx.x; i++) {
|
||||
xpwr *= x;
|
||||
}
|
||||
|
||||
// 计算这一项的结果
|
||||
if (threadIdx.x <= degree) {
|
||||
local_result = a[threadIdx.x] * xpwr;
|
||||
}
|
||||
|
||||
// 使用原子操作累加结果
|
||||
atomicAdd(&shared_result, local_result);
|
||||
|
||||
// 同步所有线程
|
||||
__syncthreads();
|
||||
|
||||
// 只有第一个线程将结果写回全局内存
|
||||
if (threadIdx.x == 0) {
|
||||
*result = shared_result;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
这个表格包含多个数组元素,每一组元素(函数名字, "描述字符串")
|
||||
将你认为最好的两个实现,放在最前面。
|
||||
比如:
|
||||
{my_poly_eval1, "超级垃圾实现"},
|
||||
{my_poly_eval2, "好一点的实现"},
|
||||
*/
|
||||
|
||||
peval_fun_rec peval_fun_tab[] =
|
||||
{
|
||||
|
||||
/* 第一项,应当是你写的最好CPE的函数实现 */
|
||||
{cuda_poly_eval_low_cpe, "CUDA optimized low CPE implementation"},
|
||||
/* 第二项,应当是你写的在10阶时具有最好性能的实现 */
|
||||
{cuda_poly_eval_degree10, "CUDA optimized degree 10 implementation"},
|
||||
|
||||
{poly_eval, "poly_eval: 参考实现"},
|
||||
|
||||
/* 下面的代码不能修改或者删除!!表明数组列表结束 */
|
||||
{NULL, ""}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
perflab/poly/poly.o
Normal file
BIN
perflab/poly/poly.o
Normal file
Binary file not shown.
@ -6,6 +6,7 @@
|
||||
#include "poly.h"
|
||||
#include "cpe.h"
|
||||
#include "clock.h"
|
||||
#include <time.h>
|
||||
|
||||
double CPU_Mhz;
|
||||
|
||||
@ -17,7 +18,7 @@ static int coeff[MAXDEGREE+1];
|
||||
|
||||
#define MAX_ITER_COUNT 100
|
||||
|
||||
#define REF_CPU_MHZ 2292.6 // <20><><EFBFBD><EFBFBD><EFBFBD>ҵĴ<D2B5><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
|
||||
#define REF_CPU_MHZ 2292.6 // <20><><EFBFBD><EFBFBD><EFBFBD>ҵĴ<D2B5><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
|
||||
|
||||
/* Define performance standards */
|
||||
static struct {
|
||||
@ -26,7 +27,7 @@ static struct {
|
||||
} cstandard[3] =
|
||||
{{4.00, 1.75}, /* CPE */
|
||||
{50, 43}, /* C(10) */
|
||||
{57,31} /* <20><>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD> */
|
||||
{57,31} /* <20><>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD> */
|
||||
};
|
||||
|
||||
int coeff_const[4];
|
||||
@ -82,7 +83,7 @@ static void init_const_poly(void)
|
||||
coeff_const[i] = rand_div+10;
|
||||
}
|
||||
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>poly.c<><63>const_poly_eval<61><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>㣡\n");
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>poly.c<><63>const_poly_eval<61><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>㣡\n");
|
||||
printf("\tresult=%d+%d*x+%d*x^2+%d*x^3\n",coeff_const[0],coeff_const[1],coeff_const[2],coeff_const[3]);
|
||||
|
||||
fixval_const = ref_poly_eval(coeff_const, 3, xval);
|
||||
@ -97,15 +98,15 @@ void test_const_poly(void)
|
||||
int my_cal = const_poly_eval(coeff_const, 3, xval);
|
||||
if (fixval_const != my_cal)
|
||||
{
|
||||
printf("<EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>const_poly_evalʵ<EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>x=%d<><64><EFBFBD><EFBFBD>Ԥ<EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD>%d<><64><EFBFBD><EFBFBD><EFBFBD>Ǽ<EFBFBD><C7BC><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%d\n",xval,fixval_const,my_cal);
|
||||
printf("<EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>const_poly_evalʵ<EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD>x=%d<><64><EFBFBD><EFBFBD>Ԥ<EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD>%d<><64><EFBFBD><EFBFBD><EFBFBD>Ǽ<EFBFBD><C7BC><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>%d\n",xval,fixval_const,my_cal);
|
||||
exit(0);
|
||||
}
|
||||
fix_time = 0;
|
||||
for (i=0;i<MAX_ITER_COUNT;i++)
|
||||
fix_time += measure_function(run_fun_const, 3);
|
||||
fix_time = fix_time / MAX_ITER_COUNT;
|
||||
printf(" <20><>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> = %.1f\n", fix_time);
|
||||
printf(" <20><><EFBFBD>ߵij<EFBFBD>ϵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD> ============== %.0f\n",
|
||||
printf(" <20><>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> = %.1f\n", fix_time);
|
||||
printf(" <20><>ߵij<DFB5>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>÷<EFBFBD> ============== %.0f\n",
|
||||
compute_score(fix_time, cstandard[2].cref, cstandard[2].cbest));
|
||||
}
|
||||
|
||||
@ -132,7 +133,7 @@ int test_poly(peval_fun f, FILE *rpt) {
|
||||
ok = 0;
|
||||
if (rpt) {
|
||||
fprintf(rpt,
|
||||
"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>㲻<EFBFBD>ԣ<EFBFBD><EFBFBD><EFBFBD>=%dʱ<64><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>%d<><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷֵ<C8B7><D6B5>%d\n",
|
||||
"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>㲻<EFBFBD>ԣ<EFBFBD><EFBFBD><EFBFBD>=%dʱ<64><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>%d<><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷֵ<C8B7><D6B5>%d\n",
|
||||
MAXDEGREE-i, v, pval[i]);
|
||||
}
|
||||
}
|
||||
@ -142,7 +143,7 @@ int test_poly(peval_fun f, FILE *rpt) {
|
||||
ok = 0;
|
||||
if (rpt) {
|
||||
fprintf(rpt,
|
||||
"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>㲻<EFBFBD>ԣ<EFBFBD><EFBFBD><EFBFBD>=%dʱ<64><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>%d<><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷֵ<C8B7><D6B5>%d\n",
|
||||
"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>㲻<EFBFBD>ԣ<EFBFBD><EFBFBD><EFBFBD>=%dʱ<64><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>%d<><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷֵ<C8B7><D6B5>%d\n",
|
||||
FIXDEGREE, v, fixval);
|
||||
}
|
||||
}
|
||||
@ -175,7 +176,7 @@ void run_poly(peval_fun f, char *descr, double *cpep, double *cfixp)
|
||||
double cpe=0;
|
||||
double fix_time=0;
|
||||
pfun = f;
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%s\n", descr);
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%s\n", descr);
|
||||
if (test_poly(f, stdout)) {
|
||||
cpe = 0;
|
||||
for (i=0;i<MAX_ITER_COUNT;i++)
|
||||
@ -206,7 +207,7 @@ static double compute_score(double cmeas, double cref, double cbest)
|
||||
return 100*((smeas-1.0)/(sbest-1.0) + 0.1);
|
||||
}
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>0~divv-1֮<31><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>0~divv-1֮<31><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
void GenerateRandomNumber(unsigned long divv)
|
||||
{
|
||||
unsigned long long x = rand1_h;
|
||||
@ -230,18 +231,18 @@ int main(int argc, char *argv[])
|
||||
|
||||
// CPU_Factor();
|
||||
// GetCpuClock();
|
||||
printf("\t2015<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD>Ż<EFBFBD>ʵ<EFBFBD>飬<EFBFBD><EFBFBD>ӭ<EFBFBD>㣡\n");
|
||||
printf("\t2015<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD>Ż<EFBFBD>ʵ<EFBFBD>飬<EFBFBD><EFBFBD>ӭ<EFBFBD>㣡\n");
|
||||
printf("============================\n");
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
printf("ʹ<EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%s ѧ<>ź<EFBFBD>6λ [ѧ<>ź<EFBFBD>6λ] [ѧ<>ź<EFBFBD>6λ] ...\n",argv[0]);
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>дpoly.c<><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD>ļ<EFBFBD><EFBFBD>㣬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܿ<EFBFBD>Ŷ....\n");
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD>⣬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>дpoly.c<><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>10<EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>㣬Ҫ<EFBFBD>죡\n");
|
||||
printf("ʹ<EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%s ѧ<>ź<EFBFBD>6λ [ѧ<>ź<EFBFBD>6λ] [ѧ<>ź<EFBFBD>6λ] ...\n",argv[0]);
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>дpoly.c<><63><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD>ļ<EFBFBD><C4BC>㣬<EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD>ܿ<EFBFBD>Ŷ....\n");
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD>⣬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>дpoly.c<><63><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>10<EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>㣬Ҫ<EFBFBD>죡\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD>ѧ<EFBFBD>ţ<EFBFBD><C5A3><EFBFBD>ʼ<EFBFBD><CABC>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
/*<2A><><EFBFBD><EFBFBD>ѧ<EFBFBD>ţ<EFBFBD><C5A3><EFBFBD>ʼ<EFBFBD><CABC>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
rand1_h = (unsigned long)atoi(argv[1]);
|
||||
rand1_l=0x29A;
|
||||
GenerateRandomNumber(0);
|
||||
@ -266,10 +267,10 @@ int main(int argc, char *argv[])
|
||||
//make_CPU_busy();
|
||||
run_poly(peval_fun_tab[i].f, peval_fun_tab[i].descr, &cpe, &cfix);
|
||||
if (i == 0)
|
||||
printf(" <20><><EFBFBD>ߵ<EFBFBD>CPE<EFBFBD>÷<EFBFBD> =========================== %.0f\n",
|
||||
printf(" <20><>ߵ<EFBFBD>CPE<50>÷<EFBFBD> =========================== %.0f\n",
|
||||
compute_score(cpe, cstandard[0].cref, cstandard[0].cbest));
|
||||
if (i == 1)
|
||||
printf(" <20><><EFBFBD>ߵ<EFBFBD>C(10)<29>÷<EFBFBD> ========================= %.0f\n",
|
||||
printf(" <20><>ߵ<EFBFBD>C(10)<29>÷<EFBFBD> ========================= %.0f\n",
|
||||
compute_score(cfix, cstandard[1].cref, cstandard[1].cbest));
|
||||
}
|
||||
return 0;
|
||||
|
||||
BIN
perflab/poly/poly_test.o
Normal file
BIN
perflab/poly/poly_test.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user