Sunday, 13 April 2014

Building Cloud using Eucalyptus


Overview
Eucalyptus consists of the following components:
• Cloud Controller (CLC): this component provides EC2 functionality
• Walrus: this component provides S3 functionality
• Cluster Controller (CC): this component provides management service for a cluster in your cloud
• Storage Controller (SC): this component provides EBS functionality
• Node Controller (NC): this component controls virtual machine instances


In the Frontend+NC configuration, the CLC, Walrus, CC, and SC are installed on one machine, called the Frontend.
The NC is installed on another machine, called the Node. In this configuration you can have one Frontend and one or more Nodes.
Before installing FastStart in the Frontend+NC configuration, make sure you have at least two machines with:
• a minimum of 100GB of disk space
• a minimum of 4GB of memory
• at least one ethernet NIC
Network Requirements
• You must have access to the internet.
• You must be able to assign static IP addresses within your network.
• You must set aside a static IP address for each physical system.
• You must set aside a range of available public IP addresses. Eucalyptus will assign these to VM instances.
• You must set aside a large range of available private IP addresses. These will be used by a virtual subnet. They can not overlap or contain any part of a physical network IP address space. Note: Eucalyptus will set aside, by default, the subnet 172.16.0.0 unless you choose to set different values.
Software Requirements
You must have access to the Eucalyptus FastStart ISO. You can get the FastStart ISO from http://www.eucalyptus.com/download/faststart. You should then burn this ISO to a DVD. This DVD will be used for installation on all physical machines in your cloud.

Installing a Node Controller:
To install a standalone Node Controller, follow the instructions below. It's strongly recommended that you install any Node Controllers before you install the Frontend.
To install a Node Controller:
1. Boot the target system from the Eucalyptus Faststart media. Wait for the boot screen to load. When the boot screen loads, select "Install CentOS 6 with Eucalyptus Node Controller".
2. You may be asked to check the media, to ensure that there are no data issues. You may check the media, or you may skip to move on to the next step. You will then be asked to select language and keyboard options. (Note that Faststart instructions are currently available in English only.)
3. Next, you will be asked for network information. For Network Interface, select your ethernet interface (usually eth0).
For Mode, Static is recommended; DHCP will work in many cases, but if DHCP leases change, your Eucalyptus cloud will no longer be functional. Also enter IP address, Netmask, Default Gateway, and a comma-delimited list of DNS servers.
4. Next, you will be asked to select timezone, and after that you will be asked to enter the root password for the system.
5. Next, you will be asked for disk install options. The Node Controller is intended to be the primary application on the system; by default, it will take up all disk space on the system. Experienced Linux admins can set up a separate partition for Eucalyptus here.
6. At this point, the Node Controller installation will begin. When this process is completed, you will be prompted to reboot the system.
7. After reboot, login as the root user, and the post-install configuration will begin. Accept the defaults for NTP configuration, networking mode, and network interface.
The installation of your Node Controller is now complete. You may now install other Node Controllers; when you've installed all Node Controllers, you may move on to install the Eucalyptus Frontend. CC-BY-SA, Eucalyptus Systems, Inc.

Installing Frontend :
To install a Frontend on a separate system, follow the instructions below. It's strongly recommended that you install any Node Controllers (NCs) before you install the Frontend.
To install the Frontend:
1. Boot the target system from the Eucalyptus Faststart media. Wait for the boot screen to load. When the boot screen loads, select "Install CentOS 6 with Eucalyptus Frontend".
2. You may be asked to check the media, to ensure that there are no data issues. You may check the media, or you may Skip to move on to the next step. You will then be asked to select language and keyboard options. (Note that Faststart
instructions are currently available in English only.)
3. Next, you will be asked for network information. For Network Interface, select your ethernet interface (usually eth0). For Mode, Static is recommended; DHCP will work in many cases, but if DHCP leases change, your Eucalyptus cloud will no longer be functional. Also enter IP address, Netmask, Default Gateway, and a list of DNS servers.
4. Next, you will be asked to select timezone, and after that you will be asked to enter the root password for the system.
5. Next, you will be asked for cloud configuration options. Most are defaults that you should not touch unless you are an experienced Eucalyptus administrator; see the Administration Guide for details. The one parameter you must enter here is the range of public IP addresses. New virtual instances created by Eucalyptus will receive IP addresses from within this specified range. Enter the lower and higher range of available public IP addresses, a dash between them (e.g.: 192.168.1.200-192.168.1.240).
6. Next, you will be asked for disk install options. Eucalyptus is intended to be the primary application on the system; by default, it will take up all disk space on the system. Experienced Linux admins can set up a separate partition for Eucalyptus here.
7. At this point, the Eucalyptus installation will begin. Software will be installed, and a default Eucalyptus machine image (EMI) will be built. When this process is completed, you will be prompted to reboot the system.
8. When the system reboots, you will be prompted to accept the license for this installation.
9. You will now be asked to enter the IP addresses of the Node Controllers that you've previously configured. Enter the IP addresses, separated by spaces, for each NC that you'd like to control with your Eucalyptus frontend.
10. You will now be asked to create a non-root login, and turn on NTP. Note that NTP is required for Eucalyptus to function properly.
The installation is now complete. You may ascertain that your cloud is running by clicking on the the web browser links from the Desktop.



Saturday, 12 April 2014

Installing OpenCL in windows and run a program of vector addition


Installation of OpenCL

1.      Microsoft Visual Studio:
·       Microsoft Visual Studio C++  Express is required on which you will right your C/C++ programs that should be run using  OpenCl libraries. 
·       Download it from the following link: http://www.visualstudio.com/en-US/products/visual-studio-express-vs#webInstall 
·       Download the latest Express version available for Windows Desktop suitable to your hardware.
·       Installation process:
1.        We start with the familiar install startup menu:

2.        Then we get a banner page, as things start up.

3.        Next, we get a license page, as well as an overview of what is going to be installed. 

4.        Next up is an options page:

5.        Now the actual installation begins and we can see a more complete list of all the components that will be installed. 


6.        You’ll have to reboot after the .NET Framework 4 installation.
                                 
   
7.        You’ll get a warning dialog, indicating that SQL Server 2008 has compatibility issues on Windows 7 and suggesting that you install SP1.





     2.  AMD-APP-SDK:
  • download APP-SDK suitable to your hardware configurations from http://developer.amd.com/tools-and-sdks/heterogeneous-computing/amd-accelerated-parallel-processing-app-sdk/downloads/

Installation Procedure:

            Step 1. Choose the AMD APP SDK executable appropriate for your system, and               double-click it.
– For 32-bit Windows Vista, Windows 7 SP1, and Windows 8 systems, choose 
AMD-APP-SDK-v2.8-Windows-32.exe.
– For 64-bit Windows Vista, Windows 7 SP1, and Windows 8 systems, choose 
AMD-APP-SDK-v2.8-Windows-64.exe.
The extracted files are placed automatically into C:\AMD\SUPPORT\<name of file you double-clicked.>\. 
Step 2. If the setup program does not start automatically after the files have been extracted, access the subdirectory of C:\AMD\SUPPORT\ with the extracted files, and double-clickSetup.exe. A welcome screen appears, prompting you to choose a language. The 
default is English. Click Next. The Select Installation Operation screen appears.
Step 3. Click the install icon. The resulting screen lets you choose the type of installation, as well as the default installation location.
Choosing Express installs: 
– AMD APP SDK v2 Developer
– AMD APP SDK v2 Samples
– AMD APP SDK v2 Runtime4 of 9 Installation Notes
Choosing Custom lets you select the components (Developer and Samples) to install. If you select Express, continue with Step 4. If you select Custom, skip to Step 9.
Step 4. If you select Express and click Next, the End User License Agreement appears. Click Accept. This causes a temporary “Analyzing System” screen to appear. The program is detecting the type of graphics hardware and software currently installed on the system. If an older version of one of the components is already installed, a warning appears, indicating that the installation cannot continue before it is removed. (In this case, use Program and Features (in Windows Vista, Windows 7 SP1, or Windows 8) to remove the older version of the component named above the lower progress bar.)
Step 5. When the InstallShield Wizard screen appears, click Next. This results in a prompt to accept the default folder into which the extracted files are placed. Click Next.
Step 6. When the License Agreement appears, first click the button next to “I accept the terms in the license agreement.” Then, click Next.
Step 7. On the next screen, click Install to begin installing the SDK files. A progress bar appears. After the installation is complete, a confirmation screen appears. Click Finish. This completes the installation of the AMD APP SDK v2.8 files. 
Step 8. The following steps are only if Custom was selected in Step 3.
Step 9. If you clicked Custom in Step 3., above, and click Next, a temporary “Analyzing System” screen appears. The program is detecting the type of graphics hardware and software currently installed on the system. After several seconds, the Customize Install screen appears. This lets you specify which components you want to install. By default, all components are checked.
Step 10. Select the component(s) you want to install, and click Next. The End User License Agreement appears. Click Accept. 
Step 11. When the InstallShield Wizard screen appears, click Next. This results in a prompt to accept the default folder into which the extracted files are placed. Click Next.
Step 12. A progress bar appears, followed by a confirmation screen that the installation is complete. The log file can be seen by clicking on the View Log option. Click Finish to complete the installation.
With SDK 2.8 or later, clinfo.exe is copied under C:\windows\system32\ instead of under C:\Program Files\AMD APP\ on 32-bit Windows, or C:\Program Files (x86)\AMD APP\ on 64-bit Windows.

Program for vector addition in OpenCL :
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <CL/opencl.h>
// OpenCL kernel. Each work item takes care of one element of c
const char *kernelSource =                                       "\n" \
"#pragma OPENCL EXTENSION cl_khr_fp64 : enable                    \n" \
"__kernel void vecAdd(  __global double *a,                       \n" \
"                       __global double *b,                       \n" \
"                       __global double *c,                       \n" \
"                       const unsigned int n)                    \n" \
"{                                                               \n" \
"    //Get our global thread ID                                  \n" \
"    int id = get_global_id(0);                                  \n" \
"                                                                \n" \
"    //Make sure we do not go out of bounds                      \n" \
"    if (id < n)                                                 \n" \
"        c[id] = a[id] + b[id];                                  \n" \
"}                                                               \n" \
                                                                "\n" ;

int main( int argc, char* argv[] )
{
    // Length of vectors
    unsigned int n = 100000;
    // Host input vectors
    double *h_a;
    double *h_b;
    // Host output vector
    double *h_c;
    // Device input buffers
    cl_mem d_a;
    cl_mem d_b;
    // Device output buffer
    cl_mem d_c;
    cl_platform_id cpPlatform;        // OpenCL platform
    cl_device_id device_id;           // device ID
    cl_context context;               // context
    cl_command_queue queue;           // command queue
    cl_program program;               // program
    cl_kernel kernel;                 // kernel
    // Size, in bytes, of each vector
    size_t bytes = n*sizeof(double);
    // Allocate memory for each vector on host
    h_a = (double*)malloc(bytes);
    h_b = (double*)malloc(bytes);
    h_c = (double*)malloc(bytes);
    // Initialize vectors on host
    int i;
    for( i = 0; i < n; i++ )
    {
        h_a[i] = sinf(i)*sinf(i);
        h_b[i] = cosf(i)*cosf(i);
    }
    size_t globalSize, localSize;
    cl_int err;
    // Number of work items in each local work group
    localSize = 64;
    // Number of total work items - localSize must be devisor
    globalSize = ceil(n/(float)localSize)*localSize;
    // Bind to platform
    err = clGetPlatformIDs(1, &cpPlatform, NULL);
    // Get ID for the device
    err = clGetDeviceIDs(cpPlatform, CL_DEVICE_TYPE_GPU, 1, &device_id, NULL);
    // Create a context 
    context = clCreateContext(0, 1, &device_id, NULL, NULL, &err);
    // Create a command queue
    queue = clCreateCommandQueue(context, device_id, 0, &err);
    // Create the compute program from the source buffer
    program = clCreateProgramWithSource(context, 1,
                            (const char **) & kernelSource, NULL, &err);
    // Build the program executable
    clBuildProgram(program, 0, NULL, NULL, NULL, NULL);
    // Create the compute kernel in the program we wish to run
    kernel = clCreateKernel(program, "vecAdd", &err);
    // Create the input and output arrays in device memory for our calculation
    d_a = clCreateBuffer(context, CL_MEM_READ_ONLY, bytes, NULL, NULL);
    d_b = clCreateBuffer(context, CL_MEM_READ_ONLY, bytes, NULL, NULL);
    d_c = clCreateBuffer(context, CL_MEM_WRITE_ONLY, bytes, NULL, NULL);
    // Write our data set into the input array in device memory
    err = clEnqueueWriteBuffer(queue, d_a, CL_TRUE, 0,
                                   bytes, h_a, 0, NULL, NULL);
    err |= clEnqueueWriteBuffer(queue, d_b, CL_TRUE, 0,
                                   bytes, h_b, 0, NULL, NULL);
    // Set the arguments to our compute kernel
    err  = clSetKernelArg(kernel, 0, sizeof(cl_mem), &d_a);
    err |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &d_b);
    err |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &d_c);
    err |= clSetKernelArg(kernel, 3, sizeof(unsigned int), &n);
    // Execute the kernel over the entire range of the data set 
    err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &globalSize, &localSize,
                                                              0, NULL, NULL);
    // Wait for the command queue to get serviced before reading back results
    clFinish(queue);
    // Read the results from the device
    clEnqueueReadBuffer(queue, d_c, CL_TRUE, 0,
                                bytes, h_c, 0, NULL, NULL );
    //Sum up vector c and print result divided by n, this should equal 1 within error
    double sum = 0;
    for(i=0; i<n; i++)
        sum += h_c[i];
    printf("final result: %f\n", sum/n);
    // release OpenCL resources
    clReleaseMemObject(d_a);
    clReleaseMemObject(d_b);
    clReleaseMemObject(d_c);
    clReleaseProgram(program);
    clReleaseKernel(kernel);
    clReleaseCommandQueue(queue);
    clReleaseContext(context);
    //release host memory
    free(h_a);
    free(h_b);
    free(h_c);
   return 0;
}