Community
cancel
Showing results for 
Search instead for 
Did you mean: 
SANJAY_S_
Beginner
288 Views

[RESOLVED] Unable to pass C struct to OCALL

Jump to solution

I need to pass a structure to an OCALL from within the enclave. The structure is defined in "../TorchHost/gpu_glue_types.h" w.r.t. to the .edl file,

// gpu_glue_types.h

struct gpu_iMat {
        int *ptr;
        int rows;
        int cols;
};

// typedef struct gpu_iMat gpu_iMat;

And the .edl file,

enclave {
	include "../TorchEnclave/TH/TH.h"
    trusted {		
        /* define ECALLs here. */
		/* public void Train([user_check] NeuralNetConfig* config); */
    	//	public void entry(int test);
	//	public void dot_product([user_check]THFloatTensor *xx, [user_check] THFloatTensor *yy);
		public void test_conv([user_check] THFloatTensor *data,[user_check] THFloatTensor *label);
	};

    untrusted {
	include "../TorchHost/gpu_glue_types.h"

        /* define OCALLs here. */
		void ocall_print_double(double test);
		/* void EmitRoundError(size_t round, double error); */
		 void ocall_error([in, string] const char* msg);
		/* void start_time();*/
		/* void end_time([in, string] const char* msg);*/
                void ocall_warn_INT_BOUNDS(float value, int iter, _Bool dir, [in, string] char* func_name, int line_no);
                /* void ocall_print_enclave_app_ptrs([in, string] const char *ptr, [user_check] void *enc_ptr);*/

		void gpu_hello();
		struct gpu_iMat alloc_gpu_iMat(int rows, int cols);
		//void free_gpu_iMat(struct gpu_iMat imat);
		void gpu_print_iMat(const struct gpu_iMat imat);
    };
};

The edger8r glue code generator fails the build with the error,

error: ../TorchEnclave/TorchEnclave.edl:13:48: unexpected token: imat

Makefile:201: recipe for target 'TorchHost/TorchEnclave_u.c' failed
make: *** [TorchHost/TorchEnclave_u.c] Error 255

removing imat pushes the error to the ')' following imat,

error: ../TorchEnclave/TorchEnclave.edl:13:44: unexpected token: )

Makefile:201: recipe for target 'TorchHost/TorchEnclave_u.c' failed
make: *** [TorchHost/TorchEnclave_u.c] Error 255

The glue code for alloc_gpu_imat is successfully generated, which returns a C struct of the type gpu_iMat. But, edger8r fails to generate code for either free_gpu_iMat or gpu_print_iMat.The declaration of the structure follows https://software.intel.com/en-us/node/708973.

Am I missing something else ?

Although this could be implemented using pointers and a shallow copy, I would appreciate any help to make it work with passing structures by copy.

Thanks in advance !

0 Kudos
1 Solution
Ishai_N_Intel
Employee
288 Views

Removing the 'const' (which is not really needed since it's a copy, so it's only a 'documentation' here) and also placing the 'include' outside the 'untrusted' block seems to solve this issue.

View solution in original post

2 Replies
Ishai_N_Intel
Employee
289 Views

Removing the 'const' (which is not really needed since it's a copy, so it's only a 'documentation' here) and also placing the 'include' outside the 'untrusted' block seems to solve this issue.

View solution in original post

SANJAY_S_
Beginner
288 Views

Alright.

Reply