use of es.bsc.compss.types.annotations.task.OpenCL in project compss by bsc-wdc.
the class ITAppEditor method replaceTaskMethodCall.
/**
* Replaces calls to local methods by executeTask
*
* @param methodName
* @param className
* @param declaredMethod
* @param calledMethod
* @return
*/
private String replaceTaskMethodCall(String methodName, String className, Method declaredMethod, CtMethod calledMethod) throws CannotCompileException {
if (DEBUG) {
LOGGER.debug("Found call to remote method " + methodName);
}
Class<?> retType = declaredMethod.getReturnType();
boolean isVoid = retType.equals(void.class);
boolean isStatic = Modifier.isStatic(calledMethod.getModifiers());
Class<?>[] paramTypes = declaredMethod.getParameterTypes();
int numParams = paramTypes.length;
if (!isStatic) {
numParams++;
}
if (!isVoid) {
numParams++;
}
// Build the executeTask call string
StringBuilder executeTask = new StringBuilder();
executeTask.append(itApiVar).append(EXECUTE_TASK);
executeTask.append(itAppIdVar).append(',');
// Common values
boolean isPrioritary = Boolean.parseBoolean(Constants.IS_NOT_PRIORITARY_TASK);
int numNodes = Constants.SINGLE_NODE;
// Scheduler hints values
boolean isReplicated = Boolean.parseBoolean(Constants.IS_NOT_REPLICATED_TASK);
boolean isDistributed = Boolean.parseBoolean(Constants.IS_NOT_DISTRIBUTED_TASK);
if (declaredMethod.isAnnotationPresent(SchedulerHints.class)) {
SchedulerHints schedAnnot = declaredMethod.getAnnotation(SchedulerHints.class);
isReplicated = Boolean.parseBoolean(EnvironmentLoader.loadFromEnvironment(schedAnnot.isReplicated()));
isDistributed = Boolean.parseBoolean(EnvironmentLoader.loadFromEnvironment(schedAnnot.isDistributed()));
}
// Specific implementation values
boolean isMethod = !(declaredMethod.isAnnotationPresent(Service.class) || declaredMethod.isAnnotationPresent(Services.class));
if (isMethod) {
// Method: native, MPI, OMPSs, Binary, OpenCL, etc.
if (declaredMethod.isAnnotationPresent(es.bsc.compss.types.annotations.task.Method.class)) {
es.bsc.compss.types.annotations.task.Method methodAnnot = declaredMethod.getAnnotation(es.bsc.compss.types.annotations.task.Method.class);
isPrioritary = Boolean.parseBoolean(EnvironmentLoader.loadFromEnvironment(methodAnnot.priority()));
} else if (declaredMethod.isAnnotationPresent(MPI.class)) {
MPI mpiAnnot = declaredMethod.getAnnotation(MPI.class);
isPrioritary = Boolean.parseBoolean(EnvironmentLoader.loadFromEnvironment(mpiAnnot.priority()));
// Parse computingNodes from environment if needed
String numNodesSTR = EnvironmentLoader.loadFromEnvironment(mpiAnnot.computingNodes());
numNodes = (numNodesSTR != null && !numNodesSTR.isEmpty() && !numNodesSTR.equals(Constants.UNASSIGNED)) ? Integer.valueOf(numNodesSTR) : Constants.SINGLE_NODE;
} else if (declaredMethod.isAnnotationPresent(Decaf.class)) {
Decaf decafAnnot = declaredMethod.getAnnotation(Decaf.class);
isPrioritary = Boolean.parseBoolean(EnvironmentLoader.loadFromEnvironment(decafAnnot.priority()));
// Parse computingNodes from environment if needed
String numNodesSTR = EnvironmentLoader.loadFromEnvironment(decafAnnot.computingNodes());
numNodes = (numNodesSTR != null && !numNodesSTR.isEmpty() && !numNodesSTR.equals(Constants.UNASSIGNED)) ? Integer.valueOf(numNodesSTR) : Constants.SINGLE_NODE;
} else if (declaredMethod.isAnnotationPresent(OmpSs.class)) {
OmpSs ompssAnnot = declaredMethod.getAnnotation(OmpSs.class);
isPrioritary = Boolean.parseBoolean(EnvironmentLoader.loadFromEnvironment(ompssAnnot.priority()));
} else if (declaredMethod.isAnnotationPresent(OpenCL.class)) {
OpenCL openCLAnnot = declaredMethod.getAnnotation(OpenCL.class);
isPrioritary = Boolean.parseBoolean(EnvironmentLoader.loadFromEnvironment(openCLAnnot.priority()));
} else if (declaredMethod.isAnnotationPresent(Binary.class)) {
Binary binaryAnnot = declaredMethod.getAnnotation(Binary.class);
isPrioritary = Boolean.parseBoolean(EnvironmentLoader.loadFromEnvironment(binaryAnnot.priority()));
}
executeTask.append("\"").append(className).append("\"").append(',');
executeTask.append("\"").append(methodName).append("\"").append(',');
} else {
// Service
Service serviceAnnot = declaredMethod.getAnnotation(Service.class);
executeTask.append("\"").append(serviceAnnot.namespace()).append("\"").append(',');
executeTask.append("\"").append(serviceAnnot.name()).append("\"").append(',');
executeTask.append("\"").append(serviceAnnot.port()).append("\"").append(',');
executeTask.append("\"").append(methodName).append("\"").append(',');
}
// Add scheduler common values
executeTask.append(isPrioritary).append(',');
executeTask.append(numNodes).append(",");
executeTask.append(isReplicated).append(',');
executeTask.append(isDistributed).append(',');
// Add if call has target object or not
executeTask.append(!isStatic).append(',');
// Add parameters
executeTask.append(numParams);
if (numParams == 0) {
executeTask.append(",null);");
} else {
Annotation[][] paramAnnot = declaredMethod.getParameterAnnotations();
CallInformation callInformation = processParameters(declaredMethod, paramAnnot, paramTypes, isVoid, isStatic, isMethod, numParams, retType);
executeTask.append(callInformation.getToAppend());
executeTask.insert(0, callInformation.getToPrepend());
}
return executeTask.toString();
}
use of es.bsc.compss.types.annotations.task.OpenCL 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);
}
}
Aggregations