Skip to content

Commit

Permalink
added DBSCAN_FPGA_CPU
Browse files Browse the repository at this point in the history
  • Loading branch information
Elizabeth A. Berzin committed Dec 31, 2021
1 parent 4a3c436 commit 4fe81b7
Show file tree
Hide file tree
Showing 8 changed files with 522 additions and 2 deletions.
72 changes: 72 additions & 0 deletions DBSCAN_FPGA/utility.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// This file
#include "utility.h"
#include <math.h>
#include <iostream>
#include <stdio.h>

void print_platform_info(std::vector<cl::Platform>* PlatformList)
{
uint num_platforms=PlatformList->size();
std::cout << "Number of Platforms: "<<num_platforms<<"\n";
//Grab Platform Info for each platform
for (uint i=0; i<num_platforms; i++)
{
std::cout <<"Platform " << i <<": "<<PlatformList->at(i).getInfo<CL_PLATFORM_NAME>()<<"\n";
}
std::cout<<"\n";
}

uint get_platform_id_with_string(std::vector<cl::Platform>* PlatformList, const char * name)
{
uint num_platforms=PlatformList->size();
uint ret_value=-1;
//Grab Platform Info for each platform
for (uint i=0; i<num_platforms; i++)
{
std::basic_string<char> platform_name = PlatformList->at(i).getInfo<CL_PLATFORM_NAME>();
if (platform_name.find(name)!=std::string::npos) {
return i;
}
}
return ret_value;
}

void print_device_info(std::vector<cl::Device>* DeviceList)
{
uint num_devices=DeviceList->size();
std::cout << "Number of Devices in Platform: "<<num_devices<<"\n";
//Grab Device Info for each device
for (uint i=0; i<num_devices; i++)
{
printf("Device Number: %d\n", i);
std::cout << "Device Name: "<<DeviceList->at(i).getInfo<CL_DEVICE_NAME>()<<"\n";
std::cout << "Is Device Available?: "<<DeviceList->at(i).getInfo<CL_DEVICE_AVAILABLE>()<<"\n";
std::cout << "Device Max Compute Units: "<<DeviceList->at(i).getInfo<CL_DEVICE_MAX_COMPUTE_UNITS>()<<"\n";
std::cout << "Device Max Work Item Dimensions: "<<DeviceList->at(i).getInfo<CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS>()<<"\n";
std::cout << "Device Max Work Group Size: "<<DeviceList->at(i).getInfo<CL_DEVICE_MAX_WORK_GROUP_SIZE>()<<"\n";
std::cout << "Device Max Frequency: "<<DeviceList->at(i).getInfo<CL_DEVICE_MAX_CLOCK_FREQUENCY>()<<"\n";
std::cout << "Device Max Mem Alloc Size: "<<DeviceList->at(i).getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>()<<"\n";
std::cout << "Device Max Local Mem Size: "<<DeviceList->at(i).getInfo<CL_DEVICE_LOCAL_MEM_SIZE>()<<"\n";
std::cout << "Device OpenCL Version: "<<DeviceList->at(i).getInfo<CL_DEVICE_OPENCL_C_VERSION>()<<"\n\n";
}
}

void fill_generate(cl_float X[], cl_float Y[], cl_float Z[], cl_float LO, cl_float HI, size_t vectorSize)
{

//Assigns randome number from LO to HI to all locatoin of X and Y
for (uint i = 0; i < vectorSize; ++i) {
X[i] = LO + (cl_float)rand()/((cl_float)RAND_MAX/(HI-LO));
Y[i] = LO + (cl_float)rand()/((cl_float)RAND_MAX/(HI-LO));
}
}

void checkErr(cl_int err, const char * name)
{
if (err != CL_SUCCESS) {
std::cerr << "ERROR: " << name
<< " (" << err << ")" << std::endl;
exit(EXIT_FAILURE);
}
}

13 changes: 13 additions & 0 deletions DBSCAN_FPGA/utility.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef __UTILITY_H
#define __UTILITY_H

//#include <CL/cl2.hpp>
#include "CL/cl.hpp"
#include <vector>

void print_platform_info(std::vector<cl::Platform>* PlatformList);
uint get_platform_id_with_string(std::vector<cl::Platform>*, const char * name);
void print_device_info(std::vector<cl::Device>*);
void checkErr(cl_int err, const char * name);

#endif
17 changes: 17 additions & 0 deletions DBSCAN_FPGA_CPU/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
AOCL_COMPILE_CONFIG=$(shell aocl compile-config)
AOCL_LINK_CONFIG=$(shell aocl link-config)

CC = g++
CCFLAGS = -std=c++11 -fPIC -g

DBSCAN : main.o utility.o
$(CC) $(CCFLAGS) $(AOCL_LINK_CONFIG) -lOpenCL -o DBSCAN main.o utility.o

main.o : main.cpp
$(CC) $(CCFLAGS) $(AOCL_COMPILE_CONFIG) -o main.o -c main.cpp

utility.o : utility.cpp utility.h
$(CC) $(CCFLAGS) $(AOCL_COMPILE_CONFIG) -o utility.o -c utility.cpp

clean :
rm -rf DBSCAN *.o
50 changes: 50 additions & 0 deletions DBSCAN_FPGA_CPU/NeighborKernel.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
__kernel void radius_neighbors(__global float* restrict X,
__global float* restrict Y,
__global uint* restrict neighbCount,
__global uint* restrict neighbIdx,
__global uint* restrict is_core,
uint N, float eps, uint min_samps) {

uint i = get_global_id(0);

uint nNeighb = 0;
float dist = 0;

float local_X = X[i];
float local_Y = Y[i];

for(uint j = 0; j < N; j++) {
dist = (local_X - X[j]) * (local_X - X[j]) + (local_Y - Y[j]) * (local_Y - Y[j]);
if(dist <= eps * eps) {
neighbIdx[N*i + nNeighb] = j;
nNeighb++;
}
}

neighbCount[i] = nNeighb;

}

__kernel void radius_neighbors_dists(__global float* restrict dist_matrix,
__global uint* restrict neighbCount,
__global uint* restrict neighbIdx,
__global uint* restrict is_core,
uint N, float eps, uint min_samps) {

uint i = get_global_id(0);

uint nNeighb = 0;
float dist = 0;

for(uint j = 0; j < N; j++) {
dist = dist_matrix[i*N + j];
if(dist <= eps) {
neighbIdx[N*i + nNeighb] = j;
nNeighb++;
}
}

neighbCount[i] = nNeighb;

}

Loading

0 comments on commit 4fe81b7

Please sign in to comment.