Search in sources :

Example 1 with Method

use of es.bsc.compss.types.annotations.task.Method in project compss by bsc-wdc.

the class Test method constraintManagerTest.

/*
     * *************************************** CONSTRAINT MANAGER TEST IMPLEMENTATION
     * ***************************************
     */
@SuppressWarnings("unchecked")
private static void constraintManagerTest() {
    // Check if the number of tasks from ITF and core is the same
    java.lang.reflect.Method[] declaredMethodsItf = TestItf.class.getDeclaredMethods();
    coreCountItf = declaredMethodsItf.length;
    if (CoreManager.getCoreCount() != coreCountItf) {
        System.out.println("[ERROR]" + CoreManager.getCoreCount() + " CE registered in the runtime and  " + coreCountItf + " declared in the CEI");
        System.exit(-1);
    }
    // Loading data from Cores
    signatureToId = CoreManager.getSignaturesToId();
    idToSignatures = new LinkedList[coreCountItf];
    for (int coreId = 0; coreId < coreCountItf; coreId++) {
        idToSignatures[coreId] = new LinkedList<String>();
    }
    for (Entry<String, Integer> entry : signatureToId.entrySet()) {
        String signature = entry.getKey();
        Integer coreId = entry.getValue();
        idToSignatures[coreId].add(signature);
    }
    // Loading Information from the interface
    declaringClassesItf = new String[coreCountItf][];
    constraintsItf = new Constraints[coreCountItf][];
    generalConstraintsItf = new Constraints[coreCountItf];
    coreToName = new String[coreCountItf];
    for (int i = 0; i < coreCountItf; i++) {
        int cutValue1 = idToSignatures[i].getFirst().indexOf("(");
        int cutValue2 = idToSignatures[i].getFirst().indexOf(")");
        coreToName[i] = idToSignatures[i].getFirst().substring(0, cutValue1);
        String params = idToSignatures[i].getFirst().substring(cutValue1, cutValue2);
        java.lang.reflect.Method m = null;
        try {
            if (params.equals("(")) {
                m = TestItf.class.getDeclaredMethod(coreToName[i], new Class[] {});
            } else {
                m = TestItf.class.getDeclaredMethod(coreToName[i], new Class[] { String.class });
            }
        } catch (NoSuchMethodException nsme) {
            System.out.println("[ERROR] Method " + coreToName[i] + "not found.");
            System.exit(-1);
        }
        // Add general constraints
        if (m.isAnnotationPresent(Constraints.class)) {
            generalConstraintsItf[i] = m.getAnnotation(Constraints.class);
        }
        // Get declaring class of each method annotation
        Method[] annotations = m.getAnnotationsByType(Method.class);
        declaringClassesItf[i] = new String[annotations.length];
        for (int j = 0; j < annotations.length; ++j) {
            Method methodAnnotation = annotations[j];
            declaringClassesItf[i][j] = methodAnnotation.declaringClass();
        }
        // Get specific constraints of each method annotation
        constraintsItf[i] = new Constraints[annotations.length];
        for (int j = 0; j < annotations.length; ++j) {
            Method methodAnnotation = annotations[j];
            constraintsItf[i][j] = methodAnnotation.constraints();
        }
    }
    // Check all cores
    for (int i = 0; i < coreCountItf; i++) {
        if (declaringClassesItf[i] != null) {
            checkCoreElementConstraints(i);
        }
    }
}
Also used : Method(es.bsc.compss.types.annotations.task.Method) Constraints(es.bsc.compss.types.annotations.Constraints)

Example 2 with Method

use of es.bsc.compss.types.annotations.task.Method in project compss by bsc-wdc.

the class ITFParser method checkDefinedImplementations.

/**
 * Check all the defined implementations of the same method
 *
 * @param m
 * @param methodId
 * @param calleeMethodSignature
 * @param hasStreams
 * @param implementations
 * @param signatures
 */
private static void checkDefinedImplementations(java.lang.reflect.Method m, Integer methodId, StringBuilder calleeMethodSignature, boolean hasStreams, boolean hasPrefixes, List<Implementation> implementations, List<String> signatures) {
    /*
         * Global constraints of the method
         */
    MethodResourceDescription defaultConstraints = MethodResourceDescription.EMPTY_FOR_CONSTRAINTS.copy();
    if (m.isAnnotationPresent(Constraints.class)) {
        defaultConstraints = new MethodResourceDescription(m.getAnnotation(Constraints.class));
    }
    /*
         * Check all annotations present at the method for versioning
         */
    String methodName = m.getName();
    int implId = 0;
    /*
         * METHOD
         */
    for (Method methodAnnot : m.getAnnotationsByType(Method.class)) {
        LOGGER.debug("   * Processing @Method annotation");
        // Warning for ignoring streams
        if (hasStreams) {
            ErrorManager.warn("Java method " + methodName + " does not support stream annotations. SKIPPING stream annotation");
        }
        // Warning for ignoring prefixes
        if (hasPrefixes) {
            ErrorManager.warn("Java method " + methodName + " does not support prefix annotations. SKIPPING prefix annotation");
        }
        String declaringClass = methodAnnot.declaringClass();
        String methodSignature = calleeMethodSignature.toString() + declaringClass;
        signatures.add(methodSignature);
        // Load specific method constraints if present
        MethodResourceDescription implConstraints = defaultConstraints;
        if (methodAnnot.constraints() != null) {
            implConstraints = new MethodResourceDescription(methodAnnot.constraints());
            implConstraints.mergeMultiConstraints(defaultConstraints);
        }
        // Register method implementation
        Implementation impl = new MethodImplementation(declaringClass, methodName, methodId, implId, implConstraints);
        ++implId;
        implementations.add(impl);
    }
    /*
         * SERVICE
         */
    for (Service serviceAnnot : m.getAnnotationsByType(Service.class)) {
        // Services don't have constraints
        LOGGER.debug("   * Processing @Service annotation");
        // Warning for ignoring streams
        if (hasStreams) {
            ErrorManager.warn("Java service " + methodName + " does not support stream annotations. SKIPPING stream annotation");
        }
        calleeMethodSignature.append(serviceAnnot.namespace()).append(',');
        calleeMethodSignature.append(serviceAnnot.name()).append(',');
        calleeMethodSignature.append(serviceAnnot.port());
        String serviceSignature = calleeMethodSignature.toString();
        signatures.add(serviceSignature);
        // Register service implementation
        Implementation impl = new ServiceImplementation(methodId, serviceAnnot.namespace(), serviceAnnot.name(), serviceAnnot.port(), serviceAnnot.operation());
        ++implId;
        implementations.add(impl);
    }
    /*
         * MPI
         */
    for (MPI mpiAnnot : m.getAnnotationsByType(MPI.class)) {
        LOGGER.debug("   * Processing @MPI annotation");
        String binary = EnvironmentLoader.loadFromEnvironment(mpiAnnot.binary());
        String workingDir = EnvironmentLoader.loadFromEnvironment(mpiAnnot.workingDir());
        String mpiRunner = EnvironmentLoader.loadFromEnvironment(mpiAnnot.mpiRunner());
        if (mpiRunner == null || mpiRunner.isEmpty()) {
            ErrorManager.error("Empty mpiRunner annotation for method " + m.getName());
        }
        if (binary == null || binary.isEmpty()) {
            ErrorManager.error("Empty binary annotation for method " + m.getName());
        }
        LOGGER.debug("Binary: " + binary);
        LOGGER.debug("mpiRunner: " + mpiRunner);
        String mpiSignature = calleeMethodSignature.toString() + LoaderUtils.MPI_SIGNATURE;
        signatures.add(mpiSignature);
        // Load specific method constraints if present
        MethodResourceDescription implConstraints = defaultConstraints;
        if (mpiAnnot.constraints() != null) {
            implConstraints = new MethodResourceDescription(mpiAnnot.constraints());
            implConstraints.mergeMultiConstraints(defaultConstraints);
        }
        // Register method implementation
        Implementation impl = new MPIImplementation(binary, workingDir, mpiRunner, methodId, implId, implConstraints);
        ++implId;
        implementations.add(impl);
    }
    /*
         * Decaf
         */
    for (Decaf decafAnnot : m.getAnnotationsByType(Decaf.class)) {
        LOGGER.debug("   * Processing @DECAF annotation");
        String dfScript = EnvironmentLoader.loadFromEnvironment(decafAnnot.dfScript());
        String dfExecutor = EnvironmentLoader.loadFromEnvironment(decafAnnot.dfExecutor());
        String dfLib = EnvironmentLoader.loadFromEnvironment(decafAnnot.dfLib());
        String workingDir = EnvironmentLoader.loadFromEnvironment(decafAnnot.workingDir());
        String mpiRunner = EnvironmentLoader.loadFromEnvironment(decafAnnot.mpiRunner());
        if (mpiRunner == null || mpiRunner.isEmpty()) {
            ErrorManager.error("Empty mpiRunner annotation for method " + m.getName());
        }
        if (dfScript == null || dfScript.isEmpty()) {
            ErrorManager.error("Empty binary annotation for method " + m.getName());
        }
        LOGGER.debug("DF Script: " + dfScript);
        LOGGER.debug("DF Executor: " + dfExecutor);
        LOGGER.debug("DF Lib: " + dfLib);
        LOGGER.debug("mpiRunner: " + mpiRunner);
        String mpiSignature = calleeMethodSignature.toString() + LoaderUtils.DECAF_SIGNATURE;
        signatures.add(mpiSignature);
        // Load specific method constraints if present
        MethodResourceDescription implConstraints = defaultConstraints;
        if (decafAnnot.constraints() != null) {
            implConstraints = new MethodResourceDescription(decafAnnot.constraints());
            implConstraints.mergeMultiConstraints(defaultConstraints);
        }
        // Register method implementation
        Implementation impl = new DecafImplementation(dfScript, dfExecutor, dfLib, workingDir, mpiRunner, methodId, implId, implConstraints);
        ++implId;
        implementations.add(impl);
    }
    /*
         * OMPSS
         */
    for (OmpSs ompssAnnot : m.getAnnotationsByType(OmpSs.class)) {
        LOGGER.debug("   * Processing @OmpSs annotation");
        String binary = EnvironmentLoader.loadFromEnvironment(ompssAnnot.binary());
        String workingDir = EnvironmentLoader.loadFromEnvironment(ompssAnnot.workingDir());
        if (binary == null || binary.isEmpty()) {
            ErrorManager.error("Empty binary annotation for method " + m.getName());
        }
        String ompssSignature = calleeMethodSignature.toString() + LoaderUtils.OMPSS_SIGNATURE;
        signatures.add(ompssSignature);
        // Load specific method constraints if present
        MethodResourceDescription implConstraints = defaultConstraints;
        if (ompssAnnot.constraints() != null) {
            implConstraints = new MethodResourceDescription(ompssAnnot.constraints());
            implConstraints.mergeMultiConstraints(defaultConstraints);
        }
        // Register method implementation
        Implementation impl = new OmpSsImplementation(binary, workingDir, methodId, implId, implConstraints);
        ++implId;
        implementations.add(impl);
    }
    /*
         * OPENCL
         */
    for (OpenCL openclAnnot : m.getAnnotationsByType(OpenCL.class)) {
        LOGGER.debug("   * Processing @OpenCL annotation");
        String kernel = EnvironmentLoader.loadFromEnvironment(openclAnnot.kernel());
        String workingDir = EnvironmentLoader.loadFromEnvironment(openclAnnot.workingDir());
        if (kernel == null || kernel.isEmpty()) {
            ErrorManager.error("Empty kernel annotation for method " + m.getName());
        }
        String openclSignature = calleeMethodSignature.toString() + LoaderUtils.OPENCL_SIGNATURE;
        signatures.add(openclSignature);
        // Load specific method constraints if present
        MethodResourceDescription implConstraints = defaultConstraints;
        if (openclAnnot.constraints() != null) {
            implConstraints = new MethodResourceDescription(openclAnnot.constraints());
            implConstraints.mergeMultiConstraints(defaultConstraints);
        }
        // Register method implementation
        Implementation impl = new OpenCLImplementation(kernel, workingDir, methodId, implId, implConstraints);
        ++implId;
        implementations.add(impl);
    }
    /*
         * BINARY
         */
    for (Binary binaryAnnot : m.getAnnotationsByType(Binary.class)) {
        LOGGER.debug("   * Processing @Binary annotation");
        String binary = EnvironmentLoader.loadFromEnvironment(binaryAnnot.binary());
        String workingDir = EnvironmentLoader.loadFromEnvironment(binaryAnnot.workingDir());
        if (binary == null || binary.isEmpty()) {
            ErrorManager.error("Empty binary annotation for method " + m.getName());
        }
        String binarySignature = calleeMethodSignature.toString() + LoaderUtils.BINARY_SIGNATURE;
        signatures.add(binarySignature);
        // Load specific method constraints if present
        MethodResourceDescription implConstraints = defaultConstraints;
        if (binaryAnnot.constraints() != null) {
            implConstraints = new MethodResourceDescription(binaryAnnot.constraints());
            implConstraints.mergeMultiConstraints(defaultConstraints);
        }
        // Register method implementation
        Implementation impl = new BinaryImplementation(binary, workingDir, methodId, implId, implConstraints);
        ++implId;
        implementations.add(impl);
    }
}
Also used : MethodImplementation(es.bsc.compss.types.implementations.MethodImplementation) MPIImplementation(es.bsc.compss.types.implementations.MPIImplementation) MPI(es.bsc.compss.types.annotations.task.MPI) Service(es.bsc.compss.types.annotations.task.Service) Decaf(es.bsc.compss.types.annotations.task.Decaf) Method(es.bsc.compss.types.annotations.task.Method) OpenCLImplementation(es.bsc.compss.types.implementations.OpenCLImplementation) Implementation(es.bsc.compss.types.implementations.Implementation) ServiceImplementation(es.bsc.compss.types.implementations.ServiceImplementation) MethodImplementation(es.bsc.compss.types.implementations.MethodImplementation) BinaryImplementation(es.bsc.compss.types.implementations.BinaryImplementation) MPIImplementation(es.bsc.compss.types.implementations.MPIImplementation) OmpSsImplementation(es.bsc.compss.types.implementations.OmpSsImplementation) DecafImplementation(es.bsc.compss.types.implementations.DecafImplementation) OpenCLImplementation(es.bsc.compss.types.implementations.OpenCLImplementation) ServiceImplementation(es.bsc.compss.types.implementations.ServiceImplementation) DecafImplementation(es.bsc.compss.types.implementations.DecafImplementation) MethodResourceDescription(es.bsc.compss.types.resources.MethodResourceDescription) OpenCL(es.bsc.compss.types.annotations.task.OpenCL) Binary(es.bsc.compss.types.annotations.task.Binary) BinaryImplementation(es.bsc.compss.types.implementations.BinaryImplementation) OmpSs(es.bsc.compss.types.annotations.task.OmpSs) MultiOmpSs(es.bsc.compss.types.annotations.task.repeatables.MultiOmpSs) OmpSsImplementation(es.bsc.compss.types.implementations.OmpSsImplementation)

Aggregations

Method (es.bsc.compss.types.annotations.task.Method)2 Constraints (es.bsc.compss.types.annotations.Constraints)1 Binary (es.bsc.compss.types.annotations.task.Binary)1 Decaf (es.bsc.compss.types.annotations.task.Decaf)1 MPI (es.bsc.compss.types.annotations.task.MPI)1 OmpSs (es.bsc.compss.types.annotations.task.OmpSs)1 OpenCL (es.bsc.compss.types.annotations.task.OpenCL)1 Service (es.bsc.compss.types.annotations.task.Service)1 MultiOmpSs (es.bsc.compss.types.annotations.task.repeatables.MultiOmpSs)1 BinaryImplementation (es.bsc.compss.types.implementations.BinaryImplementation)1 DecafImplementation (es.bsc.compss.types.implementations.DecafImplementation)1 Implementation (es.bsc.compss.types.implementations.Implementation)1 MPIImplementation (es.bsc.compss.types.implementations.MPIImplementation)1 MethodImplementation (es.bsc.compss.types.implementations.MethodImplementation)1 OmpSsImplementation (es.bsc.compss.types.implementations.OmpSsImplementation)1 OpenCLImplementation (es.bsc.compss.types.implementations.OpenCLImplementation)1 ServiceImplementation (es.bsc.compss.types.implementations.ServiceImplementation)1 MethodResourceDescription (es.bsc.compss.types.resources.MethodResourceDescription)1