141 lines
3.4 KiB
C
141 lines
3.4 KiB
C
|
/*
|
||
|
* Copyright (c) 2013, 2014, Paul Irofti <paul@irofti.net>
|
||
|
*/
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
#include "real.h"
|
||
|
#include "cl_setup.h"
|
||
|
|
||
|
#include "clccubes.h"
|
||
|
|
||
|
#include "config.h"
|
||
|
#include "logging.h"
|
||
|
|
||
|
int
|
||
|
parse_args(char *argv[], int argc,
|
||
|
uint32_t *signals, uint32_t *atoms, uint32_t *problem_size,
|
||
|
uint32_t *sparsity, uint32_t *iters, uint32_t *patoms, uint32_t *pcoding,
|
||
|
real *rmse)
|
||
|
{
|
||
|
int i = 1;
|
||
|
while (i < argc) {
|
||
|
if (strcmp(argv[i], "-signals") == 0) {
|
||
|
*signals = strtoul(argv[++i], NULL, 0);
|
||
|
} else if (strcmp(argv[i], "-atoms") == 0) {
|
||
|
*atoms = strtoul(argv[++i], NULL, 0);
|
||
|
} else if (strcmp(argv[i], "-problem") == 0) {
|
||
|
*problem_size = strtoul(argv[++i], NULL, 0);
|
||
|
} else if (strcmp(argv[i], "-sparsity") == 0) {
|
||
|
*sparsity = strtoul(argv[++i], NULL, 0);
|
||
|
} else if (strcmp(argv[i], "-iterations") == 0) {
|
||
|
*iters = strtoul(argv[++i], NULL, 0);
|
||
|
} else if (strcmp(argv[i], "-patoms") == 0) {
|
||
|
*patoms = strtoul(argv[++i], NULL, 0);
|
||
|
} else if (strcmp(argv[i], "-pcoding") == 0) {
|
||
|
*pcoding = strtoul(argv[++i], NULL, 0);
|
||
|
} else if (strcmp(argv[i], "-rmse") == 0) {
|
||
|
sscanf(argv[++i], "%f", rmse);
|
||
|
} else {
|
||
|
printf("Unrecognized option %s\n", argv[i]);
|
||
|
return 1;
|
||
|
}
|
||
|
i++;
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
usage(char *program)
|
||
|
{
|
||
|
printf("USAGE: %s [-signals sigs] [-atoms atoms] "
|
||
|
"[-problem problem_size] [-sparsity s] [-iterations iters] "
|
||
|
"[-patoms p] [-pcoding c]\n",
|
||
|
program);
|
||
|
exit(1);
|
||
|
}
|
||
|
|
||
|
int main(int argc, char *argv[])
|
||
|
{
|
||
|
int rc = 0;
|
||
|
|
||
|
real *zeroes = NULL;
|
||
|
uint64_t start, stop;
|
||
|
char log[100] = {0};
|
||
|
char *program;
|
||
|
|
||
|
struct ccubes_context ccubesctx;
|
||
|
cl_program ccubes_program;
|
||
|
|
||
|
|
||
|
/* Inputs */
|
||
|
|
||
|
/* Outputs */
|
||
|
|
||
|
/* Rounding */
|
||
|
|
||
|
/* Logging */
|
||
|
config_set_int("log", LOG_LEVEL_WARN);
|
||
|
config_set_int("log:ccubes", LOG_LEVEL_WARN);
|
||
|
config_set_int("log:test", LOG_LEVEL_WARN);
|
||
|
config_set_int("cl", LOG_LEVEL_DEBUG);
|
||
|
|
||
|
#if 0
|
||
|
rc = parse_args(argv, argc,
|
||
|
&signals, &atoms, &problem_size, &sparsity, &iters,
|
||
|
&patoms, &pcoding, &target_error);
|
||
|
if (rc != 0) {
|
||
|
usage(argv[0]);
|
||
|
}
|
||
|
|
||
|
if (strstr(argv[0], "test_ccubes") != NULL)
|
||
|
program = "ccubes";
|
||
|
sprintf(log, "log-%s-p%d-n%d-m%d-k%d-i%d-pa%d", program,
|
||
|
problem_size, atoms, signals, sparsity, iters, patoms);
|
||
|
config_set_string("out", log);
|
||
|
#endif
|
||
|
|
||
|
log_debug("test", "Starting ccubes...");
|
||
|
|
||
|
/*
|
||
|
* CCubes
|
||
|
*/
|
||
|
ccubesctx.clctx = malloc(sizeof *ccubesctx.clctx);
|
||
|
|
||
|
ccubesctx.clctx->device_type = CL_DEVICE_TYPE_GPU;
|
||
|
strcpy(ccubesctx.clctx->platform_name, "NVIDIA Corporation\0");
|
||
|
/* strcpy(ccubesctx.clctx->platform_name, "Advanced Micro Devices, Inc.\0"); */
|
||
|
/*strcpy(ccubesctx.clctx->platform_name, "Intel(R) Corporation\0");*/
|
||
|
rc = cl_init(ccubesctx.clctx);
|
||
|
if (rc != CL_SUCCESS) {
|
||
|
printf("[%d] Failed to initialize the OpenCL framework\n",
|
||
|
rc);
|
||
|
goto err;
|
||
|
}
|
||
|
|
||
|
|
||
|
rc = cl_build(*ccubesctx.clctx, CL_DEVICE_TYPE_GPU,
|
||
|
"ccubes.cl", &ccubes_program);
|
||
|
if (rc != CL_SUCCESS) {
|
||
|
log_warn("test", "Failed building ccubes.cl (%d)", rc);
|
||
|
goto err;
|
||
|
}
|
||
|
|
||
|
rc = cl_get_kern(ccubes_program, "ccubes_task",
|
||
|
&ccubesctx.ccubes_task);
|
||
|
if (rc != CL_SUCCESS) {
|
||
|
log_warn("test", "Failed fetching ccubes_task (%d)", rc);
|
||
|
goto err;
|
||
|
}
|
||
|
|
||
|
fflush(stdout);
|
||
|
err:
|
||
|
clReleaseProgram(ccubes_program);
|
||
|
|
||
|
cl_clean_up(*ccubesctx.clctx);
|
||
|
|
||
|
return rc;
|
||
|
}
|