Skip to content

Commit

Permalink
Remove ffts dep for Apple Silicon targets.
Browse files Browse the repository at this point in the history
Disables OFDMDemodulator, SpectrogramFilter, and TDRStepDeEmbedFilter.
Disables LPF in TestWaveformSource.
  • Loading branch information
lain committed Sep 25, 2022
1 parent 8318e59 commit 576eb21
Show file tree
Hide file tree
Showing 19 changed files with 145 additions and 32 deletions.
20 changes: 13 additions & 7 deletions scopeexports/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ set(SCOPEEXPORTS_SOURCES
add_library(scopeexports SHARED
${SCOPEEXPORTS_SOURCES})

target_link_libraries(scopeexports
scopehal
${LIBFFTS_LIBRARIES})

target_include_directories(scopeexports
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
${LIBFFTS_INCLUDE_DIR})
if(APPLE_SILICON)
target_link_libraries(scopeexports
scopehal)
target_include_directories(scopeexports
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
else()
target_link_libraries(scopeexports
scopehal
${LIBFFTS_LIBRARIES})
target_include_directories(scopeexports
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
${LIBFFTS_INCLUDE_DIR})
endif()

install(TARGETS scopeexports LIBRARY)
57 changes: 45 additions & 12 deletions scopehal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,25 @@ target_link_libraries(scopehal
OSDependent
glfw
)
elseif(APPLE_SILICON)
target_link_libraries(scopehal
${SIGCXX_LIBRARIES}
${GTKMM_LIBRARIES}
xptools
log
graphwidget
${YAML_LIBRARIES}
${LXI_LIBRARIES}
${LINUXGPIB_LIBRARIES}
${WIN_LIBS}
${LIN_LIBS}
${OpenMP_CXX_LIBRARIES}
${Vulkan_LIBRARIES}
Vulkan::Vulkan
Vulkan::glslang
Vulkan::shaderc_combined
glfw
)
else()
target_link_libraries(scopehal
${SIGCXX_LIBRARIES}
Expand All @@ -192,18 +211,32 @@ target_link_libraries(scopehal
)
endif()

target_include_directories(scopehal
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${LIBFFTS_INCLUDE_DIR}
${YAML_INCLUDES}

# TODO: this needs to come from FindPackage etc
/usr/include/glslang/Include
# for macOS:
/usr/local/include/glslang/Include
)
if(APPLE_SILICON)
target_include_directories(scopehal
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${YAML_INCLUDES}

# TODO: this needs to come from FindPackage etc
/usr/include/glslang/Include
# for macOS:
/usr/local/include/glslang/Include
)
else()
target_include_directories(scopehal
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${LIBFFTS_INCLUDE_DIR}
${YAML_INCLUDES}

# TODO: this needs to come from FindPackage etc
/usr/include/glslang/Include
# for macOS:
/usr/local/include/glslang/Include
)
endif()

target_include_directories(scopehal
PUBLIC SYSTEM
Expand Down
7 changes: 7 additions & 0 deletions scopehal/TestWaveformSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ using namespace std;
TestWaveformSource::TestWaveformSource(minstd_rand& rng)
: m_rng(rng)
{
#ifndef _APPLE_SILICON
m_forwardPlan = NULL;
m_reversePlan = NULL;

Expand All @@ -52,10 +53,12 @@ TestWaveformSource::TestWaveformSource(minstd_rand& rng)
m_forwardInBuf = NULL;
m_forwardOutBuf = NULL;
m_reverseOutBuf = NULL;
#endif
}

TestWaveformSource::~TestWaveformSource()
{
#ifndef _APPLE_SILICON
if(m_forwardPlan)
ffts_free(m_forwardPlan);
if(m_reversePlan)
Expand All @@ -70,6 +73,7 @@ TestWaveformSource::~TestWaveformSource()
m_forwardInBuf = NULL;
m_forwardOutBuf = NULL;
m_reverseOutBuf = NULL;
#endif
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -300,6 +304,8 @@ void TestWaveformSource::DegradeSerialData(
//RNGs
normal_distribution<> noise(0, noise_amplitude);

// ffts is not available on apple silicon, so for now we only apply noise there
#ifndef _APPLE_SILICON
//Prepare for second pass: reallocate FFT buffer if sample depth changed
const size_t npoints = next_pow2(depth);
size_t nouts = npoints/2 + 1;
Expand Down Expand Up @@ -356,6 +362,7 @@ void TestWaveformSource::DegradeSerialData(
}

else
#endif
{
for(size_t i=0; i<depth; i++)
cap->m_samples[i] += noise(m_rng);
Expand Down
4 changes: 4 additions & 0 deletions scopehal/TestWaveformSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
#define TestWaveformSource_h

#include "../scopehal/AlignedAllocator.h"
#ifndef _APPLE_SILICON
#include <ffts.h>
#endif
#include <random>

/**
Expand Down Expand Up @@ -99,6 +101,7 @@ class TestWaveformSource
protected:
std::minstd_rand& m_rng;

#ifndef _APPLE_SILICON
//FFT stuff
AlignedAllocator<float, 32> m_allocator;
ffts_plan_t* m_forwardPlan;
Expand All @@ -109,6 +112,7 @@ class TestWaveformSource
float* m_forwardInBuf;
float* m_forwardOutBuf;
float* m_reverseOutBuf;
#endif
};

#endif
26 changes: 17 additions & 9 deletions scopeprotocols/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,23 @@ set(SCOPEPROTOCOLS_SOURCES
add_library(scopeprotocols SHARED
${SCOPEPROTOCOLS_SOURCES})

target_link_libraries(scopeprotocols
scopehal
${LIBFFTS_LIBRARIES}
)

target_include_directories(scopeprotocols
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
${LIBFFTS_INCLUDE_DIR}
)
if(APPLE_SILICON)
target_link_libraries(scopeprotocols
scopehal
)
target_include_directories(scopeprotocols
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
)
else()
target_link_libraries(scopeprotocols
scopehal
${LIBFFTS_LIBRARIES}
)
target_include_directories(scopeprotocols
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
${LIBFFTS_INCLUDE_DIR}
)
endif()

# Setup for vkfft
target_compile_definitions(scopeprotocols PUBLIC -DVK_API_VERSION=10 -DVKFFT_BACKEND=0)
Expand Down
2 changes: 0 additions & 2 deletions scopeprotocols/CTLEFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#include "../scopehal/scopehal.h"
#include "CTLEFilter.h"
#include <ffts.h>
#include <complex>

using namespace std;
Expand Down Expand Up @@ -141,4 +140,3 @@ void CTLEFilter::Refresh(vk::raii::CommandBuffer& cmdBuf, vk::raii::Queue& queue
//Do the actual refresh operation
DoRefresh(false, cmdBuf, queue);
}

1 change: 0 additions & 1 deletion scopeprotocols/ChannelEmulationFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#include "../scopehal/scopehal.h"
#include "ChannelEmulationFilter.h"
#include <ffts.h>

using namespace std;

Expand Down
14 changes: 14 additions & 0 deletions scopeprotocols/DeEmbedFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ DeEmbedFilter::DeEmbedFilter(const string& color)

m_cachedBinSize = 0;

#ifndef _APPLE_SILICON
m_forwardPlan = NULL;
m_reversePlan = NULL;
#endif

m_cachedNumPoints = 0;
m_cachedMaxGain = 0;
Expand All @@ -84,13 +86,15 @@ DeEmbedFilter::DeEmbedFilter(const string& color)

DeEmbedFilter::~DeEmbedFilter()
{
#ifndef _APPLE_SILICON
if(m_forwardPlan)
ffts_free(m_forwardPlan);
if(m_reversePlan)
ffts_free(m_reversePlan);

m_forwardPlan = NULL;
m_reversePlan = NULL;
#endif
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -190,6 +194,7 @@ void DeEmbedFilter::DoRefresh(bool invert, vk::raii::CommandBuffer& cmdBuf, vk::
bool sizechange = false;
if(m_cachedNumPoints != npoints)
{
#ifndef _APPLE_SILICON
//Delete old FFTS plan objects
if(m_forwardPlan)
{
Expand All @@ -201,6 +206,7 @@ void DeEmbedFilter::DoRefresh(bool invert, vk::raii::CommandBuffer& cmdBuf, vk::
ffts_free(m_reversePlan);
m_reversePlan = nullptr;
}
#endif

m_forwardInBuf.resize(npoints);
m_forwardOutBuf.resize(2 * nouts);
Expand All @@ -213,8 +219,12 @@ void DeEmbedFilter::DoRefresh(bool invert, vk::raii::CommandBuffer& cmdBuf, vk::
//(save time, don't make FFTS plans if using vkFFT)
if(!g_gpuFilterEnabled)
{
#ifdef _APPLE_SILICON
LogFatal("DeEmbedFilter CPU fallback not available on Apple Silicon");
#else
m_forwardPlan = ffts_init_1d_real(npoints, FFTS_FORWARD);
m_reversePlan = ffts_init_1d_real(npoints, FFTS_BACKWARD);
#endif
}
}

Expand Down Expand Up @@ -353,6 +363,9 @@ void DeEmbedFilter::DoRefresh(bool invert, vk::raii::CommandBuffer& cmdBuf, vk::
cap->MarkModifiedFromGpu();
}
else
#ifdef _APPLE_SILICON
LogFatal("DeEmbedFilter CPU fallback not available on Apple Silicon");
#else
{
din->PrepareForCpuAccess();
m_forwardInBuf.PrepareForCpuAccess();
Expand Down Expand Up @@ -385,6 +398,7 @@ void DeEmbedFilter::DoRefresh(bool invert, vk::raii::CommandBuffer& cmdBuf, vk::

cap->MarkModifiedFromCpu();
}
#endif
}

/**
Expand Down
2 changes: 2 additions & 0 deletions scopeprotocols/DeEmbedFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ class DeEmbedFilter : public Filter
AcceleratorBuffer<float> m_resampledSparamSines;
AcceleratorBuffer<float> m_resampledSparamCosines;

#ifndef _APPLE_SILICON
ffts_plan_t* m_forwardPlan;
ffts_plan_t* m_reversePlan;
#endif
size_t m_cachedNumPoints;

AcceleratorBuffer<float> m_forwardInBuf;
Expand Down
1 change: 0 additions & 1 deletion scopeprotocols/EnhancedResolutionFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#include "../scopehal/scopehal.h"
#include "EnhancedResolutionFilter.h"
#include <ffts.h>

using namespace std;

Expand Down
13 changes: 13 additions & 0 deletions scopeprotocols/FFTFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ FFTFilter::FFTFilter(const string& color)

m_cachedNumPoints = 0;
m_cachedNumPointsFFT = 0;
#ifndef _APPLE_SILICON
m_plan = NULL;
#endif

//Default config
m_range = 70;
Expand All @@ -81,8 +83,10 @@ FFTFilter::FFTFilter(const string& color)

FFTFilter::~FFTFilter()
{
#ifndef _APPLE_SILICON
if(m_plan)
ffts_free(m_plan);
#endif
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -144,6 +148,7 @@ void FFTFilter::ReallocateBuffers(size_t npoints_raw, size_t npoints, size_t nou
{
m_cachedNumPointsFFT = npoints;

#ifndef _APPLE_SILICON
if(g_gpuFilterEnabled)
m_plan = nullptr;

Expand All @@ -159,6 +164,10 @@ void FFTFilter::ReallocateBuffers(size_t npoints_raw, size_t npoints, size_t nou
m_rdoutbuf.SetCpuAccessHint(AcceleratorBuffer<float>::HINT_LIKELY);
m_rdoutbuf.SetGpuAccessHint(AcceleratorBuffer<float>::HINT_NEVER);
}
#else
if(!g_gpuFilterEnabled)
LogFatal("FFTFilter cpu fallback not available on Apple Silicon (yet?)");
#endif
}

//Update our FFT plan if it's out of date
Expand Down Expand Up @@ -339,6 +348,9 @@ void FFTFilter::DoRefresh(
cap->MarkModifiedFromGpu();
}
else
#ifdef _APPLE_SILICON
LogFatal("FFTFilter cpu fallback not available on Apple Silicon (yet?)");
#else
{
data.PrepareForCpuAccess();
m_rdinbuf.PrepareForCpuAccess();
Expand Down Expand Up @@ -379,6 +391,7 @@ void FFTFilter::DoRefresh(

cap->MarkModifiedFromCpu();
}
#endif

//Peak search
FindPeaks(cap);
Expand Down
4 changes: 4 additions & 0 deletions scopeprotocols/FFTFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
#ifndef FFTFilter_h
#define FFTFilter_h

#ifndef _APPLE_SILICON
#include <ffts.h>
#endif

#ifdef HAVE_CLFFT
#include <clFFT.h>
Expand Down Expand Up @@ -130,7 +132,9 @@ class FFTFilter : public PeakDetectionFilter
size_t m_cachedNumPointsFFT;
AcceleratorBuffer<float> m_rdinbuf;
AcceleratorBuffer<float> m_rdoutbuf;
#ifndef _APPLE_SILICON
ffts_plan_t* m_plan;
#endif

float m_range;
float m_offset;
Expand Down

0 comments on commit 576eb21

Please sign in to comment.