Convolve
Calculates the linear convolution of the src1 vector (whose length is src1Len) and src2 vector (whose length is src2Len), and stores the result in the dst vector. The formula is as follows:

The function is called as follows:
- Initialize the HmppsCorrPolicy_32f structure by calling an initialization function.
- Call the main function.
- Call Release to release the memory contained in the HmppsCorrPolicy_32f function.
The function interface is declared as follows:
- Initialization:
HmppResult HMPPS_ConvInit_32f(int32_t src1Len, int32_t src2Len, HmppCalcMode calcMode, HmppsConvPolicy_32f **policy);
HmppResult HMPPS_ConvInit_64f(int32_t src1Len, int32_t src2Len, HmppCalcMode calcMode, HmppsConvPolicy_64f **policy);
- Main functions:
HmppResult HMPPS_Convolve_32f(const float *src1, int32_t src1Len, const float *src2, int32_t src2Len, float *dst, HmppsConvPolicy_32f *policy);
HmppResult HMPPS_Convolve_64f(const double *src1, int32_t src1Len, const double *src2, int32_t src2Len, double *dst, HmppsConvPolicy_64f *policy);
- Memory release:
HmppResult HMPPS_ConvRelease_32f(HmppsConvPolicy_32f *policy);
HmppResult HMPPS_ConvRelease_64f(HmppsConvPolicy_64f *policy);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src1 |
Pointer to the first source vector |
The value cannot be NULL. |
Input |
src1Len |
Length of the first source vector |
(0, INT_MAX] |
Input |
src2 |
Pointer to the second source vector |
The value cannot be NULL. |
Input |
src2Len |
Length of the second source vector |
(0, INT_MAX] |
Input |
dst |
Pointer to the destination vector |
The value cannot be NULL. |
Output |
algMode |
Algorithm model used for the calculation (defined in the HmppAlgMode enumeration type. See Enumeration Types.) |
The value is an element of HmppAlgMode:
|
Input |
policy (in the Init function) |
Pointer to the memory that stores ConvPolicy |
The value cannot be NULL. |
Output |
policy (In the main function and the Release function) |
Pointer to the ConvPolicy structure |
The value cannot be NULL. |
Input |
Return Value
- Success: HMPP_STS_NO_ERR
- Failure: An error code is returned.
Error Codes
Error Code |
Description |
|---|---|
HMPP_STS_NO_ERR |
No error occurs. |
HMPP_STS_NULL_PTR_ERR |
Any of the specified pointers is NULL. |
HMPP_STS_SIZE_ERR |
The value of src1Len or src2Len is less than or equal to 0. |
HMPP_STS_MISMATCH |
The size of the problem that the Init function applies for memory does not match the size of the problem that is actually calculated in the main function. |
HMPP_STS_OVERFLOW_ERR |
The problem size of the FFT acceleration model is too large. |
HMPP_STS_MALLOC_FAILED |
The Init function failed to allocate the memory required by the algorithm model. |
Note
- Before this interface is called for calculation, the Init interface must be called to initialize the HmppsConvPolicy_32f standard structure.
- The initialization of the HmppsConvPolicy_32f structure needs to be applied for in the Init function. You cannot apply for or define this structure by yourself.
- src1, src2, and dst cannot be the same array. Otherwise, the result may be incorrect.
- When the HMPP_ALG_AUTO or HMPP_ALG_FFT mode is used, the "OVERFLOW" error message is displayed if src1Len or src2Len is large.
Example
void Convolve_Example()
{
const int src1Len = 10;
const int src2Len = 10;
float src1[src1Len];
float src2[src2Len];
float dst[src1Len + src2Len - 1];
for (int i = 0; i < src1Len; ++i) src1[i] = 1;
for (int i = 0; i < src2Len; ++i) src2[i] = 1;
HmppsConvPolicy_32f *policy = NULL;
HmppResult result = HMPPS_ConvInit_32f(src1Len, src2Len, HMPP_ALG_FFT, &policy);
if (result != HMPP_STS_NO_ERR) {
printf("Init failed");
return;
}
result = HMPPS_Convolve_32f(src1, src1Len, src2, src2Len, dst, policy);
if (result != HMPP_STS_NO_ERR) {
printf("Convolve failed");
return;
}
for (int i = 0; i < src1Len + src2Len - 1; ++i) {
printf("%.2f ", dst[i]);
}
HMPPS_ConvRelease_32f(policy);
}
Output:
1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1