Skip to content

FIX: Check each error code instead of just last #3226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

david-cortes-intel
Copy link
Contributor

Description

This PR modifies the logic for summary statistics to make a check after each call to MKL to verify that no error occurred, instead of checking only the last one. Theoretically it shouldn't matter as only the 'compute' step is somewhat expected to fail when the rest of the procedure is correct, but internal errors in logic can still happen.


PR should start as a draft, then move to ready for review state after CI is passed and all applicable checkboxes are closed.
This approach ensures that reviewers don't spend extra time asking for regular requirements.

You can remove a checkbox as not applicable only if it doesn't relate to this PR in any way.
For example, PR with docs update doesn't require checkboxes for performance while PR with any change in actual code should have checkboxes and justify how this code change is expected to affect performance (or justification should be self-evident).

Checklist to comply with before moving PR from draft:

PR completeness and readability

  • I have reviewed my changes thoroughly before submitting this pull request.
  • Git commit message contains an appropriate signed-off-by string (see CONTRIBUTING.md for details).
  • I have added a respective label(s) to PR if I have a permission for that.
  • I have resolved any merge conflicts that might occur with the base branch.

Testing

  • I have run it locally and tested the changes extensively.
  • All CI jobs are green or I have provided justification why they aren't.

@david-cortes-intel
Copy link
Contributor Author

/intelci: run

1 similar comment
@david-cortes-intel
Copy link
Contributor Author

/intelci: run

@david-cortes-intel
Copy link
Contributor Author

/intelci: run

@david-cortes-intel
Copy link
Contributor Author

CI failures are either timeouts, or not related to the changes here.

__DAAL_VSLFN_CALL(vsliSSEditTask, (task, __DAAL_VSL_SS_ED_CP_STORAGE, (const MKL_INT *)&cpStorage), errcode);
__DAAL_VSLFN_CALL(vsldSSEditTask, (task, __DAAL_VSL_SS_ED_ACCUM_WEIGHT, weight), errcode);
__DAAL_VSLFN_CALL(vsldSSCompute, (task, __DAAL_VSL_SS_CP | __DAAL_VSL_SS_SUM, method), errcode);
__DAAL_VSLFN_CALL_WITH_CLEANUP(
Copy link
Contributor

@Vika-F Vika-F Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it in more c++ way. Something like this:

    #define __DAAL_VSLFN_CALL_AND_CHECK_ERROR(f_name, f_args, errcode)      \
        errcode = f_name f_args;                                            \
        if (errcode != 0) return errcode;
    
    static int xcp(double * data, __int64 nFeatures, __int64 nVectors, double * nPreviousObservations, double * sum, double * crossProduct,
                   __int64 method)
    {
        struct Helper
        {
            VSLSSTaskPtr task;
            double * mean;

            Helper(__int64 nFeatures, __int64 nVectors, double * data, int &errcode)
            {
                __int64 dataStorage = __DAAL_VSL_SS_MATRIX_STORAGE_COLS;
                mean = (double *)daal::services::daal_malloc(nFeatures * sizeof(double));
                if (!mean) return;

                __DAAL_VSLFN_CALL(vsldSSNewTask, (&task, (const MKL_INT *)&nFeatures, (const MKL_INT *)&nVectors, (const MKL_INT *)&dataStorage, data, 0, 0), errcode);
            }

            ~Helper()
            {
                int errcode = 0;
                __DAAL_VSLFN_CALL(vslSSDeleteTask, (&task), errcode);
                daal::services::daal_free(mean);
            }
            
            //  rule of three
            Helper(const Helper&) = delete;
            Helper& operator=(const Helper&) = delete;
        }
        
        int errcode = 0;
        __int64 cpStorage   = __DAAL_VSL_SS_MATRIX_STORAGE_FULL;
        Helper helper(nFeatures, nVectors, data, errcode);
        if (!helper.mean)
            return VSL_SS_ERROR_ALLOCATION_FAILURE;
        if (errcode != 0)
            return errcode;
        if (method == __DAAL_VSL_SS_METHOD_FAST_USER_MEAN)
        {
            double invNVectors = 1.0 / (double)nVectors;
            for (size_t i = 0; i < nFeatures; i++)
            {
                helper.mean[i] = sum[i] * invNVectors;
            }
        }

        double weight[2] = { *nPreviousObservations, *nPreviousObservations };

        __DAAL_VSLFN_CALL_AND_CHECK_ERROR(vsldSSEditTask, (helper.task, __DAAL_VSL_SS_ED_SUM, sum), errcode);
        __DAAL_VSLFN_CALL_AND_CHECK_ERROR(vsldSSEditTask, (helper.task, __DAAL_VSL_SS_ED_MEAN, helper.mean), errcode);
        __DAAL_VSLFN_CALL_AND_CHECK_ERROR(vsldSSEditTask, (helper.task, __DAAL_VSL_SS_ED_CP, crossProduct), errcode);
        __DAAL_VSLFN_CALL_AND_CHECK_ERROR(vsliSSEditTask, (helper.task, __DAAL_VSL_SS_ED_CP_STORAGE, (const MKL_INT *)&cpStorage), errcode);
        __DAAL_VSLFN_CALL_AND_CHECK_ERROR(vsldSSEditTask, (helper.task, __DAAL_VSL_SS_ED_ACCUM_WEIGHT, weight), errcode);
        __DAAL_VSLFN_CALL_AND_CHECK_ERROR(vsldSSCompute, (helper.task, __DAAL_VSL_SS_CP | __DAAL_VSL_SS_SUM, method), errcode);

        return errcode;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants