Пример #1
0
/* This function is intended to be used by external tools that should read the
 * performance model files */
int starpu_load_history_debug(const char *symbol, struct starpu_perfmodel_t *model)
{
    model->symbol = symbol;

    /* where is the file if it exists ? */
    char path[256];
    get_model_path(model, path, 256);

//	_STARPU_DEBUG("get_model_path -> %s\n", path);

    /* does it exist ? */
    int res;
    res = access(path, F_OK);
    if (res) {
        _STARPU_DISP("There is no performance model for symbol %s\n", symbol);
        return 1;
    }

    FILE *f = fopen(path, "r");
    STARPU_ASSERT(f);

    parse_model_file(f, model, 1);

    return 0;
}
static struct starpu_sched_policy *find_sched_policy_from_name(const char *policy_name)
{
	if (!policy_name)
		return NULL;

	if (strncmp(policy_name, "heft", 5) == 0)
	{
		_STARPU_DISP("Warning: heft is now called \"dmda\".\n");
		return &_starpu_sched_dmda_policy;
	}

	struct starpu_sched_policy **policy;
	for(policy=predefined_policies ; *policy!=NULL ; policy++)
	{
		struct starpu_sched_policy *p = *policy;
		if (p->policy_name)
		{
			if (strcmp(policy_name, p->policy_name) == 0)
			{
				/* we found a policy with the requested name */
				return p;
			}
		}
	}
	if (strcmp(policy_name, "help") != 0)
	     fprintf(stderr, "Warning: scheduling policy \"%s\" was not found, try \"help\" to get a list\n", policy_name);

	/* nothing was found */
	return NULL;
}
Пример #3
0
int starpu_opencl_load_opencl_from_string(char *opencl_program_source, struct starpu_opencl_program *opencl_programs)
{
    unsigned int dev;
    unsigned int nb_devices;

    nb_devices = _starpu_opencl_get_device_count();
    // Iterate over each device
    for(dev = 0; dev < nb_devices; dev ++) {
        cl_device_id device;
        cl_context   context;
        cl_program   program;
        cl_int       err;

        starpu_opencl_get_device(dev, &device);
        starpu_opencl_get_context(dev, &context);
        opencl_programs->programs[dev] = NULL;

        if (context == NULL) continue;

        // Create the compute program from the source buffer
        program = clCreateProgramWithSource(context, 1, (const char **) &opencl_program_source, NULL, &err);
        if (!program || err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);

        // Build the program executable
        err = clBuildProgram(program, 1, &device, "-Werror -cl-mad-enable", NULL, NULL);
        if (err != CL_SUCCESS) {
            size_t len;
            static char buffer[4096];

            _STARPU_DISP("Error: Failed to build program executable!\n");
            clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);

            _STARPU_DISP("<%s>\n", buffer);
            return EXIT_FAILURE;
        }

        // Store program
        opencl_programs->programs[dev] = program;
    }
    return EXIT_SUCCESS;
}
Пример #4
0
int _starpu_wait_data_request_completion(starpu_data_request_t r, unsigned may_alloc)
{
	int retval;
	int do_delete = 0;

	uint32_t local_node = _starpu_get_local_memory_node();

	do {
		_starpu_spin_lock(&r->lock);

		if (r->completed)
			break;

		_starpu_spin_unlock(&r->lock);

#ifndef STARPU_NON_BLOCKING_DRIVERS
		_starpu_wake_all_blocked_workers_on_node(r->handling_node);
#endif

		_starpu_datawizard_progress(local_node, may_alloc);

	} while (1);


	retval = r->retval;
	if (retval)
		_STARPU_DISP("REQUEST %p COMPLETED (retval %d) !\n", r, r->retval);
		

	r->refcnt--;

	/* if nobody is waiting on that request, we can get rid of it */
	if (r->refcnt == 0)
		do_delete = 1;

	_starpu_spin_unlock(&r->lock);
	
	if (do_delete)
		starpu_data_request_destroy(r);
	
	return retval;
}
Пример #5
0
int starpu_opencl_load_kernel(cl_kernel *kernel, cl_command_queue *queue, struct starpu_opencl_program *opencl_programs,
                              char *kernel_name, int devid)
{
    int err;
    cl_device_id device;
    cl_context context;
    cl_program program;

    starpu_opencl_get_device(devid, &device);
    starpu_opencl_get_context(devid, &context);
    starpu_opencl_get_queue(devid, queue);

    program = opencl_programs->programs[devid];
    if (!program) {
        _STARPU_DISP("Program not available\n");
        return CL_INVALID_PROGRAM;
    }

    // Create the compute kernel in the program we wish to run
    *kernel = clCreateKernel(program, kernel_name, &err);
    if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);

    return CL_SUCCESS;
}
Пример #6
0
void
_starpu_swap_init(void)
{
	char *backend;
	char *path;
	starpu_ssize_t size;
	struct starpu_disk_ops *ops;
	int dd;

	path = getenv("STARPU_DISK_SWAP");
	if (!path)
		return;

	backend = getenv("STARPU_DISK_SWAP_BACKEND");
	if (!backend)
	{
		_starpu_mkpath(path, S_IRWXU);
		ops = &starpu_disk_unistd_ops;
	}
	else if (!strcmp(backend, "stdio"))
	{
		_starpu_mkpath(path, S_IRWXU);
		ops = &starpu_disk_stdio_ops;
	}
	else if (!strcmp(backend, "unistd"))
	{
		_starpu_mkpath(path, S_IRWXU);
		ops = &starpu_disk_unistd_ops;
	}
	else if (!strcmp(backend, "unistd_o_direct"))
	{
#ifdef STARPU_LINUX_SYS
		_starpu_mkpath(path, S_IRWXU);
		ops = &starpu_disk_unistd_o_direct_ops;
#else
		_STARPU_DISP("Warning: o_direct support is not compiled in, could not enable disk swap");
		return;
#endif

	}
	else if (!strcmp(backend, "leveldb"))
	{
#ifdef STARPU_HAVE_LEVELDB
		ops = &starpu_disk_leveldb_ops;
#else
		_STARPU_DISP("Warning: leveldb support is not compiled in, could not enable disk swap");
		return;
#endif
	}
	else
	{
		_STARPU_DISP("Warning: unknown disk swap backend %s, could not enable disk swap", backend);
		return;
	}

	size = starpu_get_env_number_default("STARPU_DISK_SWAP_SIZE", -1);

	dd = starpu_disk_register(ops, path, size);
	if (dd < 0)
	{
		_STARPU_DISP("Warning: could not enable disk swap %s on %s with size %ld, could not enable disk swap", backend, path, (long) size);
		return;
	}
}
int starpu_opencl_load_binary_opencl(const char *kernel_id, struct starpu_opencl_program *opencl_programs)
{
	unsigned int dev;
	unsigned int nb_devices;

	nb_devices = _starpu_opencl_get_device_count();
	// Iterate over each device
	for(dev = 0; dev < nb_devices; dev ++)
	{
		cl_device_id device;
		cl_context   context;
		cl_program   program;
		cl_int       err;
		char        *binary;
		char         binary_file_name[1024];
		size_t       length;
		cl_int       binary_status;

		opencl_programs->programs[dev] = NULL;

		starpu_opencl_get_device(dev, &device);
		starpu_opencl_get_context(dev, &context);
		if (context == NULL)
		{
			_STARPU_DEBUG("[%u] is not a valid OpenCL context\n", dev);
			continue;
		}

		// Load the binary buffer
		err = _starpu_opencl_get_binary_name(binary_file_name, 1024, kernel_id, dev, device);
		if (STARPU_UNLIKELY(err != CL_SUCCESS)) STARPU_OPENCL_REPORT_ERROR(err);
		binary = _starpu_opencl_load_program_binary(binary_file_name, &length);

		// Create the compute program from the binary buffer
		program = clCreateProgramWithBinary(context, 1, &device, &length, (const unsigned char **) &binary, &binary_status, &err);
		if (!program || err != CL_SUCCESS)
		{
			_STARPU_DISP("Error: Failed to load program binary!\n");
			return EXIT_FAILURE;
		}

		// Build the program executable
		err = clBuildProgram(program, 1, &device, NULL, NULL, NULL);

		// Get the status
		{
			cl_build_status status;
			size_t len;
			static char buffer[4096] = "";

			clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
			if (len > 2)
				_STARPU_DISP("Compilation output\n%s\n", buffer);

			clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_STATUS, sizeof(status), &status, NULL);
			if (err != CL_SUCCESS || status != CL_BUILD_SUCCESS)
			{
				_STARPU_DISP("Error: Failed to build program executable!\n");
				_STARPU_DISP("clBuildProgram: %d - clGetProgramBuildInfo: %d\n", err, status);
				return EXIT_FAILURE;
			}
		}

		// Store program
		opencl_programs->programs[dev] = program;
	}
	return 0;
}
static
int _starpu_opencl_compile_or_load_opencl_from_string(const char *opencl_program_source, const char* build_options,
						      struct starpu_opencl_program *opencl_programs, const char* source_file_name)
{
	unsigned int dev;
	unsigned int nb_devices;

	nb_devices = _starpu_opencl_get_device_count();
	// Iterate over each device
	for(dev = 0; dev < nb_devices; dev ++)
	{
		cl_device_id device;
		cl_context   context;
		cl_program   program;
		cl_int       err;

		if (opencl_programs)
			opencl_programs->programs[dev] = NULL;

		starpu_opencl_get_device(dev, &device);
		starpu_opencl_get_context(dev, &context);
		if (context == NULL)
		{
			_STARPU_DEBUG("[%u] is not a valid OpenCL context\n", dev);
			continue;
		}

		// Create the compute program from the source buffer
		program = clCreateProgramWithSource(context, 1, (const char **) &opencl_program_source, NULL, &err);
		if (!program || err != CL_SUCCESS)
		{
			_STARPU_DISP("Error: Failed to load program source with options %s!\n", build_options);
			return EXIT_FAILURE;
		}

		// Build the program executable
		err = clBuildProgram(program, 1, &device, build_options, NULL, NULL);

		// Get the status
		{
			cl_build_status status;
			size_t len;
			static char buffer[4096] = "";

			clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
			if (len > 2)
				_STARPU_DISP("Compilation output\n%s\n", buffer);

			clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_STATUS, sizeof(status), &status, NULL);
			if (err != CL_SUCCESS || status != CL_BUILD_SUCCESS)
			{
				_STARPU_DISP("Error: Failed to build program executable!\n");
				_STARPU_DISP("clBuildProgram: %d - clGetProgramBuildInfo: %d\n", err, status);
				return EXIT_FAILURE;
			}
		}

		// Store program
		if (opencl_programs)
			opencl_programs->programs[dev] = program;
		else
		{
			char binary_file_name[1024];
			char *binary;
			size_t binary_len;
			FILE *fh;

			err = _starpu_opencl_get_binary_name(binary_file_name, 1024, source_file_name, dev, device);
			if (STARPU_UNLIKELY(err != CL_SUCCESS)) STARPU_OPENCL_REPORT_ERROR(err);

			err = clGetProgramInfo(program, CL_PROGRAM_BINARY_SIZES, sizeof(size_t), &binary_len, NULL);
			if (STARPU_UNLIKELY(err != CL_SUCCESS)) STARPU_OPENCL_REPORT_ERROR(err);
			binary = malloc(binary_len);

			err = clGetProgramInfo(program, CL_PROGRAM_BINARIES, sizeof(binary), &binary, NULL);
			if (STARPU_UNLIKELY(err != CL_SUCCESS)) STARPU_OPENCL_REPORT_ERROR(err);

			fh = fopen(binary_file_name, "w");
			if (fh == NULL)
			{
				_STARPU_DISP("Error: Failed to open file <%s>\n", binary_file_name);
				perror("fopen");
				return EXIT_FAILURE;
			}
			fwrite(binary, binary_len, 1, fh);
			fclose(fh);
			free(binary);
			_STARPU_DEBUG("File <%s> created\n", binary_file_name);
		}
	}
	return EXIT_SUCCESS;
}
Пример #9
0
/* We first try to grab the global lock in read mode to check whether the model
 * was loaded or not (this is very likely to have been already loaded). If the
 * model was not loaded yet, we take the lock in write mode, and if the model
 * is still not loaded once we have the lock, we do load it.  */
static void load_history_based_model(struct starpu_perfmodel_t *model, unsigned scan_history)
{

    STARPU_ASSERT(model);
    STARPU_ASSERT(model->symbol);

    int already_loaded;

    PTHREAD_RWLOCK_RDLOCK(&registered_models_rwlock);
    already_loaded = model->is_loaded;
    PTHREAD_RWLOCK_UNLOCK(&registered_models_rwlock);

    if (already_loaded)
        return;

    /* The model is still not loaded so we grab the lock in write mode, and
     * if it's not loaded once we have the lock, we do load it. */

    PTHREAD_RWLOCK_WRLOCK(&registered_models_rwlock);

    /* Was the model initialized since the previous test ? */
    if (model->is_loaded)
    {
        PTHREAD_RWLOCK_UNLOCK(&registered_models_rwlock);
        return;
    }

    PTHREAD_RWLOCK_INIT(&model->model_rwlock, NULL);

    PTHREAD_RWLOCK_WRLOCK(&model->model_rwlock);

    /* make sure the performance model directory exists (or create it) */
    _starpu_create_sampling_directory_if_needed();

    /*
     * We need to keep track of all the model that were opened so that we can
     * possibly update them at runtime termination ...
     */
    _starpu_register_model(model);

    char path[256];
    get_model_path(model, path, 256);

    _STARPU_DEBUG("Opening performance model file %s for model %s ... ", path, model->symbol);

    unsigned calibrate_flag = _starpu_get_calibrate_flag();
    model->benchmarking = calibrate_flag;

    /* try to open an existing file and load it */
    int res;
    res = access(path, F_OK);
    if (res == 0) {
        if (calibrate_flag == 2)
        {
            /* The user specified that the performance model should
             * be overwritten, so we don't load the existing file !
             * */
            _STARPU_DEBUG("Overwrite existing file\n");
            initialize_model(model);
        }
        else {
            /* We load the available file */
            _STARPU_DEBUG("File exists\n");
            FILE *f;
            f = fopen(path, "r");
            STARPU_ASSERT(f);

            parse_model_file(f, model, scan_history);

            fclose(f);
        }
    }
    else {
        _STARPU_DEBUG("File does not exists\n");
        if (!calibrate_flag) {
            _STARPU_DISP("Warning: model %s is not calibrated, forcing calibration for this run. Use the STARPU_CALIBRATE environment variable to control this.\n", model->symbol);
            _starpu_set_calibrate_flag(1);
            model->benchmarking = 1;
        }
        initialize_model(model);
    }

    model->is_loaded = 1;

    PTHREAD_RWLOCK_UNLOCK(&model->model_rwlock);

    PTHREAD_RWLOCK_UNLOCK(&registered_models_rwlock);
}