<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Yes, it is  surprise for me in Intel® Integrated Performance Primitives</title>
    <link>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-clamp-clip-some-data/m-p/1164071#M26693</link>
    <description>&lt;P&gt;Yes, it is&amp;nbsp; surprise for me too. Looks like because&amp;nbsp;&amp;nbsp;ippsThreshold_LTValGTVal_64f_I has additional parameters for replacement and therefore does additional work that affect performance. Could you please measure&amp;nbsp;with big enough volume of data &amp;gt; L3 cache?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Nov 2018 17:11:05 GMT</pubDate>
    <dc:creator>Andrey_B_Intel</dc:creator>
    <dc:date>2018-11-27T17:11:05Z</dc:date>
    <item>
      <title>How to clamp/clip some data?</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-clamp-clip-some-data/m-p/1164066#M26688</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I'd like to take advantage of IPP library and vectorization, applying a clamp/clip to an array of double (or better, to a sum of each item in two arrays of double).&lt;/P&gt;&lt;P&gt;Actual code is somethings like this:&lt;/P&gt;
&lt;PRE class="brush:cpp; class-name:dark;"&gt;double *pStart = mStartVoicesValues[voiceIndex];	
double *pMod = pModValues + voiceIndex * bufferSize;
double *pValue = mProcessedValues[voiceIndex];	

for (int sampleIndex = 0; sampleIndex &amp;lt; blockSize; sampleIndex++) {
	pValue[sampleIndex] = std::clamp(pStart[sampleIndex] + pMod[sampleIndex], 0.0, 1.0);
}&lt;/PRE&gt;

&lt;P&gt;Called often, with variable blockSize. It sum each other&amp;nbsp;pStart and&amp;nbsp;pMod, and clip if they are below/over 0.0/1.0 (for each value on each array).&amp;nbsp;Clearly, the three arrays are equals in sizes.&amp;nbsp;Note: I could also copy the result on&amp;nbsp;pStart, without using the third array&amp;nbsp;pValue.&lt;/P&gt;
&lt;P&gt;Which IPP do you suggest?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 14:49:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-clamp-clip-some-data/m-p/1164066#M26688</guid>
      <dc:creator>markzzz</dc:creator>
      <dc:date>2018-11-23T14:49:36Z</dc:date>
    </item>
    <item>
      <title>IPP doesn't offer exactly</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-clamp-clip-some-data/m-p/1164067#M26689</link>
      <description>&lt;P&gt;IPP doesn't offer exactly such function but using&amp;nbsp;&lt;A href="https://software.intel.com/en-us/ipp-dev-reference-addproduct"&gt;ippsAddProduct_64f&lt;/A&gt;(...)&amp;nbsp; &amp;nbsp;and then try to take the&amp;nbsp;the threshold computation by calling&amp;nbsp;&lt;A href="https://software.intel.com/en-us/ipp-dev-reference-threshold"&gt;ippsThreshold_64fc_I&lt;/A&gt;(). All of these&amp;nbsp;may help to see some speedup.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Nov 2018 02:50:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-clamp-clip-some-data/m-p/1164067#M26689</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2018-11-24T02:50:00Z</dc:date>
    </item>
    <item>
      <title>Quote:Gennady F. (Intel)</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-clamp-clip-some-data/m-p/1164068#M26690</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Gennady F. (Intel) wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IPP doesn't offer exactly such function but using&amp;nbsp;&lt;A href="https://software.intel.com/en-us/ipp-dev-reference-addproduct"&gt;ippsAddProduct_64f&lt;/A&gt;(...)&amp;nbsp; &amp;nbsp;and then try to take the&amp;nbsp;the threshold computation by calling&amp;nbsp;&lt;A href="https://software.intel.com/en-us/ipp-dev-reference-threshold"&gt;ippsThreshold_64fc_I&lt;/A&gt;(). All of these&amp;nbsp;may help to see some speedup.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the reply :) I believe you meant Add, not AddProduct.&lt;/P&gt;&lt;P&gt;So the result will be:&lt;/P&gt;
&lt;PRE class="brush:; class-name:dark;"&gt;ippsAdd_64f(pStart, pMod,&amp;nbsp;pValue, blockSize);
ippsThreshold_64f_I(pValue, blockSize, 0.0,&amp;nbsp;ippCmpLess);
ippsThreshold_64f_I(pValue, blockSize, 1.0,&amp;nbsp;ippCmpGreater);&lt;/PRE&gt;

&lt;P&gt;It seems&amp;nbsp;Threshold a bit redundant, isn't?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Nov 2018 08:53:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-clamp-clip-some-data/m-p/1164068#M26690</guid>
      <dc:creator>markzzz</dc:creator>
      <dc:date>2018-11-26T08:53:44Z</dc:date>
    </item>
    <item>
      <title>Quote:markzzz wrote:</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-clamp-clip-some-data/m-p/1164069#M26691</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;markzzz wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It seems&amp;nbsp;Threshold a bit redundant, isn't?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, there is special function&amp;nbsp;ippsThreshold_LTValGTVal_64f_I in ipps.h.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Nov 2018 16:18:53 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-clamp-clip-some-data/m-p/1164069#M26691</guid>
      <dc:creator>Andrey_B_Intel</dc:creator>
      <dc:date>2018-11-26T16:18:53Z</dc:date>
    </item>
    <item>
      <title>Funny :)</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-clamp-clip-some-data/m-p/1164070#M26692</link>
      <description>&lt;P&gt;Funny :)&lt;/P&gt;&lt;P&gt;In the end, this:&lt;/P&gt;
&lt;PRE class="brush:; class-name:dark;"&gt;ippsAdd_64f(mSmoothedValues, pMod, pValue, blockSize);
ippsThreshold_64f_I(pValue, blockSize, 0.0, ippCmpLess);
ippsThreshold_64f_I(pValue, blockSize, 1.0, ippCmpGreater);&lt;/PRE&gt;

&lt;P&gt;seems faster than this:&lt;/P&gt;

&lt;PRE class="brush:; class-name:dark;"&gt;ippsAdd_64f(mSmoothedValues, pMod, pValue, blockSize);
ippsThreshold_LTValGTVal_64f_I(pValue, blockSize, 0.0, 0.0, 1.0, 1.0);	&lt;/PRE&gt;

&lt;P&gt;For the test I did, ~800ms instead of ~500.&lt;/P&gt;
&lt;P&gt;Normal?&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 16:25:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-clamp-clip-some-data/m-p/1164070#M26692</guid>
      <dc:creator>markzzz</dc:creator>
      <dc:date>2018-11-27T16:25:10Z</dc:date>
    </item>
    <item>
      <title>Yes, it is  surprise for me</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-clamp-clip-some-data/m-p/1164071#M26693</link>
      <description>&lt;P&gt;Yes, it is&amp;nbsp; surprise for me too. Looks like because&amp;nbsp;&amp;nbsp;ippsThreshold_LTValGTVal_64f_I has additional parameters for replacement and therefore does additional work that affect performance. Could you please measure&amp;nbsp;with big enough volume of data &amp;gt; L3 cache?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 17:11:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-clamp-clip-some-data/m-p/1164071#M26693</guid>
      <dc:creator>Andrey_B_Intel</dc:creator>
      <dc:date>2018-11-27T17:11:05Z</dc:date>
    </item>
    <item>
      <title>Quote:Andrey Bakshaev (Intel)</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-clamp-clip-some-data/m-p/1164072#M26694</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Andrey Bakshaev (Intel) wrote:&lt;BR /&gt;Could you please measure&amp;nbsp;with big enough volume of data &amp;gt; L3 cache?&amp;nbsp;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why this would make things different? I mean, L3 is the last "chain" of the cart. I hope the cache (if any) occurs in L1 or L2. Anyway, that's the whole code of testing:&lt;/P&gt;
&lt;PRE class="brush:; class-name:dark;"&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;chrono&amp;gt;
#include &amp;lt;algorithm&amp;gt;
#include "ipp.h"

constexpr int voiceSize = 16;
constexpr int bufferSize = 256;

class Param
{
public:
	double mMin, mRange;

	Ipp64f mSmoothedValues[bufferSize];
	Ipp64f *pModulationVoicesValues;
	Ipp64f mProcessedVoicesValues[voiceSize][bufferSize];

	Param(double min, double max) : mMin { min }, mRange{ max - min } { }

	inline void AddModulation(int voiceIndex, int blockSize) {
		Ipp64f *pMod = pModulationVoicesValues + voiceIndex * bufferSize;
		Ipp64f *pValue = mProcessedVoicesValues[voiceIndex];

		// add modulation
		ippsAdd_64f(mSmoothedValues, pMod, pValue, blockSize);
		//ippsThreshold_64f_I(pValue, blockSize, 0.0, ippCmpLess);
		//ippsThreshold_64f_I(pValue, blockSize, 1.0, ippCmpGreater);
		ippsThreshold_LTValGTVal_64f_I(pValue, blockSize, 0.0, 0.0, 1.0, 1.0);
	}
};

class MyPlugin
{
public:
	Ipp64f gainModValues[voiceSize][bufferSize];
	Ipp64f offsetModValues[voiceSize][bufferSize];
	Ipp64f pitchModValues[voiceSize][bufferSize];
	
	Param mGain{ 0.0, 1.0 };
	Param mOffset{ -900.0, 900.0 };
	Param mPitch{ -48.0, 48.0 };

	MyPlugin() {
		// link mod arrays to params
		mGain.pModulationVoicesValues = gainModValues[0];
		mOffset.pModulationVoicesValues = offsetModValues[0];
		mPitch.pModulationVoicesValues = pitchModValues[0];

		// fancy data for smooth at audio rate
		for (int sampleIndex = 0; sampleIndex &amp;lt; bufferSize; sampleIndex++) {
			mGain.mSmoothedValues[sampleIndex] = 0.5;
			mOffset.mSmoothedValues[sampleIndex] = 0.5;
			mPitch.mSmoothedValues[sampleIndex] = 0.5;
		}

		// fancy data for mod at audio rate
		for (int voiceIndex = 0; voiceIndex &amp;lt; voiceSize; voiceIndex++) {
			for (int sampleIndex = 0; sampleIndex &amp;lt; bufferSize; sampleIndex++) {
				double value = (sampleIndex / ((double)bufferSize - 1)) * 2.0 - 1.0;

				gainModValues[voiceIndex][sampleIndex] = value;
				offsetModValues[voiceIndex][sampleIndex] = value;
				pitchModValues[voiceIndex][sampleIndex] = value;
			}
		}
	}
	~MyPlugin() { }

	void Process(int blockSize) {
		// voices
		for (int voiceIndex = 0; voiceIndex &amp;lt; voiceSize; voiceIndex++) {
			// add modulation
			mGain.AddModulation(voiceIndex, blockSize);
			mOffset.AddModulation(voiceIndex, blockSize);
			mPitch.AddModulation(voiceIndex, blockSize);
		}
	}
};

int main() {
	std::chrono::high_resolution_clock::time_point pStart;
	std::chrono::high_resolution_clock::time_point pEnd;
	MyPlugin myPlugin;

	// audio host call
	long long numProcessing = 1024 * 50;
	long long counterProcessing = 0;
	pStart = std::chrono::high_resolution_clock::now();
	while (counterProcessing++ &amp;lt; numProcessing) {
		// variable blockSize (i.e. it can vary)
		int blockSize = 256;

		// process data
		myPlugin.Process(blockSize);
	}
	pEnd = std::chrono::high_resolution_clock::now();
	std::cout &amp;lt;&amp;lt; "execution time: " &amp;lt;&amp;lt; std::chrono::duration_cast&amp;lt;std::chrono::milliseconds&amp;gt;(pEnd - pStart).count() &amp;lt;&amp;lt; " ms" &amp;lt;&amp;lt; std::endl;
}&lt;/PRE&gt;

&lt;P&gt;(comment/uncomment the twice&amp;nbsp;ippsThreshold_64f_I or single&amp;nbsp;ippsThreshold_LTValGTVal_64f_I to test the differences).&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 08:03:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-clamp-clip-some-data/m-p/1164072#M26694</guid>
      <dc:creator>markzzz</dc:creator>
      <dc:date>2018-11-28T08:03:14Z</dc:date>
    </item>
  </channel>
</rss>

