Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5db4455b979f
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 962b65daeea2
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Dec 19, 2020

  1. Copy the full SHA
    962b65d View commit details
Showing with 105 additions and 0 deletions.
  1. +100 −0 scopehal/scopehal.cpp
  2. +5 −0 scopehal/scopehal.h
100 changes: 100 additions & 0 deletions scopehal/scopehal.cpp
Original file line number Diff line number Diff line change
@@ -70,6 +70,8 @@ bool g_hasAvx512DQ = false;
bool g_hasAvx512VL = false;
bool g_hasAvx2 = false;

cl::Context* g_clContext = NULL;

AlignedAllocator<float, 32> g_floatVectorAllocator;

/**
@@ -88,6 +90,9 @@ void TransportStaticInit()
#endif
}

/**
@brief Static initialization for CPU feature flags
*/
void DetectCPUFeatures()
{
LogDebug("Detecting CPU features...\n");
@@ -110,12 +115,107 @@ void DetectCPUFeatures()
LogDebug("\n");
}

/**
@brief Static initialization for OpenCL
*/
void DetectGPUFeatures()
{
#ifdef HAVE_OPENCL
LogDebug("Detecting OpenCL devices...\n");
LogIndenter li;

//Find platforms and print info
vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
if(platforms.empty())
{
LogNotice("No platforms found, disabling OpenCL\n");
return;
}
else
{
for(size_t i=0; i<platforms.size(); i++)
{
LogDebug("Platform %zu\n", i);
LogIndenter li2;

string name;
string profile;
string vendor;
string version;
platforms[i].getInfo(CL_PLATFORM_NAME, &name);
platforms[i].getInfo(CL_PLATFORM_PROFILE, &profile);
platforms[i].getInfo(CL_PLATFORM_VENDOR, &vendor);
platforms[i].getInfo(CL_PLATFORM_VERSION, &version);
LogDebug("CL_PLATFORM_NAME = %s\n", name.c_str());
LogDebug("CL_PLATFORM_PROFILE = %s\n", profile.c_str());
LogDebug("CL_PLATFORM_VENDOR = %s\n", vendor.c_str());
LogDebug("CL_PLATFORM_VERSION = %s\n", version.c_str());

vector<cl::Device> devices;
platforms[i].getDevices(CL_DEVICE_TYPE_GPU, &devices);
if(devices.empty())
LogDebug("No GPUs found\n");
for(size_t j=0; j<devices.size(); j++)
{
LogDebug("Device %zu\n", j);
LogIndenter li3;

string dname;
string dcvers;
string dprof;
string dvendor;
string dversion;
string ddversion;
devices[j].getInfo(CL_DEVICE_NAME, &dname);
devices[j].getInfo(CL_DEVICE_OPENCL_C_VERSION, &dcvers);
devices[j].getInfo(CL_DEVICE_PROFILE, &dprof);
devices[j].getInfo(CL_DEVICE_VENDOR, &dvendor);
devices[j].getInfo(CL_DEVICE_VERSION, &dversion);
devices[j].getInfo(CL_DRIVER_VERSION, &ddversion);

LogDebug("CL_DEVICE_NAME = %s\n", dname.c_str());
LogDebug("CL_DEVICE_OPENCL_C_VERSION = %s\n", dcvers.c_str());
LogDebug("CL_DEVICE_PROFILE = %s\n", dprof.c_str());
LogDebug("CL_DEVICE_VENDOR = %s\n", dvendor.c_str());
LogDebug("CL_DEVICE_VERSION = %s\n", dversion.c_str());
LogDebug("CL_DRIVER_VERSION = %s\n", ddversion.c_str());
}

//For now, create a context on the first device of the first detected platform and hope for the best
if(!g_clContext)
{
vector<cl::Device> devs;
devs.push_back(devices[0]);

//Passing CL_CONTEXT_PLATFORM as parameters seems to make context creation fail. Weird.
cl_int err;
g_clContext = new cl::Context(devs, NULL, NULL, NULL, &err);
if(err != CL_SUCCESS)
{
LogNotice("OpenCL context creation failed (code %d), disabling OpenCL\n", err);
delete g_clContext;
g_clContext = NULL;
return;
}
}
}
}

#else
LogNotice("OpenCL support not present at compile time. GPU acceleration disabled.\n");
#endif

LogDebug("\n");
}

/**
@brief Static initialization for oscilloscopes
*/
void DriverStaticInit()
{
DetectCPUFeatures();
DetectGPUFeatures();

AddDriverClass(AgilentOscilloscope);
AddDriverClass(AntikernelLabsOscilloscope);
5 changes: 5 additions & 0 deletions scopehal/scopehal.h
Original file line number Diff line number Diff line change
@@ -108,6 +108,7 @@ void DriverStaticInit();

void InitializePlugins();
void DetectCPUFeatures();
void DetectGPUFeatures();

float FreqToPhase(float hz);

@@ -128,4 +129,8 @@ extern bool g_hasAvx2;
#define stos(str) static_cast<size_t>(stol(str))
#endif

#ifdef HAVE_OPENCL
extern cl::Context* g_clContext;
#endif

#endif