/*
 *  ******************************************************************************
 *  *
 *  *
 *  * This program and the accompanying materials are made available under the
 *  * terms of the Apache License, Version 2.0 which is available at
 *  * https://www.apache.org/licenses/LICENSE-2.0.
 *  *
 *  *  See the NOTICE file distributed with this work for additional
 *  *  information regarding copyright ownership.
 *  * Unless required by applicable law or agreed to in writing, software
 *  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 *  * License for the specific language governing permissions and limitations
 *  * under the License.
 *  *
 *  * SPDX-License-Identifier: Apache-2.0
 *  *****************************************************************************
 */
package org.deeplearning4j.nn.layers;

import lombok.extern.slf4j.Slf4j;
import org.deeplearning4j.common.config.DL4JClassLoading;
import org.nd4j.linalg.factory.Nd4j;

/**
 * Simple meta helper util class for instantiating
 * platform specific layer helpers that handle interaction with
 * lower level libraries like cudnn and onednn.
 *
 * @author Adam Gibson
 */
@Slf4j
public class HelperUtils {

    /**
     * Creates a {@link LayerHelper}
     * for use with platform specific code.
     * @param <T> the actual class type to be returned
     * @param cudnnHelperClassName the cudnn class name
     * @param oneDnnClassName the one dnn class name
     * @param layerHelperSuperClass the layer helper super class
     * @param layerName the name of the layer to be created
     * @param arguments the arguments to be used in creation of the layer
     * @return
     */
    public static <T extends LayerHelper> T createHelper(String cudnnHelperClassName,
                                                         String oneDnnClassName,
                                                         Class<? extends LayerHelper> layerHelperSuperClass,
                                                         String layerName,
                                                         Object... arguments) {
        String backend = Nd4j.getExecutioner().getEnvironmentInformation().getProperty("backend");
        LayerHelper helperRet = null;
        if("CUDA".equalsIgnoreCase(backend)) {
            if(DL4JClassLoading.loadClassByName(cudnnHelperClassName) != null) {
                log.debug("Attempting to initialize cudnn helper {}",cudnnHelperClassName);
                helperRet =  DL4JClassLoading.createNewInstance(
                        cudnnHelperClassName,
                        layerHelperSuperClass,
                        arguments);
                log.debug("Cudnn helper {} successfully initialized",cudnnHelperClassName);

            }
            else {
                log.warn("Unable to find class {}  using the classloader set for Dl4jClassLoading. Trying to use class loader that loaded the  class {} instead.",cudnnHelperClassName,layerHelperSuperClass.getName());
                ClassLoader classLoader = DL4JClassLoading.getDl4jClassloader();
                DL4JClassLoading.setDl4jClassloaderFromClass(layerHelperSuperClass);
                try {
                    helperRet = DL4JClassLoading.createNewInstance(
                            cudnnHelperClassName,
                            layerHelperSuperClass,
                            arguments);

                } catch (Exception e) {
                    log.warn("Unable to use  helper implementation {} for helper type {}, please check your classpath. Falling back to built in  normal  methods for now.",cudnnHelperClassName,layerHelperSuperClass.getName());
                }

                log.warn("Returning class loader to original one.");
                DL4JClassLoading.setDl4jClassloader(classLoader);

            }

            if (helperRet != null && !helperRet.checkSupported()) {
                return null;
            }

            if(helperRet != null) {
                log.debug("{} successfully initialized",cudnnHelperClassName);
            }

        } else if("CPU".equalsIgnoreCase(backend)) {
            helperRet =  DL4JClassLoading.createNewInstance(
                    oneDnnClassName,
                    arguments);
            log.trace("Created oneDNN helper: {}, layer {}", oneDnnClassName,layerName);
        }

        if (helperRet != null && !helperRet.checkSupported()) {
            log.debug("Removed helper {} as not supported", helperRet.getClass());
            return null;
        }

        return (T) helperRet;
    }

}

@@ -2364,32 +2364,99 @@
 oreCase(backend)
+ && cudnnHelperClassName != null && !cudnnHelperClassName.isEmpty()
 ) %7B%0A            
@@ -4278,16 +4278,73 @@
 backend)
+ && oneDnnClassName != null && !oneDnnClassName.isEmpty()
 ) %7B%0A    

Allow empty class names and return null as proper case