حسین خسروی

وبلاگ دانشگاهی حسین خسروی، عضو هیات علمی دانشگاه صنعتی شاهرود

حسین خسروی

وبلاگ دانشگاهی حسین خسروی، عضو هیات علمی دانشگاه صنعتی شاهرود

حسین خسروی

باتوجه به محدودیتهای صفحه شخصی موجود در سایت دانشگاه، این بلاگ را راه اندازی کردم.
اطلاعیه های مربوط به دروسی که تدریس می کنم و تمرینها در این وبلاگ قرار خواهد گرفت.
برای آگاهی از مطالب مربوط به هر درس، در قاب زیر (طبقه بندی موضوعی) روی نام درس کلیک کنید.

پیوندهای روزانه

۳ مطلب با موضوع «سیستم های چند پردازنده ای :: مثالهای MultiCore» ثبت شده است

  • ۰
  • ۰

در این مثال روش ضرب دو ماتریس با استفاده از GPU را مشاهده می کنید:

ضرب دو ماتریس

// You might need to change this header based on your install:

// You might need to change this header based on your install:
#include <CL/cl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <fstream>
#include <time.h>
#include <windows.h>

#define SUCCESS 0
#define FAILURE 1

using namespace std;

#pragma  comment(lib, "OpenCl.lib")

static void check_error(cl_int error, char* name) {
	if (error != CL_SUCCESS) {
		fprintf(stderr, "Non-successful return code %d for %s.  Exiting.\n", error, name);
		exit(1);
	}
}
//برای دیدن کد کامل، ادامه مطلب را ببینید
 
  • حسین خسروی
  • ۰
  • ۰

مثال شماره 2 درس چند پردازنده

این مثال و برخی از مثالهایی که در جلسات آینده طرح خواهد شد، از مثالهای شرکت AMD است که با تغییراتی در این درس طرح می شوند.

چاپ پیام Hello World از طریق کرنل - فایل CPP که در سمت میزبان اجرا می شود

/**********************************************************************
MultiCore Programming
Hossein Khosravi
Shahrood University of Technology
********************************************************************/

// For clarity,error checking has been omitted.

#include <CL/cl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <fstream>

#define SUCCESS 0
#define FAILURE 1

using namespace std;
 //برای دیدن کد کامل، ادامه مطلب را ببینید
  • حسین خسروی
  • ۰
  • ۰

مثال شماره 1 درس چند پردازنده

این مثال و برخی از مثالهایی که در جلسات آینده طرح خواهد شد، از مثالهای شرکت AMD است که با تغییراتی در این درس طرح می شوند.

دریافت اطلاعات پردازنده ها

// MultiCore Programming
// Hossein Khosravi
// Shahrood University of Technology

#include "stdafx.h"
// You might need to change this header based on your install:
#include <CL/cl.h>
#include <stdio.h>
#include <stdlib.h>

#pragma  comment(lib, "OpenCl.lib")
static void check_error(cl_int error, char* name) {
	if (error != CL_SUCCESS) {
		fprintf(stderr, "Non-successful return code %d for %s.  Exiting.\n", error, name);
		exit(1);
	}
}

int main(int argc, char const *argv[])
{
	cl_uint i;
	cl_int err;

	// Discover the number of platforms:
	cl_uint nplatforms;
	err = clGetPlatformIDs(0, NULL, &nplatforms);
	check_error(err, "clGetPlatformIds");

	// Now ask OpenCL for the platform IDs:
	cl_platform_id* platforms = (cl_platform_id*)malloc(sizeof(cl_platform_id) * nplatforms);
	err = clGetPlatformIDs(nplatforms, platforms, NULL);
	check_error(err, "clGetPlatformIds");

	// Ask OpenCL about each platform to understand the problem:
	char name[128];
	char vendor[128];
	char version[128];

	fprintf(stdout, "OpenCL reports %d platforms.", nplatforms);
	cl_device_id devs[3];	
	for (i = 0; i < nplatforms; i++) {
		err |= clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, 128, vendor, NULL);
		err |= clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, 128, name, NULL);
		err |= clGetPlatformInfo(platforms[i], CL_PLATFORM_VERSION, 128, version, NULL);
		check_error(err, "clGetPlatformInfo");

		fprintf(stdout, "\n********************\nPlatform %d: %s %s %s\n", i, vendor, name, version);

		cl_uint num_devices = 0;
		//find number of devices for each platform
		//status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);
		err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
		check_error(err, "clGetDeviceIDs");
		cl_device_id* devices = (cl_device_id*) malloc(sizeof(cl_device_id) * num_devices);
		clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, num_devices, devices, NULL);
		for (int j = 0; j < num_devices; j++) 
		{
			int maxComputeUnits = 0;
			// print parallel compute units
			clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS,
				sizeof(maxComputeUnits), &maxComputeUnits, NULL);
			printf("\n\tNum of compute units: %d\n", maxComputeUnits);

			cl_uint addr_data = 0;			
			char name_data[100] = { 0 }, ext_data[4096] = { 0 }, version[100] = {0};
			err = clGetDeviceInfo(devices[j], CL_DEVICE_NAME, 
				sizeof(name_data), name_data, NULL);		
			
			err |= clGetDeviceInfo(devices[j], CL_DEVICE_VERSION,
				sizeof(version), version, NULL);

			err |= clGetDeviceInfo(devices[j], CL_DEVICE_ADDRESS_BITS,
				sizeof(addr_data), &addr_data, NULL);
			err |= clGetDeviceInfo(devices[j], CL_DEVICE_EXTENSIONS,
				sizeof(ext_data), ext_data, NULL);
			check_error(err, "clGetDeviceInfo");
			printf("\tDevice #%d) NAME: %s\n\tVERSION: %s\n\tADDRESS_WIDTH: %u\n\tEXTENSIONS: %s\n\t----------\n",
				j, name_data, version, addr_data, ext_data);
		}
		free(devices);
	}

	getchar();
	free(platforms);
	return 0;
}

برای دیدن خروجی، ادامه مطلب را ببینید:

  • حسین خسروی